forked from bk192077/struct_mapping
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.cpp
73 lines (62 loc) · 1.73 KB
/
options.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
#include "struct_mapping/struct_mapping.h"
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <unordered_set>
namespace sm = struct_mapping;
struct Stage
{
unsigned short engine_count;
std::string fuel;
long length;
};
struct Spacecraft
{
bool in_development;
std::string name;
int mass;
std::map<std::string, Stage> stages;
std::list<std::string> crew;
std::set<int> ids;
std::unordered_set<std::string> tools;
};
int main()
{
sm::reg(&Stage::engine_count, "engine_count", sm::Default{6}, sm::Bounds{1, 31});
sm::reg(&Stage::fuel, "fuel", sm::Default{"subcooled"});
sm::reg(&Stage::length, "length", sm::Default{50});
sm::reg(&Spacecraft::in_development, "in_development", sm::Required{});
sm::reg(&Spacecraft::name, "name", sm::NotEmpty{});
sm::reg(&Spacecraft::mass, "mass", sm::Default{5000000}, sm::Bounds{100000, 10000000});
sm::reg(&Spacecraft::stages, "stages", sm::NotEmpty{});
sm::reg(&Spacecraft::crew, "crew", sm::Default{std::list<std::string>{"Arthur", "Ford", "Marvin"}});
sm::reg(&Spacecraft::ids, "ids", sm::Default{std::set<int>{14, 159}});
sm::reg(&Spacecraft::tools, "tools", sm::NotEmpty{});
Spacecraft starship;
std::istringstream json_data(R"json(
{
"in_development": false,
"name": "Vostok",
"stages": {
"first": {
"engine_count": 31,
"fuel": "compressed gas",
"length": 70
},
"second": {}
},
"tools": [
"Reverberating Carbonizer With Mutate Capacity",
"Noisy Cricket",
"The Series 4 De-Atomizer"
]
}
)json");
sm::map_json_to_struct(starship, json_data);
std::ostringstream out_json_data;
struct_mapping::map_struct_to_json(starship, out_json_data, " ");
std::cout << out_json_data.str() << std::endl;
}