-
Notifications
You must be signed in to change notification settings - Fork 2
/
userefl++.cc
75 lines (60 loc) · 1.28 KB
/
userefl++.cc
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
67
68
69
70
71
72
73
74
75
#include <iostream>
#include <cassert>
#include "refl++.hh"
struct other
{
int j;
};
struct mystruct
{
int i;
struct other o;
int k;
};
static int
something (int c)
{
std::cerr << "simon says: " << c << std::endl;
return c + 1;
}
int (*ddd)(int) = something;
static void
d (mystruct const &my)
{
std::cerr << '{' << my.i << ", {" << my.o.j << "}, "
<< my.k << "}" << std::endl;
}
int value = 111;
int *valuep = &value;
int **valuepp = &valuep;
int ***valueppp = &valuepp;
int
main (int argc, char *argv[])
{
reflpp::refl refl;
reflpp::module mod = refl.module_cur ();
mod.object_named ("ddd").as <int (*)(int)> () (17);
{
reflpp::type mystruct = mod.type_named ("mystruct");
std::cerr << "mystruct is: " << mystruct << std::endl;
reflpp::object obj = mystruct.create ();
obj["i"] = 1;
obj["o"]["j"] = 7;
obj["k"] = 9;
d (obj.as<struct mystruct> ());
obj["o"] = (struct other){ 13 };
d (obj.as<struct mystruct> ());
obj.as<struct mystruct> ().o.j = 15;
d (obj.as<struct mystruct> ());
}
{
reflpp::object vppp = mod.object_named ("valueppp");
while (vppp.type ().is_pointer ())
vppp = *vppp;
std::cerr << "v = " << vppp.as<int> () << std::endl;
}
{
mod.method_named ("something");
}
return 0;
}