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