Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
StringKey.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_STRINGKEY_H
2 #define GAUDIKERNEL_STRINGKEY_H 1
3 // ============================================================================
4 // Include files
5 // ============================================================================
6 // STD & STL
7 // ============================================================================
8 #include <algorithm>
9 #include <functional>
10 #include <iosfwd>
11 #include <string>
12 #include <vector>
13 // ============================================================================
14 // GaudiKernel
15 // ============================================================================
16 #include "GaudiKernel/Kernel.h"
17 #include "GaudiKernel/StatusCode.h"
18 // ============================================================================
19 namespace Gaudi {
20  // ==========================================================================
35  public:
36  // ========================================================================
38  StringKey( const char* key = "" ); // constructor, perform hashing
40  StringKey( std::string key ); // constructor, perform hashing
41  // ========================================================================
42  public:
43  // ========================================================================
45  const std::string& str() const { return m_str; }
47  operator const std::string&() const { return str(); }
49  bool empty() const { return m_str.empty(); }
51  bool operator!() const { return empty(); }
52  // ========================================================================
53  public:
54  // ========================================================================
58  bool operator==( const StringKey& o ) const { return m_hash == o.m_hash && m_str == o.m_str; }
62  bool operator==( const std::string& o ) const { return m_str == o; }
63  // ========================================================================
64  public: // non-equality
65  // ========================================================================
67  bool operator!=( const StringKey& o ) const { return !( *this == o ); }
69  bool operator!=( const std::string& o ) const { return !( *this == o ); }
70  // ========================================================================
71  // ordering
72  // ========================================================================
73  public:
94  bool operator<( const StringKey& o ) const { return m_hash == o.m_hash ? m_str < o.m_str : m_hash < o.m_hash; }
96  bool operator>( const StringKey& o ) const { return o < *this; }
98  bool operator<=( const StringKey& o ) const { return !( *this > o ); }
100  bool operator>=( const StringKey& o ) const { return !( *this < o ); }
101  // ========================================================================
102  // few helper methods for indirect usage, mainly for Python
103  // ========================================================================
104  public:
114  std::size_t __hash__() const { return m_hash; }
115  // ========================================================================
117  std::string __str__() const; // the representation of the object
119  std::string __repr__() const; // the representation of the object
121  bool __eq__( const StringKey& right ) const;
123  bool __eq__( const std::string& right ) const;
125  bool __neq__( const StringKey& right ) const;
127  bool __neq__( const std::string& right ) const;
128  // ========================================================================
129  public:
130  // ========================================================================
132  std::string toString() const; // string representation (for properties)
133  // ========================================================================
134  private:
135  // ========================================================================
137  std::string m_str; // the actual string
139  std::size_t m_hash; // the hash
140  // ========================================================================
141  };
142  // ==========================================================================
147  template <unsigned int N>
148  inline bool operator==( const Gaudi::StringKey& key1, const char ( &key2 )[N] ) {
149  return key1.str().size() == N && std::equal( key2, key2 + N, key1.str().begin() );
150  }
151  // ==========================================================================
156  template <unsigned int N>
157  inline bool operator!=( const Gaudi::StringKey& key1, const char ( &key2 )[N] ) {
158  return !( key1 == key2 );
159  }
160  // ==========================================================================
165  inline bool operator==( const std::string& key1, const Gaudi::StringKey& key2 ) { return key2 == key1; }
166  // ==========================================================================
171  template <unsigned int N>
172  inline bool operator==( const char ( &key1 )[N], const Gaudi::StringKey& key2 ) {
173  return key2 == key1;
174  }
175  // ==========================================================================
180  inline bool operator!=( const std::string& key1, const Gaudi::StringKey& key2 ) { return key2 != key1; }
181  // ==========================================================================
186  template <unsigned int N>
187  inline bool operator!=( const char ( &key1 )[N], const Gaudi::StringKey& key2 ) {
188  return key2 != key1;
189  }
190  // ==========================================================================
201  inline std::size_t hash_value( const Gaudi::StringKey& key ) { return key.__hash__(); }
202  // ==========================================================================
203 } // end of namespace Gaudi
204 // interoperability with std::string and const char*
205 inline std::string operator+( const std::string& lhs, const Gaudi::StringKey& rhs ) { return lhs + rhs.str(); }
206 inline std::string operator+( const char* lhs, const Gaudi::StringKey& rhs ) { return lhs + rhs.str(); }
207 inline std::string operator+( const Gaudi::StringKey& lhs, const std::string& rhs ) { return lhs.str() + rhs; }
208 inline std::string operator+( const Gaudi::StringKey& lhs, const char* rhs ) { return lhs.str() + rhs; }
209 // ============================================================================
210 // Streaming value -> string
211 // ============================================================================
212 namespace Gaudi {
213  // ==========================================================================
214  namespace Utils {
215  // ========================================================================
227  // ========================================================================
228  } // namespace Utils
229  // ==========================================================================
235  inline std::ostream& operator<<( std::ostream& o, const Gaudi::StringKey& key ) { return o << key.str(); }
236  // ==========================================================================
237 } // end of namespace Gaudi
238 // ============================================================================
239 // Parsing : string -> value
240 // ============================================================================
241 namespace Gaudi {
242  // ==========================================================================
243  namespace Parsers {
244  // ========================================================================
254  GAUDI_API StatusCode parse( Gaudi::StringKey& result, const std::string& input );
255  // ========================================================================
266  // ========================================================================
267  } // namespace Parsers
268  // ==========================================================================
269 } // end of namespace Gaudi
270 // ============================================================================
271 namespace std {
275  template <>
276  struct hash<Gaudi::StringKey> {
277  inline std::size_t operator()( Gaudi::StringKey const& s ) const { return hash_value( s ); }
278  };
279 } // namespace std
280 // ============================================================================
281 #endif // GAUDIKERNEL_STRINGKEY_H
bool operator>=(const StringKey &o) const
greater or equal key
Definition: StringKey.h:100
bool operator!=(const T &v, const Property< TP, V, H > &p)
delegate (value != property) to property operator!=
Definition: Property.h:701
bool operator==(const T &v, const Property< TP, V, H > &p)
delegate (value == property) to property operator==
Definition: Property.h:695
bool operator!() const
empty key?
Definition: StringKey.h:51
bool operator<(const StringKey &o) const
less key It can be used as a key for std::map, e.g.
Definition: StringKey.h:94
bool operator<=(const StringKey &o) const
less or equal key
Definition: StringKey.h:98
STL namespace.
std::size_t operator()(Gaudi::StringKey const &s) const
Definition: StringKey.h:277
std::size_t m_hash
the hash:
Definition: StringKey.h:139
The helper class to represent the efficient "key" for access.
Definition: StringKey.h:34
bool empty() const
empty key?
Definition: StringKey.h:49
STL class.
bool operator!=(const std::string &o) const
non-equality string
Definition: StringKey.h:69
bool operator==(const std::string &o) const
equality, without hashing string rely on the native string equality
Definition: StringKey.h:62
std::size_t hash_value(const Gaudi::StringKey &key)
hash-function: heeded for boost::hash
Definition: StringKey.h:201
int N
Definition: IOTest.py:99
std::string m_str
the actual string:
Definition: StringKey.h:137
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
std::ostream & toStream(const DataObjID &d, std::ostream &os)
Definition: DataObjID.cpp:82
T size(T...args)
StatusCode parse(DataObjID &dest, const std::string &src)
Definition: DataObjID.cpp:46
bool operator!=(const StringKey &o) const
non equality Key
Definition: StringKey.h:67
T begin(T...args)
decltype(auto) operator+(const T &v, const Property< TP, V, H > &p)
implemantation of (value + property)
Definition: Property.h:707
string s
Definition: gaudirun.py:312
bool operator==(const StringKey &o) const
equality Key for efficiency reason compare the hash-values first
Definition: StringKey.h:58
bool operator>(const StringKey &o) const
greater key
Definition: StringKey.h:96
std::size_t __hash__() const
the actual access to the hash
Definition: StringKey.h:114
#define GAUDI_API
Definition: Kernel.h:71
STL class.
T equal(T...args)
const std::string & str() const
the actual string
Definition: StringKey.h:45
Helper functions to set/get the application return code.
Definition: __init__.py:1
std::string toString(const Type &)
std::ostream & operator<<(std::ostream &o, const Gaudi::StringKey &key)
printout of the object reply on the native printout for the string
Definition: StringKey.h:235