ESP32-OTA-Updater
Loading...
Searching...
No Matches
SemanticVersion.h
Go to the documentation of this file.
1#ifndef SEMANTIC_VERSION_H_
2#define SEMANTIC_VERSION_H_
3
4#include <stdio.h>
5#include <string.h>
6
17{
18private:
19 int major;
20 int minor;
21 int patch;
23public:
27 Version() : major(0), minor(0), patch(0) {}
28
35 Version(int major, int minor, int patch) : major(major), minor(minor), patch(patch) {}
36
42 Version(const char *version) : major(0), minor(0), patch(0)
43 {
44 if (version != NULL && strlen(version) > 0)
45 {
46 if (version[0] == 'v')
47 {
48 version++; // Skip the 'v' prefix
49 }
50 sscanf(version, "%d.%d.%d", &major, &minor, &patch);
51 }
52 }
53
58 int getMajor() const
59 {
60 return major;
61 }
62
67 int getMinor() const
68 {
69 return minor;
70 }
71
76 int getPatch() const
77 {
78 return patch;
79 }
80
86 bool operator==(const Version &other) const
87 {
88 return (major == other.major && minor == other.minor && patch == other.patch);
89 }
90
96 bool operator!=(const Version &other) const
97 {
98 return !(*this == other);
99 }
100
106 bool operator<(const Version &other) const
107 {
108 if (major < other.major)
109 return true;
110 if (major > other.major)
111 return false;
112 if (minor < other.minor)
113 return true;
114 if (minor > other.minor)
115 return false;
116 return patch < other.patch;
117 }
118
124 bool operator>(const Version &other) const
125 {
126 return other < *this;
127 }
128
134 bool operator<=(const Version &other) const
135 {
136 return !(other < *this);
137 }
138
144 bool operator>=(const Version &other) const
145 {
146 return !(*this < other);
147 }
148};
149
150#endif // SEMANTIC_VERSION_H_
Represents a semantic version.
Definition SemanticVersion.h:17
bool operator!=(const Version &other) const
Checks if this Version object is not equal to another Version object.
Definition SemanticVersion.h:96
bool operator<=(const Version &other) const
Checks if this Version object is less than or equal to another Version object.
Definition SemanticVersion.h:134
bool operator>(const Version &other) const
Checks if this Version object is greater than another Version object.
Definition SemanticVersion.h:124
Version(int major, int minor, int patch)
Constructs a Version object with the specified major, minor, and patch version numbers.
Definition SemanticVersion.h:35
int getMajor() const
Gets the major version number.
Definition SemanticVersion.h:58
int getPatch() const
Gets the patch version number.
Definition SemanticVersion.h:76
bool operator==(const Version &other) const
Checks if this Version object is equal to another Version object.
Definition SemanticVersion.h:86
int getMinor() const
Gets the minor version number.
Definition SemanticVersion.h:67
bool operator>=(const Version &other) const
Checks if this Version object is greater than or equal to another Version object.
Definition SemanticVersion.h:144
Version()
Constructs a Version object with all version numbers set to 0.
Definition SemanticVersion.h:27
Version(const char *version)
Constructs a Version object from a string representation of the version.
Definition SemanticVersion.h:42
bool operator<(const Version &other) const
Checks if this Version object is less than another Version object.
Definition SemanticVersion.h:106