2022-07-30 12:24:03 -04:00
|
|
|
#pragma once
|
|
|
|
|
2022-11-28 12:09:39 -05:00
|
|
|
#include "../DefaultInclude.hpp"
|
2022-07-30 12:24:03 -04:00
|
|
|
#include <string_view>
|
2022-11-28 12:09:39 -05:00
|
|
|
#include "../external/json/json.hpp"
|
2022-12-11 13:44:38 -05:00
|
|
|
#include <tuple>
|
2022-07-30 12:24:03 -04:00
|
|
|
|
|
|
|
namespace geode {
|
2022-12-08 17:28:05 -05:00
|
|
|
enum class VersionCompare {
|
|
|
|
LessEq,
|
|
|
|
Exact,
|
|
|
|
MoreEq,
|
|
|
|
};
|
|
|
|
|
2022-07-30 12:24:03 -04:00
|
|
|
/**
|
2022-12-08 15:04:02 -05:00
|
|
|
* Class representing version information
|
2022-07-30 12:24:03 -04:00
|
|
|
* @class VersionInfo
|
|
|
|
*/
|
2022-12-08 17:28:05 -05:00
|
|
|
class GEODE_DLL VersionInfo final {
|
2022-07-30 12:24:03 -04:00
|
|
|
protected:
|
|
|
|
int m_major = 1;
|
|
|
|
int m_minor = 0;
|
|
|
|
int m_patch = 0;
|
2022-10-30 14:59:20 -04:00
|
|
|
|
2022-07-30 12:24:03 -04:00
|
|
|
public:
|
2022-12-08 15:04:02 -05:00
|
|
|
constexpr VersionInfo() = default;
|
2022-07-30 12:24:03 -04:00
|
|
|
constexpr VersionInfo(int major, int minor, int patch) {
|
|
|
|
m_major = major;
|
|
|
|
m_minor = minor;
|
|
|
|
m_patch = patch;
|
|
|
|
}
|
|
|
|
VersionInfo(std::string const& versionString);
|
2022-12-08 17:28:05 -05:00
|
|
|
static bool validate(std::string const& string);
|
2022-07-30 12:24:03 -04:00
|
|
|
|
2022-12-08 15:04:02 -05:00
|
|
|
constexpr int getMajor() const {
|
|
|
|
return m_major;
|
|
|
|
}
|
2022-07-30 12:24:03 -04:00
|
|
|
|
2022-12-08 15:04:02 -05:00
|
|
|
constexpr int getMinor() const {
|
|
|
|
return m_minor;
|
|
|
|
}
|
2022-07-30 12:24:03 -04:00
|
|
|
|
2022-12-08 15:04:02 -05:00
|
|
|
constexpr int getPatch() const {
|
|
|
|
return m_patch;
|
|
|
|
}
|
|
|
|
|
|
|
|
constexpr std::strong_ordering operator<=>(VersionInfo const& other) const {
|
|
|
|
return std::tie(m_major, m_minor, m_patch) <=>
|
|
|
|
std::tie(other.m_major, other.m_minor, other.m_patch);
|
|
|
|
}
|
2022-12-08 17:28:05 -05:00
|
|
|
constexpr bool operator==(VersionInfo const& other) const = default;
|
2022-07-30 12:24:03 -04:00
|
|
|
|
|
|
|
std::string toString() const;
|
|
|
|
};
|
2022-11-22 17:35:08 -05:00
|
|
|
void GEODE_DLL to_json(nlohmann::json& json, VersionInfo const& info);
|
2022-12-08 17:28:05 -05:00
|
|
|
void GEODE_DLL from_json(nlohmann::json const& json, VersionInfo& info);
|
|
|
|
GEODE_DLL std::ostream& operator<<(std::ostream& stream, VersionInfo const& version);
|
2022-11-22 17:35:08 -05:00
|
|
|
|
2022-12-08 17:28:05 -05:00
|
|
|
class GEODE_DLL ComparableVersionInfo final {
|
|
|
|
protected:
|
|
|
|
VersionInfo m_version;
|
|
|
|
VersionCompare m_compare = VersionCompare::Exact;
|
|
|
|
|
|
|
|
public:
|
|
|
|
constexpr ComparableVersionInfo() = default;
|
|
|
|
constexpr ComparableVersionInfo(
|
|
|
|
VersionInfo const& version,
|
|
|
|
VersionCompare const& compare
|
|
|
|
) : m_version(version), m_compare(compare) {}
|
|
|
|
ComparableVersionInfo(std::string const& versionString);
|
|
|
|
static bool validate(std::string const& string);
|
|
|
|
|
|
|
|
constexpr bool compare(VersionInfo const& version) const {
|
|
|
|
switch (m_compare) {
|
|
|
|
case VersionCompare::Exact: return m_version == version; break;
|
|
|
|
case VersionCompare::LessEq: return m_version <= version; break;
|
|
|
|
case VersionCompare::MoreEq: return m_version >= version; break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string toString() const;
|
|
|
|
};
|
|
|
|
void GEODE_DLL to_json(nlohmann::json& json, ComparableVersionInfo const& info);
|
|
|
|
void GEODE_DLL from_json(nlohmann::json const& json, ComparableVersionInfo& info);
|
|
|
|
GEODE_DLL std::ostream& operator<<(std::ostream& stream, ComparableVersionInfo const& version);
|
2022-07-30 12:24:03 -04:00
|
|
|
}
|