diff options
author | Mike Buland <eichlan@xagasoft.com> | 2007-04-03 04:50:36 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2007-04-03 04:50:36 +0000 |
commit | da89e6d30e57bd6dbb10b4d36b093ce9bbf5c666 (patch) | |
tree | 0c8d31d13521011dc52a3fbadbf9e7e27929308f /src/archive.cpp | |
parent | f4c20290509d7ed3a8fd5304577e7a4cc0b9d974 (diff) | |
download | libbu++-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.cpp | 337 |
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 | |||
3 | Bu::Archive::Archive(bool bLoading): | ||
4 | bLoading(bLoading) | ||
5 | { | ||
6 | } | ||
7 | Bu::Archive::~Archive() | ||
8 | { | ||
9 | } | ||
10 | |||
11 | bool Bu::Archive::isLoading() | ||
12 | { | ||
13 | return bLoading; | ||
14 | } | ||
15 | Bu::Archive &Bu::Archive::operator<<(bool p) | ||
16 | { | ||
17 | write( &p, sizeof(p) ); | ||
18 | return *this; | ||
19 | } | ||
20 | Bu::Archive &Bu::Archive::operator<<(int8_t p) | ||
21 | { | ||
22 | write( &p, sizeof(p) ); | ||
23 | return *this; | ||
24 | } | ||
25 | Bu::Archive &Bu::Archive::operator<<(int16_t p) | ||
26 | { | ||
27 | write( &p, sizeof(p) ); | ||
28 | return *this; | ||
29 | } | ||
30 | Bu::Archive &Bu::Archive::operator<<(int32_t p) | ||
31 | { | ||
32 | write( &p, sizeof(p) ); | ||
33 | return *this; | ||
34 | } | ||
35 | Bu::Archive &Bu::Archive::operator<<(int64_t p) | ||
36 | { | ||
37 | write( &p, sizeof(p) ); | ||
38 | return *this; | ||
39 | } | ||
40 | Bu::Archive &Bu::Archive::operator<<(uint8_t p) | ||
41 | { | ||
42 | write( &p, sizeof(p) ); | ||
43 | return *this; | ||
44 | } | ||
45 | Bu::Archive &Bu::Archive::operator<<(uint16_t p) | ||
46 | { | ||
47 | write( &p, sizeof(p) ); | ||
48 | return *this; | ||
49 | } | ||
50 | Bu::Archive &Bu::Archive::operator<<(uint32_t p) | ||
51 | { | ||
52 | write( &p, sizeof(p) ); | ||
53 | return *this; | ||
54 | } | ||
55 | Bu::Archive &Bu::Archive::operator<<(uint64_t p) | ||
56 | { | ||
57 | write( &p, sizeof(p) ); | ||
58 | return *this; | ||
59 | } | ||
60 | Bu::Archive &Bu::Archive::operator<<(long p) | ||
61 | { | ||
62 | write( &p, sizeof(p) ); | ||
63 | return *this; | ||
64 | } | ||
65 | Bu::Archive &Bu::Archive::operator<<(float p) | ||
66 | { | ||
67 | write( &p, sizeof(p) ); | ||
68 | return *this; | ||
69 | } | ||
70 | Bu::Archive &Bu::Archive::operator<<(double p) | ||
71 | { | ||
72 | write( &p, sizeof(p) ); | ||
73 | return *this; | ||
74 | } | ||
75 | Bu::Archive &Bu::Archive::operator<<(long double p) | ||
76 | { | ||
77 | write( &p, sizeof(p) ); | ||
78 | return *this; | ||
79 | } | ||
80 | |||
81 | Bu::Archive &Bu::Archive::operator>>(bool &p) | ||
82 | { | ||
83 | read( &p, sizeof(p) ); | ||
84 | return *this; | ||
85 | } | ||
86 | Bu::Archive &Bu::Archive::operator>>(int8_t &p) | ||
87 | { | ||
88 | read( &p, sizeof(p) ); | ||
89 | return *this; | ||
90 | } | ||
91 | Bu::Archive &Bu::Archive::operator>>(int16_t &p) | ||
92 | { | ||
93 | read( &p, sizeof(p) ); | ||
94 | return *this; | ||
95 | } | ||
96 | Bu::Archive &Bu::Archive::operator>>(int32_t &p) | ||
97 | { | ||
98 | read( &p, sizeof(p) ); | ||
99 | return *this; | ||
100 | } | ||
101 | Bu::Archive &Bu::Archive::operator>>(int64_t &p) | ||
102 | { | ||
103 | read( &p, sizeof(p) ); | ||
104 | return *this; | ||
105 | } | ||
106 | Bu::Archive &Bu::Archive::operator>>(uint8_t &p) | ||
107 | { | ||
108 | read( &p, sizeof(p) ); | ||
109 | return *this; | ||
110 | } | ||
111 | Bu::Archive &Bu::Archive::operator>>(uint16_t &p) | ||
112 | { | ||
113 | read( &p, sizeof(p) ); | ||
114 | return *this; | ||
115 | } | ||
116 | Bu::Archive &Bu::Archive::operator>>(uint32_t &p) | ||
117 | { | ||
118 | read( &p, sizeof(p) ); | ||
119 | return *this; | ||
120 | } | ||
121 | Bu::Archive &Bu::Archive::operator>>(uint64_t &p) | ||
122 | { | ||
123 | read( &p, sizeof(p) ); | ||
124 | return *this; | ||
125 | } | ||
126 | Bu::Archive &Bu::Archive::operator>>(long &p) | ||
127 | { | ||
128 | read( &p, sizeof(p) ); | ||
129 | return *this; | ||
130 | } | ||
131 | Bu::Archive &Bu::Archive::operator>>(float &p) | ||
132 | { | ||
133 | read( &p, sizeof(p) ); | ||
134 | return *this; | ||
135 | } | ||
136 | Bu::Archive &Bu::Archive::operator>>(double &p) | ||
137 | { | ||
138 | read( &p, sizeof(p) ); | ||
139 | return *this; | ||
140 | } | ||
141 | Bu::Archive &Bu::Archive::operator>>(long double &p) | ||
142 | { | ||
143 | read( &p, sizeof(p) ); | ||
144 | return *this; | ||
145 | } | ||
146 | |||
147 | Bu::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 | |||
159 | Bu::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 | |||
171 | Bu::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 | |||
183 | Bu::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 | |||
195 | Bu::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 | |||
207 | Bu::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 | |||
219 | Bu::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 | |||
231 | Bu::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 | |||
243 | Bu::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 | |||
255 | Bu::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 | |||
267 | Bu::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 | |||
279 | Bu::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 | |||
292 | Bu::Archive &Bu::operator<<(Bu::Archive &s, Bu::Archable &p) | ||
293 | { | ||
294 | p.archive( s ); | ||
295 | return s; | ||
296 | } | ||
297 | |||
298 | Bu::Archive &Bu::operator>>(Bu::Archive &s, Bu::Archable &p) | ||
299 | { | ||
300 | p.archive( s ); | ||
301 | return s; | ||
302 | } | ||
303 | |||
304 | /* | ||
305 | Bu::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 | |||
317 | Bu::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 | |||
325 | Bu::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 | |||