|
Gaudi Framework, version v23r2 |
| Home | Generated: Thu Jun 28 2012 |
00001 // $Id: $ 00002 // ============================================================================ 00003 #ifndef GAUDIKERNEL_STRINGKEY_H 00004 #define GAUDIKERNEL_STRINGKEY_H 1 00005 // ============================================================================ 00006 // Include files 00007 // ============================================================================ 00008 // STD & STL 00009 // ============================================================================ 00010 #include <iosfwd> 00011 #include <string> 00012 #include <functional> 00013 #include <algorithm> 00014 // ============================================================================ 00015 // GaudiKernel 00016 // ============================================================================ 00017 #include "GaudiKernel/Kernel.h" 00018 // ============================================================================ 00019 namespace Gaudi 00020 { 00021 // ========================================================================== 00035 class GAUDI_API StringKey 00036 { 00037 public: 00038 // ======================================================================== 00040 StringKey ( const std::string& key = "" ) ; // constructor, perform hashing 00041 // ======================================================================== 00042 public: 00043 // ======================================================================== 00045 const std::string& str() const { return m_str ; } 00047 operator const std::string&() const { return str() ; } 00049 bool empty () const { return m_str.empty() ; } 00051 bool operator!() const { return empty() ; } 00052 // ======================================================================== 00053 public: // equality 00054 // ======================================================================== 00058 bool operator == ( const StringKey& o ) const 00059 { return m_hash == o.m_hash && m_str == o.m_str ; } 00063 bool operator == ( const std::string& o ) const { return m_str == o ; } 00064 // ======================================================================== 00065 public: // non-equality 00066 // ======================================================================== 00068 bool operator!=( const StringKey& o ) const { return !(*this==o) ; } 00070 bool operator!=( const std::string& o ) const { return !(*this==o) ; } 00071 // ======================================================================== 00072 public: // ordering 00073 // ======================================================================== 00094 bool operator < ( const StringKey& o ) const 00095 { return m_hash == o.m_hash ? m_str < o.m_str : m_hash < o.m_hash ; } 00097 bool operator > ( const StringKey& o ) const { return o < *this ; } 00099 bool operator <=( const StringKey& o ) const { return !(*this > o ) ; } 00101 bool operator >=( const StringKey& o ) const { return !(*this < o ) ; } 00102 // ======================================================================== 00103 public: // few helper methods for indirect usage, mainly for Python 00104 // ======================================================================== 00114 std::size_t __hash__ () const { return m_hash ; } 00115 // ======================================================================== 00117 std::string __str__ () const ; // the representation of the object 00119 std::string __repr__ () const ; // the representation of the object 00121 bool __eq__ ( const StringKey& right ) const ; 00123 bool __eq__ ( const std::string& right ) const ; 00125 bool __neq__ ( const StringKey& right ) const ; 00127 bool __neq__ ( const std::string& right ) const ; 00128 // ======================================================================== 00129 public: 00130 // ======================================================================== 00132 std::string toString () const ; // string representation (for properties) 00133 // ======================================================================== 00134 private: 00135 // ======================================================================== 00137 std::string m_str ; // the actual string 00139 std::size_t m_hash ; // the hash 00140 // ======================================================================== 00141 }; 00142 // ========================================================================== 00147 template <unsigned int N> 00148 inline bool operator== 00149 ( const Gaudi::StringKey& key1 , 00150 const char (&key2)[N] ) 00151 { 00152 return 00153 key1.str().size() == N && 00154 std::equal ( key2 , key2 + N , key1.str().begin() ) ; 00155 } 00156 // ========================================================================== 00161 template <unsigned int N> 00162 inline bool operator!= 00163 ( const Gaudi::StringKey& key1 , 00164 const char (&key2)[N] ) 00165 { return ! ( key1 == key2 ) ; } 00166 // ========================================================================== 00171 inline bool operator== 00172 ( const std::string& key1 , 00173 const Gaudi::StringKey& key2 ) 00174 { return key2 == key1 ; } 00175 // ========================================================================== 00180 template <unsigned int N> 00181 inline bool operator== 00182 ( const char (&key1 )[N] , 00183 const Gaudi::StringKey& key2 ) 00184 { return key2 == key1 ; } 00185 // ========================================================================== 00190 inline bool operator!= 00191 ( const std::string& key1 , 00192 const Gaudi::StringKey& key2 ) 00193 { return key2 != key1 ; } 00194 // ========================================================================== 00199 template <unsigned int N> 00200 inline bool operator!= 00201 ( const char (&key1)[N] , 00202 const Gaudi::StringKey& key2 ) { return key2 != key1 ; } 00203 // ========================================================================== 00214 inline std::size_t hash_value ( const Gaudi::StringKey& key ) 00215 { return key.__hash__ () ; } 00216 // ========================================================================== 00217 } // end of namespace Gaudi 00218 // ============================================================================ 00219 // Streaming value -> string 00220 // ============================================================================ 00221 namespace Gaudi 00222 { 00223 // ========================================================================== 00224 namespace Utils 00225 { 00226 // ======================================================================== 00237 GAUDI_API std::ostream& toStream 00238 ( const Gaudi::StringKey& key , 00239 std::ostream& s ) ; 00240 // ======================================================================== 00241 } // end of namespace Gaudi::Utils 00242 // ========================================================================== 00248 inline std::ostream& operator<< 00249 ( std::ostream& o , 00250 const Gaudi::StringKey& key ) { return o << key.str() ; } 00251 // ========================================================================== 00252 } // end of namespace Gaudi 00253 // ============================================================================ 00254 // Parsing : string -> value 00255 // ============================================================================ 00256 namespace Gaudi 00257 { 00258 // ========================================================================== 00259 namespace Parsers 00260 { 00261 // ======================================================================== 00271 GAUDI_API StatusCode parse 00272 ( Gaudi::StringKey& result , 00273 const std::string& input ) ; 00274 // ======================================================================== 00284 GAUDI_API StatusCode parse 00285 ( std::vector<Gaudi::StringKey>& result , 00286 const std::string& input ) ; 00287 // ======================================================================== 00288 } // end of namespace Gaudi::Parsers 00289 // ========================================================================== 00290 } // end of namespace Gaudi 00291 // ============================================================================ 00292 // The END 00293 // ============================================================================ 00294 #endif // GAUDIKERNEL_STRINGKEY_H 00295 // ============================================================================