wowlib 0.0.0
Read & write World of Warcraft client files — a C++26 core
Loading...
Searching...
No Matches
version_range.hpp
Go to the documentation of this file.
1#pragma once
2
27
28#include <array>
29#include <span>
30#include <string>
31#include <string_view>
32
36
37namespace wowlib::formats {
50 constexpr ClientVersion versionFloor(ClientVersion v, std::span<const ClientVersion> pivots) {
51 const ClientVersion lineage = v.formatLineage();
52 ClientVersion out{0, 0, 0, 0};
53 for (const ClientVersion& p : pivots)
54 if (p <= lineage && out <= p) out = p;
55 return out;
56 }
57
70 std::span<const ClientVersion> pivots,
71 std::span<const ClientVersion> grid) {
72 const ClientVersion floor = versionFloor(v, pivots);
73 for (const ClientVersion& g : grid)
74 if (versionFloor(g, pivots) == floor) return g;
75 return grid.front();
76 }
77
87 constexpr std::string rangeSuffix(ClientVersion canonical,
88 std::span<const ClientVersion> pivots,
89 std::span<const ClientVersion> grid) {
90 const ClientVersion floor = versionFloor(canonical, pivots);
91 ClientVersion last = canonical;
92 for (const ClientVersion& g : grid)
93 if (g >= canonical && versionFloor(g, pivots) == floor) last = g;
94 const auto name = [](ClientVersion v) {
95 return std::string{enumName(*toExpansion(v))};
96 };
97 if (last == canonical) return name(canonical);
98 if (last == grid.back()) return name(canonical) + "Plus";
99 return name(canonical) + "To" + name(last);
100 }
101
104 struct RangeRow {
105 std::string_view suffix;
107 };
108
118 constexpr bool rangesValid(std::span<const RangeRow> rows,
119 std::span<const ClientVersion> pivots,
120 std::span<const ClientVersion> grid) {
121 std::size_t row = 0;
122 for (const ClientVersion& g : grid) {
123 const ClientVersion canonical = canonicalVersion(g, pivots, grid);
124 if (canonical == g) {
125 if (row >= rows.size() || rows[row].version != g || rows[row].suffix != rangeSuffix(g, pivots, grid)) return
126 false;
127 ++row;
128 }
129 }
130 return row == rows.size();
131 }
132}
Client version identity, the flavor axis that separates a client's CONTENT version from the engine ge...
The Expansion enum — the coarse, enumerable version axis the scripting bindings key on — and its mapp...
constexpr ClientVersion versionFloor(ClientVersion v, std::span< const ClientVersion > pivots)
The latest pivot at or below v — the identity of v's range.
constexpr std::string rangeSuffix(ClientVersion canonical, std::span< const ClientVersion > pivots, std::span< const ClientVersion > grid)
The suffix naming canonical's range on grid: the plain expansion name for a single-version range ("Wo...
constexpr ClientVersion canonicalVersion(ClientVersion v, std::span< const ClientVersion > pivots, std::span< const ClientVersion > grid)
The canonical version v collapses to: the FIRST grid version in v's range.
constexpr bool rangesValid(std::span< const RangeRow > rows, std::span< const ClientVersion > pivots, std::span< const ClientVersion > grid)
Does rows exactly enumerate the family's ranges — ascending, one row per distinct canonical of grid,...
constexpr std::optional< Expansion > toExpansion(ClientVersion version)
The expansion whose targeted release is exactly this version.
Definition expansion.hpp:64
constexpr std::string_view enumName(E value)
The enumerator name of value, straight from reflection — no handwritten stringification tables anywhe...
Definition reflect.hpp:19
Internal C++26 reflection utilities (<meta> based).
One row of a family's welded range table: the alias suffix (stringized from the x-macro) and the rang...
std::string_view suffix
e.g.
ClientVersion version
the range's canonical grid version.