-
Notifications
You must be signed in to change notification settings - Fork 59
/
main.cpp
47 lines (39 loc) · 1022 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
40
41
42
43
44
45
46
47
#include <UDRefl/UDRefl.hpp>
#include <iostream>
#include <array>
#include <cmath>
using namespace Ubpa;
using namespace Ubpa::UDRefl;
struct Vec {
float x;
float y;
float norm() const noexcept {
return std::sqrt(x * x + y * y);
}
Vec copy() const noexcept {
return *this;
}
Vec operator+(const Vec& v) const noexcept {
Vec rst;
rst.x = x + v.x;
rst.y = y + v.y;
return rst;
}
};
int main() {
Mngr.RegisterType<Vec>();
Mngr.AddField<&Vec::x>("x");
Mngr.AddField<&Vec::y>("y");
Mngr.AddMethod<&Vec::norm>("norm");
Mngr.AddMethod<&Vec::copy>("copy");
SharedObject v = Mngr.MakeShared(Type_of<Vec>);
v.Var("x") = 3.f;
v.Var("y") = 4.f;
auto w0 = v.MInvoke(NameIDRegistry::Meta::operator_add, std::pmr::get_default_resource(), TempArgsView{ v });
auto w1 = v.Invoke(NameIDRegistry::Meta::operator_add, TempArgsView{ v });
std::array arr_w = { w0,w1 };
for (auto w : arr_w) {
for (const auto& [name, var] : w.GetVars())
std::cout << name.GetView() << ": " << var << std::endl;
}
}