Fixed version number comparison bug and a little tidying
This commit is contained in:
@@ -347,9 +347,9 @@ namespace Bloom
|
|||||||
std::cout << QJsonDocument(QJsonObject({
|
std::cout << QJsonDocument(QJsonObject({
|
||||||
{"version", QString::fromStdString(Application::VERSION.toString())},
|
{"version", QString::fromStdString(Application::VERSION.toString())},
|
||||||
{"components", QJsonObject({
|
{"components", QJsonObject({
|
||||||
{"major", Application::VERSION.getMajor()},
|
{"major", Application::VERSION.major},
|
||||||
{"minor", Application::VERSION.getMinor()},
|
{"minor", Application::VERSION.minor},
|
||||||
{"patch", Application::VERSION.getPatch()},
|
{"patch", Application::VERSION.patch},
|
||||||
})},
|
})},
|
||||||
})).toJson().toStdString();
|
})).toJson().toStdString();
|
||||||
|
|
||||||
|
|||||||
@@ -32,9 +32,9 @@ namespace Bloom::DebugServer::Gdb::CommandPackets
|
|||||||
QJsonDocument(QJsonObject({
|
QJsonDocument(QJsonObject({
|
||||||
{"version", QString::fromStdString(Application::VERSION.toString())},
|
{"version", QString::fromStdString(Application::VERSION.toString())},
|
||||||
{"components", QJsonObject({
|
{"components", QJsonObject({
|
||||||
{"major", Application::VERSION.getMajor()},
|
{"major", Application::VERSION.major},
|
||||||
{"minor", Application::VERSION.getMinor()},
|
{"minor", Application::VERSION.minor},
|
||||||
{"patch", Application::VERSION.getPatch()},
|
{"patch", Application::VERSION.patch},
|
||||||
})},
|
})},
|
||||||
})).toJson().toStdString()
|
})).toJson().toStdString()
|
||||||
)));
|
)));
|
||||||
|
|||||||
@@ -8,24 +8,18 @@ namespace Bloom
|
|||||||
: major{major}
|
: major{major}
|
||||||
, minor{minor}
|
, minor{minor}
|
||||||
, patch{patch}
|
, patch{patch}
|
||||||
{
|
{}
|
||||||
this->combined = static_cast<std::uint32_t>(
|
|
||||||
std::stoul(std::to_string(this->major) + std::to_string(this->minor) + std::to_string(this->patch))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
VersionNumber::VersionNumber(const std::string& versionNumber)
|
VersionNumber::VersionNumber(const std::string& versionNumber)
|
||||||
: VersionNumber(QString::fromStdString(versionNumber))
|
: VersionNumber(QString::fromStdString(versionNumber))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
VersionNumber::VersionNumber(QString versionNumber) {
|
VersionNumber::VersionNumber(const QString& versionNumber) {
|
||||||
const auto explodedString = versionNumber.split('.');
|
const auto explodedString = versionNumber.split('.');
|
||||||
|
|
||||||
this->major = explodedString.value(0, "0").toUShort();
|
this->major = explodedString.value(0, "0").toUShort();
|
||||||
this->minor = explodedString.value(1, "0").toUShort();
|
this->minor = explodedString.value(1, "0").toUShort();
|
||||||
this->patch = explodedString.value(2, "0").toUShort();
|
this->patch = explodedString.value(2, "0").toUShort();
|
||||||
|
|
||||||
this->combined = versionNumber.remove('.').toUInt();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string VersionNumber::toString() const {
|
std::string VersionNumber::toString() const {
|
||||||
|
|||||||
@@ -9,57 +9,44 @@ namespace Bloom
|
|||||||
class VersionNumber
|
class VersionNumber
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
std::uint16_t major = 0;
|
||||||
|
std::uint16_t minor = 0;
|
||||||
|
std::uint16_t patch = 0;
|
||||||
|
|
||||||
VersionNumber(std::uint16_t major, std::uint16_t minor, std::uint16_t patch);
|
VersionNumber(std::uint16_t major, std::uint16_t minor, std::uint16_t patch);
|
||||||
VersionNumber(const std::string& versionNumber);
|
VersionNumber(const std::string& versionNumber);
|
||||||
VersionNumber(QString versionNumber);
|
VersionNumber(const QString& versionNumber);
|
||||||
|
|
||||||
std::string toString() const;
|
std::string toString() const;
|
||||||
|
|
||||||
[[nodiscard]] std::uint16_t getMajor() const {
|
|
||||||
return this->major;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] std::uint16_t getMinor() const {
|
|
||||||
return this->minor;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] std::uint16_t getPatch() const {
|
|
||||||
return this->patch;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator == (const VersionNumber& other) const {
|
bool operator == (const VersionNumber& other) const {
|
||||||
return this->combined == other.combined;
|
return
|
||||||
|
this->major == other.major
|
||||||
|
&& this->minor == other.minor
|
||||||
|
&& this->patch == other.patch;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator != (const VersionNumber& other) const {
|
bool operator != (const VersionNumber& other) const {
|
||||||
return !(*this == other);
|
return !(*this == other);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator < (const VersionNumber& rhs) const {
|
bool operator < (const VersionNumber& other) const {
|
||||||
return this->combined < rhs.combined;
|
return
|
||||||
|
this->major < other.major
|
||||||
|
|| (this->major == other.major && this->minor < other.minor)
|
||||||
|
|| (this->major == other.major && this->minor == other.minor && this->patch < other.patch);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator > (const VersionNumber& rhs) const {
|
bool operator > (const VersionNumber& other) const {
|
||||||
return rhs < *this;
|
return other < *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator <= (const VersionNumber& rhs) const {
|
bool operator <= (const VersionNumber& other) const {
|
||||||
return !(rhs < *this);
|
return !(other < *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator >= (const VersionNumber& rhs) const {
|
bool operator >= (const VersionNumber& other) const {
|
||||||
return !(*this < rhs);
|
return !(*this < other);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
std::uint16_t major = 0;
|
|
||||||
std::uint16_t minor = 0;
|
|
||||||
std::uint16_t patch = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Integer of the three version segments concatenated (e.g for version 1.5.6, the combined value
|
|
||||||
* would be 156).
|
|
||||||
*/
|
|
||||||
std::uint32_t combined = 0;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user