-
Notifications
You must be signed in to change notification settings - Fork 59
/
main.cpp
59 lines (49 loc) · 1.26 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
#include <UDRefl/UDRefl.hpp>
#include <iostream>
#include "Vector.hpp"
using namespace Ubpa;
using namespace Ubpa::UDRefl;
void Serializer(ObjectView obj) {
if (type_name_is_arithmetic(obj.GetType().GetName()))
std::cout << obj;
else {
std::cout << "{" << "\"TYPE\":\"" << obj.GetType().GetName() << "\",";
auto* info = Mngr.GetTypeInfo(obj.GetType());
auto iter = info->attrs.find(Type_of<ContainerType>);
if (iter != info->attrs.end()) {
if (*iter == ContainerType::Vector) {
std::cout << "\"Vector\":[";
for (size_t i = 0; i < obj.size(); i++) {
Serializer(obj[i].RemoveReference());
if (i + 1 != obj.size())
std::cout << ",";
}
std::cout << "]";
}
}
else { // normal object
auto vars = obj.GetVars();
auto iter = vars.begin();
while (iter != vars.end()) {
auto [name, var] = *iter;
std::cout << "\"" << name.GetView() << "\":";
Serializer(var);
if (++iter != vars.end())
std::cout << ",";
}
}
std::cout << "}";
}
}
int main() {
RegisterVector();
auto a = Mngr.MakeShared(Type_of<Vector>);
for (size_t i = 0; i < 10; i++) {
std::vector<size_t> row;
for (size_t j = 0; j < 10; j++)
row.push_back(j);
a.Var("data").push_back(std::move(row));
}
Serializer(a);
return 0;
}