Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v28r2p1 (f1a77ff4)
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 <iosfwd>
9 #include <string>
10 #include <functional>
11 #include <algorithm>
12 #include <vector>
13 // ============================================================================
14 // GaudiKernel
15 // ============================================================================
16 #include "GaudiKernel/Kernel.h"
17 #include "GaudiKernel/StatusCode.h"
18 // ============================================================================
19 namespace Gaudi
20 {
21  // ==========================================================================
36  {
37  public:
38  // ========================================================================
40  StringKey ( const char* key = "" ) ; // constructor, perform hashing
42  StringKey ( std::string key ) ; // constructor, perform hashing
43  // ========================================================================
44  public:
45  // ========================================================================
47  const std::string& str() const { return m_str ; }
49  operator const std::string&() const { return str() ; }
51  bool empty () const { return m_str.empty() ; }
53  bool operator!() const { return empty() ; }
54  // ========================================================================
55  public: // equality
56  // ========================================================================
60  bool operator == ( const StringKey& o ) const
61  { return m_hash == o.m_hash && m_str == o.m_str ; }
65  bool operator == ( const std::string& o ) const { return m_str == o ; }
66  // ========================================================================
67  public: // non-equality
68  // ========================================================================
70  bool operator!=( const StringKey& o ) const { return !(*this==o) ; }
72  bool operator!=( const std::string& o ) const { return !(*this==o) ; }
73  // ========================================================================
74  public: // ordering
75  // ========================================================================
96  bool operator < ( const StringKey& o ) const
97  { return m_hash == o.m_hash ? m_str < o.m_str : m_hash < o.m_hash ; }
99  bool operator > ( const StringKey& o ) const { return o < *this ; }
101  bool operator <=( const StringKey& o ) const { return !(*this > o ) ; }
103  bool operator >=( const StringKey& o ) const { return !(*this < o ) ; }
104  // ========================================================================
105  public: // few helper methods for indirect usage, mainly for Python
106  // ========================================================================
116  std::size_t __hash__ () const { return m_hash ; }
117  // ========================================================================
119  std::string __str__ () const ; // the representation of the object
121  std::string __repr__ () const ; // the representation of the object
123  bool __eq__ ( const StringKey& right ) const ;
125  bool __eq__ ( const std::string& right ) const ;
127  bool __neq__ ( const StringKey& right ) const ;
129  bool __neq__ ( const std::string& right ) const ;
130  // ========================================================================
131  public:
132  // ========================================================================
134  std::string toString () const ; // string representation (for properties)
135  // ========================================================================
136  private:
137  // ========================================================================
139  std::string m_str ; // the actual string
141  std::size_t m_hash ; // the hash
142  // ========================================================================
143  };
144  // ==========================================================================
149  template <unsigned int N>
150  inline bool operator==
151  ( const Gaudi::StringKey& key1 ,
152  const char (&key2)[N] )
153  {
154  return
155  key1.str().size() == N &&
156  std::equal ( key2 , key2 + N , key1.str().begin() ) ;
157  }
158  // ==========================================================================
163  template <unsigned int N>
164  inline bool operator!=
165  ( const Gaudi::StringKey& key1 ,
166  const char (&key2)[N] )
167  { return ! ( key1 == key2 ) ; }
168  // ==========================================================================
173  inline bool operator==
174  ( const std::string& key1 ,
175  const Gaudi::StringKey& key2 )
176  { return key2 == key1 ; }
177  // ==========================================================================
182  template <unsigned int N>
183  inline bool operator==
184  ( const char (&key1 )[N] ,
185  const Gaudi::StringKey& key2 )
186  { return key2 == key1 ; }
187  // ==========================================================================
192  inline bool operator!=
193  ( const std::string& key1 ,
194  const Gaudi::StringKey& key2 )
195  { return key2 != key1 ; }
196  // ==========================================================================
201  template <unsigned int N>
202  inline bool operator!=
203  ( const char (&key1)[N] ,
204  const Gaudi::StringKey& key2 ) { return key2 != key1 ; }
205  // ==========================================================================
217  { return key.__hash__ () ; }
218  // ==========================================================================
219 } // end of namespace Gaudi
220 // interoperability with std::string and const char*
221 inline std::string operator+(const std::string& lhs, const Gaudi::StringKey& rhs) {
222  return lhs + rhs.str();
223 }
224 inline std::string operator+(const char* lhs, const Gaudi::StringKey& rhs) {
225  return lhs + rhs.str();
226 }
227 inline std::string operator+(const Gaudi::StringKey& lhs, const std::string& rhs) {
228  return lhs.str() + rhs;
229 }
230 inline std::string operator+(const Gaudi::StringKey& lhs, const char* rhs) {
231  return lhs.str() + rhs;
232 }
233 // ============================================================================
234 // Streaming value -> string
235 // ============================================================================
236 namespace Gaudi
237 {
238  // ==========================================================================
239  namespace Utils
240  {
241  // ========================================================================
253  ( const Gaudi::StringKey& key ,
254  std::ostream& s ) ;
255  // ========================================================================
256  } // end of namespace Gaudi::Utils
257  // ==========================================================================
263  inline std::ostream& operator<<
265  const Gaudi::StringKey& key ) { return o << key.str() ; }
266  // ==========================================================================
267 } // end of namespace Gaudi
268 // ============================================================================
269 // Parsing : string -> value
270 // ============================================================================
271 namespace Gaudi
272 {
273  // ==========================================================================
274  namespace Parsers
275  {
276  // ========================================================================
287  ( Gaudi::StringKey& result ,
288  const std::string& input ) ;
289  // ========================================================================
301  const std::string& input ) ;
302  // ========================================================================
303  } // end of namespace Gaudi::Parsers
304  // ==========================================================================
305 } // end of namespace Gaudi
306 // ============================================================================
307 namespace std {
311  template <>
312  struct hash<Gaudi::StringKey> {
313  inline std::size_t operator()(Gaudi::StringKey const& s) const {
314  return hash_value(s);
315  }
316  };
317 }
318 // ============================================================================
319 #endif // GAUDIKERNEL_STRINGKEY_H
320 // ============================================================================
GAUDI_API std::ostream & toStream(const Gaudi::StringKey &key, std::ostream &s)
send the object to stream (needed to use it as property)
Definition: StringKey.cpp:69
bool operator==(const T &v, const Property< TP, V, H > &p)
delegate (value == property) to property operator==
Definition: Property.h:638
bool operator!() const
empty key?
Definition: StringKey.h:53
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:367
STL namespace.
std::size_t operator()(Gaudi::StringKey const &s) const
Definition: StringKey.h:313
std::size_t m_hash
the hash:
Definition: StringKey.h:141
The helper class to represent the efficient "key" for access.
Definition: StringKey.h:35
bool operator>(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:208
bool empty() const
empty key?
Definition: StringKey.h:51
STL class.
bool operator!=(const std::string &o) const
non-equality string
Definition: StringKey.h:72
std::size_t hash_value(const Gaudi::StringKey &key)
hash-function: heeded for boost::hash
Definition: StringKey.h:216
int N
Definition: IOTest.py:90
std::string m_str
the actual string:
Definition: StringKey.h:139
GAUDI_API StatusCode parse(std::vector< Gaudi::StringKey > &result, const std::string &input)
parse the vector of keys from the string
Definition: StringKey.cpp:100
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
bool operator<(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:185
T size(T...args)
bool operator!=(const StringKey &o) const
non equality Key
Definition: StringKey.h:70
T begin(T...args)
string s
Definition: gaudirun.py:245
bool operator>=(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:217
std::size_t __hash__() const
the actual access to the hash
Definition: StringKey.h:116
#define GAUDI_API
Definition: Kernel.h:107
STL class.
T equal(T...args)
const std::string & str() const
the actual string
Definition: StringKey.h:47
Helper functions to set/get the application return code.
Definition: __init__.py:1
bool operator<=(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:214
decltype(std::declval< TP >()+std::declval< T >()) operator+(const T &v, const Property< TP, V, H > &p)
implemantation of (value + property)
Definition: Property.h:652