wowlib
0.0.0
Read & write World of Warcraft client files — a C++26 core
Toggle main menu visibility
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
23
#include <
wowlib/core/client_version.hpp
>
24
#include <
wowlib/formats/common/annotations.hpp
>
25
26
namespace
wowlib::formats::detail
{
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.hpp
Client version identity, the flavor axis that separates a client's CONTENT version from the engine ge...
annotations.hpp
The chunk annotation vocabulary format entities declare their binary mapping with.
wowlib::formats::detail
Definition
annotations.hpp:50
wowlib::formats::detail::annotation
consteval std::optional< Spec > annotation()
The first annotation of type Spec on reflected member M, if any.
Definition
entity_reflect.hpp:32
wowlib::formats::detail::nestedInStd
consteval bool nestedInStd(std::meta::info r)
Whether r is declared inside namespace std (at any nesting depth — libstdc++ hides types in inline na...
Definition
entity_reflect.hpp:103
wowlib::formats::detail::isStdType
consteval bool isStdType()
Whether T is a standard-library type (see nestedInStd).
Definition
entity_reflect.hpp:115
wowlib::formats::detail::versionActive
consteval bool versionActive()
Whether member M participates for entity version V, per its since/until annotations (absent bounds me...
Definition
entity_reflect.hpp:43
wowlib::formats::detail::IsVectorV
constexpr bool IsVectorV
Trait: is T a std::vector (an array-chunk member)?
Definition
entity_reflect.hpp:51
wowlib::formats::detail::membersOf
consteval auto membersOf()
The reflected member list of E, public bases flattened in (see collectMembers).
Definition
entity_reflect.hpp:76
wowlib::formats::detail::memberNamed
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...
Definition
entity_reflect.hpp:91
wowlib::formats::detail::collectMembers
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,...
Definition
entity_reflect.hpp:64
src
wowlib
formats
common
entity_reflect.hpp
Generated by
1.17.0