BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
DetectorDescription/Identifier/include/Identifier/Identifier.h
Go to the documentation of this file.
1#ifndef __Identifier_h___
2#define __Identifier_h___
3
4#include <string>
5#include <vector>
6
7/**
8 **-----------------------------------------------
9 **
10 ** Identifier is a simple type-safe 32 bit unsigned integer. An
11 ** Identifier relies on other classes to encode and
12 ** decode its information.
13 **
14 ** The default constructor created an Identifier an invalid state
15 ** which can be check with the "is_valid" method to allow some error
16 ** checking.
17 **
18 **-----------------------------------------------
19 */
21public:
22 ///----------------------------------------------------------------
23 /// Define public typedefs
24 ///----------------------------------------------------------------
26 typedef unsigned int value_type;
27 typedef unsigned int size_type;
28
29 ///----------------------------------------------------------------
30 /// Constructors
31 ///----------------------------------------------------------------
32
33 /// Default constructor
34 Identifier();
35
36 /// Constructor from value_type
37 explicit Identifier( value_type value );
38
39 /// Copy constructor
40 Identifier( const Identifier& other );
41
42 ///----------------------------------------------------------------
43 /// Modifications
44 ///----------------------------------------------------------------
45
46 /// Assignment operator
48
49 /// Bitwise operations
52
53 /// build from a string form - hexadecimal
54 void set( const std::string& id );
55
56 /// Reset to invalid state
57 void clear();
58
59 ///----------------------------------------------------------------
60 /// Accessors
61 ///----------------------------------------------------------------
62 /// Get the value
63 operator value_type( void ) const;
64 value_type get_value() const;
65
66 ///----------------------------------------------------------------
67 /// Comparison operators
68 ///----------------------------------------------------------------
69 bool operator==( const Identifier& other ) const;
70 bool operator!=( const Identifier& other ) const;
71 bool operator<( const Identifier& other ) const;
72 bool operator>( const Identifier& other ) const;
73
74 ///----------------------------------------------------------------
75 /// Error management
76 ///----------------------------------------------------------------
77
78 /// Check if id is in a valid state
79 bool is_valid() const;
80
81 ///----------------------------------------------------------------
82 /// Utilities
83 ///----------------------------------------------------------------
84
85 /// Provide a string form of the identifier - hexadecimal
86 std::string getString() const;
87
88 /// Print out in hex form
89 void show() const;
90
91private:
92 typedef enum { max_value = 0xFFFFFFFF } max_value_type;
93
94 //----------------------------------------------------------------
95 // The compact identifier data.
96 //----------------------------------------------------------------
97 value_type m_id;
98};
99
100//-----------------------------------------------
101//<<<<<< INLINE MEMBER FUNCTIONS >>>>>>
102
103// Constructors
104//-----------------------------------------------
105inline Identifier::Identifier() : m_id( max_value ) {}
106
107//-----------------------------------------------
108inline Identifier::Identifier( const Identifier& other ) : m_id( other.get_value() ) {}
109
110//-----------------------------------------------
111inline Identifier::Identifier( value_type value ) : m_id( value ) {}
112
113// Modifications
114//-----------------------------------------------
115
117 m_id = value;
118 return ( *this );
119}
120
121inline Identifier& Identifier::operator|=( unsigned int value ) {
122 m_id |= value;
123 return ( *this );
124}
125
126inline Identifier& Identifier::operator&=( unsigned int value ) {
127 m_id &= value;
128 return ( *this );
129}
130
131inline void Identifier::clear() { m_id = max_value; }
132
133// Accessors
134inline Identifier::operator Identifier::value_type( void ) const { return ( m_id ); }
135
136inline Identifier::value_type Identifier::get_value() const { return ( m_id ); }
137
138// Comparison operators
139//----------------------------------------------------------------
140inline bool Identifier::operator==( const Identifier& other ) const {
141 return ( m_id == other.get_value() );
142}
143
144//----------------------------------------------------------------
145inline bool Identifier::operator!=( const Identifier& other ) const {
146 return ( m_id != other.get_value() );
147}
148
149//-----------------------------------------------
150inline bool Identifier::operator<( const Identifier& other ) const {
151 return ( m_id < other.get_value() );
152}
153
154//-----------------------------------------------
155inline bool Identifier::operator>( const Identifier& other ) const {
156 return ( m_id > other.get_value() );
157}
158
159inline bool Identifier::is_valid() const { return ( !( max_value == m_id ) ); }
160
161// others -----------------
162std::ostream& operator<<( std::ostream& os, const Identifier& Id );
163
164#endif
std::ostream & operator<<(std::ostream &os, const Identifier &Id)
Identifier & operator|=(value_type value)
Bitwise operations.
std::string getString() const
Provide a string form of the identifier - hexadecimal.
bool is_valid() const
Check if id is in a valid state.
void show() const
Print out in hex form.
void set(const std::string &id)
build from a string form - hexadecimal
Identifier & operator=(value_type value)
Assignment operator.