All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 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: // equality
54  // ========================================================================
58  bool operator == ( const StringKey& o ) const
59  { return m_hash == o.m_hash && m_str == o.m_str ; }
63  bool operator == ( const std::string& o ) const { return m_str == o ; }
64  // ========================================================================
65  public: // non-equality
66  // ========================================================================
68  bool operator!=( const StringKey& o ) const { return !(*this==o) ; }
70  bool operator!=( const std::string& o ) const { return !(*this==o) ; }
71  // ========================================================================
72  public: // ordering
73  // ========================================================================
94  bool operator < ( const StringKey& o ) const
95  { return m_hash == o.m_hash ? m_str < o.m_str : m_hash < o.m_hash ; }
97  bool operator > ( const StringKey& o ) const { return o < *this ; }
99  bool operator <=( const StringKey& o ) const { return !(*this > o ) ; }
101  bool operator >=( const StringKey& o ) const { return !(*this < o ) ; }
102  // ========================================================================
103  public: // few helper methods for indirect usage, mainly for Python
104  // ========================================================================
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==
149  ( const Gaudi::StringKey& key1 ,
150  const char (&key2)[N] )
151  {
152  return
153  key1.str().size() == N &&
154  std::equal ( key2 , key2 + N , key1.str().begin() ) ;
155  }
156  // ==========================================================================
161  template <unsigned int N>
162  inline bool operator!=
163  ( const Gaudi::StringKey& key1 ,
164  const char (&key2)[N] )
165  { return ! ( key1 == key2 ) ; }
166  // ==========================================================================
171  inline bool operator==
172  ( const std::string& key1 ,
173  const Gaudi::StringKey& key2 )
174  { return key2 == key1 ; }
175  // ==========================================================================
180  template <unsigned int N>
181  inline bool operator==
182  ( const char (&key1 )[N] ,
183  const Gaudi::StringKey& key2 )
184  { return key2 == key1 ; }
185  // ==========================================================================
190  inline bool operator!=
191  ( const std::string& key1 ,
192  const Gaudi::StringKey& key2 )
193  { return key2 != key1 ; }
194  // ==========================================================================
199  template <unsigned int N>
200  inline bool operator!=
201  ( const char (&key1)[N] ,
202  const Gaudi::StringKey& key2 ) { return key2 != key1 ; }
203  // ==========================================================================
214  inline std::size_t hash_value ( const Gaudi::StringKey& key )
215  { return key.__hash__ () ; }
216  // ==========================================================================
217 } // end of namespace Gaudi
218 // ============================================================================
219 // Streaming value -> string
220 // ============================================================================
221 namespace Gaudi
222 {
223  // ==========================================================================
224  namespace Utils
225  {
226  // ========================================================================
237  GAUDI_API std::ostream& toStream
238  ( const Gaudi::StringKey& key ,
239  std::ostream& s ) ;
240  // ========================================================================
241  } // end of namespace Gaudi::Utils
242  // ==========================================================================
248  inline std::ostream& operator<<
249  ( std::ostream& o ,
250  const Gaudi::StringKey& key ) { return o << key.str() ; }
251  // ==========================================================================
252 } // end of namespace Gaudi
253 // ============================================================================
254 // Parsing : string -> value
255 // ============================================================================
256 namespace Gaudi
257 {
258  // ==========================================================================
259  namespace Parsers
260  {
261  // ========================================================================
272  ( Gaudi::StringKey& result ,
273  const std::string& input ) ;
274  // ========================================================================
285  ( std::vector<Gaudi::StringKey>& result ,
286  const std::string& input ) ;
287  // ========================================================================
288  } // end of namespace Gaudi::Parsers
289  // ==========================================================================
290 } // end of namespace Gaudi
291 // ============================================================================
292 // The END
293 // ============================================================================
294 #endif // GAUDIKERNEL_STRINGKEY_H
295 // ============================================================================
bool operator==(const Gaudi::StringKey &key1, const char(&key2)[N])
equality operator with C-arrays
Definition: StringKey.h:149
bool operator!() const
empty key?
Definition: StringKey.h:51
bool operator<=(const Gaudi::Time &t1, const Gaudi::Time &t2)
Definition: Time.icpp:237
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:367
bool operator>=(const Gaudi::Time &t1, const Gaudi::Time &t2)
Definition: Time.icpp:245
StatusCode parse(GaudiUtils::HashMap< K, V > &result, const std::string &input)
Basic parser for the types of HashMap used in DODBasicMapper.
std::size_t m_hash
the hash:
Definition: StringKey.h:139
The helper class to represent the efficient "key" for access.
Definition: StringKey.h:35
bool empty() const
empty key?
Definition: StringKey.h:49
bool operator!=(const std::string &o) const
non-equality string
Definition: StringKey.h:70
std::size_t hash_value(const Gaudi::StringKey &key)
hash-function: heeded for boost::hash
Definition: StringKey.h:214
int N
Definition: IOTest.py:90
std::ostream & toStream(ITERATOR first, ITERATOR last, std::ostream &s, const std::string &open, const std::string &close, const std::string &delim)
the helper function to print the sequence
Definition: ToStream.h:341
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:30
bool operator>(const Gaudi::Time &t1, const Gaudi::Time &t2)
Definition: Time.icpp:241
bool operator!=(const StringKey &o) const
non equality Key
Definition: StringKey.h:68
string s
Definition: gaudirun.py:210
This is a number of static methods for bootstrapping the Gaudi framework.
Definition: Bootstrap.h:15
bool operator<(const Gaudi::Time &t1, const Gaudi::Time &t2)
Definition: Time.icpp:233
std::size_t __hash__() const
the actual access to the hash
Definition: StringKey.h:114
#define GAUDI_API
Definition: Kernel.h:108
const std::string & str() const
the actual string
Definition: StringKey.h:45