format ContentPackVersion
This commit is contained in:
@@ -37,7 +37,8 @@ DependencyVersionOperator Version::string_to_operator(const std::string& op) {
|
|||||||
return DependencyVersionOperator::more_or_equal;
|
return DependencyVersionOperator::more_or_equal;
|
||||||
else if (op == "<=" || op == "=<")
|
else if (op == "<=" || op == "=<")
|
||||||
return DependencyVersionOperator::less_or_equal;
|
return DependencyVersionOperator::less_or_equal;
|
||||||
else return DependencyVersionOperator::equal;
|
else
|
||||||
|
return DependencyVersionOperator::equal;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isNumber(const std::string& s) {
|
bool isNumber(const std::string& s) {
|
||||||
|
|||||||
@@ -3,49 +3,55 @@
|
|||||||
#include "content/ContentPack.hpp"
|
#include "content/ContentPack.hpp"
|
||||||
|
|
||||||
class Version {
|
class Version {
|
||||||
public:
|
public:
|
||||||
int major;
|
int major;
|
||||||
int minor;
|
int minor;
|
||||||
int patch;
|
int patch;
|
||||||
|
|
||||||
Version(const std::string& version);
|
Version(const std::string& version);
|
||||||
|
|
||||||
bool operator==(const Version& other) const {
|
bool operator==(const Version& other) const {
|
||||||
return major == other.major && minor == other.minor && patch == other.patch;
|
return major == other.major && minor == other.minor &&
|
||||||
|
patch == other.patch;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator<(const Version& other) const {
|
||||||
|
if (major != other.major) return major < other.major;
|
||||||
|
if (minor != other.minor) return minor < other.minor;
|
||||||
|
return patch < other.patch;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator>(const Version& other) const {
|
||||||
|
return other < *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator>=(const Version& other) const {
|
||||||
|
return !(*this < other);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator<=(const Version& other) const {
|
||||||
|
return !(*this > other);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool process_operator(const std::string& op, const Version& other) const {
|
||||||
|
auto dep_op = Version::string_to_operator(op);
|
||||||
|
|
||||||
|
switch (dep_op) {
|
||||||
|
case DependencyVersionOperator::equal:
|
||||||
|
return *this == other;
|
||||||
|
case DependencyVersionOperator::more:
|
||||||
|
return *this > other;
|
||||||
|
case DependencyVersionOperator::less:
|
||||||
|
return *this < other;
|
||||||
|
case DependencyVersionOperator::less_or_equal:
|
||||||
|
return *this <= other;
|
||||||
|
case DependencyVersionOperator::more_or_equal:
|
||||||
|
return *this >= other;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool operator<(const Version& other) const {
|
static DependencyVersionOperator string_to_operator(const std::string& op);
|
||||||
if (major != other.major) return major < other.major;
|
static bool matches_pattern(const std::string& version);
|
||||||
if (minor != other.minor) return minor < other.minor;
|
|
||||||
return patch < other.patch;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool operator>(const Version& other) const {
|
|
||||||
return other < *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator>=(const Version& other) const {
|
|
||||||
return !(*this < other);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator<=(const Version& other) const {
|
|
||||||
return !(*this > other);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool process_operator(const std::string& op, const Version& other) const {
|
|
||||||
auto dep_op = Version::string_to_operator(op);
|
|
||||||
|
|
||||||
switch(dep_op) {
|
|
||||||
case DependencyVersionOperator::equal: return *this == other;
|
|
||||||
case DependencyVersionOperator::more: return *this > other;
|
|
||||||
case DependencyVersionOperator::less: return *this < other;
|
|
||||||
case DependencyVersionOperator::less_or_equal: return *this <= other;
|
|
||||||
case DependencyVersionOperator::more_or_equal: return *this >= other;
|
|
||||||
default: return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static DependencyVersionOperator string_to_operator(const std::string& op);
|
|
||||||
static bool matches_pattern(const std::string& version);
|
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user