Gaudi Framework, version v24r2

Home   Generated: Wed Dec 4 2013
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
StringKey.h
Go to the documentation of this file.
1 // $Id: $
2 // ============================================================================
3 #ifndef GAUDIKERNEL_STRINGKEY_H
4 #define GAUDIKERNEL_STRINGKEY_H 1
5 // ============================================================================
6 // Include files
7 // ============================================================================
8 // STD & STL
9 // ============================================================================
10 #include <iosfwd>
11 #include <string>
12 #include <functional>
13 #include <algorithm>
14 // ============================================================================
15 // GaudiKernel
16 // ============================================================================
17 #include "GaudiKernel/Kernel.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  // ========================================================================
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 // ============================================================================

Generated at Wed Dec 4 2013 14:33:09 for Gaudi Framework, version v24r2 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004