Expand version api and conversions
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Version.hpp"
|
#include "Version.hpp"
|
||||||
|
#include <fmt/format.h>
|
||||||
#include <charconv>
|
#include <charconv>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
@@ -82,12 +83,20 @@ namespace OpenVulkano
|
|||||||
iss >> p.first >> p.second;
|
iss >> p.first >> p.second;
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr std::string ToString(uint32_t major, uint32_t minor, uint32_t patch, const uint32_t build)
|
||||||
|
{
|
||||||
|
if (build)
|
||||||
|
return fmt::format("v{}.{}.{}.{}", major, minor, patch, build);
|
||||||
|
else
|
||||||
|
return fmt::format("v{}.{}.{}", major, minor, patch);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Version::Version(uint32_t major, uint32_t minor, uint32_t patch, const uint32_t build)
|
Version::Version(uint32_t major, uint32_t minor, uint32_t patch, const uint32_t build)
|
||||||
: m_versionComponents(build ? std::initializer_list<uint32_t>{major, minor, patch, build} : std::initializer_list<uint32_t>{major, minor, patch})
|
: m_versionComponents(build ? std::initializer_list<uint32_t>{major, minor, patch, build} : std::initializer_list<uint32_t>{major, minor, patch})
|
||||||
, m_buildNumber(build)
|
, m_buildNumber(build)
|
||||||
, m_versionString("v" + std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(patch) + (build ? "." + std::to_string(build) : ""))
|
, m_versionString(ToString(major, minor, patch, build))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Version::Version(std::string_view versionString, bool ignoreTags)
|
Version::Version(std::string_view versionString, bool ignoreTags)
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ namespace OpenVulkano
|
|||||||
[[nodiscard]] explicit operator uint32_t() const { return (Major() << 20) | ((Minor() & 0x3FF) << 10) | (Patch() & 0x3FF); }
|
[[nodiscard]] explicit operator uint32_t() const { return (Major() << 20) | ((Minor() & 0x3FF) << 10) | (Patch() & 0x3FF); }
|
||||||
|
|
||||||
[[nodiscard]] operator const std::string&() const { return m_versionString; }
|
[[nodiscard]] operator const std::string&() const { return m_versionString; }
|
||||||
|
|
||||||
|
[[nodiscard]] const std::string& String() const { return m_versionString; }
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
//region Comparison operators
|
//region Comparison operators
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include "Math/Timestamp.hpp"
|
#include "Math/Timestamp.hpp"
|
||||||
#include "Math/UInt24.hpp"
|
#include "Math/UInt24.hpp"
|
||||||
#include "Base/UUID.hpp"
|
#include "Base/UUID.hpp"
|
||||||
|
#include "Base/Version.hpp"
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <fmt/chrono.h>
|
#include <fmt/chrono.h>
|
||||||
|
|
||||||
@@ -41,6 +42,19 @@ template<> struct fmt::formatter<OpenVulkano::ByteSize>
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<> struct fmt::formatter<OpenVulkano::Version>
|
||||||
|
{
|
||||||
|
template<typename ParseContext> constexpr auto parse(ParseContext& ctx)
|
||||||
|
{
|
||||||
|
return ctx.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename FormatContext> auto format(const OpenVulkano::Version& version, FormatContext& ctx) const
|
||||||
|
{
|
||||||
|
return fmt::format_to(ctx.out(), "{}", static_cast<const std::string&>(version));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template<> struct fmt::formatter<std::filesystem::path> : fmt::formatter<std::string>
|
template<> struct fmt::formatter<std::filesystem::path> : fmt::formatter<std::string>
|
||||||
{
|
{
|
||||||
template<typename PATH = std::filesystem::path>
|
template<typename PATH = std::filesystem::path>
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#include "Math/RGB565.hpp"
|
#include "Math/RGB565.hpp"
|
||||||
#include "Math/RGBA5551.hpp"
|
#include "Math/RGBA5551.hpp"
|
||||||
#include "Math/Timestamp.hpp"
|
#include "Math/Timestamp.hpp"
|
||||||
|
#include "Base/Version.hpp"
|
||||||
#include <ryml.hpp>
|
#include <ryml.hpp>
|
||||||
#include <ryml_std.hpp>
|
#include <ryml_std.hpp>
|
||||||
#include <c4/format.hpp>
|
#include <c4/format.hpp>
|
||||||
@@ -150,6 +151,17 @@ namespace c4
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline size_t to_chars(ryml::substr buf, const OpenVulkano::Version& version)
|
||||||
|
{
|
||||||
|
return ryml::format(buf, "{}", static_cast<const std::string&>(version));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool from_chars(ryml::csubstr buf, OpenVulkano::Version* version)
|
||||||
|
{
|
||||||
|
*version = OpenVulkano::Version(buf.str);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T, bool REDUCE_Y_RESOLUTION, bool ASSERT_INPUT_VALUES, int BITS_PER_COMPONENT>
|
template<typename T, bool REDUCE_Y_RESOLUTION, bool ASSERT_INPUT_VALUES, int BITS_PER_COMPONENT>
|
||||||
inline size_t to_chars(
|
inline size_t to_chars(
|
||||||
ryml::substr buf,
|
ryml::substr buf,
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#include "Math/RGBA5551.hpp"
|
#include "Math/RGBA5551.hpp"
|
||||||
#include "Math/Timestamp.hpp"
|
#include "Math/Timestamp.hpp"
|
||||||
#include "Data/Containers/String.hpp"
|
#include "Data/Containers/String.hpp"
|
||||||
|
#include "Base/Version.hpp"
|
||||||
#include <yaml-cpp/yaml.h>
|
#include <yaml-cpp/yaml.h>
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
#include <c4/format.hpp>
|
#include <c4/format.hpp>
|
||||||
@@ -61,6 +62,25 @@ namespace YAML
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct convert<OpenVulkano::Version>
|
||||||
|
{
|
||||||
|
static Node encode(const OpenVulkano::Version& version)
|
||||||
|
{
|
||||||
|
return Node(static_cast<const std::string&>(version));
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool decode(const Node& node, OpenVulkano::Version& version)
|
||||||
|
{
|
||||||
|
if (node.IsScalar())
|
||||||
|
{
|
||||||
|
version = OpenVulkano::Version(node.Scalar());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct convert<OpenVulkano::Math::AABB>
|
struct convert<OpenVulkano::Math::AABB>
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user