From ece90a201183341f7103d0cfa7a975465f6a9780 Mon Sep 17 00:00:00 2001 From: Alexander Frick Date: Tue, 2 Dec 2025 22:24:01 -0600 Subject: [PATCH] bump version to 1.1.5, and add version.cc file --- src/version.cc | 127 +++++++++++++++++++++++++++++++++++++++++++++++++ src/version.h | 2 +- 2 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 src/version.cc diff --git a/src/version.cc b/src/version.cc new file mode 100644 index 0000000..182b8fd --- /dev/null +++ b/src/version.cc @@ -0,0 +1,127 @@ +#include "version.h" + +#include + +// Version represents a dotted version number, like "1.2.3.4", supporting +// parsing and comparison. +class Version { + public: + // The only thing you can legally do to a default constructed + // Version object is assign to it. + Version(); + + Version(const Version& other); + Version(Version&& other); + + Version& operator=(const Version& other) = default; + Version& operator=(Version&& other) = default; + + // Initializes from a decimal dotted version number, like "0.1.1". + // Each component is limited to a uint32_t. Call IsValid() to learn + // the outcome. + explicit Version(std::string_view version_str); + + ~Version(); + + // Compares two versions. Returns -1 for less than, 0 for equal to, and 1 for more than + int CompareVersions(const Version& verToCompare) const; + + // Returns true if the object contains a valid version number. + bool IsValid() const; + + // Return the string representation of this version. + std::string GetString() const; + + const std::vector& components() const { return components_; } + + private: + std::vector components_; +}; + +bool operator==(const Version& v1, const Version& v2); +bool operator<(const Version& v1, const Version& v2); +bool operator<=(const Version& v1, const Version& v2); +bool operator>(const Version& v1, const Version& v2); +bool operator>=(const Version& v1, const Version& v2); +std::ostream& operator<<(std::ostream& stream, const Version& v); + +Version::Version() = default; + +Version::Version(const Version& other) = default; + +Version::Version(Version&& other) = default; + +Version::~Version() = default; + +Version::Version(std::string_view version_str) { + std::vector parsed; +} + +// Compares version components in |components1| with components in +// |components2|. Returns -1, 0 or 1 if |components1| is less than, equal to, +// or greater than |components2|, respectively. +int CompareVersionComponents(const std::vector& components1, + const std::vector& components2) { + const size_t count = std::min(components1.size(), components2.size()); + for (size_t i = 0; i < count; ++i) { + if (components1[i] > components2[i]) { + return 1; + } + if (components1[i] < components2[i]) { + return -1; + } + } + if (components1.size() > components2.size()) { + for (size_t i = count; i < components1.size(); ++i) { + if (components1[i] > 0) { + return 1; + } + } + } else if (components1.size() < components2.size()) { + for (size_t i = count; i < components2.size(); ++i) { + if (components2[i] > 0) { + return -1; + } + } + } + return 0; +} + +int Version::CompareVersions(const Version& verToCompare) const { + return CompareVersionComponents(components_, verToCompare.components_); +} + +bool Version::IsValid() const { + return (!components_.empty()); +} + +std::string Version::GetString() const { + if (!IsValid()) { + return "invalid"; + } + return std::string(); +} + +bool operator==(const Version& v1, const Version& v2) { + return v1.CompareVersions(v2) == 0; +} + +bool operator<(const Version& v1, const Version& v2) { + return v1.CompareVersions(v2) < 0; +} + +bool operator<=(const Version& v1, const Version& v2) { + return v1.CompareVersions(v2) <= 0; +} + +bool operator>(const Version& v1, const Version& v2) { + return v1.CompareVersions(v2) > 0; +} + +bool operator>=(const Version& v1, const Version& v2) { + return v1.CompareVersions(v2) >= 0; +} + +std::ostream& operator<<(std::ostream& stream, const Version& ver) { + return stream << ver.GetString(); +} diff --git a/src/version.h b/src/version.h index 9f13024..0aa08f6 100644 --- a/src/version.h +++ b/src/version.h @@ -21,7 +21,7 @@ // Adhere to semver > semver.org #define MAJOR_VERSION 1 #define MINOR_VERSION 1 -#define BUILD_VERSION 4 +#define BUILD_VERSION 5 #define MAIN_TITLE L"XP_Activate32"