-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathmain.cpp
53 lines (41 loc) · 1.05 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
#include <UDRefl/UDRefl.hpp>
#include <iostream>
#include <cmath>
using namespace Ubpa;
using namespace Ubpa::UDRefl;
struct Vec {
float x;
float y;
float Norm2() const noexcept {
return x * x + y * y;
}
void NormalizeSelf() noexcept {
float n = std::sqrt(Norm2());
assert(n != 0);
x /= n;
y /= n;
}
Vec& operator+=(const Vec& p) noexcept {
x += p.x;
y += p.y;
return *this;
}
};
int main() {
{ // register Vec
Mngr.RegisterType<Vec>();
Mngr.AddConstructor<Vec, float, float>();
Mngr.AddField<&Vec::x>("x");
Mngr.AddField<&Vec::y>("y");
Mngr.AddMethod<&Vec::Norm2>("Norm2");
Mngr.AddMethod<&Vec::NormalizeSelf>("NormalizeSelf");
Mngr.AddMethod<&Vec::operator+= >(NameIDRegistry::Meta::operator_assignment_add);
}
auto v = Mngr.MakeShared(Type_of<Vec>, TempArgsView{ 1.f, 2.f });
v.Invoke("NormalizeSelf");
std::cout << v.Var("x") << ", " << v.Var("y") << std::endl;
std::cout << v.Invoke("Norm2") << std::endl;
auto w = v += Vec{ 10.f,10.f };
std::cout << w.Var("x") << ", " << w.Var("y") << std::endl;
return 0;
}