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