Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JUPI_t.hh
Go to the documentation of this file.
1#ifndef __JDB__JUPI_T__
2#define __JDB__JUPI_T__
3
4#include <istream>
5#include <ostream>
6#include <sstream>
7#include <string>
8#include <cctype>
9
10#include <TROOT.h>
11
12#include "JDB/JPBS_t.hh"
13
14
15/**
16 * \author mdejong
17 */
18namespace JDATABASE {}
19namespace JPP { using namespace JDATABASE; }
20
21namespace JDATABASE {
22
23 /**
24 * Universal product identifier (%UPI).
25 *
26 * The %UPI consists of a %PBS, variant, version and serial number.\n
27 * The corresponding ASCII format reads <tt>\"<int>[.<int>]*</tt><tt>/<variant>/<int>.<int>\"</tt>.\n
28 * The version and serial number are not subject to I/O in case their value is default.
29 */
30 struct JUPI_t :
31 public JPBS_t
32 {
33 /**
34 * Separator between %PBS, variant and version.
35 */
36 static const char SEPARATOR = '/';
37
38 static const int DEFAULT_VERSION = -1; //!< Default version
39 static const int DEFAULT_NUMBER = -1; //!< Default number
40
41 /**
42 * Default constructor.
43 */
50
51
52 /**
53 * Constructor.
54 *
55 * \param pbs %PBS
56 */
57 JUPI_t(const JPBS_t& pbs) :
58 JPBS_t (pbs),
59 variant(),
62 {}
63
64
65 /**
66 * Constructor.
67 *
68 * \param pbs %PBS
69 * \param variant variant
70 * \param version version
71 * \param number serial number
72 */
73 JUPI_t(const JPBS_t& pbs,
74 const std::string& variant,
75 const int version,
76 const int number) :
77 JPBS_t (pbs),
81 {}
82
83
84 /**
85 * Constructor.
86 *
87 * \param upi %UPI
88 */
89 JUPI_t(const std::string& upi)
90 {
91 std::istringstream(upi) >> *this;
92 }
93
94
95 /**
96 * Get %UPI.
97 *
98 * \return %UPI
99 */
100 const JUPI_t& getUPI() const
101 {
102 return static_cast<const JUPI_t&>(*this);
103 }
104
105
106 /**
107 * Get variant.
108 *
109 * \return variant
110 */
111 const std::string& getVariant() const
112 {
113 return variant;
114 }
115
116
117 /**
118 * Get version.
119 *
120 * \return version
121 */
122 int getVersion() const
123 {
124 return version;
125 }
126
127
128 /**
129 * Get serial number.
130 *
131 * \return serial number
132 */
133 int getNumber() const
134 {
135 return number;
136 }
137
138
139 /**
140 * Convert %UPI.
141 *
142 * \return %UPI
143 */
144 std::string toString() const
145 {
146 std::ostringstream os;
147
148 os << *this;
149
150 return os.str();
151 }
152
153
154 /**
155 * Equality.
156 *
157 * \param first first %UPI
158 * \param second second %UPI
159 * \return true if %UPIs are equals; else false
160 */
161 friend inline bool operator==(const JUPI_t& first, const JUPI_t& second)
162 {
163 return (first.getPBS() == second.getPBS() &&
164 first.getVariant() == second.getVariant() &&
165 first.getVersion() == second.getVersion() &&
166 first.getNumber() == second.getNumber());
167 }
168
169
170 /**
171 * Less-than operator.
172 *
173 * \param first first %UPI
174 * \param second second %UPI
175 * \return true if first %UPI less than second %UPI; else false
176 */
177 friend inline bool operator<(const JUPI_t& first, const JUPI_t& second)
178 {
179 if (first.getPBS() == second.getPBS()) {
180
181 if (first.getVariant() == second.getVariant()) {
182
183 if (first.getVersion() == second.getVersion())
184 return first.getNumber() < second.getNumber();
185 else
186 return first.getVersion() < second.getVersion();
187
188 } else {
189
190 return first.getVariant() < second.getVariant();
191 }
192
193 } else {
194
195 return first.getPBS() < second.getPBS();
196 }
197 }
198
199
200 /**
201 * Read %UPI from input stream.
202 *
203 * \param in input stream
204 * \param object %UPI
205 * \return input stream
206 */
207 friend inline std::istream& operator>>(std::istream& in, JUPI_t& object)
208 {
209 using namespace std;
210
211 object = JUPI_t();
212
213 if (in.peek() != (int) SEPARATOR) {
214 in >> static_cast<JPBS_t&>(object);
215 }
216
217 if (in.get() == (int) SEPARATOR) {
218
219 if (in.peek() == (int) SEPARATOR)
220 in.ignore();
221 else
222 getline(in, object.variant, SEPARATOR);
223
224 if (in.peek() == (int) DOT) {
225
226 in.ignore();
227
228 object.version = DEFAULT_VERSION;
229 object.number = DEFAULT_NUMBER;
230
231 return in;
232
233 } else if (in >> object.version &&
234 in.get() == (int) DOT &&
235 in >> object.number) {
236
237 return in;
238 }
239 }
240
241 in.setstate(ios::failbit);
242
243 return in;
244 }
245
246
247 /**
248 * Write %UPI to output stream.
249 *
250 * \param out output stream
251 * \param object %UPI
252 * \return output stream
253 */
254 friend inline std::ostream& operator<<(std::ostream& out, const JUPI_t& object)
255 {
256 using namespace std;
257
258 ostringstream os; // allow for width formatting
259
260 os << object.getPBS() << JUPI_t::SEPARATOR
261 << object.getVariant() << JUPI_t::SEPARATOR;
262
263 if (object.getVersion() != DEFAULT_VERSION) {
264 os << object.getVersion();
265 }
266
267 os << JUPI_t::DOT;
268
269 if (object.getNumber() != DEFAULT_NUMBER) {
270 os << object.getNumber();
271 }
272
273 return out << os.str();
274 }
275
277
278 protected:
279 std::string variant;
282 };
283}
284
285#endif
Auxiliary classes and methods for database I/O.
Definition JAHRS.hh:14
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Product breakdown structure (PBS).
Definition JPBS_t.hh:29
static const char DOT
Separator between PBS values.
Definition JPBS_t.hh:33
const JPBS_t & getPBS() const
Get PBS.
Definition JPBS_t.hh:101
Universal product identifier (UPI).
Definition JUPI_t.hh:32
JUPI_t(const std::string &upi)
Constructor.
Definition JUPI_t.hh:89
std::string variant
Definition JUPI_t.hh:279
static const int DEFAULT_VERSION
Default version.
Definition JUPI_t.hh:38
std::string toString() const
Convert UPI.
Definition JUPI_t.hh:144
int getVersion() const
Get version.
Definition JUPI_t.hh:122
friend bool operator==(const JUPI_t &first, const JUPI_t &second)
Equality.
Definition JUPI_t.hh:161
static const int DEFAULT_NUMBER
Default number.
Definition JUPI_t.hh:39
friend std::ostream & operator<<(std::ostream &out, const JUPI_t &object)
Write UPI to output stream.
Definition JUPI_t.hh:254
JUPI_t(const JPBS_t &pbs, const std::string &variant, const int version, const int number)
Constructor.
Definition JUPI_t.hh:73
JUPI_t(const JPBS_t &pbs)
Constructor.
Definition JUPI_t.hh:57
ClassDefNV(JUPI_t, 1)
friend bool operator<(const JUPI_t &first, const JUPI_t &second)
Less-than operator.
Definition JUPI_t.hh:177
friend std::istream & operator>>(std::istream &in, JUPI_t &object)
Read UPI from input stream.
Definition JUPI_t.hh:207
static const char SEPARATOR
Separator between PBS, variant and version.
Definition JUPI_t.hh:36
const JUPI_t & getUPI() const
Get UPI.
Definition JUPI_t.hh:100
const std::string & getVariant() const
Get variant.
Definition JUPI_t.hh:111
JUPI_t()
Default constructor.
Definition JUPI_t.hh:44
int getNumber() const
Get serial number.
Definition JUPI_t.hh:133