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( key ) ) // NB! hashing here!!!
28 {}
29 // ============================================================================
30 // the representation of the object
31 // ============================================================================
32 std::string Gaudi::StringKey::toString() const
33 { return Gaudi::Utils::toString ( m_str ) ; }
34 // ============================================================================
35 // the representation of the object
36 // ============================================================================
37 std::string Gaudi::StringKey:: __str__ () const { return toString() ; }
38 // ============================================================================
39 // the representation of the object
40 // ============================================================================
41 std::string Gaudi::StringKey:: __repr__() const { return toString() ; }
42 // ============================================================================
43 // equality operator for python
44 bool Gaudi::StringKey::__eq__ ( const Gaudi::StringKey& right ) const
45 { return this == &right || *this == right ; }
46 // ============================================================================
47 // equality operators for python
48 // ============================================================================
49 bool Gaudi::StringKey::__eq__ ( const std::string& right ) const
50 { return *this == right ; }
51 // ============================================================================
52 // non-equality operator for python
53 // ============================================================================
54 bool Gaudi::StringKey::__neq__ ( const Gaudi::StringKey& right ) const
55 { return this != &right && *this != right ; }
56 // ============================================================================
57 // non-equality operator for python
58 // ============================================================================
59 bool Gaudi::StringKey::__neq__ ( const std::string& right ) const
60 { return *this != right ; }
61 // ============================================================================
62 /* send the object to stream (needed to use it as property)
63  * @see Gaudi::Utils::toString
64  * @see Gaudi::Utils::toStream
65  */
66 // ============================================================================
67 std::ostream& Gaudi::Utils::toStream
68 ( const Gaudi::StringKey& key , std::ostream& s )
69 { return Gaudi::Utils::toStream ( key.str() , s ) ; }
70 // ============================================================================
71 /* parse the key from the string
72  * @attention: this function is needed to use it as property
73  * @param result (OUTPUT) the parsing result
74  * @param input the input string
75  * @return status code
76  */
77 // ============================================================================
79 ( Gaudi::StringKey& result ,
80  const std::string& input )
81 {
82  std::string _result ;
83  StatusCode sc = parse ( _result , input ) ;
84  result = Gaudi::StringKey ( _result ) ;
85  return sc ;
86 }
87 // ============================================================================
88 /* parse the vector of keys from the string
89  * @see Gaudi::Parsers
90  * @see Gaudi::Parsers::parse
91  * @see Gaudi::StringKey
92  * @attention: this function is needed to use it as property
93  * @param result (OUTPUT) the parsing result
94  * @param input the input string
95  * @return status code
96  */
97 // ============================================================================
99 ( std::vector<Gaudi::StringKey>& result ,
100  const std::string& input )
101 {
102  result.clear() ;
103  typedef std::vector<std::string> Strings ;
104  Strings _result ;
105  StatusCode sc = parse ( _result , input ) ;
106  if ( sc.isFailure() ) { return sc ; } // RETURN
107  result.reserve ( _result.size() ) ;
108  //
109  std::copy ( _result.begin() ,
110  _result.end () , std::back_inserter ( result ) ) ;
111  //
112  return StatusCode::SUCCESS ;
113 }
114 
115 
116 
117 
118 // ============================================================================
119 // The END
120 // ============================================================================
121 
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: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:41
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:72
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
std::size_t hash_value(const Gaudi::StringKey &key)
hash-function: heeded for boost::hash
Definition: StringKey.h:214
StringKey(const std::string &key="")
constructor from the string, perform hashing
Definition: StringKey.cpp:25
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:54
const std::string & str() const
the actual string
Definition: StringKey.h:45
std::string toString() const
string representation (for properties)
Definition: StringKey.cpp:32