All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
StringKey.cpp
Go to the documentation of this file.
1 // ============================================================================
2 // Include files
3 // ============================================================================
4 // GaudiKernel
5 // ============================================================================
6 #include "GaudiKernel/Parsers.h"
7 #include "GaudiKernel/ToStream.h"
9 // ============================================================================
16 // ============================================================================
17 // constructor from the string: perform hashing
18 // ============================================================================
20  : m_str ( std::move(key) )
21  , m_hash ( std::hash<std::string>()(m_str) ) // NB! hashing here!!!
22 {}
23 // ============================================================================
24 // constructor from the string: perform hashing
25 // ============================================================================
26 Gaudi::StringKey::StringKey ( const char* key )
27  : m_str ( key )
28  , m_hash ( std::hash<std::string>()(m_str) ) // NB! hashing here!!!
29 {}
30 // ============================================================================
31 // the representation of the object
32 // ============================================================================
34 { return Gaudi::Utils::toString ( m_str ) ; }
35 // ============================================================================
36 // the representation of the object
37 // ============================================================================
39 // ============================================================================
40 // the representation of the object
41 // ============================================================================
43 // ============================================================================
44 // equality operator for python
45 bool Gaudi::StringKey::__eq__ ( const Gaudi::StringKey& right ) const
46 { return this == &right || *this == right ; }
47 // ============================================================================
48 // equality operators for python
49 // ============================================================================
50 bool Gaudi::StringKey::__eq__ ( const std::string& right ) const
51 { return *this == right ; }
52 // ============================================================================
53 // non-equality operator for python
54 // ============================================================================
55 bool Gaudi::StringKey::__neq__ ( const Gaudi::StringKey& right ) const
56 { return this != &right && *this != right ; }
57 // ============================================================================
58 // non-equality operator for python
59 // ============================================================================
60 bool Gaudi::StringKey::__neq__ ( const std::string& right ) const
61 { return *this != right ; }
62 // ============================================================================
63 /* send the object to stream (needed to use it as property)
64  * @see Gaudi::Utils::toString
65  * @see Gaudi::Utils::toStream
66  */
67 // ============================================================================
69 ( const Gaudi::StringKey& key , std::ostream& s )
70 { return Gaudi::Utils::toStream ( key.str() , s ) ; }
71 // ============================================================================
72 /* parse the key from the string
73  * @attention: this function is needed to use it as property
74  * @param result (OUTPUT) the parsing result
75  * @param input the input string
76  * @return status code
77  */
78 // ============================================================================
80 ( Gaudi::StringKey& result ,
81  const std::string& input )
82 {
83  std::string _result ;
84  StatusCode sc = parse ( _result , input ) ;
85  result = Gaudi::StringKey ( _result ) ;
86  return sc ;
87 }
88 // ============================================================================
89 /* parse the vector of keys from the string
90  * @see Gaudi::Parsers
91  * @see Gaudi::Parsers::parse
92  * @see Gaudi::StringKey
93  * @attention: this function is needed to use it as property
94  * @param result (OUTPUT) the parsing result
95  * @param input the input string
96  * @return status code
97  */
98 // ============================================================================
101  const std::string& input )
102 {
103  result.clear() ;
104  typedef std::vector<std::string> Strings ;
105  Strings _result ;
106  StatusCode sc = parse ( _result , input ) ;
107  if ( sc.isFailure() ) { return sc ; } // RETURN
108  result.reserve ( _result.size() ) ;
109  //
110  std::copy ( _result.begin() ,
111  _result.end () , std::back_inserter ( result ) ) ;
112  //
113  return StatusCode::SUCCESS ;
114 }
115 
116 
117 
118 
119 // ============================================================================
120 // The END
121 // ============================================================================
122 
T copy(T...args)
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:315
The declaration of major parsing functions used e.g for (re)implementation of new extended properties...
bool __eq__(const StringKey &right) const
equality operator for python
Definition: StringKey.cpp:45
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:367
STL namespace.
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:141
std::string __repr__() const
the representation of the object
Definition: StringKey.cpp:42
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:84
The helper class to represent the efficient "key" for access.
Definition: StringKey.h:35
std::string __str__() const
the representation of the object
Definition: StringKey.cpp:38
STL class.
StringKey(const char *key="")
constructor from plain C-string, perform hashing
Definition: StringKey.cpp:26
std::string m_str
the actual string:
Definition: StringKey.h:139
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
T clear(T...args)
T back_inserter(T...args)
string s
Definition: gaudirun.py:245
implementation of various functions for streaming.
bool __neq__(const StringKey &right) const
non-equality operator for python
Definition: StringKey.cpp:55
STL class.
const std::string & str() const
the actual string
Definition: StringKey.h:47
std::string toString() const
string representation (for properties)
Definition: StringKey.cpp:33
T reserve(T...args)