diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-10-18 07:05:43 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-07-06 07:39:33 +0200 |
commit | 6bb79ef033c2a2e8f12c9da6409e3547af40417c (patch) | |
tree | 6fe6c5bea99cc0b38af92a7aa4714e5614de4868 /src/Version.cpp | |
parent | 4e38f2af2b97850ec5b395d4e0ea8310e664e52f (diff) |
Use ranges for dependency version
Diffstat (limited to 'src/Version.cpp')
-rw-r--r-- | src/Version.cpp | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/Version.cpp b/src/Version.cpp new file mode 100644 index 0000000..26e5dbd --- /dev/null +++ b/src/Version.cpp @@ -0,0 +1,86 @@ +#include "../include/Version.hpp" +#include <cassert> + +namespace sibs +{ + const char* asString(VersionOperation operation) + { + switch(operation) + { + case VersionOperation::LESS: return "<"; + case VersionOperation::LESS_EQUAL: return "<="; + case VersionOperation::EQUAL: return "="; + case VersionOperation::GREATER: return ">"; + case VersionOperation::GREATER_EQUAL: return ">="; + default: return ""; + } + } + + std::string PackageVersion::toString() const + { + std::string result; + result += std::to_string(major); + result += "."; + result += std::to_string(minor); + result += "."; + result += std::to_string(patch); + return result; + } + + std::string PackageVersionRange::toString() const + { + std::string result; + result += asString(startOperation); + result += start.toString(); + if(endDefined) + { + result += " and "; + result += asString(endOperation); + result += end.toString(); + } + return result; + } + + static bool isInRangeOfEnd(const PackageVersionRange &versionRange, const PackageVersion &version) + { + if(!versionRange.endDefined) + return true; + + switch(versionRange.endOperation) + { + case VersionOperation::LESS: + return version < versionRange.end; + case VersionOperation::LESS_EQUAL: + return version <= versionRange.end; + default: + assert(false); + return true; + } + } + + bool PackageVersionRange::isInRange(const PackageVersion &version) const + { + switch(startOperation) + { + case VersionOperation::LESS: + return version < start; + case VersionOperation::LESS_EQUAL: + return version <= start; + case VersionOperation::EQUAL: + return version == start; + case VersionOperation::GREATER: + { + if(version <= start) + return false; + return isInRangeOfEnd(*this, version); + } + case VersionOperation::GREATER_EQUAL: + { + if(version < start) + return false; + return isInRangeOfEnd(*this, version); + } + } + return true; + } +}
\ No newline at end of file |