forked from bk192077/struct_mapping
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathin_struct_reg.cpp
51 lines (44 loc) · 991 Bytes
/
in_struct_reg.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
#include "struct_mapping/struct_mapping.h"
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
struct Planet
{
bool giant = []
{
struct_mapping::reg(&Planet::giant, "giant");
return false;
} ();
long long surface_area = []
{
struct_mapping::reg(&Planet::surface_area, "surface_area");
return 0;
} ();
double mass = []
{
struct_mapping::reg(&Planet::mass, "mass");
return 0;
} ();
std::vector<std::string> satellites = []
{
struct_mapping::reg(&Planet::satellites, "satellites");
return std::vector<std::string>{};
} ();
};
int main()
{
std::istringstream json_data(R"json(
{
"giant": false,
"surface_area": 510072000000000,
"mass": 5.97237e24,
"satellites": ["Moon", "R24"]
}
)json");
Planet earth;
struct_mapping::map_json_to_struct(earth, json_data);
std::ostringstream out_json_data;
struct_mapping::map_struct_to_json(earth, out_json_data, " ");
std::cout << out_json_data.str() << std::endl;
}