forked from bk192077/struct_mapping
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray.cpp
98 lines (86 loc) · 1.69 KB
/
array.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <iostream>
#include <sstream>
#include "struct_mapping/struct_mapping.h"
BEGIN_MANAGED_STRUCT(MiB)
MANAGED_FIELD_ARRAY(std::string, friends)
MANAGED_FIELD_ARRAY(MANAGED_ARRAY(std::string), alien_groups)
MANAGED_FIELD_ARRAY(MANAGED_ARRAY(MANAGED_ARRAY(std::string)), planet_groups)
END_MANAGED_STRUCT
int main() {
MiB mib;
std::istringstream json_data(R"json(
{
"friends": [
"Griffin",
"Boris",
"Agent K"
],
"alien_groups": [
[
"Edgar the Bug",
"Boris the Animal",
"Charlie",
"Serleena"
],
[
"Agent J",
"Agent K",
"Zed",
"Griffin",
"Roman the Fabulist"
]
],
"planet_groups": [
[
[
"Mercury",
"Venus",
"Earth",
"Mars"
],
[
"Jupiter",
"Saturn",
"Uranus",
"Neptune"
]
],
[
[
"Titan",
"Ganymede"
],
[
"Eris",
"Titania"
]
]
]
}
)json");
struct_mapping::mapper::map_json_to_struct(mib, json_data);
std::cout << "mib:" << std::endl;
std::cout << " friends :" << std::endl;
for (auto& f : mib.friends.get_data()) {
std::cout << " " << f << std::endl;
}
std::cout << " aliens_groups :" << std::endl;
for (auto& alien : mib.alien_groups.get_data()) {
for (auto& name : alien.get_data()) {
std::cout << " " << name << std::endl;
}
std::cout << std::endl;
}
std::cout << " planets_groups :" << std::endl;
for (auto& group : mib.planet_groups.get_data()) {
std::cout << " ---" << std::endl;
for (auto& category : group.get_data()) {
for (auto& planet : category.get_data()) {
std::cout << " " << planet << std::endl;
}
std::cout << std::endl;
}
std::cout << std::endl;
}
std::cout << std::endl;
}