-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSerialization.h
140 lines (92 loc) · 3.01 KB
/
Serialization.h
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
#pragma once
#include <map>
#include <vector>
#include <string>
class Stream
{
public:
virtual void write(char* buffer, unsigned int byteCount) = 0;
virtual void read(char* buffer, unsigned int byteCount) = 0;
};
Stream& operator<<(Stream& stream, char& value);
Stream& operator<<(Stream& stream, const char& value);
Stream& operator<<(Stream& stream, bool& value);
Stream& operator<<(Stream& stream, short& value);
Stream& operator<<(Stream& stream, unsigned short& value);
Stream& operator<<(Stream& stream, int& value);
Stream& operator<<(Stream& stream, const int& value);
Stream& operator<<(Stream& stream, unsigned int& value);
Stream& operator<<(Stream& stream, const unsigned int& value);
Stream& operator<<(Stream& stream, long& value);
Stream& operator<<(Stream& stream, unsigned long& value);
Stream& operator<<(Stream& stream, const unsigned long& value);
Stream& operator<<(Stream& stream, long long& value);
Stream& operator<<(Stream& stream, unsigned long long& value);
Stream& operator<<(Stream& stream, float& value);
Stream& operator<<(Stream& stream, double& value);
Stream& operator<<(Stream& stream, long double& value);
Stream& operator>>(Stream& stream, char& value);
Stream& operator>>(Stream& stream, bool& value);
Stream& operator>>(Stream& stream, short& value);
Stream& operator>>(Stream& stream, unsigned short& value);
Stream& operator>>(Stream& stream, int& value);
Stream& operator>>(Stream& stream, unsigned int& value);
Stream& operator>>(Stream& stream, long& value);
Stream& operator>>(Stream& stream, unsigned long& value);
Stream& operator>>(Stream& stream, long long& value);
Stream& operator>>(Stream& stream, unsigned long long& value);
Stream& operator>>(Stream& stream, float& value);
Stream& operator>>(Stream& stream, double& value);
Stream& operator>>(Stream& stream, long double& value);
Stream& operator<<(Stream& stream, std::string& str);
Stream& operator>>(Stream& stream, std::string& str);
template <typename T>
Stream& operator<<(Stream& stream, std::vector<T>& vec)
{
stream << vec.size();
for (size_t i = 0; i < vec.size(); i++)
{
stream << vec[i];
}
return stream;
}
template <typename T>
Stream& operator>>(Stream& stream, std::vector<T>& vec)
{
vec.clear();
size_t contSize = 0;
stream >> contSize;
vec.resize(contSize);
for (size_t i = 0; i < contSize; i++)
{
stream >> vec[i];
}
return stream;
}
template <typename T, typename C>
Stream& operator<<(Stream& stream, std::map<T, C>& map)
{
stream << map.size();
for (auto it = map.begin(); it != map.end(); it++)
{
stream << it->first;
stream << it->second;
}
return stream;
}
template <typename T, typename C>
Stream& operator>>(Stream& stream, std::map<T, C>& map)
{
map.clear();
size_t contSize = 0;
stream >> contSize;
for (size_t i = 0; i < contSize; i++)
{
T key;
C val;
stream >> key;
stream >> val;
map.emplace(key, val);
}
return stream;
}