| The Gaudi Framework v32r1 (f65d50dc)

GaudiHistoID.h
Go to the documentation of this file.
1 #ifndef GAUDIALG_GAUDIHISTOID_H
2 #define GAUDIALG_GAUDIHISTOID_H 1
3 // ============================================================================
4 // Include files
5 // ============================================================================
6 // STD&STL
7 // ============================================================================
8 #include <string>
9 // ============================================================================
10 // GaudiKernel
11 // ============================================================================
12 #include "GaudiKernel/Hash.h"
13 #include "GaudiKernel/Kernel.h"
14 // ============================================================================
15 /* @file
16 *
17 * Header file for class GaudiAlg::ID
18 *
19 * @author Chris Jones Christopher.Rob.Jones@cern.ch
20 * @author Vanya BELYAEV Ivan.Belyaev@itep.ru
21 * @date 2004-01-23
22 */
23 // ============================================================================
32 // ============================================================================
33 namespace GaudiAlg {
34 // ==========================================================================
43 class GAUDI_API ID {
44 public:
45 // ========================================================================
47 typedef int NumericID;
49 typedef std::string LiteralID;
50 // ========================================================================
51 public:
52 // ========================================================================
54 ID( const NumericID id = -1 ) : m_nID( id ), m_hash( boost::hash_value( id ) ) {}
56 ID( LiteralID&& id ) : m_aID( std::move( id ) ), m_hash( boost::hash_value( m_aID ) ) {}
58 ID( const LiteralID& id ) : m_aID( id ), m_hash( boost::hash_value( m_aID ) ) {}
60 ID( const char* id ) : m_aID( id ), m_hash( boost::hash_value( m_aID ) ) {}
62 ~ID() = default;
64 inline bool numeric() const noexcept { return -1 != m_nID; }
66 inline bool literal() const noexcept { return !m_aID.empty(); }
68 inline bool undefined() const noexcept { return !numeric() && !literal(); }
70 inline const LiteralID& literalID() const noexcept { return m_aID; }
72 inline NumericID numericID() const noexcept { return m_nID; }
74 GAUDI_API LiteralID idAsString() const;
76 operator std::string() const { return idAsString(); }
81 inline bool operator==( const ID& id ) const noexcept {
82 return hash() != id.hash()
83 ? false
84 : numeric() && id.numeric()
85 ? id.numericID() == numericID()
86 : literal() && id.literal() ? id.literalID() == literalID() : idAsString() == id.idAsString();
87 }
89 inline bool operator!=( const ID& id ) const { return !( *this == id ); }
94 inline bool operator<( const ID& id ) const noexcept {
95 return
96 // hash () < id.hash () ? true :
97 // hash () > id.hash () ? false :
98 numeric() && id.numeric()
99 ? numericID() < id.numericID()
100 : literal() && id.literal() ? literalID() < id.literalID() : idAsString() < id.idAsString();
101 }
102 // ========================================================================
103 GAUDI_API std::ostream& fillStream( std::ostream& s ) const;
104 // ========================================================================
105 public:
106 // ========================================================================
108 bool operator!() const noexcept { return undefined(); }
109 // ========================================================================
110 public:
111 // ========================================================================
113 inline size_t hash() const noexcept { return m_hash; }
115 inline size_t __hash__() const noexcept { return hash(); }
116 // ========================================================================
117 private:
118 // ========================================================================
120 NumericID m_nID{-1}; // Internal numeric ID
122 LiteralID m_aID; // Internal alpha-numeric ID
123 // ========================================================================
124 private:
125 // ========================================================================
127 size_t m_hash{0}; // the hash value of ID
128 // ========================================================================
129 };
130 // ==========================================================================
132 inline std::ostream& operator<<( std::ostream& str, const GaudiAlg::ID& id ) { return id.fillStream( str ); }
133 // ==========================================================================
134 } // end of namespace GaudiAlg
135 // ============================================================================
136 namespace GaudiUtils {
137 // ==========================================================================
139 template <>
140 inline size_t Hash<GaudiAlg::ID>::operator()( const GaudiAlg::ID& key ) const {
141 return key.hash();
142 }
143 // ==========================================================================
144 } // end of namespace GaudiUtils
145 // ============================================================================
146 // The END
147 // ============================================================================
148 #endif // GAUDIALG_GAUDIHISTOID_H
GaudiAlg::ID::ID
ID(const LiteralID &id)
Implicit 'copy' constructor from a literal ID.
Definition: GaudiHistoID.h:58
GaudiAlg::ID::literalID
const LiteralID & literalID() const noexcept
Returns the ID as a LiteralID.
Definition: GaudiHistoID.h:70
Kernel.h
GaudiUtils::Hash::operator()
std::size_t operator()(const T &key) const
the hash-function
Definition: Hash.h:141
GaudiAlg::ID::operator!
bool operator!() const noexcept
good ID?
Definition: GaudiHistoID.h:108
GaudiAlg::ID::ID
ID(LiteralID &&id)
Implicit 'move' constructor from a literal ID.
Definition: GaudiHistoID.h:56
boost
Definition: iter_pos.hpp:13
GaudiAlg::ID::operator!=
bool operator!=(const ID &id) const
Implement the != operator, using the == operator.
Definition: GaudiHistoID.h:89
GaudiAlg::ID::NumericID
int NumericID
type for internal numeric ID
Definition: GaudiHistoID.h:47
std
STL namespace.
std::string
STL class.
GaudiAlg::ID::numericID
NumericID numericID() const noexcept
Returns the numerical ID.
Definition: GaudiHistoID.h:72
GaudiAlg::ID::undefined
bool undefined() const noexcept
Is this ID undefined.
Definition: GaudiHistoID.h:68
GaudiAlg::ID::literal
bool literal() const noexcept
Is this ID numeric.
Definition: GaudiHistoID.h:66
GaudiAlg::ID::ID
ID(const NumericID id=-1)
Implicit constructor from a numeric ID.
Definition: GaudiHistoID.h:54
GaudiAlg::hash_value
std::size_t hash_value(TupleID const &b)
Definition: TupleID.h:31
GaudiAlg::ID::__hash__
size_t __hash__() const noexcept
return hash value (for python)
Definition: GaudiHistoID.h:115
GaudiAlg::ID::operator<
bool operator<(const ID &id) const noexcept
Implement the operator < Implementation depends on type of ID.
Definition: GaudiHistoID.h:94
GaudiAlg::ID::LiteralID
std::string LiteralID
type for internal literal ID
Definition: GaudiHistoID.h:49
GaudiAlg::ID::hash
size_t hash() const noexcept
return hash value (for python)
Definition: GaudiHistoID.h:113
GaudiUtils
Forward declarations for the functions in SerializeSTL.h.
Definition: GaudiHistoID.h:136
GaudiAlg::ID::operator==
bool operator==(const ID &id) const noexcept
Implement the operator == Implementation depends on type of ID.
Definition: GaudiHistoID.h:81
gaudirun.s
string s
Definition: gaudirun.py:316
GaudiAlg::ID::m_aID
LiteralID m_aID
Internal alpha-numeric ID.
Definition: GaudiHistoID.h:122
GaudiAlg::ID::numeric
bool numeric() const noexcept
Is this ID numeric.
Definition: GaudiHistoID.h:64
Hash.h
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:71
GaudiAlg
GaudiAlg.h GaudiAlg/GaudiAlg.h Namespace with definition of useful constants, types and function,...
std::ostream
STL class.
GaudiAlg::ID
ID class for Histogram and Ntuples.
Definition: GaudiHistoID.h:43
GaudiAlg::operator<<
std::ostream & operator<<(std::ostream &str, const GaudiAlg::ID &id)
Operator overloading for ostream.
Definition: GaudiHistoID.h:132
GaudiAlg::ID::ID
ID(const char *id)
Implicit constructor from a literal ID.
Definition: GaudiHistoID.h:60