From 6bb79ef033c2a2e8f12c9da6409e3547af40417c Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 18 Oct 2018 07:05:43 +0200 Subject: Use ranges for dependency version --- include/Version.hpp | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 include/Version.hpp (limited to 'include/Version.hpp') 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 + +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 -- cgit v1.2.3