mirror of
https://github.com/vcmi/vcmi.git
synced 2025-04-23 12:08:45 +02:00
Support partial versions
This commit is contained in:
parent
ea7ab9d5ed
commit
e9ba1d73d1
@ -20,9 +20,9 @@ CModVersion CModVersion::GameVersion()
|
|||||||
|
|
||||||
CModVersion CModVersion::fromString(std::string from)
|
CModVersion CModVersion::fromString(std::string from)
|
||||||
{
|
{
|
||||||
int major = 0;
|
int major = Any;
|
||||||
int minor = 0;
|
int minor = Any;
|
||||||
int patch = 0;
|
int patch = Any;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
auto pointPos = from.find('.');
|
auto pointPos = from.find('.');
|
||||||
@ -45,11 +45,29 @@ CModVersion CModVersion::fromString(std::string from)
|
|||||||
|
|
||||||
std::string CModVersion::toString() const
|
std::string CModVersion::toString() const
|
||||||
{
|
{
|
||||||
return std::to_string(major) + '.' + std::to_string(minor) + '.' + std::to_string(patch);
|
std::string res;
|
||||||
|
if(major != Any)
|
||||||
|
{
|
||||||
|
res += std::to_string(major);
|
||||||
|
if(minor != Any)
|
||||||
|
{
|
||||||
|
res += '.' + std::to_string(minor);
|
||||||
|
if(patch != Any)
|
||||||
|
res += '.' + std::to_string(patch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CModVersion::compatible(const CModVersion & other, bool checkMinor, bool checkPatch) const
|
bool CModVersion::compatible(const CModVersion & other, bool checkMinor, bool checkPatch) const
|
||||||
{
|
{
|
||||||
|
if(minor == Any || other.minor == Any)
|
||||||
|
checkMinor = false;
|
||||||
|
if(patch == Any || other.patch == Any)
|
||||||
|
checkPatch = false;
|
||||||
|
|
||||||
|
assert(checkMinor || !checkPatch);
|
||||||
|
|
||||||
return (major == other.major &&
|
return (major == other.major &&
|
||||||
(!checkMinor || minor >= other.minor) &&
|
(!checkMinor || minor >= other.minor) &&
|
||||||
(!checkPatch || minor > other.minor || (minor == other.minor && patch >= other.patch)));
|
(!checkPatch || minor > other.minor || (minor == other.minor && patch >= other.patch)));
|
||||||
@ -57,11 +75,12 @@ bool CModVersion::compatible(const CModVersion & other, bool checkMinor, bool ch
|
|||||||
|
|
||||||
bool CModVersion::isNull() const
|
bool CModVersion::isNull() const
|
||||||
{
|
{
|
||||||
return major == 0 && minor == 0 && patch == 0;
|
return major == Any;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator < (const CModVersion & lesser, const CModVersion & greater)
|
bool operator < (const CModVersion & lesser, const CModVersion & greater)
|
||||||
{
|
{
|
||||||
|
//specific is "greater" than non-specific, that's why do not check for Any value
|
||||||
if(lesser.major == greater.major)
|
if(lesser.major == greater.major)
|
||||||
{
|
{
|
||||||
if(lesser.minor == greater.minor)
|
if(lesser.minor == greater.minor)
|
||||||
|
@ -20,9 +20,11 @@ VCMI_LIB_NAMESPACE_BEGIN
|
|||||||
|
|
||||||
struct DLL_LINKAGE CModVersion
|
struct DLL_LINKAGE CModVersion
|
||||||
{
|
{
|
||||||
int major = 0;
|
static const int Any = -1;
|
||||||
int minor = 0;
|
|
||||||
int patch = 0;
|
int major = Any;
|
||||||
|
int minor = Any;
|
||||||
|
int patch = Any;
|
||||||
|
|
||||||
CModVersion() = default;
|
CModVersion() = default;
|
||||||
CModVersion(int mj, int mi, int p): major(mj), minor(mi), patch(p) {}
|
CModVersion(int mj, int mi, int p): major(mj), minor(mi), patch(p) {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user