-
Notifications
You must be signed in to change notification settings - Fork 71
/
main.cpp
66 lines (54 loc) · 1.46 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <USRefl/USRefl.h>
#include <iostream>
using namespace Ubpa::USRefl;
using namespace std;
struct [[size(8)]] Point {
[[not_serialize]]
float x;
[[info("hello")]]
float y;
static constexpr std::size_t id = 1024;
};
template<>
struct Ubpa::USRefl::TypeInfo<Point> :
TypeInfoBase<Point>
{
static constexpr AttrList attrs = {
Attr {TSTR("size"), 8},
};
static constexpr FieldList fields = {
Field {TSTR("x"), &Type::x, AttrList {
Attr {TSTR("not_serialize")},
}},
Field {TSTR("y"), &Type::y, AttrList {
Attr {TSTR("info"), "hello"},
}},
Field {TSTR("id"), Type::id},
};
};
int main() {
Point p{ 1,2 };
TypeInfo<Point>::fields.ForEach([](auto field) {
cout << field.name << endl;
field.attrs.ForEach([](auto attr) {
cout << "name : " << attr.name << endl;
if constexpr (attr.has_value)
cout << "value : " << attr.value << endl;
});
});
constexpr auto y_field = TypeInfo<Point>::fields.Find(TSTR("y"));
static_assert(y_field.name == "y");
static_assert(TypeInfo<Point>::fields.Contains(TSTR("x")));
TypeInfo<Point>::attrs.ForEach([](auto attr) {
cout << "name : " << attr.name << endl;
if constexpr (!attr.has_value)
cout << "value : " << attr.value << endl;
});
TypeInfo<Point>::ForEachVarOf(p, [](auto field, auto&& var) {
cout << field.name << " : " << var << endl;
});
TypeInfo<Point>::fields.ForEach([](auto field) {
if constexpr (field.is_static)
cout << field.name << ": " << field.value << endl;
});
}