#include "utils/StringTools.h" #include #include class WUPSVersion { public: WUPSVersion(int major, int minor, int revision) : mVersion((static_cast(major) << 32) | (static_cast(minor) << 16) | static_cast(revision)) {} WUPSVersion(const WUPSVersion &other) = default; static std::optional createFromString(const std::string &versionStr) { char *end; errno = 0; // Initialize errno before calling strtol auto major = strtol(versionStr.c_str(), &end, 10); if (errno || *end != '.') { return std::nullopt; } auto minor = strtol(end + 1, &end, 10); if (errno || *end != '.') { return std::nullopt; } auto revision = strtol(end + 1, &end, 10); if (errno || *end != '\0') { return std::nullopt; } return WUPSVersion(static_cast(major), static_cast(minor), static_cast(revision)); } std::strong_ordering operator<=>(const WUPSVersion &other) const { return mVersion <=> other.mVersion; } [[nodiscard]] std::string toString() const { return string_format("%d.%d.%d", static_cast((mVersion >> 32) & 0xFFFF), static_cast((mVersion >> 16) & 0xFFFF), static_cast((mVersion) &0xFFFF)); } private: uint64_t mVersion{}; };