Mech-Eye API Reference 2.1.4-alpha
API reference documentation for Mech-Eye 3D Laser Profiler
All Classes Functions Variables Enumerations Enumerator Pages
Version.h
1#pragma once
2#include <string>
3#include <regex>
4#include "api_global.h"
5
6namespace mmind {
7
8namespace eye {
9
10MMIND_API_EXPORT std::string getApiVersionInfo();
11
16{
17public:
18
22 Version() = default;
23
27 Version(int major, int minor, int patch) : _major(major), _minor(minor), _patch(patch) {}
28
32 explicit Version(const std::string& version) { fromString(version); }
33
37 bool operator==(const Version& other) const { return toString() == other.toString(); }
38
42 bool operator!=(const Version& other) const { return !(*this == (other)); }
43
47 bool operator>=(const Version& other) const
48 {
49 return _major > other._major ||
50 (_major == other._major &&
51 (_minor > other._minor || (_minor == other._minor && _patch >= other._patch)));
52 }
53
57 bool operator<(const Version& other) const { return !(*this >= (other)); }
58
62 bool operator<=(const Version& other) const { return *this < other || *this == other; }
63
67 std::string toString() const
68 {
69 char buff[16] = {0};
70 snprintf(buff, sizeof(buff), "%d.%d.%d", _major, _minor, _patch);
71 return buff;
72 }
73
77 void fromString(const std::string& version)
78 {
79 std::regex rege(R"((\d+).(\d+).(\d+))");
80 std::smatch result;
81 if (std::regex_search(version, result, rege)) {
82 _major = std::stoi(result.str(1));
83 _minor = std::stoi(result.str(2));
84 _patch = std::stoi(result.str(3));
85 }
86 }
87
91 bool isEmpty() const { return *this == Version(); }
92
93private:
94 int _major = 0;
95 int _minor = 0;
96 int _patch = 0;
97};
98} // namespace eye
99
100} // namespace mmind
Version information.
Definition Version.h:16
Version(const std::string &version)
Constructor with a string input parameter.
Definition Version.h:32
bool operator==(const Version &other) const
Overloads the == operator to determine if two Version objects are equal.
Definition Version.h:37
Version()=default
Default constructor.
void fromString(const std::string &version)
Converts a string of version to a Version object.
Definition Version.h:77
bool operator!=(const Version &other) const
Overloads the != operator to determine if two Version objects are unequal.
Definition Version.h:42
bool operator<=(const Version &other) const
Overloads the <= operator to determine if one Version object is smaller than or equal to another.
Definition Version.h:62
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:47
std::string toString() const
Converts a Version object to string.
Definition Version.h:67
bool operator<(const Version &other) const
Overloads the < operator to determine if one Version object is smaller than the other.
Definition Version.h:57
bool isEmpty() const
Checks if a Version object is empty.
Definition Version.h:91
Version(int major, int minor, int patch)
Constructor with three integer input parameters.
Definition Version.h:27