aboutsummaryrefslogtreecommitdiff
path: root/include/Version.hpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-10-18 07:05:43 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-06 07:39:33 +0200
commit6bb79ef033c2a2e8f12c9da6409e3547af40417c (patch)
tree6fe6c5bea99cc0b38af92a7aa4714e5614de4868 /include/Version.hpp
parent4e38f2af2b97850ec5b395d4e0ea8310e664e52f (diff)
Use ranges for dependency version
Diffstat (limited to 'include/Version.hpp')
-rw-r--r--include/Version.hpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/include/Version.hpp b/include/Version.hpp
new file mode 100644
index 0000000..915f622
--- /dev/null
+++ b/include/Version.hpp
@@ -0,0 +1,68 @@
+#pragma once
+
+#include <string>
+
+namespace sibs
+{
+ enum class VersionOperation
+ {
+ LESS,
+ LESS_EQUAL,
+ EQUAL,
+ GREATER,
+ GREATER_EQUAL
+ };
+
+ const char* asString(VersionOperation operation);
+
+ struct PackageVersion
+ {
+ int major;
+ int minor;
+ int patch;
+
+ bool operator < (const PackageVersion &other) const
+ {
+ if(major < other.major) return true;
+ if(major == other.major && minor < other.minor) return true;
+ if(major == other.major && minor == other.minor && patch < other.patch) return true;
+ return false;
+ }
+
+ bool operator == (const PackageVersion &other) const
+ {
+ return (major == other.major) && (minor == other.minor) && (patch == other.patch);
+ }
+
+ bool operator <= (const PackageVersion &other) const
+ {
+ return *this < other || *this == other;
+ }
+
+ std::string toString() const;
+ };
+ static_assert(sizeof(PackageVersion) == sizeof(int) * 3, "Expected PackageVersion to be the same size as 3 ints");
+
+ struct PackageVersionRange
+ {
+ PackageVersionRange()
+ {
+ start = { 0, 0, 0 };
+ end = { 0, 0, 0 };
+ startDefined = false;
+ endDefined = false;
+ startOperation = VersionOperation::LESS;
+ endOperation = VersionOperation::LESS;
+ }
+
+ bool isInRange(const PackageVersion &version) const;
+ std::string toString() const;
+
+ PackageVersion start;
+ PackageVersion end;
+ bool startDefined;
+ bool endDefined;
+ VersionOperation startOperation;
+ VersionOperation endOperation;
+ };
+} \ No newline at end of file