Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JUPI.hh
Go to the documentation of this file.
1 #ifndef __JDB__JUPI__
2 #define __JDB__JUPI__
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.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 and a variant, seperated by JPBS::SEPARATOR.\n
27  * The ASCII format should therefore read <tt>"<int>[.<int>]+/<variant>"</tt>.\n
28  * The variant cannot start with any kind of white space.
29  */
30  struct JUPI :
31  public JPBS
32  {
33  /**
34  * Default constructor.
35  */
36  JUPI()
37  {}
38 
39 
40  /**
41  * Constructor.
42  *
43  * \param pbs %PBS
44  * \param variant variant
45  */
46  JUPI(const JPBS& pbs, const std::string& variant = "") :
47  JPBS (pbs),
49  {}
50 
51 
52  /**
53  * Constructor.
54  *
55  * \param upi %UPI
56  */
57  JUPI(const std::string& upi)
58  {
59  std::istringstream(upi) >> *this;
60  }
61 
62 
63  /**
64  * Get %UPI.
65  *
66  * \return %UPI
67  */
68  const JUPI& getUPI() const
69  {
70  return static_cast<const JUPI&>(*this);
71  }
72 
73 
74  /**
75  * Get variant.
76  *
77  * \return variant
78  */
79  const std::string& getVariant() const
80  {
81  return variant;
82  }
83 
84 
85  /**
86  * Equality.
87  *
88  * \param first first %UPI
89  * \param second second %UPI
90  * \return true if %UPIs are equals; else false
91  */
92  friend inline bool operator==(const JUPI& first, const JUPI& second)
93  {
94  return (first.getPBS() == second.getPBS() &&
95  first.getVariant() == second.getVariant());
96  }
97 
98 
99  /**
100  * Less-than operator.
101  *
102  * \param first first %UPI
103  * \param second second %UPI
104  * \return true if first %UPI higher in hierarchy or lesser variant; else false
105  */
106  friend inline bool operator<(const JUPI& first, const JUPI& second)
107  {
108  if (first.getPBS() == second.getPBS())
109  return first.getVariant() < second.getVariant();
110  else
111  return first.getPBS() < second.getPBS();
112  }
113 
114 
115  /**
116  * Read %UPI from input stream.
117  *
118  * \param in input stream
119  * \param object %UPI
120  * \return input stream
121  */
122  friend inline std::istream& operator>>(std::istream& in, JUPI& object)
123  {
124  using namespace std;
125 
126  object.variant.clear();
127 
128  if (in >> static_cast<JPBS&>(object)) {
129 
130  if (in.get() == (int) JPBS::SEPARATOR) {
131 
132  const int c = in.peek();
133 
134  if (c != EOF && !isspace(c))
135  in >> object.variant;
136  else
137  in.setstate(ios::failbit);
138 
139  } else {
140 
141  in.setstate(ios::failbit);
142  }
143  }
144 
145  return in;
146  }
147 
148 
149  /**
150  * Write %UPI to output stream.
151  *
152  * \param out output stream
153  * \param object %UPI
154  * \return output stream
155  */
156  friend inline std::ostream& operator<<(std::ostream& out, const JUPI& object)
157  {
158  using namespace std;
159 
160  ostringstream os;
161 
162  os << object.getPBS() << JPBS::SEPARATOR << object.getVariant();
163 
164  return out << os.str();
165  }
166 
167  ClassDefNV(JUPI, 1);
168 
169  protected:
170  std::string variant;
171  };
172 }
173 
174 #endif
JUPI()
Default constructor.
Definition: JUPI.hh:36
const JPBS & getPBS() const
Get PBS.
Definition: JPBS.hh:105
esac print_variable DETECTOR INPUT_FILE OUTPUT_FILE CDF for TYPE in
Definition: JSirene.sh:45
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
std::string variant
Definition: JUPI.hh:170
friend bool operator==(const JUPI &first, const JUPI &second)
Equality.
Definition: JUPI.hh:92
const std::string & getVariant() const
Get variant.
Definition: JUPI.hh:79
ClassDefNV(JUPI, 1)
JUPI(const JPBS &pbs, const std::string &variant="")
Constructor.
Definition: JUPI.hh:46
Product breakdown structure (PBS).
Definition: JPBS.hh:27
friend bool operator<(const JUPI &first, const JUPI &second)
Less-than operator.
Definition: JUPI.hh:106
Universal product identifier (UPI).
Definition: JUPI.hh:30
JUPI(const std::string &upi)
Constructor.
Definition: JUPI.hh:57
friend std::ostream & operator<<(std::ostream &out, const JUPI &object)
Write UPI to output stream.
Definition: JUPI.hh:156
const JUPI & getUPI() const
Get UPI.
Definition: JUPI.hh:68
static const char SEPARATOR
Separator between PBS and variant.
Definition: JPBS.hh:39
friend std::istream & operator>>(std::istream &in, JUPI &object)
Read UPI from input stream.
Definition: JUPI.hh:122