diff options
Diffstat (limited to '')
-rw-r--r-- | src/archive.cpp (renamed from src/old/serializer.cpp) | 103 |
1 files changed, 51 insertions, 52 deletions
diff --git a/src/old/serializer.cpp b/src/archive.cpp index 636224e..5f5145c 100644 --- a/src/old/serializer.cpp +++ b/src/archive.cpp | |||
@@ -1,152 +1,150 @@ | |||
1 | #include "serializer.h" | 1 | #include "archive.h" |
2 | #include "serializable.h" | ||
3 | #include <list> | ||
4 | 2 | ||
5 | Serializer::Serializer(bool bLoading): | 3 | Bu::Archive::Archive(bool bLoading): |
6 | bLoading(bLoading) | 4 | bLoading(bLoading) |
7 | { | 5 | { |
8 | } | 6 | } |
9 | Serializer::~Serializer() | 7 | Bu::Archive::~Archive() |
10 | { | 8 | { |
11 | } | 9 | } |
12 | 10 | ||
13 | bool Serializer::isLoading() | 11 | bool Bu::Archive::isLoading() |
14 | { | 12 | { |
15 | return bLoading; | 13 | return bLoading; |
16 | } | 14 | } |
17 | Serializer &Serializer::operator<<(bool p) | 15 | Bu::Archive &Bu::Archive::operator<<(bool p) |
18 | { | 16 | { |
19 | write( &p, sizeof(p) ); | 17 | write( &p, sizeof(p) ); |
20 | return *this; | 18 | return *this; |
21 | } | 19 | } |
22 | Serializer &Serializer::operator<<(int8_t p) | 20 | Bu::Archive &Bu::Archive::operator<<(int8_t p) |
23 | { | 21 | { |
24 | write( &p, sizeof(p) ); | 22 | write( &p, sizeof(p) ); |
25 | return *this; | 23 | return *this; |
26 | } | 24 | } |
27 | Serializer &Serializer::operator<<(int16_t p) | 25 | Bu::Archive &Bu::Archive::operator<<(int16_t p) |
28 | { | 26 | { |
29 | write( &p, sizeof(p) ); | 27 | write( &p, sizeof(p) ); |
30 | return *this; | 28 | return *this; |
31 | } | 29 | } |
32 | Serializer &Serializer::operator<<(int32_t p) | 30 | Bu::Archive &Bu::Archive::operator<<(int32_t p) |
33 | { | 31 | { |
34 | write( &p, sizeof(p) ); | 32 | write( &p, sizeof(p) ); |
35 | return *this; | 33 | return *this; |
36 | } | 34 | } |
37 | Serializer &Serializer::operator<<(int64_t p) | 35 | Bu::Archive &Bu::Archive::operator<<(int64_t p) |
38 | { | 36 | { |
39 | write( &p, sizeof(p) ); | 37 | write( &p, sizeof(p) ); |
40 | return *this; | 38 | return *this; |
41 | } | 39 | } |
42 | Serializer &Serializer::operator<<(uint8_t p) | 40 | Bu::Archive &Bu::Archive::operator<<(uint8_t p) |
43 | { | 41 | { |
44 | write( &p, sizeof(p) ); | 42 | write( &p, sizeof(p) ); |
45 | return *this; | 43 | return *this; |
46 | } | 44 | } |
47 | Serializer &Serializer::operator<<(uint16_t p) | 45 | Bu::Archive &Bu::Archive::operator<<(uint16_t p) |
48 | { | 46 | { |
49 | write( &p, sizeof(p) ); | 47 | write( &p, sizeof(p) ); |
50 | return *this; | 48 | return *this; |
51 | } | 49 | } |
52 | Serializer &Serializer::operator<<(uint32_t p) | 50 | Bu::Archive &Bu::Archive::operator<<(uint32_t p) |
53 | { | 51 | { |
54 | write( &p, sizeof(p) ); | 52 | write( &p, sizeof(p) ); |
55 | return *this; | 53 | return *this; |
56 | } | 54 | } |
57 | Serializer &Serializer::operator<<(uint64_t p) | 55 | Bu::Archive &Bu::Archive::operator<<(uint64_t p) |
58 | { | 56 | { |
59 | write( &p, sizeof(p) ); | 57 | write( &p, sizeof(p) ); |
60 | return *this; | 58 | return *this; |
61 | } | 59 | } |
62 | Serializer &Serializer::operator<<(long p) | 60 | Bu::Archive &Bu::Archive::operator<<(long p) |
63 | { | 61 | { |
64 | write( &p, sizeof(p) ); | 62 | write( &p, sizeof(p) ); |
65 | return *this; | 63 | return *this; |
66 | } | 64 | } |
67 | Serializer &Serializer::operator<<(float p) | 65 | Bu::Archive &Bu::Archive::operator<<(float p) |
68 | { | 66 | { |
69 | write( &p, sizeof(p) ); | 67 | write( &p, sizeof(p) ); |
70 | return *this; | 68 | return *this; |
71 | } | 69 | } |
72 | Serializer &Serializer::operator<<(double p) | 70 | Bu::Archive &Bu::Archive::operator<<(double p) |
73 | { | 71 | { |
74 | write( &p, sizeof(p) ); | 72 | write( &p, sizeof(p) ); |
75 | return *this; | 73 | return *this; |
76 | } | 74 | } |
77 | Serializer &Serializer::operator<<(long double p) | 75 | Bu::Archive &Bu::Archive::operator<<(long double p) |
78 | { | 76 | { |
79 | write( &p, sizeof(p) ); | 77 | write( &p, sizeof(p) ); |
80 | return *this; | 78 | return *this; |
81 | } | 79 | } |
82 | 80 | ||
83 | Serializer &Serializer::operator>>(bool &p) | 81 | Bu::Archive &Bu::Archive::operator>>(bool &p) |
84 | { | 82 | { |
85 | read( &p, sizeof(p) ); | 83 | read( &p, sizeof(p) ); |
86 | return *this; | 84 | return *this; |
87 | } | 85 | } |
88 | Serializer &Serializer::operator>>(int8_t &p) | 86 | Bu::Archive &Bu::Archive::operator>>(int8_t &p) |
89 | { | 87 | { |
90 | read( &p, sizeof(p) ); | 88 | read( &p, sizeof(p) ); |
91 | return *this; | 89 | return *this; |
92 | } | 90 | } |
93 | Serializer &Serializer::operator>>(int16_t &p) | 91 | Bu::Archive &Bu::Archive::operator>>(int16_t &p) |
94 | { | 92 | { |
95 | read( &p, sizeof(p) ); | 93 | read( &p, sizeof(p) ); |
96 | return *this; | 94 | return *this; |
97 | } | 95 | } |
98 | Serializer &Serializer::operator>>(int32_t &p) | 96 | Bu::Archive &Bu::Archive::operator>>(int32_t &p) |
99 | { | 97 | { |
100 | read( &p, sizeof(p) ); | 98 | read( &p, sizeof(p) ); |
101 | return *this; | 99 | return *this; |
102 | } | 100 | } |
103 | Serializer &Serializer::operator>>(int64_t &p) | 101 | Bu::Archive &Bu::Archive::operator>>(int64_t &p) |
104 | { | 102 | { |
105 | read( &p, sizeof(p) ); | 103 | read( &p, sizeof(p) ); |
106 | return *this; | 104 | return *this; |
107 | } | 105 | } |
108 | Serializer &Serializer::operator>>(uint8_t &p) | 106 | Bu::Archive &Bu::Archive::operator>>(uint8_t &p) |
109 | { | 107 | { |
110 | read( &p, sizeof(p) ); | 108 | read( &p, sizeof(p) ); |
111 | return *this; | 109 | return *this; |
112 | } | 110 | } |
113 | Serializer &Serializer::operator>>(uint16_t &p) | 111 | Bu::Archive &Bu::Archive::operator>>(uint16_t &p) |
114 | { | 112 | { |
115 | read( &p, sizeof(p) ); | 113 | read( &p, sizeof(p) ); |
116 | return *this; | 114 | return *this; |
117 | } | 115 | } |
118 | Serializer &Serializer::operator>>(uint32_t &p) | 116 | Bu::Archive &Bu::Archive::operator>>(uint32_t &p) |
119 | { | 117 | { |
120 | read( &p, sizeof(p) ); | 118 | read( &p, sizeof(p) ); |
121 | return *this; | 119 | return *this; |
122 | } | 120 | } |
123 | Serializer &Serializer::operator>>(uint64_t &p) | 121 | Bu::Archive &Bu::Archive::operator>>(uint64_t &p) |
124 | { | 122 | { |
125 | read( &p, sizeof(p) ); | 123 | read( &p, sizeof(p) ); |
126 | return *this; | 124 | return *this; |
127 | } | 125 | } |
128 | Serializer &Serializer::operator>>(long &p) | 126 | Bu::Archive &Bu::Archive::operator>>(long &p) |
129 | { | 127 | { |
130 | read( &p, sizeof(p) ); | 128 | read( &p, sizeof(p) ); |
131 | return *this; | 129 | return *this; |
132 | } | 130 | } |
133 | Serializer &Serializer::operator>>(float &p) | 131 | Bu::Archive &Bu::Archive::operator>>(float &p) |
134 | { | 132 | { |
135 | read( &p, sizeof(p) ); | 133 | read( &p, sizeof(p) ); |
136 | return *this; | 134 | return *this; |
137 | } | 135 | } |
138 | Serializer &Serializer::operator>>(double &p) | 136 | Bu::Archive &Bu::Archive::operator>>(double &p) |
139 | { | 137 | { |
140 | read( &p, sizeof(p) ); | 138 | read( &p, sizeof(p) ); |
141 | return *this; | 139 | return *this; |
142 | } | 140 | } |
143 | Serializer &Serializer::operator>>(long double &p) | 141 | Bu::Archive &Bu::Archive::operator>>(long double &p) |
144 | { | 142 | { |
145 | read( &p, sizeof(p) ); | 143 | read( &p, sizeof(p) ); |
146 | return *this; | 144 | return *this; |
147 | } | 145 | } |
148 | 146 | ||
149 | Serializer &Serializer::operator&&(bool &p) | 147 | Bu::Archive &Bu::Archive::operator&&(bool &p) |
150 | { | 148 | { |
151 | if (bLoading) | 149 | if (bLoading) |
152 | { | 150 | { |
@@ -158,7 +156,7 @@ Serializer &Serializer::operator&&(bool &p) | |||
158 | } | 156 | } |
159 | } | 157 | } |
160 | 158 | ||
161 | Serializer &Serializer::operator&&(int8_t &p) | 159 | Bu::Archive &Bu::Archive::operator&&(int8_t &p) |
162 | { | 160 | { |
163 | if (bLoading) | 161 | if (bLoading) |
164 | { | 162 | { |
@@ -170,7 +168,7 @@ Serializer &Serializer::operator&&(int8_t &p) | |||
170 | } | 168 | } |
171 | } | 169 | } |
172 | 170 | ||
173 | Serializer &Serializer::operator&&(int16_t &p) | 171 | Bu::Archive &Bu::Archive::operator&&(int16_t &p) |
174 | { | 172 | { |
175 | if (bLoading) | 173 | if (bLoading) |
176 | { | 174 | { |
@@ -182,7 +180,7 @@ Serializer &Serializer::operator&&(int16_t &p) | |||
182 | } | 180 | } |
183 | } | 181 | } |
184 | 182 | ||
185 | Serializer &Serializer::operator&&(int32_t &p) | 183 | Bu::Archive &Bu::Archive::operator&&(int32_t &p) |
186 | { | 184 | { |
187 | if (bLoading) | 185 | if (bLoading) |
188 | { | 186 | { |
@@ -194,7 +192,7 @@ Serializer &Serializer::operator&&(int32_t &p) | |||
194 | } | 192 | } |
195 | } | 193 | } |
196 | 194 | ||
197 | Serializer &Serializer::operator&&(int64_t &p) | 195 | Bu::Archive &Bu::Archive::operator&&(int64_t &p) |
198 | { | 196 | { |
199 | if (bLoading) | 197 | if (bLoading) |
200 | { | 198 | { |
@@ -206,7 +204,7 @@ Serializer &Serializer::operator&&(int64_t &p) | |||
206 | } | 204 | } |
207 | } | 205 | } |
208 | 206 | ||
209 | Serializer &Serializer::operator&&(uint8_t &p) | 207 | Bu::Archive &Bu::Archive::operator&&(uint8_t &p) |
210 | { | 208 | { |
211 | if (bLoading) | 209 | if (bLoading) |
212 | { | 210 | { |
@@ -218,7 +216,7 @@ Serializer &Serializer::operator&&(uint8_t &p) | |||
218 | } | 216 | } |
219 | } | 217 | } |
220 | 218 | ||
221 | Serializer &Serializer::operator&&(uint16_t &p) | 219 | Bu::Archive &Bu::Archive::operator&&(uint16_t &p) |
222 | { | 220 | { |
223 | if (bLoading) | 221 | if (bLoading) |
224 | { | 222 | { |
@@ -230,7 +228,7 @@ Serializer &Serializer::operator&&(uint16_t &p) | |||
230 | } | 228 | } |
231 | } | 229 | } |
232 | 230 | ||
233 | Serializer &Serializer::operator&&(uint32_t &p) | 231 | Bu::Archive &Bu::Archive::operator&&(uint32_t &p) |
234 | { | 232 | { |
235 | if (bLoading) | 233 | if (bLoading) |
236 | { | 234 | { |
@@ -242,7 +240,7 @@ Serializer &Serializer::operator&&(uint32_t &p) | |||
242 | } | 240 | } |
243 | } | 241 | } |
244 | 242 | ||
245 | Serializer &Serializer::operator&&(uint64_t &p) | 243 | Bu::Archive &Bu::Archive::operator&&(uint64_t &p) |
246 | { | 244 | { |
247 | if (bLoading) | 245 | if (bLoading) |
248 | { | 246 | { |
@@ -254,7 +252,7 @@ Serializer &Serializer::operator&&(uint64_t &p) | |||
254 | } | 252 | } |
255 | } | 253 | } |
256 | 254 | ||
257 | Serializer &Serializer::operator&&(float &p) | 255 | Bu::Archive &Bu::Archive::operator&&(float &p) |
258 | { | 256 | { |
259 | if (bLoading) | 257 | if (bLoading) |
260 | { | 258 | { |
@@ -266,7 +264,7 @@ Serializer &Serializer::operator&&(float &p) | |||
266 | } | 264 | } |
267 | } | 265 | } |
268 | 266 | ||
269 | Serializer &Serializer::operator&&(double &p) | 267 | Bu::Archive &Bu::Archive::operator&&(double &p) |
270 | { | 268 | { |
271 | if (bLoading) | 269 | if (bLoading) |
272 | { | 270 | { |
@@ -278,7 +276,7 @@ Serializer &Serializer::operator&&(double &p) | |||
278 | } | 276 | } |
279 | } | 277 | } |
280 | 278 | ||
281 | Serializer &Serializer::operator&&(long double &p) | 279 | Bu::Archive &Bu::Archive::operator&&(long double &p) |
282 | { | 280 | { |
283 | if (bLoading) | 281 | if (bLoading) |
284 | { | 282 | { |
@@ -291,19 +289,20 @@ Serializer &Serializer::operator&&(long double &p) | |||
291 | } | 289 | } |
292 | 290 | ||
293 | 291 | ||
294 | Serializer &operator<<(Serializer &s, Serializable &p) | 292 | Bu::Archive &Bu::operator<<(Bu::Archive &s, Bu::Archable &p) |
295 | { | 293 | { |
296 | p.serialize( s ); | 294 | p.archive( s ); |
297 | return s; | 295 | return s; |
298 | } | 296 | } |
299 | 297 | ||
300 | Serializer &operator>>(Serializer &s, Serializable &p) | 298 | Bu::Archive &Bu::operator>>(Bu::Archive &s, Bu::Archable &p) |
301 | { | 299 | { |
302 | p.serialize( s ); | 300 | p.archive( s ); |
303 | return s; | 301 | return s; |
304 | } | 302 | } |
305 | 303 | ||
306 | Serializer &operator&&(Serializer &s, Serializable &p) | 304 | /* |
305 | Bu::Archive &Bu::operator&&(Bu::Archive &s, Bu::Archable &p) | ||
307 | { | 306 | { |
308 | if (s.isLoading()) | 307 | if (s.isLoading()) |
309 | { | 308 | { |
@@ -313,9 +312,9 @@ Serializer &operator&&(Serializer &s, Serializable &p) | |||
313 | { | 312 | { |
314 | return s << p; | 313 | return s << p; |
315 | } | 314 | } |
316 | } | 315 | }*/ |
317 | 316 | ||
318 | Serializer &operator<<( Serializer &ar, std::string &s ) | 317 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, std::string &s ) |
319 | { | 318 | { |
320 | ar << (uint32_t)s.length(); | 319 | ar << (uint32_t)s.length(); |
321 | ar.write( s.c_str(), s.length() ); | 320 | ar.write( s.c_str(), s.length() ); |
@@ -323,7 +322,7 @@ Serializer &operator<<( Serializer &ar, std::string &s ) | |||
323 | return ar; | 322 | return ar; |
324 | } | 323 | } |
325 | 324 | ||
326 | Serializer &operator>>( Serializer &ar, std::string &s ) | 325 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, std::string &s ) |
327 | { | 326 | { |
328 | uint32_t l; | 327 | uint32_t l; |
329 | ar >> l; | 328 | ar >> l; |