Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
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
9
10
11/**
12 * \author bjung
13 */
14
15namespace JEEP {};
16namespace JPP { using namespace JEEP; }
17
18namespace JEEP {
19
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),
50 {}
51
52
53 /**
54 * Constructor.
55 *
56 * \param major major version
57 * \param minor minor version
58 * \param patch patch version
59 */
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 */
74 JVersion(const std::string& version) :
75 majorVersion(0),
76 minorVersion(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 */
149 std::string toString() const
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
170 version_type version;
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
General puprpose classes and methods.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary data structure for general purpose version number.
static const char SEPARATOR
Separator between [sub-]versions.
version_type getMinorVersion() const
Get minor version.
bool less(const JVersion &version) const
Compare version.
JVersion(const version_type major, const version_type minor, const version_type patch)
Constructor.
unsigned int version_type
Type definition of [sub-]versions.
version_type majorVersion
major version
version_type patchVersion
patch version
JVersion(const std::string &version)
Constructor.
std::string toString() const
Convert version to string.
friend std::ostream & operator<<(std::ostream &out, const JVersion &object)
Write version to output stream.
version_type getPatchVersion() const
Get patch version.
JVersion()
Default constructor.
version_type getMajorVersion() const
Get major version.
version_type minorVersion
minor version
friend std::istream & operator>>(std::istream &in, JVersion &object)
Read version from input stream.
Template definition of auxiliary base class for comparison of data structures.