forked from bk192077/struct_mapping
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap_like.cpp
62 lines (53 loc) · 1.01 KB
/
map_like.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
#include "struct_mapping/struct_mapping.h"
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <unordered_map>
struct Library
{
std::unordered_map<
std::string,
std::multimap<std::string, int>> counters;
std::multimap<
std::string,
std::unordered_multimap<std::string, std::string>> books;
};
int main()
{
struct_mapping::reg(&Library::counters, "counters");
struct_mapping::reg(&Library::books, "books");
Library library;
std::istringstream json_data(R"json(
{
"counters": {
"first": {
"112": 13,
"142": 560,
"112": 0
},
"second": {
"2": 28,
"20": 411
},
"third": {
}
},
"books": {
"asd": {
"Leo": "aaa",
"Leo": "bbb",
"Mark": "ccc"
},
"wwert": {
"Gogol": "ddd",
"Tom": "eee"
}
}
}
)json");
struct_mapping::map_json_to_struct(library, json_data);
std::ostringstream out_json_data;
struct_mapping::map_struct_to_json(library, out_json_data, " ");
std::cout << out_json_data.str() << std::endl;
}