Files
Bigfoot/Bigfoot/Sources/Utils/Include/Utils/Version.hpp
Romain BOULLARD e78d648178
All checks were successful
Bigfoot / Build & Test Debug (Unity Build: OFF) (push) Successful in 25s
Bigfoot / Build & Test Debug (Unity Build: ON) (push) Successful in 25s
Bigfoot / Build & Test RelWithDebInfo (Unity Build: OFF) (push) Successful in 25s
Bigfoot / Build & Test RelWithDebInfo (Unity Build: ON) (push) Successful in 25s
Bigfoot / Build & Test Release (Unity Build: OFF) (push) Successful in 20s
Bigfoot / Build & Test Release (Unity Build: ON) (push) Successful in 18s
Bigfoot / Clang Format Checks (push) Successful in 10s
FormatChecks (#2)
Reviewed-on: #2
Co-authored-by: Romain BOULLARD <romain.boullard@protonmail.com>
Co-committed-by: Romain BOULLARD <romain.boullard@protonmail.com>
2026-01-28 16:41:08 +00:00

159 lines
3.7 KiB
C++

/*********************************************************************
* \file Version.hpp
*
* \author Romain BOULLARD
* \date October 2025
*********************************************************************/
#ifndef BIGFOOT_UTILS_VERSION_HPP
#define BIGFOOT_UTILS_VERSION_HPP
#include <Utils/Caster.hpp>
#include <Utils/TargetMacros.h>
#include <cstdint>
#include <format>
#include <string>
namespace Bigfoot
{
class Version
{
public:
Version() = default;
/**
* Constructor.
*
* \param p_combined The combined version.
*/
explicit constexpr Version(const std::uint32_t p_combined):
m_combined(p_combined)
{
}
/**
* Constructor.
*
* \param p_major Major
* \param p_minor Minor
* \param p_patch Patch
*/
constexpr Version(const std::uint8_t p_major, const std::uint8_t p_minor, const std::uint8_t p_patch):
m_combined((p_major << 16) | (p_minor << 8) | p_patch)
{
}
Version(const Version& p_version) = default;
Version(Version&& p_version) = default;
~Version() = default;
/**
* Get the major part of the version.
*
* \return The major part of the version.
*/
[[nodiscard]]
constexpr std::uint8_t Major() const
{
constexpr std::uint32_t mask = 0b00000000111111110000000000000000;
return static_cast<std::uint8_t>((m_combined & mask) >> 16);
}
/**
* Get the minor part of the version.
*
* \return The minor part of the version.
*/
[[nodiscard]]
constexpr std::uint8_t Minor() const
{
constexpr std::uint32_t mask = 0b00000000000000001111111100000000;
return static_cast<std::uint8_t>((m_combined & mask) >> 8);
}
/**
* Get the patch part of the version.
*
* \return The patch part of the version.
*/
[[nodiscard]]
constexpr std::uint8_t Patch() const
{
constexpr std::uint32_t mask = 0b00000000000000000000000011111111;
return static_cast<std::uint8_t>(m_combined & mask);
}
[[nodiscard]]
constexpr operator std::uint32_t() const
{
return m_combined;
}
[[nodiscard]] operator std::string() const;
constexpr Version& operator=(const Version& p_version) = default;
constexpr Version& operator=(Version&& p_version) = default;
[[nodiscard]]
constexpr bool operator>(const Version& p_version) const
{
return m_combined > p_version.m_combined;
}
[[nodiscard]]
constexpr bool operator<(const Version& p_version) const
{
return m_combined < p_version.m_combined;
}
[[nodiscard]]
constexpr bool operator>=(const Version& p_version) const
{
return m_combined >= p_version.m_combined;
}
[[nodiscard]]
constexpr bool operator<=(const Version& p_version) const
{
return m_combined <= p_version.m_combined;
}
[[nodiscard]]
constexpr bool operator==(const Version& p_version) const = default;
[[nodiscard]]
constexpr bool operator!=(const Version& p_version) const = default;
private:
/**
* The combined version.
*/
std::uint32_t m_combined = 0;
};
} // namespace Bigfoot
/****************************************************************************************/
#if defined BIGFOOT_NOT_OPTIMIZED
template<>
struct std::formatter<Bigfoot::Version>
{
template<typename ParseContext>
constexpr auto parse(ParseContext& p_context)
{
return p_context.begin();
}
template<typename FormatContext>
auto format(const Bigfoot::Version& p_version, FormatContext& p_context) const
{
return std::format_to(p_context.out(), "{}", static_cast<std::string>(p_version));
}
};
#endif
#endif