BOSS 7.0.4
BESIII Offline Software System
Loading...
Searching...
No Matches
DetectorDescription/Identifier/Identifier-00-02-17/Identifier/Identifier.h
Go to the documentation of this file.
1#ifndef __Identifier_h___
2#define __Identifier_h___
3
4#include <vector>
5#include <string>
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 ///----------------------------------------------------------------
24 /// Define public typedefs
25 ///----------------------------------------------------------------
27 typedef unsigned int value_type;
28 typedef unsigned int size_type;
29
30 ///----------------------------------------------------------------
31 /// Constructors
32 ///----------------------------------------------------------------
33
34 /// Default constructor
35 Identifier ();
36
37 /// Constructor from value_type
38 explicit Identifier (value_type value);
39
40 /// Copy constructor
41 Identifier (const Identifier& other);
42
43 ///----------------------------------------------------------------
44 /// Modifications
45 ///----------------------------------------------------------------
46
47 /// Assignment operator
49
50 /// Bitwise operations
53
54 /// build from a string form - hexadecimal
55 void set (const std::string& id);
56
57 /// Reset to invalid state
58 void clear ();
59
60 ///----------------------------------------------------------------
61 /// Accessors
62 ///----------------------------------------------------------------
63 /// Get the value
64 operator value_type (void) const;
65 value_type get_value() const;
66
67 ///----------------------------------------------------------------
68 /// Comparison operators
69 ///----------------------------------------------------------------
70 bool operator == (const Identifier& other) const;
71 bool operator != (const Identifier& other) const;
72 bool operator < (const Identifier& other) const;
73 bool operator > (const Identifier& other) const;
74
75 ///----------------------------------------------------------------
76 /// Error management
77 ///----------------------------------------------------------------
78
79 /// Check if id is in a valid state
80 bool is_valid () const;
81
82 ///----------------------------------------------------------------
83 /// Utilities
84 ///----------------------------------------------------------------
85
86 /// Provide a string form of the identifier - hexadecimal
87 std::string getString() const;
88
89 /// Print out in hex form
90 void show () const;
91
92private:
93
94 typedef enum {
95 max_value = 0xFFFFFFFF
96 } max_value_type;
97
98 //----------------------------------------------------------------
99 // The compact identifier data.
100 //----------------------------------------------------------------
101 value_type m_id;
102};
103
104//-----------------------------------------------
105//<<<<<< INLINE MEMBER FUNCTIONS >>>>>>
106
107
108// Constructors
109//-----------------------------------------------
111 : m_id(max_value)
112{}
113
114//-----------------------------------------------
116 : m_id(other.get_value())
117{
118}
119
120//-----------------------------------------------
122 : m_id(value)
123{
124}
125
126
127// Modifications
128//-----------------------------------------------
129
130inline Identifier&
132{
133 m_id = value;
134 return (*this);
135}
136
137inline Identifier&
138Identifier::operator |= (unsigned int value)
139{
140 m_id |= value;
141 return (*this);
142}
143
144inline Identifier&
145Identifier::operator &= (unsigned int value)
146{
147 m_id &= value;
148 return (*this);
149}
150
151inline void
153{
154 m_id = max_value;
155}
156
157// Accessors
158inline Identifier::operator Identifier::value_type (void) const
159{
160 return (m_id);
161}
162
164{
165 return (m_id);
166}
167
168// Comparison operators
169//----------------------------------------------------------------
170inline bool
172{
173 return (m_id == other.get_value());
174}
175
176//----------------------------------------------------------------
177inline bool
179{
180 return (m_id != other.get_value());
181}
182
183//-----------------------------------------------
184inline bool
185Identifier::operator < (const Identifier& other) const
186{
187 return (m_id < other.get_value());
188}
189
190//-----------------------------------------------
191inline bool
193{
194 return (m_id > other.get_value());
195}
196
197inline bool
199{
200 return (!(max_value == m_id));
201}
202
203//others -----------------
204std::ostream& operator<<(std::ostream & os, const Identifier& Id);
205
206#endif
207
std::ostream & operator<<(std::ostream &os, const Identifier &Id)
Definition: Identifier.cxx:36
Identifier & operator|=(value_type value)
Bitwise operations.
std::string getString() const
Provide a string form of the identifier - hexadecimal.
Definition: Identifier.cxx:17
void show() const
Print out in hex form.
Definition: Identifier.cxx:30
void set(const std::string &id)
build from a string form - hexadecimal
Definition: Identifier.cxx:10
Identifier & operator=(value_type value)
Assignment operator.