Jpp - the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Jeep/JVersion.hh
Go to the documentation of this file.
1 #ifndef __JEEP_JVERSION__
2 #define __JEEP_JVERSION__
3 
4 #include <istream>
5 #include <ostream>
6 
7 #include "JLang/JException.hh"
8 #include "JLang/JComparable.hh"
9 
10 #include "Jeep/JPrint.hh"
11 
12 
13 /**
14  * \author bjung
15  */
16 
17 namespace JEEP {};
18 namespace JPP { using namespace JEEP; }
19 
20 /**
21  * Auxiliary class for I/O of version number.
22  */
23 namespace JEEP {
24 
25  using JLANG::JComparable;
27 
28 
29  /**
30  * Auxiliary data structure for I/O of version number.
31  */
32  struct JVersion :
33  public JComparable<JVersion>
34  {
35  static const char SEPARATOR = '.';
36 
37  /**
38  * Default constructor.
39  */
41  majorVersion(0),
42  minorVersion(0),
43  patchVersion(0)
44  {}
45 
46 
47  /**
48  * Constructor.
49  *
50  * \param major major version
51  * \param minor minor version
52  * \param patch patch version
53  */
54  JVersion(const int major,
55  const int minor,
56  const int patch) :
57  majorVersion(major),
58  minorVersion(minor),
59  patchVersion(patch)
60  {}
61 
62 
63  /**
64  * Get major version.
65  *
66  * \return major version.
67  */
68  int getMajorVersion() const
69  {
70  return majorVersion;
71  }
72 
73 
74  /**
75  * Get minor version.
76  *
77  * \return minor version.
78  */
79  int getMinorVersion() const
80  {
81  return minorVersion;
82  }
83 
84 
85  /**
86  * Get patch version.
87  *
88  * \return patch version.
89  */
90  int getPatchVersion() const
91  {
92  return patchVersion;
93  }
94 
95 
96  /**
97  * Compare database API version.
98  *
99  * \param object true if this version is less than given version; else false
100  */
101  bool less(const JVersion& object) const
102  {
103  if (this->majorVersion == object.majorVersion) {
104 
105  if (this->minorVersion == object.minorVersion) {
106 
107  return this->patchVersion < object.patchVersion;
108 
109  } else {
110 
111  return this->minorVersion < object.minorVersion;
112  }
113 
114  } else {
115 
116  return this->majorVersion < object.majorVersion;
117  }
118  }
119 
120 
121  /**
122  * Read in version from input stream.
123  *
124  * \param in input stream
125  * \param object database API version
126  * \return input stream
127  */
128  friend inline std::istream& operator>>(std::istream& in, JVersion& object)
129  {
130  using namespace std;
131 
132  unsigned int version;
133 
134  if (in >> version) {
135  object.majorVersion = version;
136  } else {
137  in.setstate(ios::failbit);
138  }
139 
140  if ((in.peek() == (int) JVersion::SEPARATOR) && (in.ignore() && in >> version)) {
141  object.minorVersion = version;
142  } else {
143  in.setstate(ios::failbit);
144  }
145 
146  if ((in.peek() == (int) JVersion::SEPARATOR) && (in.ignore() && in >> version)) {
147  object.patchVersion = version;
148  } else {
149  in.setstate(ios::failbit);
150  }
151 
152  return in;
153  }
154 
155 
156  /**
157  * Write version to output stream.
158  *
159  * \param out output stream
160  * \param object database API version
161  * \return output stream
162  */
163  friend inline std::ostream& operator<<(std::ostream& out, const JVersion& object)
164  {
165  return out <<
166  object.majorVersion << JVersion::SEPARATOR <<
167  object.minorVersion << JVersion::SEPARATOR <<
168  object.patchVersion;
169  }
170 
171 
172  protected:
173 
174  unsigned int majorVersion; //!< API major version
175  unsigned int minorVersion; //!< API minor version
176  unsigned int patchVersion; //!< API patch version
177  };
178 }
179 
180 #endif
int getMajorVersion() const
Get major version.
Exceptions.
unsigned int majorVersion
API major version.
JVersion(const int major, const int minor, const int patch)
Constructor.
friend std::istream & operator>>(std::istream &in, JVersion &object)
Read in version from input stream.
unsigned int minorVersion
API minor version.
int getPatchVersion() const
Get patch version.
int getMinorVersion() const
Get minor version.
friend std::ostream & operator<<(std::ostream &out, const JVersion &object)
Write version to output stream.
I/O formatting auxiliaries.
static const char SEPARATOR
Template definition of auxiliary base class for comparison of data structures.
Definition: JComparable.hh:24
JVersion()
Default constructor.
unsigned int patchVersion
API patch version.
bool less(const JVersion &object) const
Compare database API version.
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:162
Auxiliary data structure for I/O of version number.
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 source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:38
version
Definition: JCalibratePMT.sh:7