aboutsummaryrefslogtreecommitdiff
path: root/src/old/serializer.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-04-03 03:49:53 +0000
committerMike Buland <eichlan@xagasoft.com>2007-04-03 03:49:53 +0000
commitf4c20290509d7ed3a8fd5304577e7a4cc0b9d974 (patch)
tree13cdf64f7cf134f397a7165b7a3fe0807e37026b /src/old/serializer.cpp
parent74d4c8cd27334fc7204d5a8773deb3d424565778 (diff)
downloadlibbu++-f4c20290509d7ed3a8fd5304577e7a4cc0b9d974.tar.gz
libbu++-f4c20290509d7ed3a8fd5304577e7a4cc0b9d974.tar.bz2
libbu++-f4c20290509d7ed3a8fd5304577e7a4cc0b9d974.tar.xz
libbu++-f4c20290509d7ed3a8fd5304577e7a4cc0b9d974.zip
Ok, no code is left in src, it's all in src/old. We'll gradually move code back
into src as it's fixed and re-org'd. This includes tests, which, I may write a unit test system into libbu++ just to make my life easier.
Diffstat (limited to 'src/old/serializer.cpp')
-rw-r--r--src/old/serializer.cpp338
1 files changed, 338 insertions, 0 deletions
diff --git a/src/old/serializer.cpp b/src/old/serializer.cpp
new file mode 100644
index 0000000..636224e
--- /dev/null
+++ b/src/old/serializer.cpp
@@ -0,0 +1,338 @@
1#include "serializer.h"
2#include "serializable.h"
3#include <list>
4
5Serializer::Serializer(bool bLoading):
6 bLoading(bLoading)
7{
8}
9Serializer::~Serializer()
10{
11}
12
13bool Serializer::isLoading()
14{
15 return bLoading;
16}
17Serializer &Serializer::operator<<(bool p)
18{
19 write( &p, sizeof(p) );
20 return *this;
21}
22Serializer &Serializer::operator<<(int8_t p)
23{
24 write( &p, sizeof(p) );
25 return *this;
26}
27Serializer &Serializer::operator<<(int16_t p)
28{
29 write( &p, sizeof(p) );
30 return *this;
31}
32Serializer &Serializer::operator<<(int32_t p)
33{
34 write( &p, sizeof(p) );
35 return *this;
36}
37Serializer &Serializer::operator<<(int64_t p)
38{
39 write( &p, sizeof(p) );
40 return *this;
41}
42Serializer &Serializer::operator<<(uint8_t p)
43{
44 write( &p, sizeof(p) );
45 return *this;
46}
47Serializer &Serializer::operator<<(uint16_t p)
48{
49 write( &p, sizeof(p) );
50 return *this;
51}
52Serializer &Serializer::operator<<(uint32_t p)
53{
54 write( &p, sizeof(p) );
55 return *this;
56}
57Serializer &Serializer::operator<<(uint64_t p)
58{
59 write( &p, sizeof(p) );
60 return *this;
61}
62Serializer &Serializer::operator<<(long p)
63{
64 write( &p, sizeof(p) );
65 return *this;
66}
67Serializer &Serializer::operator<<(float p)
68{
69 write( &p, sizeof(p) );
70 return *this;
71}
72Serializer &Serializer::operator<<(double p)
73{
74 write( &p, sizeof(p) );
75 return *this;
76}
77Serializer &Serializer::operator<<(long double p)
78{
79 write( &p, sizeof(p) );
80 return *this;
81}
82
83Serializer &Serializer::operator>>(bool &p)
84{
85 read( &p, sizeof(p) );
86 return *this;
87}
88Serializer &Serializer::operator>>(int8_t &p)
89{
90 read( &p, sizeof(p) );
91 return *this;
92}
93Serializer &Serializer::operator>>(int16_t &p)
94{
95 read( &p, sizeof(p) );
96 return *this;
97}
98Serializer &Serializer::operator>>(int32_t &p)
99{
100 read( &p, sizeof(p) );
101 return *this;
102}
103Serializer &Serializer::operator>>(int64_t &p)
104{
105 read( &p, sizeof(p) );
106 return *this;
107}
108Serializer &Serializer::operator>>(uint8_t &p)
109{
110 read( &p, sizeof(p) );
111 return *this;
112}
113Serializer &Serializer::operator>>(uint16_t &p)
114{
115 read( &p, sizeof(p) );
116 return *this;
117}
118Serializer &Serializer::operator>>(uint32_t &p)
119{
120 read( &p, sizeof(p) );
121 return *this;
122}
123Serializer &Serializer::operator>>(uint64_t &p)
124{
125 read( &p, sizeof(p) );
126 return *this;
127}
128Serializer &Serializer::operator>>(long &p)
129{
130 read( &p, sizeof(p) );
131 return *this;
132}
133Serializer &Serializer::operator>>(float &p)
134{
135 read( &p, sizeof(p) );
136 return *this;
137}
138Serializer &Serializer::operator>>(double &p)
139{
140 read( &p, sizeof(p) );
141 return *this;
142}
143Serializer &Serializer::operator>>(long double &p)
144{
145 read( &p, sizeof(p) );
146 return *this;
147}
148
149Serializer &Serializer::operator&&(bool &p)
150{
151 if (bLoading)
152 {
153 return *this >> p;
154 }
155 else
156 {
157 return *this << p;
158 }
159}
160
161Serializer &Serializer::operator&&(int8_t &p)
162{
163 if (bLoading)
164 {
165 return *this >> p;
166 }
167 else
168 {
169 return *this << p;
170 }
171}
172
173Serializer &Serializer::operator&&(int16_t &p)
174{
175 if (bLoading)
176 {
177 return *this >> p;
178 }
179 else
180 {
181 return *this << p;
182 }
183}
184
185Serializer &Serializer::operator&&(int32_t &p)
186{
187 if (bLoading)
188 {
189 return *this >> p;
190 }
191 else
192 {
193 return *this << p;
194 }
195}
196
197Serializer &Serializer::operator&&(int64_t &p)
198{
199 if (bLoading)
200 {
201 return *this >> p;
202 }
203 else
204 {
205 return *this << p;
206 }
207}
208
209Serializer &Serializer::operator&&(uint8_t &p)
210{
211 if (bLoading)
212 {
213 return *this >> p;
214 }
215 else
216 {
217 return *this << p;
218 }
219}
220
221Serializer &Serializer::operator&&(uint16_t &p)
222{
223 if (bLoading)
224 {
225 return *this >> p;
226 }
227 else
228 {
229 return *this << p;
230 }
231}
232
233Serializer &Serializer::operator&&(uint32_t &p)
234{
235 if (bLoading)
236 {
237 return *this >> p;
238 }
239 else
240 {
241 return *this << p;
242 }
243}
244
245Serializer &Serializer::operator&&(uint64_t &p)
246{
247 if (bLoading)
248 {
249 return *this >> p;
250 }
251 else
252 {
253 return *this << p;
254 }
255}
256
257Serializer &Serializer::operator&&(float &p)
258{
259 if (bLoading)
260 {
261 return *this >> p;
262 }
263 else
264 {
265 return *this << p;
266 }
267}
268
269Serializer &Serializer::operator&&(double &p)
270{
271 if (bLoading)
272 {
273 return *this >> p;
274 }
275 else
276 {
277 return *this << p;
278 }
279}
280
281Serializer &Serializer::operator&&(long double &p)
282{
283 if (bLoading)
284 {
285 return *this >> p;
286 }
287 else
288 {
289 return *this << p;
290 }
291}
292
293
294Serializer &operator<<(Serializer &s, Serializable &p)
295{
296 p.serialize( s );
297 return s;
298}
299
300Serializer &operator>>(Serializer &s, Serializable &p)
301{
302 p.serialize( s );
303 return s;
304}
305
306Serializer &operator&&(Serializer &s, Serializable &p)
307{
308 if (s.isLoading())
309 {
310 return s >> p;
311 }
312 else
313 {
314 return s << p;
315 }
316}
317
318Serializer &operator<<( Serializer &ar, std::string &s )
319{
320 ar << (uint32_t)s.length();
321 ar.write( s.c_str(), s.length() );
322
323 return ar;
324}
325
326Serializer &operator>>( Serializer &ar, std::string &s )
327{
328 uint32_t l;
329 ar >> l;
330 char *tmp = new char[l+1];
331 tmp[l] = '\0';
332 ar.read( tmp, l );
333 s = tmp;
334 delete[] tmp;
335
336 return ar;
337}
338