19 _impl{ a_v1, a_v2, a_v3, a_v4 }
22 explicit constexpr
Version(std::string_view a_version)
24 std::array<value_type, 4> powers{ 1, 1, 1, 1 };
25 std::size_t position = 0;
26 for (std::size_t i = 0; i < a_version.size(); ++i) {
27 if (a_version[i] ==
'.') {
28 if (++position == powers.size()) {
29 throw std::invalid_argument(
"Too many parts in version number.");
32 powers[position] *= 10;
36 for (std::size_t i = 0; i < a_version.size(); ++i) {
37 if (a_version[i] ==
'.') {
39 }
else if (a_version[i] <
'0' || a_version[i] >
'9') {
40 throw std::invalid_argument(
"Invalid character in version number.");
42 powers[position] /= 10;
43 _impl[position] +=
static_cast<value_type>((a_version[i] -
'0') * powers[position]);
51 [[nodiscard]] constexpr decltype(
auto)
begin() const noexcept {
return _impl.begin(); }
52 [[nodiscard]] constexpr decltype(
auto)
cbegin() const noexcept {
return _impl.cbegin(); }
53 [[nodiscard]] constexpr decltype(
auto)
end() const noexcept {
return _impl.end(); }
54 [[nodiscard]] constexpr decltype(
auto)
cend() const noexcept {
return _impl.cend(); }
56 [[nodiscard]] std::strong_ordering constexpr
compare(
const Version& a_rhs)
const noexcept
58 for (std::size_t i = 0; i < _impl.size(); ++i) {
59 if ((*
this)[i] != a_rhs[i]) {
60 return (*
this)[i] < a_rhs[i] ? std::strong_ordering::less : std::strong_ordering::greater;
63 return std::strong_ordering::equal;
66 [[nodiscard]] constexpr std::uint32_t
pack() const noexcept
68 return static_cast<std::uint32_t
>(
69 (_impl[0] & 0x0FF) << 24u |
70 (_impl[1] & 0x0FF) << 16u |
71 (_impl[2] & 0xFFF) << 4u |
72 (_impl[3] & 0x00F) << 0u);
78 for (
auto&& ver : _impl) {
86 [[nodiscard]] std::wstring
wstring()
const
89 for (
auto&& ver : _impl) {
90 result += std::to_wstring(ver);
97 [[nodiscard]]
static constexpr
Version unpack(std::uint32_t a_packedVersion) noexcept
100 static_cast<value_type>((a_packedVersion >> 24) & 0x0FF),
101 static_cast<value_type>((a_packedVersion >> 16) & 0x0FF),
102 static_cast<value_type>((a_packedVersion >> 4) & 0xFFF),
103 static_cast<value_type>(a_packedVersion & 0x0F)
108 std::array<value_type, 4> _impl{ 0, 0, 0, 0 };
112 [[nodiscard]] constexpr std::strong_ordering
operator<=>(
const Version& a_lhs,
const Version& a_rhs) noexcept {
return a_lhs.compare(a_rhs); }
117 #ifdef __cpp_lib_format
118 template <
class CharT>
119 struct std::formatter<
REL::Version, CharT> : formatter<std::string, CharT>
121 template <
class FormatContext>
122 constexpr
auto format(
const REL::Version a_version, FormatContext& a_ctx)
const
124 return formatter<std::string, CharT>::format(a_version.
string(), a_ctx);
130 template <
class CharT>
131 struct fmt::formatter<
REL::Version, CharT> : formatter<std::string, CharT>
133 template <
class FormatContext>
134 auto format(
const REL::Version a_version, FormatContext& a_ctx)
const
136 return formatter<std::string, CharT>::format(a_version.
string(), a_ctx);
constexpr decltype(auto) end() const noexcept
Definition: Version.h:53
constexpr Version(value_type a_v1, value_type a_v2=0, value_type a_v3=0, value_type a_v4=0) noexcept
Definition: Version.h:18
constexpr reference operator[](std::size_t a_idx) noexcept
Definition: Version.h:48
constexpr decltype(auto) cbegin() const noexcept
Definition: Version.h:52
std::string string() const
Definition: Version.h:75
constexpr std::uint32_t pack() const noexcept
Definition: Version.h:66
constexpr Version(std::string_view a_version)
Definition: Version.h:22
constexpr const_reference operator[](std::size_t a_idx) const noexcept
Definition: Version.h:49
static constexpr Version unpack(std::uint32_t a_packedVersion) noexcept
Definition: Version.h:97
std::uint16_t value_type
Definition: Version.h:8
constexpr decltype(auto) cend() const noexcept
Definition: Version.h:54
value_type & reference
Definition: Version.h:9
const value_type & const_reference
Definition: Version.h:10
constexpr Version() noexcept=default
constexpr std::strong_ordering compare(const Version &a_rhs) const noexcept
Definition: Version.h:56
constexpr decltype(auto) begin() const noexcept
Definition: Version.h:51
std::wstring wstring() const
Definition: Version.h:86
constexpr std::strong_ordering operator<=>(const Version &a_lhs, const Version &a_rhs) noexcept
Definition: Version.h:112
constexpr bool operator==(const Version &a_lhs, const Version &a_rhs) noexcept
Definition: Version.h:111
std::optional< Version > GetFileVersion(stl::zwstring a_filename)
string(const CharT(&)[N]) -> string< CharT, N - 1 >
basic_zstring< wchar_t > zwstring
Definition: PCH.h:80
Definition: EffectArchetypes.h:65
std::string to_string(RE::EffectArchetype a_archetype)
Definition: EffectArchetypes.h:66