20 #ifndef MIRTK_Version_H 21 #define MIRTK_Version_H 23 #include "mirtk/CommonExport.h" 24 #include "mirtk/VersionInfo.h" 26 #include "mirtk/Object.h" 38 mirtkPublicAttributeMacro(
unsigned int, Major);
39 mirtkPublicAttributeMacro(
unsigned int, Minor);
40 mirtkPublicAttributeMacro(
unsigned int, Patch);
45 Version(
unsigned int major = 0u,
46 unsigned int minor = 0u,
47 unsigned int patch = 0u);
50 Version(
int major,
int minor = 0,
int patch = 0);
62 operator bool()
const;
111 inline ostream &operator <<(ostream &os,
const Version &version)
113 os << version.Major() <<
"." << version.Minor();
114 if (version.Patch() != 0u) os <<
"." << version.Patch();
120 inline istream &operator >>(istream &is,
Version &version)
124 while (is.get(c) && (isdigit(c) || c ==
'.')) token.push_back(c);
125 if (is.bad())
return is;
126 if (is.eof()) is.clear(ios::eofbit);
127 istringstream ss(token);
128 unsigned int number[3] = {0u, 0u, 0u};
130 while (getline(ss, token,
'.')) {
131 if (++i == 3 || !
FromString(token.c_str(), number[i])) {
136 if (i == -1) is.setstate(ios::failbit);
138 version.Major(number[0]);
139 version.Minor(number[1]);
140 version.Patch(number[2]);
158 _Major(major), _Minor(minor), _Patch(patch)
165 _Major(major >= 0 ? static_cast<unsigned int>(major) : 0u),
166 _Minor(minor >= 0 ? static_cast<unsigned int>(minor) : 0u),
167 _Patch(patch >= 0 ? static_cast<unsigned int>(patch) : 0u)
174 _Major(0u), _Minor(0u), _Patch(0u)
182 _Major(other._Major), _Minor(other._Minor), _Patch(other._Patch)
189 if (
this != &other) {
190 _Major = other._Major;
191 _Minor = other._Minor;
192 _Patch = other._Patch;
198 inline Version::operator bool()
const 200 return (_Major != 0u || _Minor != 0u || _Patch != 0u);
206 return _Major == rhs._Major && _Minor == rhs._Minor && _Patch == rhs._Patch;
212 return !(*
this == rhs);
219 return bool(*
this) && (!rhs || (_Major < rhs._Major || (_Major == rhs._Major && (_Minor < rhs._Minor || (_Minor == rhs._Minor && _Patch < rhs._Patch)))));
225 return (*
this == rhs) || (*
this < rhs);
232 return !(*
this <= rhs);
238 return (*
this == rhs) || (*
this > rhs);
244 #endif // MIRTK_Version_H bool operator==(const Version &) const
Equality operator.
bool operator>=(const Version &) const
Greater or equal operator.
bool operator<(const Version &) const
Less operator.
Version(unsigned int major=0u, unsigned int minor=0u, unsigned int patch=0u)
Constructor.
MIRTK_Common_EXPORT Version version
Version to emulate.
bool operator!=(const Version &) const
Inequality operator.
bool operator<=(const Version &) const
Less or equal operator.
void PrintVersion(ostream &, const char *=NULL)
Print build time stamp as version string.
bool FromString(const char *str, EnergyMeasure &value)
Convert energy measure string to enumeration value.
void PrintRevision(ostream &)
Print software revision number (or version if not available) only.
Version & operator=(const Version &)
Assignment operator.
const Version current_version(MIRTK_VERSION_MAJOR, MIRTK_VERSION_MINOR, MIRTK_VERSION_PATCH)
Current software version.
bool operator>(const Version &) const
Greater operator.
string ToString() const
Get version information as string.