Fixed version number comparison bug and a little tidying

This commit is contained in:
Nav
2023-07-18 21:56:35 +01:00
parent 1383886545
commit 614255c850
4 changed files with 28 additions and 47 deletions

View File

@@ -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();

View File

@@ -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()
)));

View File

@@ -8,24 +8,18 @@ namespace Bloom
: major{major}
, minor{minor}
, 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(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 {

View File

@@ -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;
};
}