From 81848e05f100a135ad1d307ccabb796be0540daa Mon Sep 17 00:00:00 2001 From: flow Date: Thu, 19 Jan 2023 21:31:55 -0300 Subject: [PATCH] refactor: simplify Version operators Signed-off-by: flow --- launcher/Version.cpp | 66 +++++++++++++++++--------------------------- launcher/Version.h | 4 +-- 2 files changed, 28 insertions(+), 42 deletions(-) diff --git a/launcher/Version.cpp b/launcher/Version.cpp index 9b96f68e5..9307aab36 100644 --- a/launcher/Version.cpp +++ b/launcher/Version.cpp @@ -1,67 +1,41 @@ #include "Version.h" #include -#include #include #include +#include -Version::Version(const QString &str) : m_string(str) +Version::Version(QString str) : m_string(std::move(str)) { parse(); } -bool Version::operator<(const Version &other) const +bool Version::operator<(const Version& other) const { - const int size = qMax(m_sections.size(), other.m_sections.size()); - for (int i = 0; i < size; ++i) - { - const Section sec1 = (i >= m_sections.size()) ? Section("") : m_sections.at(i); + const auto size = qMax(m_sections.size(), other.m_sections.size()); + for (int i = 0; i < size; ++i) { + const Section sec1 = + (i >= m_sections.size()) ? Section("") : m_sections.at(i); const Section sec2 = (i >= other.m_sections.size()) ? Section("") : other.m_sections.at(i); + if (sec1 != sec2) - { return sec1 < sec2; - } } return false; } -bool Version::operator<=(const Version &other) const +bool Version::operator==(const Version& other) const { - return *this < other || *this == other; -} -bool Version::operator>(const Version &other) const -{ - const int size = qMax(m_sections.size(), other.m_sections.size()); - for (int i = 0; i < size; ++i) - { - const Section sec1 = (i >= m_sections.size()) ? Section("") : m_sections.at(i); + const auto size = qMax(m_sections.size(), other.m_sections.size()); + for (int i = 0; i < size; ++i) { + const Section sec1 = + (i >= m_sections.size()) ? Section("") : m_sections.at(i); const Section sec2 = (i >= other.m_sections.size()) ? Section("") : other.m_sections.at(i); - if (sec1 != sec2) - { - return sec1 > sec2; - } - } - return false; -} -bool Version::operator>=(const Version &other) const -{ - return *this > other || *this == other; -} -bool Version::operator==(const Version &other) const -{ - const int size = qMax(m_sections.size(), other.m_sections.size()); - for (int i = 0; i < size; ++i) - { - const Section sec1 = (i >= m_sections.size()) ? Section("") : m_sections.at(i); - const Section sec2 = - (i >= other.m_sections.size()) ? Section("") : other.m_sections.at(i); if (sec1 != sec2) - { return false; - } } return true; @@ -70,6 +44,18 @@ bool Version::operator!=(const Version &other) const { return !operator==(other); } +bool Version::operator<=(const Version &other) const +{ + return *this < other || *this == other; +} +bool Version::operator>(const Version &other) const +{ + return !(*this <= other); +} +bool Version::operator>=(const Version &other) const +{ + return !(*this < other); +} void Version::parse() { @@ -96,7 +82,7 @@ void Version::parse() } -/// qDebug print support for the BlockedMod struct +/// qDebug print support for the Version class QDebug operator<<(QDebug debug, const Version& v) { QDebugStateSaver saver(debug); diff --git a/launcher/Version.h b/launcher/Version.h index 9db03521f..b587319ab 100644 --- a/launcher/Version.h +++ b/launcher/Version.h @@ -45,8 +45,8 @@ class QUrl; class Version { public: - Version(const QString &str); - Version() {} + Version(QString str); + Version() = default; bool operator<(const Version &other) const; bool operator<=(const Version &other) const;