From 614255c850715f131743c2a62113cd0ff713263d Mon Sep 17 00:00:00 2001 From: Nav Date: Tue, 18 Jul 2023 21:56:35 +0100 Subject: [PATCH] Fixed version number comparison bug and a little tidying --- src/Application.cpp | 6 +-- .../CommandPackets/BloomVersionMachine.cpp | 6 +-- src/VersionNumber.cpp | 10 +--- src/VersionNumber.hpp | 53 +++++++------------ 4 files changed, 28 insertions(+), 47 deletions(-) diff --git a/src/Application.cpp b/src/Application.cpp index ef3e0e92..b38474f6 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -347,9 +347,9 @@ namespace Bloom std::cout << QJsonDocument(QJsonObject({ {"version", QString::fromStdString(Application::VERSION.toString())}, {"components", QJsonObject({ - {"major", Application::VERSION.getMajor()}, - {"minor", Application::VERSION.getMinor()}, - {"patch", Application::VERSION.getPatch()}, + {"major", Application::VERSION.major}, + {"minor", Application::VERSION.minor}, + {"patch", Application::VERSION.patch}, })}, })).toJson().toStdString(); diff --git a/src/DebugServer/Gdb/CommandPackets/BloomVersionMachine.cpp b/src/DebugServer/Gdb/CommandPackets/BloomVersionMachine.cpp index 0c69e576..dafff3ed 100644 --- a/src/DebugServer/Gdb/CommandPackets/BloomVersionMachine.cpp +++ b/src/DebugServer/Gdb/CommandPackets/BloomVersionMachine.cpp @@ -32,9 +32,9 @@ namespace Bloom::DebugServer::Gdb::CommandPackets QJsonDocument(QJsonObject({ {"version", QString::fromStdString(Application::VERSION.toString())}, {"components", QJsonObject({ - {"major", Application::VERSION.getMajor()}, - {"minor", Application::VERSION.getMinor()}, - {"patch", Application::VERSION.getPatch()}, + {"major", Application::VERSION.major}, + {"minor", Application::VERSION.minor}, + {"patch", Application::VERSION.patch}, })}, })).toJson().toStdString() ))); diff --git a/src/VersionNumber.cpp b/src/VersionNumber.cpp index a44f1724..d72efd7d 100644 --- a/src/VersionNumber.cpp +++ b/src/VersionNumber.cpp @@ -8,24 +8,18 @@ namespace Bloom : major{major} , minor{minor} , patch{patch} - { - this->combined = static_cast( - std::stoul(std::to_string(this->major) + std::to_string(this->minor) + std::to_string(this->patch)) - ); - } + {} VersionNumber::VersionNumber(const std::string& versionNumber) : VersionNumber(QString::fromStdString(versionNumber)) {} - VersionNumber::VersionNumber(QString versionNumber) { + VersionNumber::VersionNumber(const QString& versionNumber) { const auto explodedString = versionNumber.split('.'); this->major = explodedString.value(0, "0").toUShort(); this->minor = explodedString.value(1, "0").toUShort(); this->patch = explodedString.value(2, "0").toUShort(); - - this->combined = versionNumber.remove('.').toUInt(); } std::string VersionNumber::toString() const { diff --git a/src/VersionNumber.hpp b/src/VersionNumber.hpp index 27089d45..eb0ac89f 100644 --- a/src/VersionNumber.hpp +++ b/src/VersionNumber.hpp @@ -9,57 +9,44 @@ namespace Bloom class VersionNumber { 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(const std::string& versionNumber); - VersionNumber(QString versionNumber); + VersionNumber(const QString& versionNumber); 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 { - return this->combined == other.combined; + return + this->major == other.major + && this->minor == other.minor + && this->patch == other.patch; } bool operator != (const VersionNumber& other) const { return !(*this == other); } - bool operator < (const VersionNumber& rhs) const { - return this->combined < rhs.combined; + bool operator < (const VersionNumber& other) const { + 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 { - return rhs < *this; + bool operator > (const VersionNumber& other) const { + return other < *this; } - bool operator <= (const VersionNumber& rhs) const { - return !(rhs < *this); + bool operator <= (const VersionNumber& other) const { + return !(other < *this); } - bool operator >= (const VersionNumber& rhs) const { - return !(*this < rhs); + bool operator >= (const VersionNumber& other) const { + 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; }; }