-
Notifications
You must be signed in to change notification settings - Fork 59
/
main.cpp
39 lines (30 loc) · 900 Bytes
/
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
#include <UDRefl/UDRefl.hpp>
#include <iostream>
#include <cmath>
using namespace Ubpa;
using namespace Ubpa::UDRefl;
struct Vec {
float x;
float y;
float norm() const {
return std::sqrt(x * x + y * y);
}
};
int main() {
Mngr.RegisterType<Vec>();
Mngr.AddField<&Vec::x>("x");
Mngr.AddField<&Vec::y>("y");
Mngr.AddMethod<&Vec::norm>("norm");
SharedObject v = Mngr.MakeShared(Type_of<Vec>);
std::cout << v.GetType().GetName() << std::endl; // prints "Vec"
v.Var("x") = 3;
v.Var("y") = 4;
std::cout << "x: " << v.Var("x") << std::endl;
std::cout << "norm: " << v.Invoke("norm") << std::endl;
for (auto&& [name, info] : FieldRange_of<Vec>)
std::cout << name.GetView() << std::endl;
for (auto&& [name, info] : MethodRange_of<Vec>)
std::cout << name.GetView() << std::endl;
for (auto&& [name, var] : v.GetVars())
std::cout << name.GetView() << ": " << var << std::endl;
}