Jpp  15.0.4
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/JComparable.hh"
8 
9 
10 /**
11  * \author bjung
12  */
13 
14 namespace JEEP {};
15 namespace JPP { using namespace JEEP; }
16 
17 namespace JEEP {
18 
19  using JLANG::JComparable;
20 
21  /**
22  * Auxiliary data structure for general purpose version number.
23  *
24  * A version consists of a major, minor and patch number.\n
25  * The I/O format is <major>.<minor>.<patch>.
26  */
27  struct JVersion :
28  public JComparable<JVersion>
29  {
30  /**
31  * Type definition of [sub-]versions.
32  */
33  typedef unsigned int version_type;
34 
35 
36  /**
37  * Separator between [sub-]versions.
38  */
39  static const char SEPARATOR = '.';
40 
41 
42  /**
43  * Default constructor.
44  */
46  majorVersion(0),
47  minorVersion(0),
48  patchVersion(0)
49  {}
50 
51 
52  /**
53  * Constructor.
54  *
55  * \param major major version
56  * \param minor minor version
57  * \param patch patch version
58  */
59  JVersion(const version_type major,
60  const version_type minor,
61  const version_type patch) :
62  majorVersion(major),
63  minorVersion(minor),
64  patchVersion(patch)
65  {}
66 
67 
68  /**
69  * Get major version.
70  *
71  * \return major version.
72  */
74  {
75  return majorVersion;
76  }
77 
78 
79  /**
80  * Get minor version.
81  *
82  * \return minor version.
83  */
85  {
86  return minorVersion;
87  }
88 
89 
90  /**
91  * Get patch version.
92  *
93  * \return patch version.
94  */
96  {
97  return patchVersion;
98  }
99 
100 
101  /**
102  * Compare version.
103  *
104  * \param version version
105  * \return true if this version is less than given version; else false
106  */
107  bool less(const JVersion& version) const
108  {
109  if (this->majorVersion == version.majorVersion) {
110 
111  if (this->minorVersion == version.minorVersion) {
112 
113  return this->patchVersion < version.patchVersion;
114 
115  } else {
116 
117  return this->minorVersion < version.minorVersion;
118  }
119 
120  } else {
121 
122  return this->majorVersion < version.majorVersion;
123  }
124  }
125 
126 
127  /**
128  * Read version from input stream.
129  *
130  * \param in input stream
131  * \param object version
132  * \return input stream
133  */
134  friend inline std::istream& operator>>(std::istream& in, JVersion& object)
135  {
136  using namespace std;
137 
139 
140  if (in >> version) {
141  object.majorVersion = version;
142  } else {
143  in.setstate(ios::failbit);
144  }
145 
146  if ((in.peek() == (int) JVersion::SEPARATOR) && (in.ignore() && in >> version)) {
147  object.minorVersion = version;
148  } else {
149  in.setstate(ios::failbit);
150  }
151 
152  if ((in.peek() == (int) JVersion::SEPARATOR) && (in.ignore() && in >> version)) {
153  object.patchVersion = version;
154  } else {
155  in.setstate(ios::failbit);
156  }
157 
158  return in;
159  }
160 
161 
162  /**
163  * Write version to output stream.
164  *
165  * \param out output stream
166  * \param object version
167  * \return output stream
168  */
169  friend inline std::ostream& operator<<(std::ostream& out, const JVersion& object)
170  {
171  return out <<
172  object.majorVersion << JVersion::SEPARATOR <<
173  object.minorVersion << JVersion::SEPARATOR <<
174  object.patchVersion;
175  }
176 
177 
178  protected:
179 
180  version_type majorVersion; //!< major version
181  version_type minorVersion; //!< minor version
182  version_type patchVersion; //!< patch version
183  };
184 }
185 
186 #endif
version_type minorVersion
minor version
friend std::istream & operator>>(std::istream &in, JVersion &object)
Read version from input stream.
version_type getMajorVersion() const
Get major version.
JVersion(const version_type major, const version_type minor, const version_type patch)
Constructor.
version_type majorVersion
major version
friend std::ostream & operator<<(std::ostream &out, const JVersion &object)
Write version to output stream.
static const char SEPARATOR
Separator between [sub-]versions.
unsigned int version_type
Type definition of [sub-]versions.
version_type patchVersion
patch version
Template definition of auxiliary base class for comparison of data structures.
Definition: JComparable.hh:24
JVersion()
Default constructor.
bool less(const JVersion &version) const
Compare version.
version_type getMinorVersion() const
Get minor version.
Auxiliary data structure for general purpose 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:41
version_type getPatchVersion() const
Get patch version.
version
Definition: JCalibratePMT.sh:7