Mech-Eye API 2.4.0
API reference documentation for Mech-Eye 3D Laser Profiler
Loading...
Searching...
No Matches
Version.h
1#pragma once
2#include <string>
3#include <regex>
4#include "api_global.h"
5
6namespace mmind {
7
8namespace eye {
9
13MMIND_API_EXPORT std::string getApiVersionInfo();
14
19{
20public:
24 Version() = default;
25
29 Version(int major, int minor, int patch) : _major(major), _minor(minor), _patch(patch) {}
30
34 explicit Version(const std::string& version) { fromString(version); }
35
39 bool operator==(const Version& other) const { return toString() == other.toString(); }
40
44 bool operator!=(const Version& other) const { return !(*this == (other)); }
45
50 bool operator>=(const Version& other) const
51 {
52 return _major > other._major ||
53 (_major == other._major &&
54 (_minor > other._minor || (_minor == other._minor && _patch >= other._patch)));
55 }
56
60 bool operator<(const Version& other) const { return !(*this >= (other)); }
61
66 bool operator<=(const Version& other) const { return *this < other || *this == other; }
67
71 std::string toString() const
72 {
73 char buff[16] = {0};
74 snprintf(buff, sizeof(buff), "%d.%d.%d", _major, _minor, _patch);
75 return buff;
76 }
77
81 void fromString(const std::string& version)
82 {
83 std::regex rege(R"((\d+).(\d+).(\d+))");
84 std::smatch result;
85 if (std::regex_search(version, result, rege)) {
86 _major = std::stoi(result.str(1));
87 _minor = std::stoi(result.str(2));
88 _patch = std::stoi(result.str(3));
89 }
90 }
91
95 bool isEmpty() const { return *this == Version(); }
96
97private:
98 int _major = 0;
99 int _minor = 0;
100 int _patch = 0;
101};
102} // namespace eye
103
104} // namespace mmind
Describes the version information.
Definition Version.h:19
Version(const std::string &version)
Constructor.
Definition Version.h:34
bool operator==(const Version &other) const
Overloads the == operator to determine if two Version objects are equal.
Definition Version.h:39
Version()=default
Default constructor.
void fromString(const std::string &version)
Converts a version in the string format to a Version object.
Definition Version.h:81
bool operator!=(const Version &other) const
Overloads the != operator to determine if two Version objects are unequal.
Definition Version.h:44
bool operator<=(const Version &other) const
Overloads the <= operator to determine if one Version object is smaller than or equal to the other.
Definition Version.h:66
bool operator>=(const Version &other) const
Overloads the >= operator to determine if one Version object is greater than or equal to the other.
Definition Version.h:50
std::string toString() const
Converts a Version object to a string.
Definition Version.h:71
bool operator<(const Version &other) const
Overloads the < operator to determine if one Version object is smaller than the other.
Definition Version.h:60
bool isEmpty() const
Checks if a Version object is empty.
Definition Version.h:95
Version(int major, int minor, int patch)
Constructor.
Definition Version.h:29