Jpp
Public Member Functions | Static Public Attributes | Protected Attributes | Friends | List of all members
JDATABASE::JUPI Struct Reference

Universal product identifier (UPI). More...

#include <JUPI.hh>

Inheritance diagram for JDATABASE::JUPI:
JDATABASE::JPBS JLANG::JEquals< JUPI > std::vector< int > JLANG::JEquals< JPBS >

Public Member Functions

 JUPI ()
 Default constructor. More...
 
 JUPI (const JPBS &pbs, const std::string &variant="")
 Constructor. More...
 
 JUPI (const std::string &upi)
 Constructor. More...
 
const JUPIgetUPI () const
 Get UPI. More...
 
const std::string & getVariant () const
 Get variant. More...
 
bool equals (const JUPI &upi) const
 Equality. More...
 
const JPBSgetPBS () const
 Get PBS. More...
 
bool is_valid () const
 Check validity. More...
 
bool equals (const JPBS &pbs) const
 Equality. More...
 

Static Public Attributes

static const char DOT = '.'
 Separator between PBS values. More...
 
static const char SEPARATOR = '/'
 Separator between PBS and variant. More...
 

Protected Attributes

std::string variant
 

Friends

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

Detailed Description

Universal product identifier (UPI).

The UPI consists of a PBS and a variant, seperated by JPBS::SEPARATOR.
The ASCII format should therefore read "<int>[.<int>]+/<variant>".
The variant cannot start with any kind of white space.

Definition at line 29 of file JUPI.hh.

Constructor & Destructor Documentation

◆ JUPI() [1/3]

JDATABASE::JUPI::JUPI ( )
inline

Default constructor.

Definition at line 36 of file JUPI.hh.

37  {}

◆ JUPI() [2/3]

JDATABASE::JUPI::JUPI ( const JPBS pbs,
const std::string &  variant = "" 
)
inline

Constructor.

Parameters
pbsPBS
variantvariant

Definition at line 46 of file JUPI.hh.

46  :
47  JPBS (pbs),
49  {}

◆ JUPI() [3/3]

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

Constructor.

Parameters
upiUPI

Definition at line 57 of file JUPI.hh.

58  {
59  std::istringstream(upi) >> *this;
60  }

Member Function Documentation

◆ getUPI()

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

Get UPI.

Returns
UPI

Definition at line 68 of file JUPI.hh.

69  {
70  return static_cast<const JUPI&>(*this);
71  }

◆ getVariant()

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

Get variant.

Returns
variant

Definition at line 79 of file JUPI.hh.

80  {
81  return variant;
82  }

◆ equals() [1/2]

bool JDATABASE::JUPI::equals ( const JUPI upi) const
inline

Equality.

Parameters
upiUPI
Returns
true if UPIs are equals; else false

Definition at line 91 of file JUPI.hh.

92  {
93  return (this->getPBS() == upi.getPBS() &&
94  this->getVariant() == upi.getVariant());
95  }

◆ getPBS()

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

Get PBS.

Returns
PBS

Definition at line 106 of file JPBS.hh.

107  {
108  return static_cast<const JPBS&>(*this);
109  }

◆ is_valid()

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

Check validity.

Returns
true if valid; else false

Definition at line 117 of file JPBS.hh.

118  {
119  return !this->empty();
120  }

◆ equals() [2/2]

bool JDATABASE::JPBS::equals ( const JPBS pbs) const
inlineinherited

Equality.

Parameters
pbsPBS
Returns
true if PBS is equal; else false

Definition at line 129 of file JPBS.hh.

130  {
131  if (this->size() == pbs.size()) {
132 
133  for (const_iterator p = this->begin(), q = pbs.begin(); p != this->end(); ++p, ++q) {
134  if (*p != *q) {
135  return false;
136  }
137  }
138 
139  return true;
140  }
141 
142  return false;
143  }

Friends And Related Function Documentation

◆ operator<

bool operator< ( const JUPI first,
const JUPI second 
)
friend

Less-than operator.

Parameters
firstfirst UPI
secondsecond UPI
Returns
true if first UPI higher in hierarchy or lesser variant; else false

Definition at line 105 of file JUPI.hh.

106  {
107  if (first.getPBS() == second.getPBS())
108  return first.getVariant() < second.getVariant();
109  else
110  return first.getPBS() < second.getPBS();
111  }

◆ operator>>

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

Read UPI from input stream.

Parameters
ininput stream
objectUPI
Returns
input stream

Definition at line 121 of file JUPI.hh.

122  {
123  using namespace std;
124 
125  object.variant.clear();
126 
127  if (in >> static_cast<JPBS&>(object)) {
128 
129  if (in.get() == (int) JPBS::SEPARATOR) {
130 
131  const int c = in.peek();
132 
133  if (c != EOF && !isspace(c))
134  in >> object.variant;
135  else
136  in.setstate(ios::failbit);
137 
138  } else {
139 
140  in.setstate(ios::failbit);
141  }
142  }
143 
144  return in;
145  }

◆ operator<<

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

Write UPI to output stream.

Parameters
outoutput stream
objectUPI
Returns
output stream

Definition at line 155 of file JUPI.hh.

156  {
157  return out << object.getPBS() << JPBS::SEPARATOR << object.getVariant();
158  }

Member Data Documentation

◆ variant

std::string JDATABASE::JUPI::variant
protected

Definition at line 161 of file JUPI.hh.

◆ DOT

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

Separator between PBS values.

Definition at line 34 of file JPBS.hh.

◆ SEPARATOR

const char JDATABASE::JPBS::SEPARATOR = '/'
staticinherited

Separator between PBS and variant.

Definition at line 40 of file JPBS.hh.


The documentation for this struct was generated from the following file:
JDATABASE::JUPI::variant
std::string variant
Definition: JUPI.hh:161
JDATABASE::JPBS::SEPARATOR
static const char SEPARATOR
Separator between PBS and variant.
Definition: JPBS.hh:40
std
Definition: jaanetDictionary.h:36
JDATABASE::JUPI::getVariant
const std::string & getVariant() const
Get variant.
Definition: JUPI.hh:79
JDATABASE::JPBS::getPBS
const JPBS & getPBS() const
Get PBS.
Definition: JPBS.hh:106
JDATABASE::JPBS::JPBS
JPBS()
Default constructor.
Definition: JPBS.hh:46