Jpp 19.3.0
the software that should make you happy
Loading...
Searching...
No Matches
JDATABASE::JUPI_t Struct Reference

Universal product identifier (UPI). More...

#include <JUPI_t.hh>

Inheritance diagram for JDATABASE::JUPI_t:
JDATABASE::JPBS_t std::vector< int > JDETECTOR::JHVCalibration_t JDETECTOR::JPMTThresholdCalibration_t

Public Member Functions

 JUPI_t ()
 Default constructor.
 
 JUPI_t (const JPBS_t &pbs)
 Constructor.
 
 JUPI_t (const JPBS_t &pbs, const std::string &variant, const int version, const int number)
 Constructor.
 
 JUPI_t (const std::string &upi)
 Constructor.
 
const JUPI_tgetUPI () const
 Get UPI.
 
const std::string & getVariant () const
 Get variant.
 
int getVersion () const
 Get version.
 
int getNumber () const
 Get serial number.
 
std::string toString () const
 Convert UPI.
 
 ClassDefNV (JUPI_t, 1)
 
const JPBS_tgetPBS () const
 Get PBS.
 
bool is_valid () const
 Check validity.
 
 ClassDefNV (JPBS_t, 1)
 

Static Public Member Functions

static int compare (const std::string &first, const std::string &second)
 Compare sub-strings.
 

Static Public Attributes

static const char SEPARATOR = '/'
 Separator between PBS, variant and version.
 
static const int DEFAULT_VERSION = -1
 Default version.
 
static const int DEFAULT_NUMBER = -1
 Default number.
 
static const char DOT = '.'
 Separator between PBS values.
 

Protected Attributes

std::string variant
 
int version
 
int number
 

Friends

bool operator== (const JUPI_t &first, const JUPI_t &second)
 Equality.
 
bool operator< (const JUPI_t &first, const JUPI_t &second)
 Less-than operator.
 
std::istream & operator>> (std::istream &in, JUPI_t &object)
 Read UPI from input stream.
 
std::ostream & operator<< (std::ostream &out, const JUPI_t &object)
 Write UPI to output stream.
 

Detailed Description

Universal product identifier (UPI).

The UPI consists of a PBS, variant, version and serial number.
The corresponding ASCII format reads "<int>[.<int>]*/<variant>/<int>.<int>".
The version and serial number are not subject to I/O in case their value is default.

Definition at line 31 of file JUPI_t.hh.

Constructor & Destructor Documentation

◆ JUPI_t() [1/4]

JDATABASE::JUPI_t::JUPI_t ( )
inline

Default constructor.

Definition at line 45 of file JUPI_t.hh.

45 :
46 JPBS_t (),
47 variant(),
50 {}
JPBS_t()
Default constructor.
Definition JPBS_t.hh:39
std::string variant
Definition JUPI_t.hh:305
static const int DEFAULT_VERSION
Default version.
Definition JUPI_t.hh:39
static const int DEFAULT_NUMBER
Default number.
Definition JUPI_t.hh:40

◆ JUPI_t() [2/4]

JDATABASE::JUPI_t::JUPI_t ( const JPBS_t & pbs)
inline

Constructor.

Parameters
pbsPBS

Definition at line 58 of file JUPI_t.hh.

58 :
59 JPBS_t (pbs),
60 variant(),
63 {}

◆ JUPI_t() [3/4]

JDATABASE::JUPI_t::JUPI_t ( const JPBS_t & pbs,
const std::string & variant,
const int version,
const int number )
inline

Constructor.

Parameters
pbsPBS
variantvariant
versionversion
numberserial number

Definition at line 74 of file JUPI_t.hh.

77 :
78 JPBS_t (pbs),
82 {}

◆ JUPI_t() [4/4]

JDATABASE::JUPI_t::JUPI_t ( const std::string & upi)
inline

Constructor.

Parameters
upiUPI

Definition at line 90 of file JUPI_t.hh.

