Jpp  18.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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  */
18 namespace JDATABASE {}
19 namespace JPP { using namespace JDATABASE; }
20 
21 namespace 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>.
28  */
29  struct JUPI_t :
30  public JPBS_t
31  {
32  /**
33  * Separator between %PBS, variant and version.
34  */
35  static const char SEPARATOR = '/';
36 
37 
38  /**
39  * Default constructor.
40  */
41  JUPI_t() :
42  JPBS_t (),
43  variant(),
44  version(-1),
45  number (-1)
46  {}
47 
48 
49  /**
50  * Constructor.
51  *
52  * \param pbs %PBS
53  */
54  JUPI_t(const JPBS_t& pbs) :
55  JPBS_t (pbs),
56  variant(),
57  version(-1),
58  number (-1)
59  {}
60 
61 
62  /**
63  * Constructor.
64  *
65  * \param pbs %PBS
66  * \param variant variant
67  * \param version version
68  * \param number serial number
69  */
70  JUPI_t(const JPBS_t& pbs,
71  const std::string& variant,
72  const int version,
73  const int number) :
74  JPBS_t (pbs),
75  variant(variant),
76  version(version),
77  number (number)
78  {}
79 
80 
81  /**
82  * Constructor.
83  *
84  * \param upi %UPI
85  */
86  JUPI_t(const std::string& upi)
87  {
88  std::istringstream(upi) >> *this;
89  }
90 
91 
92  /**
93  * Get %UPI.
94  *
95  * \return %UPI
96  */
97  const JUPI_t& getUPI() const
98  {
99  return static_cast<const JUPI_t&>(*this);
100  }
101 
102 
103  /**
104  * Get variant.
105  *
106  * \return variant
107  */
108  const std::string& getVariant() const
109  {
110  return variant;
111  }
112 
113 
114  /**
115  * Get version.
116  *
117  * \return version
118  */
119  int getVersion() const
120  {
121  return version;
122  }
123 
124 
125  /**
126  * Get serial number.
127  *
128  * \return serial number
129  */
130  int getNumber() const
131  {
132  return number;
133  }
134 
135 
136  /**
137  * Convert %UPI.
138  *
139  * \return %UPI
140  */
142  {
143  std::ostringstream os;
144 
145  os << *this;
146 
147  return os.str();
148  }
149 
150 
151  /**
152  * Equality.
153  *
154  * \param first first %UPI
155  * \param second second %UPI
156  * \return true if %UPIs are equals; else false
157  */
158  friend inline bool operator==(const JUPI_t& first, const JUPI_t& second)
159  {
160  return (first.getPBS() == second.getPBS() &&
161  first.getVariant() == second.getVariant() &&
162  first.getVersion() == second.getVersion() &&
163  first.getNumber() == second.getNumber());
164  }
165 
166 
167  /**
168  * Less-than operator.
169  *
170  * \param first first %UPI
171  * \param second second %UPI
172  * \return true if first %UPI less then second %UPI; else false
173  */
174  friend inline bool operator<(const JUPI_t& first, const JUPI_t& second)
175  {
176  if (first.getPBS() == second.getPBS()) {
177 
178  if (first.getVariant() == second.getVariant()) {
179 
180  if (first.getVersion() == second.getVersion())
181  return first.getNumber() < second.getNumber();
182  else
183  return first.getVersion() < second.getVersion();
184 
185  } else {
186 
187  return first.getVariant() < second.getVariant();
188  }
189 
190  } else {
191 
192  return first.getPBS() < second.getPBS();
193  }
194  }
195 
196 
197  /**
198  * Read %UPI from input stream.
199  *
200  * \param in input stream
201  * \param object %UPI
202  * \return input stream
203  */
204  friend inline std::istream& operator>>(std::istream& in, JUPI_t& object)
205  {
206  using namespace std;
207 
208  object = JUPI_t();
209 
210  if (in >> static_cast<JPBS_t&>(object)) {
211 
212  if (!(in.get() == (int) SEPARATOR &&
213  getline(in, object.variant, SEPARATOR) &&
214  in >> object.version &&
215  in.get() == (int) DOT &&
216  in >> object.number)) {
217 
218  in.setstate(ios::failbit);
219  }
220  }
221 
222  return in;
223  }
224 
225 
226  /**
227  * Write %UPI to output stream.
228  *
229  * \param out output stream
230  * \param object %UPI
231  * \return output stream
232  */
233  friend inline std::ostream& operator<<(std::ostream& out, const JUPI_t& object)
234  {
235  using namespace std;
236 
237  ostringstream os; // allow for width formatting
238 
239  os << object.getPBS() << JUPI_t::SEPARATOR
240  << object.getVariant() << JUPI_t::SEPARATOR
241  << object.getVersion() << JUPI_t::DOT
242  << object.getNumber();
243 
244  return out << os.str();
245  }
246 
247  ClassDefNV(JUPI_t, 1);
248 
249  protected:
251  int version;
252  int number;
253  };
254 }
255 
256 #endif
JUPI_t(const std::string &upi)
Constructor.
Definition: JUPI_t.hh:86
int getNumber() const
Get serial number.
Definition: JUPI_t.hh:130
const std::string & getVariant() const
Get variant.
Definition: JUPI_t.hh:108
JUPI_t(const JPBS_t &pbs, const std::string &variant, const int version, const int number)
Constructor.
Definition: JUPI_t.hh:70
ClassDefNV(JUPI_t, 1)
Universal product identifier (UPI).
Definition: JUPI_t.hh:29
static const char SEPARATOR
Separator between PBS, variant and version.
Definition: JUPI_t.hh:35
std::string variant
Definition: JUPI_t.hh:250
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
const JPBS_t & getPBS() const
Get PBS.
Definition: JPBS_t.hh:101
const JUPI_t & getUPI() const
Get UPI.
Definition: JUPI_t.hh:97
friend std::istream & operator>>(std::istream &in, JUPI_t &object)
Read UPI from input stream.
Definition: JUPI_t.hh:204
int getVersion() const
Get version.
Definition: JUPI_t.hh:119
JUPI_t()
Default constructor.
Definition: JUPI_t.hh:41
JUPI_t(const JPBS_t &pbs)
Constructor.
Definition: JUPI_t.hh:54
friend bool operator<(const JUPI_t &first, const JUPI_t &second)
Less-than operator.
Definition: JUPI_t.hh:174
then awk string
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:478
friend bool operator==(const JUPI_t &first, const JUPI_t &second)
Equality.
Definition: JUPI_t.hh:158
std::string toString() const
Convert UPI.
Definition: JUPI_t.hh:141
Product breakdown structure (PBS).
Definition: JPBS_t.hh:27
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
static const char DOT
Separator between PBS values.
Definition: JPBS_t.hh:33
friend std::ostream & operator<<(std::ostream &out, const JUPI_t &object)
Write UPI to output stream.
Definition: JUPI_t.hh:233