diff options
Diffstat (limited to 'src/version.h')
| -rw-r--r-- | src/version.h | 40 |
1 files changed, 40 insertions, 0 deletions
| diff --git a/src/version.h b/src/version.h new file mode 100644 index 0000000..c45ff53 --- /dev/null +++ b/src/version.h | |||
| @@ -0,0 +1,40 @@ | |||
| 1 | #ifndef VERSION_H_C757E53C | ||
| 2 | #define VERSION_H_C757E53C | ||
| 3 | |||
| 4 | #include <iostream> | ||
| 5 | #include <regex> | ||
| 6 | |||
| 7 | struct Version { | ||
| 8 | int major = 0; | ||
| 9 | int minor = 0; | ||
| 10 | int revision = 0; | ||
| 11 | |||
| 12 | constexpr Version(int major_arg, int minor_arg, int rev_arg) | ||
| 13 | : major(major_arg), minor(minor_arg), revision(rev_arg) {} | ||
| 14 | |||
| 15 | Version(const std::string& ver_str) { | ||
| 16 | const std::regex version_regex("v([0-9]*)\.([0-9]*)\.([0-9]*)"); | ||
| 17 | std::smatch version_match; | ||
| 18 | |||
| 19 | if (std::regex_match(ver_str, version_match, version_regex)) { | ||
| 20 | major = std::atoi(version_match[1].str().c_str()); | ||
| 21 | minor = std::atoi(version_match[2].str().c_str()); | ||
| 22 | revision = std::atoi(version_match[3].str().c_str()); | ||
| 23 | } | ||
| 24 | } | ||
| 25 | |||
| 26 | bool operator<(const Version& rhs) const { | ||
| 27 | return (major < rhs.major) || | ||
| 28 | (major == rhs.major && | ||
| 29 | (minor < rhs.minor || | ||
| 30 | (minor == rhs.minor && revision < rhs.revision))); | ||
| 31 | } | ||
| 32 | }; | ||
| 33 | |||
| 34 | std::ostream& operator<<(std::ostream& out, const Version& ver) { | ||
| 35 | return out << "v" << ver.major << "." << ver.minor << "." << ver.revision; | ||
| 36 | } | ||
| 37 | |||
| 38 | constexpr const Version kTrackerVersion = Version(0, 1, 0); | ||
| 39 | |||
| 40 | #endif /* end of include guard: VERSION_H_C757E53C */ \ No newline at end of file | ||