91 {
92 std::istringstream(upi) >> *this;
93 }

Member Function Documentation

◆ getUPI()

const JUPI_t & JDATABASE::JUPI_t::getUPI ( ) const
inline

Get UPI.

Returns
UPI

Definition at line 101 of file JUPI_t.hh.

102 {
103 return static_cast<const JUPI_t&>(*this);
104 }
JUPI_t()
Default constructor.
Definition JUPI_t.hh:45

◆ getVariant()

const std::string & JDATABASE::JUPI_t::getVariant ( ) const
inline

Get variant.

Returns
variant

Definition at line 112 of file JUPI_t.hh.

113 {
114 return variant;
115 }

◆ getVersion()

int JDATABASE::JUPI_t::getVersion ( ) const
inline

Get version.

Returns
version

Definition at line 123 of file JUPI_t.hh.

124 {
125 return version;
126 }

◆ getNumber()

int JDATABASE::JUPI_t::getNumber ( ) const
inline

Get serial number.

Returns
serial number

Definition at line 134 of file JUPI_t.hh.

135 {
136 return number;
137 }

◆ toString()

std::string JDATABASE::JUPI_t::toString ( ) const
inline

Convert UPI.

Returns
UPI

Definition at line 145 of file JUPI_t.hh.

146 {
147 std::ostringstream os;
148
149 os << *this;
150
151 return os.str();
152 }

◆ ClassDefNV() [1/2]

JDATABASE::JUPI_t::ClassDefNV ( JUPI_t ,
1  )

◆ compare()

static int JDATABASE::JUPI_t::compare ( const std::string & first,
const std::string & second )
inlinestatic

Compare sub-strings.

Parameters
firstfirst string
secondsecond string
Returns
-1, 0, +1 if first sub-string is less, equal, greater than second sub-string

Definition at line 290 of file JUPI_t.hh.

291 {
292 using namespace std;
293
294 const size_t pos = min(first.size(), second.size());
295
296 if (first.substr(0,pos) < second.substr(0,pos))
297 return -1;
298 else if (first.substr(0,pos) > second.substr(0,pos))
299 return +1;
300 else
301 return 0;
302 }

◆ getPBS()

const JPBS_t & JDATABASE::JPBS_t::getPBS ( ) const
inlineinherited

Get PBS.

Returns
PBS

Definition at line 101 of file JPBS_t.hh.

102 {
103 return static_cast<const JPBS_t&>(*this);
104 }

◆ is_valid()

bool JDATABASE::JPBS_t::is_valid ( ) const
inlineinherited

Check validity.

Returns
true if valid; else false

Definition at line 112 of file JPBS_t.hh.

113 {
114 return !this->empty();
115 }

◆ ClassDefNV() [2/2]

JDATABASE::JPBS_t::ClassDefNV ( JPBS_t ,
1  )
inherited

Friends And Related Symbol Documentation

◆ operator==

bool operator== ( const JUPI_t & first,
const JUPI_t & second )
friend

Equality.

Parameters
firstfirst UPI
secondsecond UPI
Returns
true if UPIs are equals; else false

Definition at line 162 of file JUPI_t.hh.

163 {
164 return (first.getPBS() == second.getPBS() &&
165 compare(first .getVariant(),
166 second.getVariant()) == 0 &&
167 first.getVersion() == second.getVersion() &&
168 first.getNumber() == second.getNumber());
169 }
static int compare(const std::string &first, const std::string &second)
Compare sub-strings.
Definition JUPI_t.hh:290
const std::string & getVariant() const
Get variant.
Definition JUPI_t.hh:112

◆ operator<

bool operator< ( const JUPI_t & first,
const JUPI_t & second )
friend

Less-than operator.

Parameters
firstfirst UPI
secondsecond UPI
Returns
true if first UPI less than second UPI; else false

Definition at line 179 of file JUPI_t.hh.

