The Gaudi Framework  v33r0 (d5ea422b)
StringKey.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 // ============================================================================
12 // Include files
13 // ============================================================================
14 // GaudiKernel
15 // ============================================================================
16 #include "GaudiKernel/StringKey.h"
17 #include "GaudiKernel/ToStream.h"
19 // ============================================================================
26 // ============================================================================
27 // constructor from the string: perform hashing
28 // ============================================================================
30  : m_str( std::move( key ) )
31  , m_hash( std::hash<std::string>()( m_str ) ) // NB! hashing here!!!
32 {}
33 // ============================================================================
34 // constructor from the string: perform hashing
35 // ============================================================================
36 Gaudi::StringKey::StringKey( const char* key )
37  : m_str( key )
38  , m_hash( std::hash<std::string>()( m_str ) ) // NB! hashing here!!!
39 {}
40 // ============================================================================
41 // the representation of the object
42 // ============================================================================
44 // ============================================================================
45 // the representation of the object
46 // ============================================================================
48 // ============================================================================
49 // the representation of the object
50 // ============================================================================
52 // ============================================================================
53 // equality operator for python
54 bool Gaudi::StringKey::__eq__( const Gaudi::StringKey& right ) const { return this == &right || *this == right; }
55 // ============================================================================
56 // equality operators for python
57 // ============================================================================
58 bool Gaudi::StringKey::__eq__( const std::string& right ) const { return *this == right; }
59 // ============================================================================
60 // non-equality operator for python
61 // ============================================================================
62 bool Gaudi::StringKey::__neq__( const Gaudi::StringKey& right ) const { return this != &right && *this != right; }
63 // ============================================================================
64 // non-equality operator for python
65 // ============================================================================
66 bool Gaudi::StringKey::__neq__( const std::string& right ) const { return *this != right; }
67 // ============================================================================
68 /* send the object to stream (needed to use it as property)
69  * @see Gaudi::Utils::toString
70  * @see Gaudi::Utils::toStream
71  */
72 // ============================================================================
74  return Gaudi::Utils::toStream( key.str(), s );
75 }
76 // ============================================================================
77 /* parse the key from the string
78  * @attention: this function is needed to use it as property
79  * @param result (OUTPUT) the parsing result
80  * @param input the input string
81  * @return status code
82  */
83 // ============================================================================
85  std::string _result;
86  StatusCode sc = parse( _result, input );
87  result = Gaudi::StringKey( _result );
88  return sc;
89 }
90 // ============================================================================
91 /* parse the vector of keys from the string
92  * @see Gaudi::Parsers
93  * @see Gaudi::Parsers::parse
94  * @see Gaudi::StringKey
95  * @attention: this function is needed to use it as property
96  * @param result (OUTPUT) the parsing result
97  * @param input the input string
98  * @return status code
99  */
100 // ============================================================================
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(), _result.end(), std::back_inserter( result ) );
110  //
111  return StatusCode::SUCCESS;
112 }
113 
114 // ============================================================================
115 // The END
116 // ============================================================================
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:291
const std::string & str() const
the actual string
Definition: StringKey.h:55
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:341
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
STL namespace.
StatusCode parse(GaudiUtils::HashMap< K, V > &result, const std::string &input)
Basic parser for the types of HashMap used in DODBasicMapper.
The declaration of major parsing functions used e.g for (re)implementation of new extended properties...
The helper class to represent the efficient "key" for access.
Definition: StringKey.h:44
STL class.
StringKey(const char *key="")
constructor from plain C-string, perform hashing
Definition: StringKey.cpp:36
bool __eq__(const StringKey &right) const
equality operator for python
Definition: StringKey.cpp:54
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
T clear(T... args)
std::string __str__() const
the representation of the object
Definition: StringKey.cpp:47
StatusCode parse(DataObjID &dest, const std::string &src)
Definition: DataObjID.cpp:56
std::string __repr__() const
the representation of the object
Definition: StringKey.cpp:51
T back_inserter(T... args)
string s
Definition: gaudirun.py:328
bool isFailure() const
Definition: StatusCode.h:141
implementation of various functions for streaming.
bool __neq__(const StringKey &right) const
non-equality operator for python
Definition: StringKey.cpp:62
std::string toString() const
string representation (for properties)
Definition: StringKey.cpp:43
STL class.
T reserve(T... args)