-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.cpp
149 lines (130 loc) · 3.56 KB
/
demo.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include "Serializer.h"
using namespace femto;
#include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
using namespace std;
struct DB {
typedef unsigned long Id;
struct Table {
struct Entry {
Entry(const string & data_="") : data(data_) {}
string data;
private:
SERIALIZE_MEMBERS(Entry, data)
};
Table(const string & descr_="") : _id(++lastId), _descr(descr_) {}
Id id() const { return _id; }
Entry & addEntry(const string & d="") { _entries.emplace_back(d); return _entries.back(); }
private:
static Id lastId;
Id _id;
string _descr;
vector<Entry> _entries;
SERIALIZE_MEMBERS(Table, _id, _descr, _entries)
};
Table & newTable(const string & descr="") { Table t(descr); return _tables[t.id()] = move(t); }
private:
unordered_map<Id, Table> _tables;
SERIALIZE_MEMBERS(DB,_tables)
};
DB::Id DB::Table::lastId=0;
int main() {
{
stringstream ss;
auto s = serializer(ss);
{
DB db;
{
auto & t = db.newTable("First table");
t.addEntry("a");
t.addEntry("s");
t.addEntry("d");
t.addEntry("f");
}
{
auto & t = db.newTable("Second table");
t.addEntry("a");
t.addEntry("s");
t.addEntry("d");
t.addEntry("f");
}
s << db;
}
{
DB db;
s >> db;
}
}
{
stringstream ss;
auto s = serializer(ss);
vector<char> aVector = {'a','s','d','f'};
s << aVector;
vector<char> bVector;
s >> bVector;
for(auto a: bVector) cout << a << ",";
cout << endl;
cout << "vector-> " << ss.str() << endl;
}
{
stringstream ss;
auto s = serializer(ss);
array<char,4> aArray = {{'a','s','d','f'}};
s << aArray;
array<char,4> bArray;
s >> bArray;
for(auto a: bArray) cout << a << ",";
cout << endl;
cout << "array-> " << ss.str() << endl;
}
{
stringstream ss;
auto s = serializer(ss);
set<char> aSet = {'a','s','d','f'};
s << aSet;
set<char> bSet;
s >> bSet;
for(auto a: bSet) cout << a << ",";
cout << endl;
cout << "set-> " << ss.str() << endl;
}
{
stringstream ss;
auto s = serializer(ss);
unordered_set<char> aSet = {'a','s','d','f'};
s << aSet;
unordered_set<char> bSet;
s >> bSet;
for(auto a: bSet) cout << a << ",";
cout << endl;
cout << "unordered_set-> " << ss.str() << endl;
}
{
stringstream ss;
auto s = serializer(ss);
map<char,char> aMap = {{'a','a'},{'b','b'},{'x','x'},};
s << aMap;
map<char,char> bMap;
s >> bMap;
for(auto a: bMap) cout << a.first << "=" << a.second << ",";
cout << endl;
cout << "map-> " << ss.str() << endl;
}
{
stringstream ss;
auto s = serializer(ss);
unordered_map<char,char> aMap = {{'a','a'},{'b','b'},{'x','x'},};
s << aMap;
unordered_map<char,char> bMap;
s >> bMap;
for(auto a: bMap) cout << a.first << "=" << a.second << ",";
cout << endl;
cout << "unordered_map-> " << ss.str() << endl;
}
return 0;
}