180 {
181 if (first.getPBS() == second.getPBS()) {
182
183 if (compare(first .getVariant(),
184 second.getVariant()) == 0) {
185
186 if (first.getVersion() == second.getVersion())
187 return first.getNumber() < second.getNumber();
188 else
189 return first.getVersion() < second.getVersion();
190
191 } else {
192
193 return (compare(first .getVariant(),
194 second.getVariant()) < 0);
195 }
196
197 } else {
198
199 return first.getPBS() < second.getPBS();
200 }
201 }

◆ operator>>

std::istream & operator>> ( std::istream & in,
JUPI_t & object )
friend

Read UPI from input stream.

Parameters
ininput stream
objectUPI
Returns
input stream

Definition at line 211 of file JUPI_t.hh.

212 {
213 using namespace std;
214
215 object = JUPI_t();
216
217 if (in.peek() != (int) SEPARATOR) {
218 in >> static_cast<JPBS_t&>(object);
219 }
220
221 if (in.get() == (int) SEPARATOR) {
222
223 if (in.peek() == (int) SEPARATOR)
224 in.ignore();
225 else
226 getline(in, object.variant, SEPARATOR);
227
228 if (in.peek() == (int) DOT) {
229
230 in.ignore();
231
232 object.version = DEFAULT_VERSION;
233 object.number = DEFAULT_NUMBER;
234
235 return in;
236
237 } else if (in >> object.version &&
238 in.get() == (int) DOT &&
239 in >> object.number) {
240
241 return in;
242 }
243 }
244
245 in.setstate(ios::failbit);
246
247 return in;
248 }
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition JString.hh:478
static const char DOT
Separator between PBS values.
Definition JPBS_t.hh:33
static const char SEPARATOR
Separator between PBS, variant and version.
Definition JUPI_t.hh:37

◆ operator<<

std::ostream & operator<< ( std::ostream & out,
const JUPI_t & object )
friend

Write UPI to output stream.

Parameters
outoutput stream
objectUPI
Returns
output stream

Definition at line 258 of file JUPI_t.hh.

259 {
260 using namespace std;
261
262 ostringstream os; // allow for width formatting
263
264 os << object.getPBS() << JUPI_t::SEPARATOR
265 << object.getVariant() << JUPI_t::SEPARATOR;
266
267 if (object.getVersion() != DEFAULT_VERSION) {
268 os << object.getVersion();
269 }
270
271 os << JUPI_t::DOT;
272
273 if (object.getNumber() != DEFAULT_NUMBER) {
274 os << object.getNumber();
275 }
276
277 return out << os.str();
278 }
int getVersion() const
Get version.
Definition JUPI_t.hh:123
int getNumber() const
Get serial number.
Definition JUPI_t.hh:134

Member Data Documentation

◆ SEPARATOR

const char JDATABASE::JUPI_t::SEPARATOR = '/'
static

Separator between PBS, variant and version.

Definition at line 37 of file JUPI_t.hh.

◆ DEFAULT_VERSION

const int JDATABASE::JUPI_t::DEFAULT_VERSION = -1
static

Default version.

Definition at line 39 of file JUPI_t.hh.

◆ DEFAULT_NUMBER

const int JDATABASE::JUPI_t::DEFAULT_NUMBER = -1
static

Default number.

Definition at line 40 of file JUPI_t.hh.

◆ variant

std::string JDATABASE::JUPI_t::variant
protected

Definition at line 305 of file JUPI_t.hh.

◆ version

int JDATABASE::JUPI_t::version
protected

Definition at line 306 of file JUPI_t.hh.

◆ number

int JDATABASE::JUPI_t::number
protected

Definition at line 307 of file JUPI_t.hh.

◆ DOT

const char JDATABASE::JPBS_t::DOT = '.'
staticinherited

Separator between PBS values.

Definition at line 33 of file JPBS_t.hh.


The documentation for this struct was generated from the following file: