aboutsummaryrefslogtreecommitdiff
path: root/src/archive.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/archive.h')
-rw-r--r--src/archive.h252
1 files changed, 2 insertions, 250 deletions
diff --git a/src/archive.h b/src/archive.h
index dcbd219..6eaf408 100644
--- a/src/archive.h
+++ b/src/archive.h
@@ -9,11 +9,8 @@
9#define BU_ARCHIVE_H 9#define BU_ARCHIVE_H
10 10
11#include <stdint.h> 11#include <stdint.h>
12#include <string> 12#include "bu/archivebase.h"
13#include <list>
14#include "bu/hash.h" 13#include "bu/hash.h"
15#include "bu/list.h"
16//#include "bu/set.h"
17#include "bu/util.h" 14#include "bu/util.h"
18 15
19namespace Bu 16namespace Bu
@@ -68,7 +65,7 @@ namespace Bu
68 * One way of dealing with the latter problem is to make sure and use 65 * One way of dealing with the latter problem is to make sure and use
69 * explicit primitive types from the stdint.h header, i.e. int32_t. 66 * explicit primitive types from the stdint.h header, i.e. int32_t.
70 */ 67 */
71 class Archive 68 class Archive : public ArchiveBase
72 { 69 {
73 private: 70 private:
74 bool bLoading; 71 bool bLoading;
@@ -88,81 +85,6 @@ namespace Bu
88 virtual void write(const void *, int32_t); 85 virtual void write(const void *, int32_t);
89 virtual void read(void *, int32_t); 86 virtual void read(void *, int32_t);
90 87
91 virtual Archive &operator<<(bool p);
92 virtual Archive &operator<<(char p);
93 virtual Archive &operator<<(signed char p);
94 virtual Archive &operator<<(unsigned char p);
95 virtual Archive &operator<<(signed short p);
96 virtual Archive &operator<<(unsigned short p);
97 virtual Archive &operator<<(signed int p);
98 virtual Archive &operator<<(unsigned int p);
99 virtual Archive &operator<<(signed long p);
100 virtual Archive &operator<<(unsigned long p);
101 virtual Archive &operator<<(signed long long p);
102 virtual Archive &operator<<(unsigned long long p);
103 virtual Archive &operator<<(float p);
104 virtual Archive &operator<<(double p);
105 virtual Archive &operator<<(long double p);
106
107 virtual Archive &operator>>(bool &p);
108 virtual Archive &operator>>(char &p);
109 virtual Archive &operator>>(signed char &p);
110 virtual Archive &operator>>(unsigned char &p);
111 virtual Archive &operator>>(signed short &p);
112 virtual Archive &operator>>(unsigned short &p);
113 virtual Archive &operator>>(signed int &p);
114 virtual Archive &operator>>(unsigned int &p);
115 virtual Archive &operator>>(signed long &p);
116 virtual Archive &operator>>(unsigned long &p);
117 virtual Archive &operator>>(signed long long &p);
118 virtual Archive &operator>>(unsigned long long &p);
119 virtual Archive &operator>>(float &p);
120 virtual Archive &operator>>(double &p);
121 virtual Archive &operator>>(long double &p);
122
123 /*
124 virtual Archive &operator<<(bool);
125 virtual Archive &operator<<(int8_t);
126 virtual Archive &operator<<(int16_t);
127 virtual Archive &operator<<(int32_t);
128 virtual Archive &operator<<(int64_t);
129 virtual Archive &operator<<(uint8_t);
130 virtual Archive &operator<<(uint16_t);
131 virtual Archive &operator<<(uint32_t);
132 virtual Archive &operator<<(uint64_t);
133// virtual Archive &operator<<(long);
134 virtual Archive &operator<<(float);
135 virtual Archive &operator<<(double);
136 virtual Archive &operator<<(long double);
137
138 virtual Archive &operator>>(bool &);
139 virtual Archive &operator>>(int8_t &);
140 virtual Archive &operator>>(int16_t &);
141 virtual Archive &operator>>(int32_t &);
142 virtual Archive &operator>>(int64_t &);
143 virtual Archive &operator>>(uint8_t &);
144 virtual Archive &operator>>(uint16_t &);
145 virtual Archive &operator>>(uint32_t &);
146 virtual Archive &operator>>(uint64_t &);
147// virtual Archive &operator>>(long &);
148 virtual Archive &operator>>(float &);
149 virtual Archive &operator>>(double &);
150 virtual Archive &operator>>(long double &);
151
152 virtual Archive &operator&&(bool &);
153 virtual Archive &operator&&(int8_t &);
154 virtual Archive &operator&&(int16_t &);
155 virtual Archive &operator&&(int32_t &);
156 virtual Archive &operator&&(int64_t &);
157 virtual Archive &operator&&(uint8_t &);
158 virtual Archive &operator&&(uint16_t &);
159 virtual Archive &operator&&(uint32_t &);
160 virtual Archive &operator&&(uint64_t &);
161 virtual Archive &operator&&(float &);
162 virtual Archive &operator&&(double &);
163 virtual Archive &operator&&(long double &);
164 */
165
166 /** 88 /**
167 * For storage, get an ID for the pointer to the object you're going to 89 * For storage, get an ID for the pointer to the object you're going to
168 * write. 90 * write.
@@ -193,176 +115,6 @@ namespace Bu
193 Hash<uint32_t,uint32_t> hPtrID; 115 Hash<uint32_t,uint32_t> hPtrID;
194 Hash<uint32_t,List<void **> > hPtrDest; 116 Hash<uint32_t,List<void **> > hPtrDest;
195 }; 117 };
196
197 Archive &operator<<(Archive &, class Bu::Archival &);
198 Archive &operator>>(Archive &, class Bu::Archival &);
199 //Archive &operator&&(Archive &s, class Bu::Archival &p);
200
201 Archive &operator<<(Archive &, std::string &);
202 Archive &operator>>(Archive &, std::string &);
203 //Archive &operator&&(Archive &, std::string &);
204
205 template<typename T> Archive &operator&&( Archive &ar, T &dat )
206 {
207 if( ar.isLoading() )
208 {
209 return ar >> dat;
210 }
211 else
212 {
213 return ar << dat;
214 }
215 }
216
217 template<typename T> Archive &operator<<( Archive &ar, std::list<T> &l )
218 {
219 typename std::list<T>::size_type num = l.getSize();
220 ar << num;
221 for( typename std::list<T>::const_iterator i = l.begin(); i != l.end();
222 i++ )
223 {
224 ar << *i;
225 }
226
227 return ar;
228 }
229
230 template<typename T> Archive &operator>>( Archive &ar, std::list<T> &l )
231 {
232 typename std::list<T>::size_type num;
233 ar >> num;
234
235 l.resize( num );
236 for( typename std::list<T>::const_iterator i = l.begin();
237 i != l.end(); i++ )
238 {
239 ar >> *i;
240 }
241
242 return ar;
243 }
244
245 Archive &operator<<(Archive &, class Bu::Archival *p);
246 Archive &operator>>(Archive &, class Bu::Archival *p);
247
248 template<typename key, typename value>
249 Archive &operator<<( Archive &ar, Hash<key,value> &h )
250 {
251 ar << h.getSize();
252 for( typename Hash<key,value>::iterator i = h.begin(); i != h.end(); i++ )
253 {
254 //std::pair<key,value> p = *i;
255 ar << (i.getKey()) << (i.getValue());
256 }
257
258 return ar;
259 }
260
261 template<typename key, typename value>
262 Archive &operator>>( Archive &ar, Hash<key,value> &h )
263 {
264 h.clear();
265 long nSize;
266 ar >> nSize;
267
268 for( long j = 0; j < nSize; j++ )
269 {
270 key k; value v;
271 ar >> k >> v;
272 h.insert( k, v );
273 }
274
275 return ar;
276 }
277
278 template<typename value>
279 Archive &operator<<( Archive &ar, List<value> &h )
280 {
281 ar << h.getSize();
282 for( typename List<value>::iterator i = h.begin(); i != h.end(); i++ )
283 {
284 ar << (*i);
285 }
286
287 return ar;
288 }
289
290 template<typename value>
291 Archive &operator>>( Archive &ar, List<value> &h )
292 {
293 h.clear();
294 long nSize;
295 ar >> nSize;
296
297 for( long j = 0; j < nSize; j++ )
298 {
299 value v;
300 ar >> v;
301 h.append( v );
302 }
303
304 return ar;
305 }
306
307 template<typename value, int inc, typename valuealloc> class Array;
308 template<typename value, int inc, typename valuealloc>
309 Archive &operator<<( Archive &ar, Array<value, inc, valuealloc> &h )
310 {
311 ar << h.getSize();
312 for( typename Array<value, inc, valuealloc>::iterator i = h.begin(); i != h.end(); i++ )
313 {
314 ar << (*i);
315 }
316
317 return ar;
318 }
319
320 template<typename value, int inc, typename valuealloc>
321 Archive &operator>>(Archive &ar, Array<value, inc, valuealloc> &h )
322 {
323 h.clear();
324 long nSize;
325 ar >> nSize;
326
327 h.setCapacity( nSize );
328 for( long j = 0; j < nSize; j++ )
329 {
330 value v;
331 ar >> v;
332 h.append( v );
333 }
334 return ar;
335 }
336
337 template<typename key, typename b, typename c, typename d> class Set;
338 template<typename key, typename b, typename c, typename d>
339 Archive &operator<<( Archive &ar, Set<key, b, c, d> &h )
340 {
341 ar << h.getSize();
342 for( typename Set<key, b, c, d>::iterator i = h.begin(); i != h.end(); i++ )
343 {
344 ar << (*i);
345 }
346
347 return ar;
348 }
349
350 template<typename key, typename b, typename c, typename d>
351 Archive &operator>>( Archive &ar, Set<key, b, c, d> &h )
352 {
353 h.clear();
354 long nSize;
355 ar >> nSize;
356
357 for( long j = 0; j < nSize; j++ )
358 {
359 key v;
360 ar >> v;
361 h.insert( v );
362 }
363
364 return ar;
365 }
366} 118}
367 119
368#endif 120#endif