|
||||
File indexing completed on 2025-01-18 09:57:33
0001 /***********************************************************************************\ 0002 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations * 0003 * * 0004 * This software is distributed under the terms of the Apache version 2 licence, * 0005 * copied verbatim in the file "LICENSE". * 0006 * * 0007 * In applying this licence, CERN does not waive the privileges and immunities * 0008 * granted to it by virtue of its status as an Intergovernmental Organization * 0009 * or submit itself to any jurisdiction. * 0010 \***********************************************************************************/ 0011 #ifndef GAUDIALG_GAUDIHISTOID_H 0012 #define GAUDIALG_GAUDIHISTOID_H 1 0013 // ============================================================================ 0014 // Include files 0015 // ============================================================================ 0016 // STD&STL 0017 // ============================================================================ 0018 #include <string> 0019 // ============================================================================ 0020 // GaudiKernel 0021 // ============================================================================ 0022 #include "GaudiKernel/Hash.h" 0023 #include "GaudiKernel/Kernel.h" 0024 // ============================================================================ 0025 /* @file 0026 * 0027 * Header file for class GaudiAlg::ID 0028 * 0029 * @author Chris Jones Christopher.Rob.Jones@cern.ch 0030 * @author Vanya BELYAEV Ivan.Belyaev@itep.ru 0031 * @date 2004-01-23 0032 */ 0033 // ============================================================================ 0034 /** @namespace GaudiAlg 0035 * 0036 * Definitions of few useful hash-maps, classes and typedefs 0037 * used for classes GaudiHistos and GaudiTuples. 0038 * 0039 * @author Vanya BELYAEV Ivan.Belyaev@itep.ru 0040 * @date 2004-01-23 0041 */ 0042 // ============================================================================ 0043 namespace GaudiAlg { 0044 // ========================================================================== 0045 /** @class ID GaudiHistoID.h GaudiAlg/GaudiHistoID.h 0046 * 0047 * ID class for Histogram and Ntuples. Internally handles both 0048 * numeric and string like IDs 0049 * 0050 * @author Chris Jones Christopher.Rob.Jones@cern.ch 0051 * @date 2005-08-12 0052 */ 0053 class GAUDI_API ID { 0054 public: 0055 // ======================================================================== 0056 /// type for internal numeric ID 0057 typedef int NumericID; 0058 /// type for internal literal ID 0059 typedef std::string LiteralID; 0060 // ======================================================================== 0061 public: 0062 // ======================================================================== 0063 /// Implicit constructor from a numeric ID 0064 ID( const NumericID id = -1 ) : m_nID( id ), m_hash( boost::hash_value( id ) ) {} 0065 /// Implicit 'move' constructor from a literal ID 0066 ID( LiteralID&& id ) : m_aID( std::move( id ) ), m_hash( boost::hash_value( m_aID ) ) {} 0067 /// Implicit 'copy' constructor from a literal ID 0068 ID( const LiteralID& id ) : m_aID( id ), m_hash( boost::hash_value( m_aID ) ) {} 0069 /// Implicit constructor from a literal ID 0070 ID( const char* id ) : m_aID( id ), m_hash( boost::hash_value( m_aID ) ) {} 0071 /// Destructor 0072 ~ID() = default; 0073 /// Is this ID numeric 0074 inline bool numeric() const noexcept { return -1 != m_nID; } 0075 /// Is this ID numeric 0076 inline bool literal() const noexcept { return !m_aID.empty(); } 0077 /// Is this ID undefined 0078 inline bool undefined() const noexcept { return !numeric() && !literal(); } 0079 /// Returns the ID as a LiteralID 0080 inline const LiteralID& literalID() const noexcept { return m_aID; } 0081 /// Returns the numerical ID 0082 inline NumericID numericID() const noexcept { return m_nID; } 0083 /// Return ID as string, for both numeric and literal IDs 0084 GAUDI_API LiteralID idAsString() const; 0085 /// cast operator to std::string 0086 operator std::string() const { return idAsString(); } 0087 /** @brief Implement the operator == 0088 * Implementation depends on type of ID 0089 * @return boolean indicating if the IDs are equal 0090 */ 0091 inline bool operator==( const ID& id ) const noexcept { 0092 return hash() != id.hash() ? false 0093 : numeric() && id.numeric() ? id.numericID() == numericID() 0094 : literal() && id.literal() ? id.literalID() == literalID() 0095 : idAsString() == id.idAsString(); 0096 } 0097 /// Implement the != operator, using the == operator 0098 inline bool operator!=( const ID& id ) const { return !( *this == id ); } 0099 /** @brief Implement the operator < 0100 * Implementation depends on type of ID 0101 * @return boolean indicating the order of the IDs 0102 */ 0103 inline bool operator<( const ID& id ) const noexcept { 0104 return 0105 // hash () < id.hash () ? true : 0106 // hash () > id.hash () ? false : 0107 numeric() && id.numeric() ? numericID() < id.numericID() 0108 : literal() && id.literal() ? literalID() < id.literalID() 0109 : idAsString() < id.idAsString(); 0110 } 0111 // ======================================================================== 0112 GAUDI_API std::ostream& fillStream( std::ostream& s ) const; 0113 // ======================================================================== 0114 public: 0115 // ======================================================================== 0116 /// good ID? 0117 bool operator!() const noexcept { return undefined(); } 0118 // ======================================================================== 0119 public: 0120 // ======================================================================== 0121 /// return hash value (for python) 0122 inline size_t hash() const noexcept { return m_hash; } 0123 /// return hash value (for python) 0124 inline size_t __hash__() const noexcept { return hash(); } 0125 // ======================================================================== 0126 private: 0127 // ======================================================================== 0128 /// Internal numeric ID 0129 NumericID m_nID{ -1 }; // Internal numeric ID 0130 /// Internal alpha-numeric ID 0131 LiteralID m_aID; // Internal alpha-numeric ID 0132 // ======================================================================== 0133 private: 0134 // ======================================================================== 0135 /// the hash value of ID 0136 size_t m_hash{ 0 }; // the hash value of ID 0137 // ======================================================================== 0138 }; 0139 // ========================================================================== 0140 /// Operator overloading for ostream 0141 inline std::ostream& operator<<( std::ostream& str, const GaudiAlg::ID& id ) { return id.fillStream( str ); } 0142 // ========================================================================== 0143 } // end of namespace GaudiAlg 0144 // ============================================================================ 0145 namespace GaudiUtils { 0146 // ========================================================================== 0147 /// Hash-function for class GaudiAlg::ID 0148 template <> 0149 inline size_t Hash<GaudiAlg::ID>::operator()( const GaudiAlg::ID& key ) const { 0150 return key.hash(); 0151 } 0152 // ========================================================================== 0153 } // end of namespace GaudiUtils 0154 // ============================================================================ 0155 // The END 0156 // ============================================================================ 0157 #endif // GAUDIALG_GAUDIHISTOID_H
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |