wowlib 0.0.0
Read & write World of Warcraft client files — a C++26 core
Loading...
Searching...
No Matches
annotations.hpp
Go to the documentation of this file.
1#pragma once
2
40
41#include <meta>
42
43#include <cstdint>
44#include <string_view>
45
48
49namespace wowlib::formats {
50 namespace detail {
52 struct ChunkSpec {
53 std::uint32_t magic;
55 };
56
58 struct SinceSpec {
60 };
61
63 struct UntilSpec {
65 };
66
68 struct OptionalSpec {};
69
72 struct HeaderSpec {};
73
76 struct ContainerSpec {};
77
79 struct RepeatsSpec {
80 std::uint32_t max;
81 };
82
85 struct RepeatingSpec {};
86
92
95 struct GatedBySpec {
96 std::uint32_t mask;
97 };
98
104 const char* name;
105
106 constexpr std::string_view view() const { return name; }
107 };
108
109 // --- validation specs (validate(), never the serializer) ------------------
110
114 const char* name;
115 std::uint32_t scale;
116
117 constexpr std::string_view view() const { return name; }
118 };
119
123 std::uint32_t divisor;
124 };
125
129 std::uint32_t count;
130 };
131
134 struct IndexesSpec {
135 const char* name;
136
137 constexpr std::string_view view() const { return name; }
138 };
139
144 const char* name;
145
146 constexpr std::string_view view() const { return name; }
147 };
148
154 const char* name;
155
156 constexpr std::string_view view() const { return name; }
157 };
158
162 std::uint32_t value;
163 };
164
167 struct NonemptySpec {};
168 }
169
174 consteval detail::ChunkSpec chunk(const char(&cc)[5], FourCCEndian endian = FourCCEndian::Reversed) {
175 return {fourcc(cc, endian), endian};
176 }
177
180 consteval detail::SinceSpec since(ClientVersion v) { return {v}; }
181
184 consteval detail::UntilSpec until(ClientVersion v) { return {v}; }
185
188 inline constexpr detail::OptionalSpec Optional{};
189
192 inline constexpr detail::HeaderSpec Header{};
193
197
201 consteval detail::RepeatsSpec repeats(std::uint32_t max) { return {max}; }
202
213
221
227 consteval detail::GatedBySpec gatedBy(std::uint32_t mask) {
228 return {mask};
229 }
230
240 consteval detail::OffsetAfterSpec offsetAfter(std::string_view name) {
241 return {std::define_static_string(name)};
242 }
243
244 // --- validation annotations (validate() contracts, never the serializer) ----
245
255 consteval detail::CountMatchesSpec countMatches(std::string_view name, std::uint32_t scale = 1) {
256 return {std::define_static_string(name), scale};
257 }
258
262 consteval detail::CountMultipleOfSpec countMultipleOf(std::uint32_t divisor) {
263 return {divisor};
264 }
265
271 consteval detail::CountExactlySpec countExactly(std::uint32_t count) {
272 return {count};
273 }
274
280 consteval detail::IndexesSpec indexes(std::string_view name) {
281 return {std::define_static_string(name)};
282 }
283
290 consteval detail::IndexesOptionalSpec indexesOptional(std::string_view name) {
291 return {std::define_static_string(name)};
292 }
293
300 consteval detail::IndexesInRootSpec
301 indexesInRoot(std::string_view name) {
302 return {std::define_static_string(name)};
303 }
304
308 consteval detail::ExpectedValueSpec expectedValue(std::uint32_t value) {
309 return {value};
310 }
311
315 inline constexpr detail::NonemptySpec Nonempty{};
316}
Client version identity, the flavor axis that separates a client's CONTENT version from the engine ge...
FourCC chunk identifiers: compile-time conversion of the four-letter codes to the host integers chunk...
consteval detail::IndexesSpec indexes(std::string_view name)
Declare a referential contract: every element of this (integral) vector member is an index into the n...
constexpr detail::NonemptySpec Nonempty
Declare a presence contract: the member must hold data for the file to be meaningful to the client,...
consteval detail::CountExactlySpec countExactly(std::uint32_t count)
Declare a fixed-size contract: when engaged, the member holds exactly count elements because the form...
constexpr std::uint32_t fourcc(const char(&cc)[5], FourCCEndian endian=FourCCEndian::Reversed)
The host integer a scanned chunk id compares equal to for code cc.
Definition fourcc.hpp:33
consteval detail::CountMultipleOfSpec countMultipleOf(std::uint32_t divisor)
Declare a granularity contract: the member's element count must be a multiple of divisor (triangle in...
constexpr detail::HeaderSpec Header
Mark a member as a container payload's raw header prelude (e.g.
constexpr detail::ContainerSpec Container
Mark a chunk member whose payload is itself a chunk stream (e.g.
constexpr detail::RepeatingSpec Repeating
Mark a chunk that appears once PER ELEMENT of a std::vector<Element> member, any number of times: eac...
constexpr detail::OptionalSpec Optional
Mark a chunk member the format does not require: absence on read is fine.
consteval detail::OffsetAfterSpec offsetAfter(std::string_view name)
Anchor a version-trait member at its positional layout position: the offset serializer walks the enti...
consteval detail::UntilSpec until(ClientVersion v)
Restrict a member to entity versions < v (exclusive).
consteval detail::ExpectedValueSpec expectedValue(std::uint32_t value)
Declare an exact-value contract on an integral data member (format version fields: WMO MVER is always...
FourCCEndian
How a chunk's FourCC characters are laid out on disk.
Definition fourcc.hpp:14
@ Reversed
The characters are stored reversed: 'MVER' appears in the file as the bytes "REVM".
Definition fourcc.hpp:18
consteval detail::IndexesInRootSpec indexesInRoot(std::string_view name)
Declare a cross-entity referential contract: every element of this (integral) vector member is an ind...
consteval detail::ChunkSpec chunk(const char(&cc)[5], FourCCEndian endian=FourCCEndian::Reversed)
Declare the chunk a member maps to.
consteval detail::IndexesOptionalSpec indexesOptional(std::string_view name)
Declare a referential contract that tolerates the "none" sentinel: like indexes, except an element th...
consteval detail::SinceSpec since(ClientVersion v)
Restrict a member to entity versions >= v (inclusive).
consteval detail::CountMatchesSpec countMatches(std::string_view name, std::uint32_t scale=1)
Declare a companion-count contract: when this member is engaged (non-empty), its element count times ...
consteval detail::RepeatsSpec repeats(std::uint32_t max)
Allow a chunk to appear up to max times (e.g.
constexpr detail::SequenceDataSpec SequenceData
Mark an offset-entity member (a nested std::vector<std::vector<T>>, one inner array per animation seq...
consteval detail::GatedBySpec gatedBy(std::uint32_t mask)
Make an offset-entity member's binary presence conditional on the entity's globalFlags: it occupies b...
Stored form of a chunk annotation: the member's binary identity.
FourCCEndian endian
Disk layout of the code (for diagnostics).
std::uint32_t magic
Comparison value, see fourCc().
Stored form of container: the chunk payload is itself a chunk stream; the member is a nested chunked ...
Stored form of countExactly: the member's element count is fixed by the format (an ADT map chunk's 14...
Stored form of countMatches: when the member is engaged, its element count times scale must equal the...
std::uint32_t scale
This member's count is 1/scale of the sibling's.
constexpr std::string_view view() const
const char * name
The sibling member (interned, see OffsetAfterSpec).
Stored form of countMultipleOf: the member's element count must be a multiple of divisor.
Stored form of expectedValue: the (integral) data member must hold exactly this value (format-version...
Stored form of gatedBy (offset entities): the member occupies binary bytes only when the entity's glo...
Stored form of header: raw leading bytes of a container payload, memcpy'd before chunk scanning start...
Stored form of indexesInRoot: every element of the (integral) vector member must be a valid index int...
constexpr std::string_view view() const
const char * name
The root-entity member the elements index.
Stored form of indexesOptional: like indexes, but the client's "no reference" sentinel (a negative va...
constexpr std::string_view view() const
const char * name
The sibling member the elements index.
Stored form of indexes: every element of the (integral) vector member must be a valid index into the ...
const char * name
The sibling member the elements index.
constexpr std::string_view view() const
Stored form of nonempty: the member must hold data for the file to be meaningful to the client,...
Stored form of offsetAfter (offset entities): the trait-base member's positional layout position — ri...
constexpr std::string_view view() const
Stored form of optional: absence on read is not an error.
Stored form of repeating: the chunk appears once per element, any number of times (WDL MARE tiles,...
Stored form of repeats: the chunk may appear up to max times.
Stored form of SequenceData (offset entities): the member's nested per-element data may live in an ex...
Stored form of since: member active for entity versions >= v.
Stored form of until: member active for entity versions < v.