wowlib 0.0.0
Read & write World of Warcraft client files — a C++26 core
Loading...
Searching...
No Matches
entity_reflect.hpp
Go to the documentation of this file.
1#pragma once
2
14
15#include <meta>
16
17#include <cstddef>
18#include <cstdint>
19#include <optional>
20#include <string_view>
21#include <vector>
22
25
31 template <typename Spec, std::meta::info M>
32 consteval std::optional<Spec> annotation() {
33 auto anns = std::meta::annotations_of_with_type(M, ^^Spec);
34 if (anns.empty()) return std::nullopt;
35 return std::meta::extract<Spec>(anns[0]);
36 }
37
42 template <ClientVersion V, std::meta::info M>
43 consteval bool versionActive() {
44 if (auto s = annotation<SinceSpec, M>(); s && V < s->v) return false;
45 if (auto u = annotation<UntilSpec, M>(); u && V >= u->v) return false;
46 return true;
47 }
48
50 template <typename T>
51 inline constexpr bool IsVectorV = false;
52 template <typename U, typename A>
53 inline constexpr bool IsVectorV<std::vector<U, A>> = true;
54
64 consteval void collectMembers(std::meta::info type, std::vector<std::meta::info>& out) {
65 for (auto b : std::meta::bases_of(type, std::meta::access_context::unchecked()))
66 if (std::meta::is_public(b)) collectMembers(std::meta::type_of(b), out);
67 for (auto m : std::meta::nonstatic_data_members_of(type, std::meta::access_context::unchecked())) out.push_back(m);
68 }
69
75 template <typename E>
76 consteval auto membersOf() {
77 std::vector<std::meta::info> out;
78 collectMembers(^^E, out);
79 return std::define_static_array(out);
80 }
81
90 template <typename E>
91 consteval std::meta::info memberNamed(std::string_view name) {
92 for (auto m : membersOf<E>())
93 if (std::meta::has_identifier(m) && std::meta::identifier_of(m) == name) return m;
94 return {};
95 }
96
103 consteval bool nestedInStd(std::meta::info r) {
104 while (r != std::meta::info{} && r != ^^::) {
105 if (r == ^^std) return true;
106 if (!std::meta::has_parent(r)) return false;
107 r = std::meta::parent_of(r);
108 }
109 return false;
110 }
111
114 template <typename T>
115 consteval bool isStdType() {
116 return nestedInStd(^^T);
117 }
118}
Client version identity, the flavor axis that separates a client's CONTENT version from the engine ge...
The chunk annotation vocabulary format entities declare their binary mapping with.
consteval std::optional< Spec > annotation()
The first annotation of type Spec on reflected member M, if any.
consteval bool nestedInStd(std::meta::info r)
Whether r is declared inside namespace std (at any nesting depth — libstdc++ hides types in inline na...
consteval bool isStdType()
Whether T is a standard-library type (see nestedInStd).
consteval bool versionActive()
Whether member M participates for entity version V, per its since/until annotations (absent bounds me...
constexpr bool IsVectorV
Trait: is T a std::vector (an array-chunk member)?
consteval auto membersOf()
The reflected member list of E, public bases flattened in (see collectMembers).
consteval std::meta::info memberNamed(std::string_view name)
The reflected member of E named name (public bases flattened, like membersOf), or the null reflection...
consteval void collectMembers(std::meta::info type, std::vector< std::meta::info > &out)
Collect type's non-static data members with its public bases flattened in FIRST (recursively,...