00001 00002 // ============================================================================ 00003 /* @file gaudiHistoID.h 00004 * 00005 * Header file for class GaudiAlg::ID 00006 * 00007 * $Id: GaudiHistoID.h,v 1.7 2007/09/19 08:17:54 marcocle Exp $ 00008 * 00009 * @author Chris Jones Christopher.Rob.Jones@cern.ch 00010 * @author Vanya BELYAEV Ivan.Belyaev@itep.ru 00011 * @date 2004-01-23 00012 */ 00013 // ============================================================================ 00014 00015 #ifndef GAUDIALG_GAUDIHISTOID_H 00016 #define GAUDIALG_GAUDIHISTOID_H 1 00017 // STD 00018 #include <string> 00019 00020 // ============================================================================ 00029 // ============================================================================ 00030 00031 namespace GaudiAlg 00032 { 00033 // ============================================================================ 00042 class ID 00043 { 00044 public: 00046 typedef int NumericID; 00048 typedef std::string LiteralID; 00049 public: 00051 ID( const NumericID id = -1 ) : m_nID ( id ) , m_aID( "" ) { } 00053 ID( const LiteralID& id ) : m_nID ( -1 ) , m_aID( id ) { } 00055 ID( const char* id ) : m_nID ( -1 ) , m_aID( id ) { } 00057 ~ID( ) { } 00059 inline bool numeric () const { return -1 != m_nID ; } 00061 inline bool literal () const { return !m_aID.empty() ; } 00063 inline bool undefined () const { return !numeric() && !literal(); } 00065 inline const LiteralID& literalID() const { return m_aID; } 00067 inline NumericID numericID() const { return m_nID; } 00071 inline ID& operator++() 00072 { 00073 if ( numeric() ) { ++m_nID; } ; 00074 return *this ; 00075 } 00079 inline ID operator++( int ) 00080 { 00081 const ID retID = *this; 00082 this->operator++(); 00083 return retID; 00084 } 00088 inline ID& operator--() 00089 { 00090 if ( numeric() ) { --m_nID; } ; 00091 return *this ; 00092 } 00096 inline ID operator--( int ) 00097 { 00098 const ID retID = *this; 00099 this->operator--(); 00100 return retID; 00101 } 00103 LiteralID idAsString() const ; 00105 operator std::string () const { return idAsString () ; } 00110 inline bool operator==( const ID& id ) const 00111 { 00112 return ( numeric() && id.numeric() ? id.numericID() == numericID() : 00113 ( literal() && id.literal() ? id.literalID() == literalID() : 00114 id.idAsString() == idAsString() ) ); 00115 } 00117 inline bool operator!=( const ID& id ) const 00118 { 00119 return ! this->operator==(id); 00120 } 00125 inline bool operator<( const ID& id ) const 00126 { 00127 return ( numeric() && id.numeric() ? this->numericID() < id.numericID() : 00128 ( literal() && id.literal() ? this->literalID() < id.literalID() : 00129 this->idAsString() < id.idAsString() ) ); 00130 } 00131 private: 00133 NumericID m_nID ; 00135 LiteralID m_aID ; 00136 }; 00137 } 00139 inline std::ostream& operator << ( std::ostream& str , const GaudiAlg::ID& id ) 00140 { 00141 if ( id.numeric() ) { str << id.numericID(); } 00142 else if ( id.literal() ) { str << id.literalID(); } 00143 else { str << "UNDEFINED"; } 00144 return str; 00145 } 00146 #endif // GAUDIALG_GAUDIHISTOID_H