The Gaudi Framework  v33r1 (b1225454)
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 // the representation of the object
35 // ============================================================================
37 // ============================================================================
38 // the representation of the object
39 // ============================================================================
41 // ============================================================================
42 // the representation of the object
43 // ============================================================================
45 // ============================================================================
46 // equality operator for python
47 bool Gaudi::StringKey::__eq__( const Gaudi::StringKey& right ) const { return *this == right; }
48 // ============================================================================
49 // equality operators for python
50 // ============================================================================
51 bool Gaudi::StringKey::__eq__( std::string_view right ) const { return *this == right; }
52 // ============================================================================
53 // non-equality operator for python
54 // ============================================================================
55 bool Gaudi::StringKey::__neq__( const Gaudi::StringKey& right ) const { return *this != right; }
56 // ============================================================================
57 // non-equality operator for python
58 // ============================================================================
59 bool Gaudi::StringKey::__neq__( std::string_view right ) const { return *this != right; }
60 // ============================================================================
61 /* send the object to stream (needed to use it as property)
62  * @see Gaudi::Utils::toString
63  * @see Gaudi::Utils::toStream
64  */
65 // ============================================================================
67  return Gaudi::Utils::toStream( key.str(), s );
68 }
69 // ============================================================================
70 /* parse the key from the string
71  * @attention: this function is needed to use it as property
72  * @param result (OUTPUT) the parsing result
73  * @param input the input string
74  * @return status code
75  */
76 // ============================================================================
78  std::string _result;
79  StatusCode sc = parse( _result, input );
80  result = Gaudi::StringKey( _result );
81  return sc;
82 }
83 // ============================================================================
84 /* parse the vector of keys from the string
85  * @see Gaudi::Parsers
86  * @see Gaudi::Parsers::parse
87  * @see Gaudi::StringKey
88  * @attention: this function is needed to use it as property
89  * @param result (OUTPUT) the parsing result
90  * @param input the input string
91  * @return status code
92  */
93 // ============================================================================
95  result.clear();
96  typedef std::vector<std::string> Strings;
97  Strings _result;
98  StatusCode sc = parse( _result, input );
99  if ( sc.isFailure() ) { return sc; } // RETURN
100  result.reserve( _result.size() );
101  //
102  std::copy( _result.begin(), _result.end(), std::back_inserter( result ) );
103  //
104  return StatusCode::SUCCESS;
105 }
106 
107 // ============================================================================
108 // The END
109 // ============================================================================
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:56
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:100
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.h:48
bool __eq__(const StringKey &right) const
equality operator for python
Definition: StringKey.cpp:47
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:40
StatusCode parse(DataObjID &dest, const std::string &src)
Definition: DataObjID.cpp:57
std::string __repr__() const
the representation of the object
Definition: StringKey.cpp:44
T back_inserter(T... args)
string s
Definition: gaudirun.py:328
bool isFailure() const
Definition: StatusCode.h:145
implementation of various functions for streaming.
bool __neq__(const StringKey &right) const
non-equality operator for python
Definition: StringKey.cpp:55
std::string toString() const
string representation (for properties)
Definition: StringKey.cpp:36
STL class.
T reserve(T... args)