geode/loader/include/Geode/utils/VersionInfo.hpp

72 lines
2 KiB
C++
Raw Normal View History

2022-07-30 12:24:03 -04:00
#pragma once
#include "../DefaultInclude.hpp"
2022-07-30 12:24:03 -04:00
#include <string_view>
#include "../external/json/json.hpp"
2022-07-30 12:24:03 -04:00
namespace geode {
/**
2022-10-30 14:59:20 -04:00
* Class representing version
2022-07-30 12:24:03 -04:00
* information
* @class VersionInfo
*/
class GEODE_DLL VersionInfo {
public:
enum Compare : char {
// Other version is lower or exactly the same
Lower,
// Other version is exactly the same
Exact,
// Other version is higher or exactly the same
Higher,
// Other version does not even have to match lol
Any,
};
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:
VersionInfo() = default;
2022-11-02 06:57:03 -04:00
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;
}
2022-10-30 14:59:20 -04:00
VersionInfo(char const* versionString);
2022-07-30 12:24:03 -04:00
VersionInfo(std::string const& versionString);
int getMajor() const;
int getMinor() const;
int getPatch() const;
bool operator<(VersionInfo const& other) const;
bool operator<=(VersionInfo const& other) const;
bool operator>(VersionInfo const& other) const;
bool operator>=(VersionInfo const& other) const;
bool operator==(VersionInfo const& other) const;
bool match(VersionInfo const& other) const;
2022-10-30 14:59:20 -04:00
bool match(VersionInfo const& other, VersionInfo::Compare compare) const;
2022-07-30 12:24:03 -04:00
bool match(
2022-10-30 14:59:20 -04:00
VersionInfo const& other, VersionInfo::Compare major, VersionInfo::Compare minor,
2022-07-30 12:24:03 -04:00
VersionInfo::Compare patch
) const;
static bool validate(std::string const& string);
std::string toString() const;
};
2022-11-09 10:45:59 -05:00
2022-11-22 17:35:08 -05:00
void GEODE_DLL to_json(nlohmann::json& json, VersionInfo const& info);
2022-11-09 10:45:59 -05:00
inline std::ostream& operator<<(std::ostream& stream, VersionInfo const& version) {
stream << version.toString();
return stream;
}
2022-07-30 12:24:03 -04:00
}