All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
StringKey.cpp
Go to the documentation of this file.
1 // $Id: $
2 // ============================================================================
3 // Include files
4 // ============================================================================
5 // GaudiKernel
6 // ============================================================================
7 #include "GaudiKernel/Parsers.h"
8 #include "GaudiKernel/ToStream.h"
10 // ============================================================================
11 // Boost
12 // ============================================================================
13 #include "boost/functional/hash.hpp"
14 #include "boost/bind.hpp"
15 // ============================================================================
22 // ============================================================================
23 // constructor from the string: perform hashing
24 // ============================================================================
25 Gaudi::StringKey::StringKey ( const std::string& key )
26  : m_str ( key )
27  , m_hash ( boost::hash_value( m_str ) ) // NB! hashing here!!!
28 {}
29 // ============================================================================
30 // constructor from the string: perform hashing
31 // ============================================================================
32 Gaudi::StringKey::StringKey ( const char* key )
33  : m_str ( key )
34  , m_hash ( boost::hash_value( m_str ) ) // NB! hashing here!!!
35 {}
36 // ============================================================================
37 // the representation of the object
38 // ============================================================================
39 std::string Gaudi::StringKey::toString() const
40 { return Gaudi::Utils::toString ( m_str ) ; }
41 // ============================================================================
42 // the representation of the object
43 // ============================================================================
44 std::string Gaudi::StringKey:: __str__ () const { return toString() ; }
45 // ============================================================================
46 // the representation of the object
47 // ============================================================================
48 std::string Gaudi::StringKey:: __repr__() const { return toString() ; }
49 // ============================================================================
50 // equality operator for python
51 bool Gaudi::StringKey::__eq__ ( const Gaudi::StringKey& right ) const
52 { return this == &right || *this == right ; }
53 // ============================================================================
54 // equality operators for python
55 // ============================================================================
56 bool Gaudi::StringKey::__eq__ ( const std::string& right ) const
57 { return *this == right ; }
58 // ============================================================================
59 // non-equality operator for python
60 // ============================================================================
61 bool Gaudi::StringKey::__neq__ ( const Gaudi::StringKey& right ) const
62 { return this != &right && *this != right ; }
63 // ============================================================================
64 // non-equality operator for python
65 // ============================================================================
66 bool Gaudi::StringKey::__neq__ ( const std::string& right ) const
67 { return *this != right ; }
68 // ============================================================================
69 /* send the object to stream (needed to use it as property)
70  * @see Gaudi::Utils::toString
71  * @see Gaudi::Utils::toStream
72  */
73 // ============================================================================
74 std::ostream& Gaudi::Utils::toStream
75 ( const Gaudi::StringKey& key , std::ostream& s )
76 { return Gaudi::Utils::toStream ( key.str() , s ) ; }
77 // ============================================================================
78 /* parse the key from the string
79  * @attention: this function is needed to use it as property
80  * @param result (OUTPUT) the parsing result
81  * @param input the input string
82  * @return status code
83  */
84 // ============================================================================
86 ( Gaudi::StringKey& result ,
87  const std::string& input )
88 {
89  std::string _result ;
90  StatusCode sc = parse ( _result , input ) ;
91  result = Gaudi::StringKey ( _result ) ;
92  return sc ;
93 }
94 // ============================================================================
95 /* parse the vector of keys from the string
96  * @see Gaudi::Parsers
97  * @see Gaudi::Parsers::parse
98  * @see Gaudi::StringKey
99  * @attention: this function is needed to use it as property
100  * @param result (OUTPUT) the parsing result
101  * @param input the input string
102  * @return status code
103  */
104 // ============================================================================
106 ( std::vector<Gaudi::StringKey>& result ,
107  const std::string& input )
108 {
109  result.clear() ;
110  typedef std::vector<std::string> Strings ;
111  Strings _result ;
112  StatusCode sc = parse ( _result , input ) ;
113  if ( sc.isFailure() ) { return sc ; } // RETURN
114  result.reserve ( _result.size() ) ;
115  //
116  std::copy ( _result.begin() ,
117  _result.end () , std::back_inserter ( result ) ) ;
118  //
119  return StatusCode::SUCCESS ;
120 }
121 
122 
123 
124 
125 // ============================================================================
126 // The END
127 // ============================================================================
128 
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:51
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:367
StatusCode parse(GaudiUtils::HashMap< K, V > &result, const std::string &input)
Basic parser for the types of HashMap used in DODBasicMapper.
std::string __repr__() const
the representation of the object
Definition: StringKey.cpp:48
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:85
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:44
StringKey(const char *key="")
constructor from plain C-string, perform hashing
Definition: StringKey.cpp:32
std::size_t hash_value(const Gaudi::StringKey &key)
hash-function: heeded for boost::hash
Definition: StringKey.h:216
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
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
string s
Definition: gaudirun.py:210
implemenattiono fvarioud functions for streaming.
bool __neq__(const StringKey &right) const
non-equality operator for python
Definition: StringKey.cpp:61
const std::string & str() const
the actual string
Definition: StringKey.h:47
std::string toString() const
string representation (for properties)
Definition: StringKey.cpp:39