The Gaudi Framework  v30r3 (a5ef0a68)
StringKey.cpp
Go to the documentation of this file.
1 // ============================================================================
2 // Include files
3 // ============================================================================
4 // GaudiKernel
5 // ============================================================================
7 #include "GaudiKernel/Parsers.h"
8 #include "GaudiKernel/ToStream.h"
9 // ============================================================================
16 // ============================================================================
17 // constructor from the string: perform hashing
18 // ============================================================================
20  : m_str( std::move( key ) ), m_hash( std::hash<std::string>()( m_str ) ) // NB! hashing here!!!
21 {
22 }
23 // ============================================================================
24 // constructor from the string: perform hashing
25 // ============================================================================
26 Gaudi::StringKey::StringKey( const char* key )
27  : m_str( key ), m_hash( std::hash<std::string>()( m_str ) ) // NB! hashing here!!!
28 {
29 }
30 // ============================================================================
31 // the representation of the object
32 // ============================================================================
34 // ============================================================================
35 // the representation of the object
36 // ============================================================================
38 // ============================================================================
39 // the representation of the object
40 // ============================================================================
42 // ============================================================================
43 // equality operator for python
44 bool Gaudi::StringKey::__eq__( const Gaudi::StringKey& right ) const { return this == &right || *this == right; }
45 // ============================================================================
46 // equality operators for python
47 // ============================================================================
48 bool Gaudi::StringKey::__eq__( const std::string& right ) const { return *this == right; }
49 // ============================================================================
50 // non-equality operator for python
51 // ============================================================================
52 bool Gaudi::StringKey::__neq__( const Gaudi::StringKey& right ) const { return this != &right && *this != right; }
53 // ============================================================================
54 // non-equality operator for python
55 // ============================================================================
56 bool Gaudi::StringKey::__neq__( const std::string& right ) const { return *this != right; }
57 // ============================================================================
58 /* send the object to stream (needed to use it as property)
59  * @see Gaudi::Utils::toString
60  * @see Gaudi::Utils::toStream
61  */
62 // ============================================================================
64 {
65  return Gaudi::Utils::toStream( key.str(), s );
66 }
67 // ============================================================================
68 /* parse the key from the string
69  * @attention: this function is needed to use it as property
70  * @param result (OUTPUT) the parsing result
71  * @param input the input string
72  * @return status code
73  */
74 // ============================================================================
76 {
77  std::string _result;
78  StatusCode sc = parse( _result, input );
79  result = Gaudi::StringKey( _result );
80  return sc;
81 }
82 // ============================================================================
83 /* parse the vector of keys from the string
84  * @see Gaudi::Parsers
85  * @see Gaudi::Parsers::parse
86  * @see Gaudi::StringKey
87  * @attention: this function is needed to use it as property
88  * @param result (OUTPUT) the parsing result
89  * @param input the input string
90  * @return status code
91  */
92 // ============================================================================
94 {
95  result.clear();
96  typedef std::vector<std::string> Strings;
97  Strings _result;
98  StatusCode sc = parse( _result, input );
99  if ( sc.isFailure() ) {
100  return sc;
101  } // RETURN
102  result.reserve( _result.size() );
103  //
104  std::copy( _result.begin(), _result.end(), std::back_inserter( result ) );
105  //
106  return StatusCode::SUCCESS;
107 }
108 
109 // ============================================================================
110 // The END
111 // ============================================================================
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:303
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:44
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:356
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:41
bool isFailure() const
Definition: StatusCode.h:139
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:37
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:51
T clear(T...args)
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
StatusCode parse(DataObjID &dest, const std::string &src)
Definition: DataObjID.cpp:52
T back_inserter(T...args)
string s
Definition: gaudirun.py:253
implementation of various functions for streaming.
bool __neq__(const StringKey &right) const
non-equality operator for python
Definition: StringKey.cpp:52
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)