aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/archival.cpp18
-rw-r--r--src/archival.h9
-rw-r--r--src/archive.cpp476
-rw-r--r--src/archive.h252
-rw-r--r--src/archivebase.cpp190
-rw-r--r--src/archivebase.h67
-rw-r--r--src/array.h33
-rw-r--r--src/cachestorenids.h1
-rw-r--r--src/client.h1
-rw-r--r--src/exceptionbase.cpp1
-rw-r--r--src/exceptionbase.h1
-rw-r--r--src/fastcgi.cpp1
-rw-r--r--src/fbasicstring.h108
-rw-r--r--src/fifo.cpp1
-rw-r--r--src/formatter.cpp2
-rw-r--r--src/fstring.cpp6
-rw-r--r--src/fstring.h6
-rw-r--r--src/hash.cpp19
-rw-r--r--src/hash.h56
-rw-r--r--src/heap.h81
-rw-r--r--src/httpget.h1
-rw-r--r--src/list.h127
-rw-r--r--src/logger.cpp1
-rw-r--r--src/nidsstream.cpp2
-rw-r--r--src/paramproc.cpp1
-rw-r--r--src/protocolhttp.h1
-rw-r--r--src/server.cpp1
-rw-r--r--src/server.h1
-rw-r--r--src/set.h30
-rw-r--r--src/tests/archive.cpp3
-rw-r--r--src/tests/archive2.cpp6
-rw-r--r--src/tests/cache.cpp1
-rw-r--r--src/tests/fastcgi.cpp2
-rw-r--r--src/tests/heap.cpp53
-rw-r--r--src/tests/itoheap.cpp1
-rw-r--r--src/tests/listsort.cpp60
-rw-r--r--src/tests/ringbuffer.cpp2
-rw-r--r--src/tests/serverticks.cpp1
-rw-r--r--src/tests/socketblock.cpp1
-rw-r--r--src/tests/socketbreak.cpp1
-rw-r--r--src/tests/uuid.cpp14
-rw-r--r--src/unit/archive.unit89
-rw-r--r--src/unit/file.unit2
-rw-r--r--src/unit/fstring.unit21
-rw-r--r--src/unit/list.unit80
-rw-r--r--src/util.cpp19
-rw-r--r--src/util.h10
47 files changed, 931 insertions, 929 deletions
diff --git a/src/archival.cpp b/src/archival.cpp
index daec60a..cae183a 100644
--- a/src/archival.cpp
+++ b/src/archival.cpp
@@ -15,3 +15,21 @@ Bu::Archival::~Archival()
15{ 15{
16} 16}
17 17
18Bu::ArchiveBase &Bu::operator<<(Bu::ArchiveBase &s, const Bu::Archival &p)
19{
20 const_cast<Bu::Archival &>(p).archive( s );
21 return s;
22}
23
24Bu::ArchiveBase &Bu::operator<<(Bu::ArchiveBase &s, Bu::Archival &p)
25{
26 p.archive( s );
27 return s;
28}
29
30Bu::ArchiveBase &Bu::operator>>(Bu::ArchiveBase &s, Bu::Archival &p)
31{
32 p.archive( s );
33 return s;
34}
35
diff --git a/src/archival.h b/src/archival.h
index d758f3d..76f0f5f 100644
--- a/src/archival.h
+++ b/src/archival.h
@@ -8,6 +8,8 @@
8#ifndef BU_ARCHIVAL_H 8#ifndef BU_ARCHIVAL_H
9#define BU_ARCHIVAL_H 9#define BU_ARCHIVAL_H
10 10
11#include "bu/archivebase.h"
12
11namespace Bu 13namespace Bu
12{ 14{
13 /** 15 /**
@@ -38,8 +40,13 @@ namespace Bu
38 * you are loading or saving. 40 * you are loading or saving.
39 * @param ar A reference to the Archive object to use. 41 * @param ar A reference to the Archive object to use.
40 */ 42 */
41 virtual void archive( class Archive &ar )=0; 43 virtual void archive( class ArchiveBase &ar )=0;
42 }; 44 };
45
46 ArchiveBase &operator<<(ArchiveBase &, const class Bu::Archival &);
47 ArchiveBase &operator<<(ArchiveBase &, class Bu::Archival &);
48 ArchiveBase &operator>>(ArchiveBase &, class Bu::Archival &);
49
43} 50}
44 51
45#endif 52#endif
diff --git a/src/archive.cpp b/src/archive.cpp
index 6bad44c..1b48ec8 100644
--- a/src/archive.cpp
+++ b/src/archive.cpp
@@ -46,482 +46,6 @@ bool Bu::Archive::isLoading()
46 return bLoading; 46 return bLoading;
47} 47}
48 48
49Bu::Archive &Bu::Archive::operator<<(bool p)
50{
51 write( &p, sizeof(p) );
52 return *this;
53}
54Bu::Archive &Bu::Archive::operator<<(char p)
55{
56 write( &p, sizeof(p) );
57 return *this;
58}
59Bu::Archive &Bu::Archive::operator<<(signed char p)
60{
61 write( &p, sizeof(p) );
62 return *this;
63}
64Bu::Archive &Bu::Archive::operator<<(unsigned char p)
65{
66 write( &p, sizeof(p) );
67 return *this;
68}
69Bu::Archive &Bu::Archive::operator<<(signed short p)
70{
71 write( &p, sizeof(p) );
72 return *this;
73}
74Bu::Archive &Bu::Archive::operator<<(unsigned short p)
75{
76 write( &p, sizeof(p) );
77 return *this;
78}
79Bu::Archive &Bu::Archive::operator<<(signed int p)
80{
81 write( &p, sizeof(p) );
82 return *this;
83}
84Bu::Archive &Bu::Archive::operator<<(unsigned int p)
85{
86 write( &p, sizeof(p) );
87 return *this;
88}
89Bu::Archive &Bu::Archive::operator<<(signed long p)
90{
91 write( &p, sizeof(p) );
92 return *this;
93}
94Bu::Archive &Bu::Archive::operator<<(unsigned long p)
95{
96 write( &p, sizeof(p) );
97 return *this;
98}
99Bu::Archive &Bu::Archive::operator<<(signed long long p)
100{
101 write( &p, sizeof(p) );
102 return *this;
103}
104Bu::Archive &Bu::Archive::operator<<(unsigned long long p)
105{
106 write( &p, sizeof(p) );
107 return *this;
108}
109Bu::Archive &Bu::Archive::operator<<(float p)
110{
111 write( &p, sizeof(p) );
112 return *this;
113}
114Bu::Archive &Bu::Archive::operator<<(double p)
115{
116 write( &p, sizeof(p) );
117 return *this;
118}
119Bu::Archive &Bu::Archive::operator<<(long double p)
120{
121 write( &p, sizeof(p) );
122 return *this;
123}
124
125Bu::Archive &Bu::Archive::operator>>(bool &p)
126{
127 read( &p, sizeof(p) );
128 return *this;
129}
130Bu::Archive &Bu::Archive::operator>>(char &p)
131{
132 read( &p, sizeof(p) );
133 return *this;
134}
135Bu::Archive &Bu::Archive::operator>>(signed char &p)
136{
137 read( &p, sizeof(p) );
138 return *this;
139}
140Bu::Archive &Bu::Archive::operator>>(unsigned char &p)
141{
142 read( &p, sizeof(p) );
143 return *this;
144}
145Bu::Archive &Bu::Archive::operator>>(signed short &p)
146{
147 read( &p, sizeof(p) );
148 return *this;
149}
150Bu::Archive &Bu::Archive::operator>>(unsigned short &p)
151{
152 read( &p, sizeof(p) );
153 return *this;
154}
155Bu::Archive &Bu::Archive::operator>>(signed int &p)
156{
157 read( &p, sizeof(p) );
158 return *this;
159}
160Bu::Archive &Bu::Archive::operator>>(unsigned int &p)
161{
162 read( &p, sizeof(p) );
163 return *this;
164}
165Bu::Archive &Bu::Archive::operator>>(signed long &p)
166{
167 read( &p, sizeof(p) );
168 return *this;
169}
170Bu::Archive &Bu::Archive::operator>>(unsigned long &p)
171{
172 read( &p, sizeof(p) );
173 return *this;
174}
175Bu::Archive &Bu::Archive::operator>>(signed long long &p)
176{
177 read( &p, sizeof(p) );
178 return *this;
179}
180Bu::Archive &Bu::Archive::operator>>(unsigned long long &p)
181{
182 read( &p, sizeof(p) );
183 return *this;
184}
185Bu::Archive &Bu::Archive::operator>>(float &p)
186{
187 read( &p, sizeof(p) );
188 return *this;
189}
190Bu::Archive &Bu::Archive::operator>>(double &p)
191{
192 read( &p, sizeof(p) );
193 return *this;
194}
195Bu::Archive &Bu::Archive::operator>>(long double &p)
196{
197 read( &p, sizeof(p) );
198 return *this;
199}
200
201/*
202Bu::Archive &Bu::Archive::operator<<(bool p)
203{
204 write( &p, sizeof(p) );
205 return *this;
206}
207Bu::Archive &Bu::Archive::operator<<(int8_t p)
208{
209 write( &p, sizeof(p) );
210 return *this;
211}
212Bu::Archive &Bu::Archive::operator<<(int16_t p)
213{
214 write( &p, sizeof(p) );
215 return *this;
216}
217Bu::Archive &Bu::Archive::operator<<(int32_t p)
218{
219 write( &p, sizeof(p) );
220 return *this;
221}
222Bu::Archive &Bu::Archive::operator<<(int64_t p)
223{
224 write( &p, sizeof(p) );
225 return *this;
226}
227Bu::Archive &Bu::Archive::operator<<(uint8_t p)
228{
229 write( &p, sizeof(p) );
230 return *this;
231}
232Bu::Archive &Bu::Archive::operator<<(uint16_t p)
233{
234 write( &p, sizeof(p) );
235 return *this;
236}
237Bu::Archive &Bu::Archive::operator<<(uint32_t p)
238{
239 write( &p, sizeof(p) );
240 return *this;
241}
242Bu::Archive &Bu::Archive::operator<<(uint64_t p)
243{
244 write( &p, sizeof(p) );
245 return *this;
246}
247Bu::Archive &Bu::Archive::operator<<(long p)
248{
249 write( &p, sizeof(p) );
250 return *this;
251}
252Bu::Archive &Bu::Archive::operator<<(float p)
253{
254 write( &p, sizeof(p) );
255 return *this;
256}
257Bu::Archive &Bu::Archive::operator<<(double p)
258{
259 write( &p, sizeof(p) );
260 return *this;
261}
262Bu::Archive &Bu::Archive::operator<<(long double p)
263{
264 write( &p, sizeof(p) );
265 return *this;
266}
267
268Bu::Archive &Bu::Archive::operator>>(bool &p)
269{
270 read( &p, sizeof(p) );
271 return *this;
272}
273Bu::Archive &Bu::Archive::operator>>(int8_t &p)
274{
275 read( &p, sizeof(p) );
276 return *this;
277}
278Bu::Archive &Bu::Archive::operator>>(int16_t &p)
279{
280 read( &p, sizeof(p) );
281 return *this;
282}
283Bu::Archive &Bu::Archive::operator>>(int32_t &p)
284{
285 read( &p, sizeof(p) );
286 return *this;
287}
288Bu::Archive &Bu::Archive::operator>>(int64_t &p)
289{
290 read( &p, sizeof(p) );
291 return *this;
292}
293Bu::Archive &Bu::Archive::operator>>(uint8_t &p)
294{
295 read( &p, sizeof(p) );
296 return *this;
297}
298Bu::Archive &Bu::Archive::operator>>(uint16_t &p)
299{
300 read( &p, sizeof(p) );
301 return *this;
302}
303Bu::Archive &Bu::Archive::operator>>(uint32_t &p)
304{
305 read( &p, sizeof(p) );
306 return *this;
307}
308Bu::Archive &Bu::Archive::operator>>(uint64_t &p)
309{
310 read( &p, sizeof(p) );
311 return *this;
312}
313Bu::Archive &Bu::Archive::operator>>(long &p)
314{
315 read( &p, sizeof(p) );
316 return *this;
317}
318Bu::Archive &Bu::Archive::operator>>(float &p)
319{
320 read( &p, sizeof(p) );
321 return *this;
322}
323Bu::Archive &Bu::Archive::operator>>(double &p)
324{
325 read( &p, sizeof(p) );
326 return *this;
327}
328Bu::Archive &Bu::Archive::operator>>(long double &p)
329{
330 read( &p, sizeof(p) );
331 return *this;
332}
333
334Bu::Archive &Bu::Archive::operator&&(bool &p)
335{
336 if (bLoading)
337 {
338 return *this >> p;
339 }
340 else
341 {
342 return *this << p;
343 }
344}
345
346Bu::Archive &Bu::Archive::operator&&(int8_t &p)
347{
348 if (bLoading)
349 {
350 return *this >> p;
351 }
352 else
353 {
354 return *this << p;
355 }
356}
357
358Bu::Archive &Bu::Archive::operator&&(int16_t &p)
359{
360 if (bLoading)
361 {
362 return *this >> p;
363 }
364 else
365 {
366 return *this << p;
367 }
368}
369
370Bu::Archive &Bu::Archive::operator&&(int32_t &p)
371{
372 if (bLoading)
373 {
374 return *this >> p;
375 }
376 else
377 {
378 return *this << p;
379 }
380}
381
382Bu::Archive &Bu::Archive::operator&&(int64_t &p)
383{
384 if (bLoading)
385 {
386 return *this >> p;
387 }
388 else
389 {
390 return *this << p;
391 }
392}
393
394Bu::Archive &Bu::Archive::operator&&(uint8_t &p)
395{
396 if (bLoading)
397 {
398 return *this >> p;
399 }
400 else
401 {
402 return *this << p;
403 }
404}
405
406Bu::Archive &Bu::Archive::operator&&(uint16_t &p)
407{
408 if (bLoading)
409 {
410 return *this >> p;
411 }
412 else
413 {
414 return *this << p;
415 }
416}
417
418Bu::Archive &Bu::Archive::operator&&(uint32_t &p)
419{
420 if (bLoading)
421 {
422 return *this >> p;
423 }
424 else
425 {
426 return *this << p;
427 }
428}
429
430Bu::Archive &Bu::Archive::operator&&(uint64_t &p)
431{
432 if (bLoading)
433 {
434 return *this >> p;
435 }
436 else
437 {
438 return *this << p;
439 }
440}
441
442Bu::Archive &Bu::Archive::operator&&(float &p)
443{
444 if (bLoading)
445 {
446 return *this >> p;
447 }
448 else
449 {
450 return *this << p;
451 }
452}
453
454Bu::Archive &Bu::Archive::operator&&(double &p)
455{
456 if (bLoading)
457 {
458 return *this >> p;
459 }
460 else
461 {
462 return *this << p;
463 }
464}
465
466Bu::Archive &Bu::Archive::operator&&(long double &p)
467{
468 if (bLoading)
469 {
470 return *this >> p;
471 }
472 else
473 {
474 return *this << p;
475 }
476}
477*/
478
479Bu::Archive &Bu::operator<<(Bu::Archive &s, Bu::Archival &p)
480{
481 p.archive( s );
482 return s;
483}
484
485Bu::Archive &Bu::operator>>(Bu::Archive &s, Bu::Archival &p)
486{
487 p.archive( s );
488 return s;
489}
490
491Bu::Archive &Bu::operator<<(Bu::Archive &ar, class Bu::Archival *p )
492{
493 ar << *p;
494 return ar;
495}
496
497Bu::Archive &Bu::operator>>(Bu::Archive &ar, class Bu::Archival *p )
498{
499 ar >> *p;
500 return ar;
501}
502
503Bu::Archive &Bu::operator<<( Bu::Archive &ar, std::string &s )
504{
505 // This should be defined as long anyway, this is just insurance
506 ar << (long)s.length();
507 ar.write( s.c_str(), s.length() );
508
509 return ar;
510}
511
512Bu::Archive &Bu::operator>>( Bu::Archive &ar, std::string &s )
513{
514 long l;
515 ar >> l;
516 char *tmp = new char[l+1];
517 tmp[l] = '\0';
518 ar.read( tmp, l );
519 s = tmp;
520 delete[] tmp;
521
522 return ar;
523}
524
525uint32_t Bu::Archive::getID( const void *ptr ) 49uint32_t Bu::Archive::getID( const void *ptr )
526{ 50{
527 if( hPtrID.has( (ptrdiff_t)ptr ) ) 51 if( hPtrID.has( (ptrdiff_t)ptr ) )
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
diff --git a/src/archivebase.cpp b/src/archivebase.cpp
new file mode 100644
index 0000000..41b7ebe
--- /dev/null
+++ b/src/archivebase.cpp
@@ -0,0 +1,190 @@
1#include "bu/archivebase.h"
2
3Bu::ArchiveBase::ArchiveBase()
4{
5}
6
7Bu::ArchiveBase::~ArchiveBase()
8{
9}
10
11Bu::ArchiveBase &Bu::operator<<( Bu::ArchiveBase &ar, bool p)
12{
13 ar.write( &p, sizeof(p) );
14 return ar;
15}
16
17Bu::ArchiveBase &Bu::operator<<( Bu::ArchiveBase &ar, char p)
18{
19 ar.write( &p, sizeof(p) );
20 return ar;
21}
22
23Bu::ArchiveBase &Bu::operator<<( Bu::ArchiveBase &ar, signed char p)
24{
25 ar.write( &p, sizeof(p) );
26 return ar;
27}
28
29Bu::ArchiveBase &Bu::operator<<( Bu::ArchiveBase &ar, unsigned char p)
30{
31 ar.write( &p, sizeof(p) );
32 return ar;
33}
34
35Bu::ArchiveBase &Bu::operator<<( Bu::ArchiveBase &ar, signed short p)
36{
37 ar.write( &p, sizeof(p) );
38 return ar;
39}
40
41Bu::ArchiveBase &Bu::operator<<( Bu::ArchiveBase &ar, unsigned short p)
42{
43 ar.write( &p, sizeof(p) );
44 return ar;
45}
46
47Bu::ArchiveBase &Bu::operator<<( Bu::ArchiveBase &ar, signed int p)
48{
49 ar.write( &p, sizeof(p) );
50 return ar;
51}
52
53Bu::ArchiveBase &Bu::operator<<( Bu::ArchiveBase &ar, unsigned int p)
54{
55 ar.write( &p, sizeof(p) );
56 return ar;
57}
58
59Bu::ArchiveBase &Bu::operator<<( Bu::ArchiveBase &ar, signed long p)
60{
61 ar.write( &p, sizeof(p) );
62 return ar;
63}
64
65Bu::ArchiveBase &Bu::operator<<( Bu::ArchiveBase &ar, unsigned long p)
66{
67 ar.write( &p, sizeof(p) );
68 return ar;
69}
70
71Bu::ArchiveBase &Bu::operator<<( Bu::ArchiveBase &ar, signed long long p)
72{
73 ar.write( &p, sizeof(p) );
74 return ar;
75}
76
77Bu::ArchiveBase &Bu::operator<<( Bu::ArchiveBase &ar, unsigned long long p)
78{
79 ar.write( &p, sizeof(p) );
80 return ar;
81}
82
83Bu::ArchiveBase &Bu::operator<<( Bu::ArchiveBase &ar, float p)
84{
85 ar.write( &p, sizeof(p) );
86 return ar;
87}
88
89Bu::ArchiveBase &Bu::operator<<( Bu::ArchiveBase &ar, double p)
90{
91 ar.write( &p, sizeof(p) );
92 return ar;
93}
94
95Bu::ArchiveBase &Bu::operator<<( Bu::ArchiveBase &ar, long double p)
96{
97 ar.write( &p, sizeof(p) );
98 return ar;
99}
100
101Bu::ArchiveBase &Bu::operator>>( Bu::ArchiveBase &ar, bool &p)
102{
103 ar.read( &p, sizeof(p) );
104 return ar;
105}
106
107Bu::ArchiveBase &Bu::operator>>( Bu::ArchiveBase &ar, char &p)
108{
109 ar.read( &p, sizeof(p) );
110 return ar;
111}
112
113Bu::ArchiveBase &Bu::operator>>( Bu::ArchiveBase &ar, signed char &p)
114{
115 ar.read( &p, sizeof(p) );
116 return ar;
117}
118
119Bu::ArchiveBase &Bu::operator>>( Bu::ArchiveBase &ar, unsigned char &p)
120{
121 ar.read( &p, sizeof(p) );
122 return ar;
123}
124
125Bu::ArchiveBase &Bu::operator>>( Bu::ArchiveBase &ar, signed short &p)
126{
127 ar.read( &p, sizeof(p) );
128 return ar;
129}
130
131Bu::ArchiveBase &Bu::operator>>( Bu::ArchiveBase &ar, unsigned short &p)
132{
133 ar.read( &p, sizeof(p) );
134 return ar;
135}
136
137Bu::ArchiveBase &Bu::operator>>( Bu::ArchiveBase &ar, signed int &p)
138{
139 ar.read( &p, sizeof(p) );
140 return ar;
141}
142
143Bu::ArchiveBase &Bu::operator>>( Bu::ArchiveBase &ar, unsigned int &p)
144{
145 ar.read( &p, sizeof(p) );
146 return ar;
147}
148
149Bu::ArchiveBase &Bu::operator>>( Bu::ArchiveBase &ar, signed long &p)
150{
151 ar.read( &p, sizeof(p) );
152 return ar;
153}
154
155Bu::ArchiveBase &Bu::operator>>( Bu::ArchiveBase &ar, unsigned long &p)
156{
157 ar.read( &p, sizeof(p) );
158 return ar;
159}
160
161Bu::ArchiveBase &Bu::operator>>( Bu::ArchiveBase &ar, signed long long &p)
162{
163 ar.read( &p, sizeof(p) );
164 return ar;
165}
166
167Bu::ArchiveBase &Bu::operator>>( Bu::ArchiveBase &ar, unsigned long long &p)
168{
169 ar.read( &p, sizeof(p) );
170 return ar;
171}
172
173Bu::ArchiveBase &Bu::operator>>( Bu::ArchiveBase &ar, float &p)
174{
175 ar.read( &p, sizeof(p) );
176 return ar;
177}
178
179Bu::ArchiveBase &Bu::operator>>( Bu::ArchiveBase &ar, double &p)
180{
181 ar.read( &p, sizeof(p) );
182 return ar;
183}
184
185Bu::ArchiveBase &Bu::operator>>( Bu::ArchiveBase &ar, long double &p)
186{
187 ar.read( &p, sizeof(p) );
188 return ar;
189}
190
diff --git a/src/archivebase.h b/src/archivebase.h
new file mode 100644
index 0000000..f421efb
--- /dev/null
+++ b/src/archivebase.h
@@ -0,0 +1,67 @@
1#ifndef BU_ARCHIVE_BASE_H
2#define BU_ARCHIVE_BASE_H
3
4#include <stdint.h>
5
6namespace Bu
7{
8 class ArchiveBase
9 {
10 public:
11 ArchiveBase();
12 virtual ~ArchiveBase();
13
14 virtual void close()=0;
15 virtual void write( const void *pData, int32_t iLength )=0;
16 virtual void read( void *pData, int32_t iLength )=0;
17 virtual bool isLoading()=0;
18 };
19
20 template<typename T> ArchiveBase &operator&&( ArchiveBase &ar, T &dat )
21 {
22 if( ar.isLoading() )
23 {
24 return ar >> dat;
25 }
26 else
27 {
28 return ar << dat;
29 }
30 }
31
32 ArchiveBase &operator<<( ArchiveBase &ar, bool p );
33 ArchiveBase &operator<<( ArchiveBase &ar, char p );
34 ArchiveBase &operator<<( ArchiveBase &ar, signed char p );
35 ArchiveBase &operator<<( ArchiveBase &ar, unsigned char p );
36 ArchiveBase &operator<<( ArchiveBase &ar, signed short p );
37 ArchiveBase &operator<<( ArchiveBase &ar, unsigned short p );
38 ArchiveBase &operator<<( ArchiveBase &ar, signed int p );
39 ArchiveBase &operator<<( ArchiveBase &ar, unsigned int p );
40 ArchiveBase &operator<<( ArchiveBase &ar, signed long p );
41 ArchiveBase &operator<<( ArchiveBase &ar, unsigned long p );
42 ArchiveBase &operator<<( ArchiveBase &ar, signed long long p );
43 ArchiveBase &operator<<( ArchiveBase &ar, unsigned long long p );
44 ArchiveBase &operator<<( ArchiveBase &ar, float p );
45 ArchiveBase &operator<<( ArchiveBase &ar, double p );
46 ArchiveBase &operator<<( ArchiveBase &ar, long double p );
47
48 ArchiveBase &operator>>( ArchiveBase &ar, bool &p );
49 ArchiveBase &operator>>( ArchiveBase &ar, char &p );
50 ArchiveBase &operator>>( ArchiveBase &ar, signed char &p );
51 ArchiveBase &operator>>( ArchiveBase &ar, unsigned char &p );
52 ArchiveBase &operator>>( ArchiveBase &ar, signed short &p );
53 ArchiveBase &operator>>( ArchiveBase &ar, unsigned short &p );
54 ArchiveBase &operator>>( ArchiveBase &ar, signed int &p );
55 ArchiveBase &operator>>( ArchiveBase &ar, unsigned int &p );
56 ArchiveBase &operator>>( ArchiveBase &ar, signed long &p );
57 ArchiveBase &operator>>( ArchiveBase &ar, unsigned long &p );
58 ArchiveBase &operator>>( ArchiveBase &ar, signed long long &p );
59 ArchiveBase &operator>>( ArchiveBase &ar, unsigned long long &p );
60 ArchiveBase &operator>>( ArchiveBase &ar, float &p );
61 ArchiveBase &operator>>( ArchiveBase &ar, double &p );
62 ArchiveBase &operator>>( ArchiveBase &ar, long double &p );
63
64
65};
66
67#endif
diff --git a/src/array.h b/src/array.h
index ca4ec21..6279382 100644
--- a/src/array.h
+++ b/src/array.h
@@ -10,6 +10,7 @@
10 10
11#include <memory> 11#include <memory>
12#include "bu/exceptionbase.h" 12#include "bu/exceptionbase.h"
13#include "bu/archivebase.h"
13 14
14namespace Bu 15namespace Bu
15{ 16{
@@ -442,6 +443,38 @@ namespace Bu
442 443
443 return f; 444 return f;
444 } 445 }
446
447 template<typename value, int inc, typename valuealloc>
448 ArchiveBase &operator<<( ArchiveBase &ar,
449 const Array<value, inc, valuealloc> &h )
450 {
451 ar << h.getSize();
452 for( typename Array<value, inc, valuealloc>::const_iterator i =
453 h.begin(); i != h.end(); i++ )
454 {
455 ar << (*i);
456 }
457
458 return ar;
459 }
460
461 template<typename value, int inc, typename valuealloc>
462 ArchiveBase &operator>>(ArchiveBase &ar, Array<value, inc, valuealloc> &h )
463 {
464 h.clear();
465 long nSize;
466 ar >> nSize;
467
468 h.setCapacity( nSize );
469 for( long j = 0; j < nSize; j++ )
470 {
471 value v;
472 ar >> v;
473 h.append( v );
474 }
475 return ar;
476 }
477
445} 478}
446 479
447#endif 480#endif
diff --git a/src/cachestorenids.h b/src/cachestorenids.h
index 3859900..ae2b9a2 100644
--- a/src/cachestorenids.h
+++ b/src/cachestorenids.h
@@ -15,6 +15,7 @@
15#include "bu/cachestore.h" 15#include "bu/cachestore.h"
16 16
17#include "bu/file.h" 17#include "bu/file.h"
18#include "bu/archive.h"
18 19
19namespace Bu 20namespace Bu
20{ 21{
diff --git a/src/client.h b/src/client.h
index 72b1b05..e91dead 100644
--- a/src/client.h
+++ b/src/client.h
@@ -15,6 +15,7 @@
15namespace Bu 15namespace Bu
16{ 16{
17 class Protocol; 17 class Protocol;
18 class Stream;
18 class Socket; 19 class Socket;
19 class ClientLinkFactory; 20 class ClientLinkFactory;
20 21
diff --git a/src/exceptionbase.cpp b/src/exceptionbase.cpp
index a3b10af..b3f06f4 100644
--- a/src/exceptionbase.cpp
+++ b/src/exceptionbase.cpp
@@ -8,6 +8,7 @@
8#include "exceptionbase.h" 8#include "exceptionbase.h"
9#include <stdarg.h> 9#include <stdarg.h>
10#include <string.h> 10#include <string.h>
11#include <stdio.h>
11 12
12Bu::ExceptionBase::ExceptionBase( const char *lpFormat, ... ) throw() : 13Bu::ExceptionBase::ExceptionBase( const char *lpFormat, ... ) throw() :
13 nErrorCode( 0 ), 14 nErrorCode( 0 ),
diff --git a/src/exceptionbase.h b/src/exceptionbase.h
index de63177..20e8ee1 100644
--- a/src/exceptionbase.h
+++ b/src/exceptionbase.h
@@ -8,7 +8,6 @@
8#ifndef BU_EXCEPTION_BASE_H 8#ifndef BU_EXCEPTION_BASE_H
9#define BU_EXCEPTION_BASE_H 9#define BU_EXCEPTION_BASE_H
10 10
11#include <string>
12#include <exception> 11#include <exception>
13#include <stdarg.h> 12#include <stdarg.h>
14 13
diff --git a/src/fastcgi.cpp b/src/fastcgi.cpp
index 3cc3a10..1662fe6 100644
--- a/src/fastcgi.cpp
+++ b/src/fastcgi.cpp
@@ -9,6 +9,7 @@
9 9
10#include <arpa/inet.h> 10#include <arpa/inet.h>
11#include <errno.h> 11#include <errno.h>
12#include <unistd.h>
12 13
13#include "bu/membuf.h" 14#include "bu/membuf.h"
14 15
diff --git a/src/fbasicstring.h b/src/fbasicstring.h
index 225bc80..0e63efe 100644
--- a/src/fbasicstring.h
+++ b/src/fbasicstring.h
@@ -15,10 +15,13 @@
15#include <wordexp.h> 15#include <wordexp.h>
16#endif 16#endif
17 17
18#include "bu/archival.h"
19#include "bu/archive.h"
20#include "bu/util.h" 18#include "bu/util.h"
21#include "bu/sharedcore.h" 19#include "bu/sharedcore.h"
20#include "bu/exceptionbase.h"
21#include "bu/archivebase.h"
22#include "bu/list.h"
23
24#include <string.h>
22 25
23namespace Bu 26namespace Bu
24{ 27{
@@ -30,21 +33,8 @@ namespace Bu
30 FStringChunk *pNext; 33 FStringChunk *pNext;
31 }; 34 };
32 35
33#ifndef VALTEST 36#define cpy( dest, src, size ) Bu::memcpy( dest, src, size*sizeof(chr) )
34#define cpy( dest, src, size ) memcpy( dest, src, size*sizeof(chr) )
35#endif
36 37
37#ifdef VALTEST
38 void cpy( chr *dest, const chr *src, long count ) const
39 {
40 for( int j = 0; j < count; j++ )
41 {
42 *dest = *src;
43 dest++;
44 src++;
45 }
46 }
47#endif
48 template<typename chr, int nMinSize, typename chralloc, typename chunkalloc> 38 template<typename chr, int nMinSize, typename chralloc, typename chunkalloc>
49 struct FStringCore 39 struct FStringCore
50 { 40 {
@@ -185,7 +175,7 @@ namespace Bu
185 *@param chunkalloc (typename) Memory Allocator for chr chunks 175 *@param chunkalloc (typename) Memory Allocator for chr chunks
186 */ 176 */
187 template< typename chr, int nMinSize=256, typename chralloc=std::allocator<chr>, typename chunkalloc=std::allocator<struct FStringChunk<chr> > > 177 template< typename chr, int nMinSize=256, typename chralloc=std::allocator<chr>, typename chunkalloc=std::allocator<struct FStringChunk<chr> > >
188 class FBasicString : public SharedCore< FStringCore<chr, nMinSize, chralloc, chunkalloc> >, public Archival 178 class FBasicString : public SharedCore< FStringCore<chr, nMinSize, chralloc, chunkalloc> >
189 { 179 {
190 protected: 180 protected:
191 typedef struct FStringChunk<chr> Chunk; 181 typedef struct FStringChunk<chr> Chunk;
@@ -211,8 +201,7 @@ namespace Bu
211 } 201 }
212 202
213 FBasicString( const MyType &rSrc ) : 203 FBasicString( const MyType &rSrc ) :
214 SharedCore<Core>( rSrc ), 204 SharedCore<Core>( rSrc )
215 Archival()
216 { 205 {
217 } 206 }
218 207
@@ -1284,13 +1273,6 @@ namespace Bu
1284 return (*this); 1273 return (*this);
1285 } 1274 }
1286 1275
1287 MyType &operator=( const std::basic_string<chr> &rData )
1288 {
1289 set( rData.c_str(), rData.size() );
1290
1291 return (*this);
1292 }
1293
1294 MyType operator+( const MyType &rRight ) const 1276 MyType operator+( const MyType &rRight ) const
1295 { 1277 {
1296 MyType ret( *this ); 1278 MyType ret( *this );
@@ -1505,8 +1487,8 @@ namespace Bu
1505 flatten(); 1487 flatten();
1506 pData.flatten(); 1488 pData.flatten();
1507 1489
1508 const chr *a = pData.core->pFirst->pData; 1490 const chr *a = core->pFirst->pData;
1509 chr *b = core->pFirst->pData; 1491 chr *b = pData.core->pFirst->pData;
1510 for( long j = 0; j < core->nLength; j++, a++, b++ ) 1492 for( long j = 0; j < core->nLength; j++, a++, b++ )
1511 { 1493 {
1512 if( *a != *b ) 1494 if( *a != *b )
@@ -1521,8 +1503,8 @@ namespace Bu
1521 flatten(); 1503 flatten();
1522 pData.flatten(); 1504 pData.flatten();
1523 1505
1524 const chr *a = pData.core->pFirst->pData; 1506 const chr *a = core->pFirst->pData;
1525 chr *b = core->pFirst->pData; 1507 chr *b = pData.core->pFirst->pData;
1526 for( long j = 0; j < core->nLength; j++, a++, b++ ) 1508 for( long j = 0; j < core->nLength; j++, a++, b++ )
1527 { 1509 {
1528 if( *a != *b ) 1510 if( *a != *b )
@@ -1902,51 +1884,6 @@ namespace Bu
1902 va_end( ap ); 1884 va_end( ap );
1903 } 1885 }
1904 1886
1905 /**
1906 * Function the archiver calls to archive your FString.
1907 *@param ar (Archive) The archive which is archiving your FString.
1908 */
1909 void archive( class Archive &ar )
1910 {
1911 if( ar.isLoading() )
1912 {
1913 _hardCopy();
1914 core->clear();
1915 long nLen;
1916 ar >> nLen;
1917
1918 if( nLen > 0 )
1919 {
1920 Chunk *pNew = core->newChunk( nLen );
1921 ar.read( pNew->pData, nLen*sizeof(chr) );
1922 core->appendChunk( pNew );
1923 }
1924 }
1925 else
1926 {
1927 flatten();
1928
1929 ar << core->nLength;
1930 if( core->nLength )
1931 ar.write( core->pFirst->pData, core->nLength*sizeof(chr) );
1932 }
1933 }
1934 /*
1935 void archive( class Archive &ar ) const
1936 {
1937 if( ar.isLoading() )
1938 {
1939 }
1940 else
1941 {
1942 flatten();
1943
1944 ar << core->nLength;
1945 if( core->nLength )
1946 ar.write( core->pFirst->pData, core->nLength*sizeof(chr) );
1947 }
1948 }*/
1949
1950 iterator begin() 1887 iterator begin()
1951 { 1888 {
1952 if( core->nLength == 0 ) 1889 if( core->nLength == 0 )
@@ -2016,10 +1953,27 @@ namespace Bu
2016 ret.append( rRight ); 1953 ret.append( rRight );
2017 return ret; 1954 return ret;
2018 } 1955 }
1956
1957 template<class chr, int b, class c, class d>
1958 ArchiveBase &operator<<( ArchiveBase &ar, const FBasicString<chr, b, c, d> &s )
1959 {
1960 long n = s.getSize();
1961 ar << n;
1962 ar.write( s.getConstStr(), n );
1963 return ar;
1964 }
1965
1966 template<class chr, int b, class c, class d>
1967 ArchiveBase &operator>>( ArchiveBase &ar, FBasicString<chr, b, c, d> &s )
1968 {
1969 long n;
1970 ar >> n;
1971 s.setSize( n );
1972 ar.read( s.getStr(), n );
1973 return ar;
1974 }
2019} 1975}
2020 1976
2021#ifndef VALTEST
2022#undef cpy 1977#undef cpy
2023#endif
2024 1978
2025#endif 1979#endif
diff --git a/src/fifo.cpp b/src/fifo.cpp
index f34bb91..f72e965 100644
--- a/src/fifo.cpp
+++ b/src/fifo.cpp
@@ -10,6 +10,7 @@
10#include <sys/types.h> 10#include <sys/types.h>
11#include <sys/stat.h> 11#include <sys/stat.h>
12#include <fcntl.h> 12#include <fcntl.h>
13#include <unistd.h>
13 14
14namespace Bu { subExceptionDef( FifoException ) } 15namespace Bu { subExceptionDef( FifoException ) }
15 16
diff --git a/src/formatter.cpp b/src/formatter.cpp
index b841c5e..830e527 100644
--- a/src/formatter.cpp
+++ b/src/formatter.cpp
@@ -7,6 +7,8 @@
7 7
8#include "formatter.h" 8#include "formatter.h"
9 9
10#include <string.h>
11
10Bu::Formatter::Formatter( Stream &rOut ) : 12Bu::Formatter::Formatter( Stream &rOut ) :
11 rOut( rOut ), 13 rOut( rOut ),
12 uIndent( 0 ), 14 uIndent( 0 ),
diff --git a/src/fstring.cpp b/src/fstring.cpp
index f77e718..a036d72 100644
--- a/src/fstring.cpp
+++ b/src/fstring.cpp
@@ -33,12 +33,6 @@ template<> bool Bu::__cmpHashKeys<Bu::FString>(
33 return a == b; 33 return a == b;
34} 34}
35 35
36std::basic_ostream<char>& operator<< (std::basic_ostream<char> &os, const Bu::FString &val )
37{
38 os.write( val.getStr(), val.getSize() );
39 return os;
40}
41
42template<> void Bu::__tracer_format<Bu::FString>( const Bu::FString &v ) 36template<> void Bu::__tracer_format<Bu::FString>( const Bu::FString &v )
43{ 37{
44 printf("(%ld)\"%s\"", v.getSize(), v.getStr() ); 38 printf("(%ld)\"%s\"", v.getSize(), v.getStr() );
diff --git a/src/fstring.h b/src/fstring.h
index 1fc02ca..0bffd3e 100644
--- a/src/fstring.h
+++ b/src/fstring.h
@@ -14,6 +14,12 @@ namespace Bu
14{ 14{
15 typedef FBasicString<char> FString; 15 typedef FBasicString<char> FString;
16 16
17 template<typename T>
18 uint32_t __calcHashCode( const T &k );
19
20 template<typename T>
21 bool __cmpHashKeys( const T &a, const T &b );
22
17 template<> uint32_t __calcHashCode<FString>( const FString &k ); 23 template<> uint32_t __calcHashCode<FString>( const FString &k );
18 template<> bool __cmpHashKeys<FString>( 24 template<> bool __cmpHashKeys<FString>(
19 const FString &a, const FString &b ); 25 const FString &a, const FString &b );
diff --git a/src/hash.cpp b/src/hash.cpp
index de925a7..dfd5d80 100644
--- a/src/hash.cpp
+++ b/src/hash.cpp
@@ -67,22 +67,3 @@ template<> bool Bu::__cmpHashKeys<char *>( char * const &a, char * const &b )
67 return false; 67 return false;
68} 68}
69 69
70template<> uint32_t Bu::__calcHashCode<std::string>( const std::string &k )
71{
72 std::string::size_type j, sz = k.size();
73 const char *s = k.c_str();
74
75 unsigned long int nPos = 0;
76 for( j = 0; j < sz; j++, s++ )
77 {
78 nPos = *s + (nPos << 6) + (nPos << 16) - nPos;
79 }
80
81 return nPos;
82}
83
84template<> bool Bu::__cmpHashKeys<std::string>( const std::string &a, const std::string &b )
85{
86 return a == b;
87}
88
diff --git a/src/hash.h b/src/hash.h
index 10c661f..09025ba 100644
--- a/src/hash.h
+++ b/src/hash.h
@@ -8,17 +8,11 @@
8#ifndef BU_HASH_H 8#ifndef BU_HASH_H
9#define BU_HASH_H 9#define BU_HASH_H
10 10
11#include <stddef.h>
12#include <string.h>
13#include <memory> 11#include <memory>
14#include <iostream>
15#include <list>
16#include <utility>
17#include "bu/exceptionbase.h" 12#include "bu/exceptionbase.h"
18#include "bu/list.h" 13#include "bu/list.h"
19#include "bu/util.h" 14#include "bu/util.h"
20//#include "archival.h" 15#include "archivebase.h"
21//#include "archive.h"
22 16
23#define bitsToBytes( n ) (n/32+(n%32>0 ? 1 : 0)) 17#define bitsToBytes( n ) (n/32+(n%32>0 ? 1 : 0))
24 18
@@ -373,6 +367,11 @@ namespace Bu
373 return nFilled-nDeleted; 367 return nFilled-nDeleted;
374 } 368 }
375 369
370 bool isEmpty() const
371 {
372 return (nFilled-nDeleted) == 0;
373 }
374
376 /** 375 /**
377 * Get the number of items which have been deleted, but not yet 376 * Get the number of items which have been deleted, but not yet
378 * cleaned up. 377 * cleaned up.
@@ -1171,9 +1170,6 @@ namespace Bu
1171 template<> uint32_t __calcHashCode<char *>( char * const &k ); 1170 template<> uint32_t __calcHashCode<char *>( char * const &k );
1172 template<> bool __cmpHashKeys<char *>( char * const &a, char * const &b ); 1171 template<> bool __cmpHashKeys<char *>( char * const &a, char * const &b );
1173 1172
1174 template<> uint32_t __calcHashCode<std::string>( const std::string &k );
1175 template<> bool __cmpHashKeys<std::string>( const std::string &a, const std::string &b );
1176
1177 class Formatter; 1173 class Formatter;
1178 Formatter &operator<<( Formatter &rOut, char *sStr ); 1174 Formatter &operator<<( Formatter &rOut, char *sStr );
1179 Formatter &operator<<( Formatter &rOut, signed char c ); 1175 Formatter &operator<<( Formatter &rOut, signed char c );
@@ -1190,30 +1186,30 @@ namespace Bu
1190 f << '}'; 1186 f << '}';
1191 1187
1192 return f; 1188 return f;
1193 } 1189 }
1194 1190
1195 /* 1191 template<typename key, typename value, typename a, typename b,
1196 template<typename key, typename value> 1192 typename c, typename d>
1197 Archive &operator<<( Archive &ar, Hash<key,value> &h ) 1193 ArchiveBase &operator<<( ArchiveBase &ar, const Hash<key,value,a,b,c,d> &h )
1198 { 1194 {
1199 ar << h.size(); 1195 ar << h.getSize();
1200 for( typename Hash<key,value>::iterator i = h.begin(); i != h.end(); i++ ) 1196 for( typename Hash<key,value>::const_iterator i = h.begin(); i != h.end(); i++ )
1201 { 1197 {
1202 std::pair<key,value> p = *i; 1198 ar << (i.getKey()) << (i.getValue());
1203 ar << p.first << p.second;
1204 } 1199 }
1205 1200
1206 return ar; 1201 return ar;
1207 } 1202 }
1208 1203
1209 template<typename key, typename value> 1204 template<typename key, typename value, typename a, typename b,
1210 Archive &operator>>( Archive &ar, Hash<key,value> &h ) 1205 typename c, typename d>
1206 ArchiveBase &operator>>( ArchiveBase &ar, Hash<key,value,a,b,c,d> &h )
1211 { 1207 {
1212 h.clear(); 1208 h.clear();
1213 uint32_t nSize; 1209 long nSize;
1214 ar >> nSize; 1210 ar >> nSize;
1215 1211
1216 for( uint32_t j = 0; j < nSize; j++ ) 1212 for( long j = 0; j < nSize; j++ )
1217 { 1213 {
1218 key k; value v; 1214 key k; value v;
1219 ar >> k >> v; 1215 ar >> k >> v;
@@ -1221,21 +1217,7 @@ namespace Bu
1221 } 1217 }
1222 1218
1223 return ar; 1219 return ar;
1224 }*/ 1220 }
1225
1226 /*
1227 template<typename key, typename value>
1228 Serializer &operator&&( Serializer &ar, Hash<key,value> &h )
1229 {
1230 if( ar.isLoading() )
1231 {
1232 return ar >> h;
1233 }
1234 else
1235 {
1236 return ar << h;
1237 }
1238 }*/
1239} 1221}
1240 1222
1241#endif 1223#endif
diff --git a/src/heap.h b/src/heap.h
index 2741818..a8d904c 100644
--- a/src/heap.h
+++ b/src/heap.h
@@ -9,11 +9,10 @@
9#define BU_HEAP_H 9#define BU_HEAP_H
10 10
11#include <stddef.h> 11#include <stddef.h>
12#include <string.h>
13#include <memory> 12#include <memory>
14#include <iostream>
15#include "bu/exceptionbase.h" 13#include "bu/exceptionbase.h"
16#include "bu/util.h" 14#include "bu/util.h"
15// #include "bu/formatter.h"
17 16
18namespace Bu 17namespace Bu
19{ 18{
@@ -29,6 +28,33 @@ namespace Bu
29 aItem( ia.allocate( iSize ) ) 28 aItem( ia.allocate( iSize ) )
30 { 29 {
31 } 30 }
31
32 Heap( cmpfunc cmpin ) :
33 iSize( 7 ),
34 iFill( 0 ),
35 aItem( ia.allocate( iSize ) ),
36 cmp( cmpin )
37 {
38 }
39
40 Heap( int iInitialCapacity ) :
41 iSize( 0 ),
42 iFill( 0 ),
43 aItem( NULL )
44 {
45 for( iSize = 1; iSize < iInitialCapacity; iSize=iSize*2+1 ) { }
46 aItem = ia.allocate( iSize );
47 }
48
49 Heap( cmpfunc cmpin, int iInitialCapacity ) :
50 iSize( 0 ),
51 iFill( 0 ),
52 aItem( NULL ),
53 cmp( cmpin )
54 {
55 for( iSize = 1; iSize < iInitialCapacity; iSize=iSize*2+1 ) { }
56 aItem = ia.allocate( iSize );
57 }
32 58
33 virtual ~Heap() 59 virtual ~Heap()
34 { 60 {
@@ -47,9 +73,11 @@ namespace Bu
47 { 73 {
48 if( cmp( i, aItem[j] ) ) 74 if( cmp( i, aItem[j] ) )
49 { 75 {
50 swap( i, aItem[j] ); 76 Bu::swap( i, aItem[j] );
51 } 77 }
52 78
79 if( j*2+1 >= iFill )
80 break;
53 if( cmp( i, aItem[j*2+1] ) ) 81 if( cmp( i, aItem[j*2+1] ) )
54 { 82 {
55 j = j*2+1; 83 j = j*2+1;
@@ -68,7 +96,7 @@ namespace Bu
68 if( cmp( aItem[k], aItem[j] ) ) 96 if( cmp( aItem[k], aItem[j] ) )
69 break; 97 break;
70 98
71 swap( aItem[k], aItem[j] ); 99 Bu::swap( aItem[k], aItem[j] );
72 j = k; 100 j = k;
73 } 101 }
74 } 102 }
@@ -90,20 +118,22 @@ namespace Bu
90 int j; 118 int j;
91 for( j = 0; j < iFill; ) 119 for( j = 0; j < iFill; )
92 { 120 {
93 if( cmp( aItem[j*2+2], aItem[j*2+1] ) && j*2+2 < iFill ) 121 int k = j*2+1;
122 if( k+1 < iFill && cmp( aItem[k+1], aItem[k] ) )
94 { 123 {
95 aItem[j] = aItem[j*2+2]; 124 aItem[j] = aItem[k+1];
96 j = j*2+2; 125 j = k+1;
97 } 126 }
98 else if( j*2+1 < iFill ) 127 else if( k < iFill )
99 { 128 {
100 aItem[j] = aItem[j*2+1]; 129 aItem[j] = aItem[k];
101 j = j*2+1; 130 j = k;
102 } 131 }
103 else 132 else
104 break; 133 break;
105 } 134 }
106 aItem[j] = aItem[iFill-1]; 135 if( j < iFill-1 )
136 aItem[j] = aItem[iFill-1];
107 ia.destroy( &aItem[iFill-1] ); 137 ia.destroy( &aItem[iFill-1] );
108 iFill--; 138 iFill--;
109 139
@@ -119,35 +149,34 @@ namespace Bu
119 { 149 {
120 return iFill; 150 return iFill;
121 } 151 }
122 152/*
123 void print() 153 void print( Formatter &f )
124 { 154 {
125 printf("graph G {\n"); 155 f << "graph G {" << f.nl;
126 for( int j = 0; j < iFill; j++ ) 156 for( int j = 0; j < iFill; j++ )
127 { 157 {
128 if( j*2+1 < iFill ) 158 if( j*2+1 < iFill )
129 printf(" %d -- %d;\n", 159 f << " " << j << " -- " << j*2+1 << ";" << f.nl;
130 j, j*2+1
131 );
132 if( j*2+2 < iFill ) 160 if( j*2+2 < iFill )
133 printf(" %d -- %d;\n", 161 f << " " << j << " -- " << j*2+2 << ";" << f.nl;
134 j, j*2+2
135 );
136 } 162 }
137 for( int j = 0; j < iFill; j++ ) 163 for( int j = 0; j < iFill; j++ )
138 { 164 {
139 printf(" %d [label=\"%d\"];\n", 165 f << " " << j << " [label=\"" << aItem[j] << "\"];" << f.nl;
140 j, aItem[j]
141 );
142 } 166 }
143 printf("}\n"); 167 f << "}" << f.nl;
144 } 168 } */
145 169
146 private: 170 private:
147 void upSize() 171 void upSize()
148 { 172 {
149 item *aNewItems = ia.allocate( iSize*2+1 ); 173 item *aNewItems = ia.allocate( iSize*2+1 );
150 memcpy( aNewItems, aItem, sizeof(item)*iFill ); 174// memcpy( aNewItems, aItem, sizeof(item)*iFill );
175 for( int j = 0; j < iFill; j++ )
176 {
177 ia.construct( &aNewItems[j], aItem[j] );
178 ia.destroy( &aItem[j] );
179 }
151 ia.deallocate( aItem, iSize ); 180 ia.deallocate( aItem, iSize );
152 aItem = aNewItems; 181 aItem = aNewItems;
153 iSize = iSize*2+1; 182 iSize = iSize*2+1;
diff --git a/src/httpget.h b/src/httpget.h
index 7484566..840c893 100644
--- a/src/httpget.h
+++ b/src/httpget.h
@@ -12,6 +12,7 @@
12#include "bu/fstring.h" 12#include "bu/fstring.h"
13#include "bu/url.h" 13#include "bu/url.h"
14#include "bu/socket.h" 14#include "bu/socket.h"
15#include "bu/hash.h"
15 16
16namespace Bu 17namespace Bu
17{ 18{
diff --git a/src/list.h b/src/list.h
index d8c5a4a..f76c505 100644
--- a/src/list.h
+++ b/src/list.h
@@ -11,7 +11,8 @@
11#include <memory> 11#include <memory>
12#include "bu/exceptionbase.h" 12#include "bu/exceptionbase.h"
13#include "bu/sharedcore.h" 13#include "bu/sharedcore.h"
14//#include "bu/util.h" 14#include "bu/archivebase.h"
15#include "bu/heap.h"
15 16
16namespace Bu 17namespace Bu
17{ 18{
@@ -23,7 +24,7 @@ namespace Bu
23 ListLink *pPrev; 24 ListLink *pPrev;
24 }; 25 };
25 26
26 template<typename value, typename cmpfunc, typename valuealloc, 27 template<typename value, typename valuealloc,
27 typename linkalloc> 28 typename linkalloc>
28 struct ListCore 29 struct ListCore
29 { 30 {
@@ -42,7 +43,6 @@ namespace Bu
42 Link *pFirst; 43 Link *pFirst;
43 Link *pLast; 44 Link *pLast;
44 long nSize; 45 long nSize;
45 cmpfunc cmp;
46 linkalloc la; 46 linkalloc la;
47 valuealloc va; 47 valuealloc va;
48 48
@@ -189,16 +189,15 @@ namespace Bu
189 *@param linkalloc (typename) Memory Allocator for the list links. 189 *@param linkalloc (typename) Memory Allocator for the list links.
190 *@ingroup Containers 190 *@ingroup Containers
191 */ 191 */
192 template<typename value, typename cmpfunc=__basicGTCmp<value>, 192 template<typename value, typename valuealloc=std::allocator<value>,
193 typename valuealloc=std::allocator<value>,
194 typename linkalloc=std::allocator<struct ListLink<value> > > 193 typename linkalloc=std::allocator<struct ListLink<value> > >
195 class List : public SharedCore< struct ListCore<value, cmpfunc, valuealloc, 194 class List : public SharedCore< struct ListCore<value, valuealloc,
196 linkalloc> > 195 linkalloc> >
197 { 196 {
198 private: 197 private:
199 typedef struct ListLink<value> Link; 198 typedef struct ListLink<value> Link;
200 typedef class List<value, cmpfunc, valuealloc, linkalloc> MyType; 199 typedef class List<value, valuealloc, linkalloc> MyType;
201 typedef struct ListCore<value, cmpfunc, valuealloc, linkalloc> Core; 200 typedef struct ListCore<value, valuealloc, linkalloc> Core;
202 201
203 protected: 202 protected:
204 using SharedCore< Core >::core; 203 using SharedCore< Core >::core;
@@ -241,6 +240,26 @@ namespace Bu
241 return *this; 240 return *this;
242 } 241 }
243 242
243 bool operator==( const MyType &rhs )
244 {
245 if( getSize() != rhs.getSize() )
246 return false;
247
248 for( typename MyType::const_iterator a = begin(), b = rhs.begin();
249 a; a++, b++ )
250 {
251 if( *a != *b )
252 return false;
253 }
254
255 return true;
256 }
257
258 bool operator!=( const MyType &rhs )
259 {
260 return !(*this == rhs);
261 }
262
244 /** 263 /**
245 * Clear the data from the list. 264 * Clear the data from the list.
246 */ 265 */
@@ -350,6 +369,41 @@ namespace Bu
350 return *this; 369 return *this;
351 } 370 }
352 371
372 template<typename cmptype>
373 void sort( cmptype cmp )
374 {
375 Heap<value, cmptype, valuealloc> hSort( cmp, getSize() );
376 for( typename MyType::iterator i = begin(); i; i++ )
377 {
378 hSort.enqueue( *i );
379 }
380 clear();
381 while( !hSort.isEmpty() )
382 {
383 append( hSort.dequeue() );
384 }
385 }
386
387 void sort()
388 {
389 sort<__basicLTCmp<value> >();
390 }
391
392 template<typename cmptype>
393 void sort()
394 {
395 Heap<value, cmptype, valuealloc> hSort( getSize() );
396 for( typename MyType::iterator i = begin(); i; i++ )
397 {
398 hSort.enqueue( *i );
399 }
400 clear();
401 while( !hSort.isEmpty() )
402 {
403 append( hSort.dequeue() );
404 }
405 }
406
353 /** 407 /**
354 * Insert a new item in sort order by searching for the first item that 408 * Insert a new item in sort order by searching for the first item that
355 * is larger and inserting this before it, or at the end if none are 409 * is larger and inserting this before it, or at the end if none are
@@ -357,7 +411,8 @@ namespace Bu
357 * List all items will be sorted. To use this, the value type must 411 * List all items will be sorted. To use this, the value type must
358 * support the > operator. 412 * support the > operator.
359 */ 413 */
360 MyType &insertSorted( const value &v ) 414 template<typename cmptype>
415 MyType &insertSorted( cmptype cmp, const value &v )
361 { 416 {
362 _hardCopy(); 417 _hardCopy();
363 if( core->pFirst == NULL ) 418 if( core->pFirst == NULL )
@@ -371,7 +426,7 @@ namespace Bu
371 Link *pCur = core->pFirst; 426 Link *pCur = core->pFirst;
372 for(;;) 427 for(;;)
373 { 428 {
374 if( !core->cmp( v, *(pCur->pValue)) ) 429 if( cmp( v, *(pCur->pValue)) )
375 { 430 {
376 core->insert( pCur, v ); 431 core->insert( pCur, v );
377 return *this; 432 return *this;
@@ -385,6 +440,18 @@ namespace Bu
385 } 440 }
386 } 441 }
387 } 442 }
443
444 MyType &insertSorted( const value &v )
445 {
446 return insertSorted<__basicLTCmp<value> >( v );
447 }
448
449 template<typename cmptype>
450 MyType &insertSorted( const value &v )
451 {
452 cmptype cmp;
453 return insertSorted( cmp, v );
454 }
388 455
389 /** 456 /**
390 * An iterator to iterate through your list. 457 * An iterator to iterate through your list.
@@ -392,7 +459,7 @@ namespace Bu
392 typedef struct iterator 459 typedef struct iterator
393 { 460 {
394 friend struct const_iterator; 461 friend struct const_iterator;
395 friend class List<value, cmpfunc, valuealloc, linkalloc>; 462 friend class List<value, valuealloc, linkalloc>;
396 private: 463 private:
397 Link *pLink; 464 Link *pLink;
398 465
@@ -559,7 +626,7 @@ namespace Bu
559 */ 626 */
560 typedef struct const_iterator 627 typedef struct const_iterator
561 { 628 {
562 friend class List<value, cmpfunc, valuealloc, linkalloc>; 629 friend class List<value, valuealloc, linkalloc>;
563 private: 630 private:
564 Link *pLink; 631 Link *pLink;
565 632
@@ -844,11 +911,11 @@ namespace Bu
844 class Formatter; 911 class Formatter;
845 Formatter &operator<<( Formatter &rOut, char *sStr ); 912 Formatter &operator<<( Formatter &rOut, char *sStr );
846 Formatter &operator<<( Formatter &rOut, signed char c ); 913 Formatter &operator<<( Formatter &rOut, signed char c );
847 template<typename a, typename b, typename c, typename d> 914 template<typename a, typename b, typename c>
848 Formatter &operator<<( Formatter &f, const Bu::List<a,b,c,d> &l ) 915 Formatter &operator<<( Formatter &f, const Bu::List<a,b,c> &l )
849 { 916 {
850 f << '['; 917 f << '[';
851 for( typename Bu::List<a,b,c,d>::const_iterator i = l.begin(); i; i++ ) 918 for( typename Bu::List<a,b,c>::const_iterator i = l.begin(); i; i++ )
852 { 919 {
853 if( i != l.begin() ) 920 if( i != l.begin() )
854 f << ", "; 921 f << ", ";
@@ -858,6 +925,36 @@ namespace Bu
858 925
859 return f; 926 return f;
860 } 927 }
928
929 template<typename value, typename a, typename b>
930 ArchiveBase &operator<<( ArchiveBase &ar, const List<value,a,b> &h )
931 {
932 ar << h.getSize();
933 for( typename List<value>::const_iterator i = h.begin(); i != h.end(); i++ )
934 {
935 ar << (*i);
936 }
937
938 return ar;
939 }
940
941 template<typename value, typename a, typename b>
942 ArchiveBase &operator>>( ArchiveBase &ar, List<value,a,b> &h )
943 {
944 h.clear();
945 long nSize;
946 ar >> nSize;
947
948 for( long j = 0; j < nSize; j++ )
949 {
950 value v;
951 ar >> v;
952 h.append( v );
953 }
954
955 return ar;
956 }
957
861} 958}
862 959
863#endif 960#endif
diff --git a/src/logger.cpp b/src/logger.cpp
index 8cba1b9..e3de2fb 100644
--- a/src/logger.cpp
+++ b/src/logger.cpp
@@ -10,6 +10,7 @@
10#include <time.h> 10#include <time.h>
11#include <stdio.h> 11#include <stdio.h>
12#include <stdlib.h> 12#include <stdlib.h>
13#include <unistd.h>
13 14
14Bu::Logger::Logger() 15Bu::Logger::Logger()
15{ 16{
diff --git a/src/nidsstream.cpp b/src/nidsstream.cpp
index 9aee156..e8c3323 100644
--- a/src/nidsstream.cpp
+++ b/src/nidsstream.cpp
@@ -7,6 +7,8 @@
7 7
8#include "bu/nidsstream.h" 8#include "bu/nidsstream.h"
9 9
10#include <string.h>
11
10Bu::NidsStream::NidsStream( Nids &rNids, uint32_t uStream ) : 12Bu::NidsStream::NidsStream( Nids &rNids, uint32_t uStream ) :
11 rNids( rNids ), 13 rNids( rNids ),
12 uStream( uStream ), 14 uStream( uStream ),
diff --git a/src/paramproc.cpp b/src/paramproc.cpp
index 819a4da..fb07894 100644
--- a/src/paramproc.cpp
+++ b/src/paramproc.cpp
@@ -8,6 +8,7 @@
8#include "paramproc.h" 8#include "paramproc.h"
9#include <stdio.h> 9#include <stdio.h>
10#include <stdlib.h> 10#include <stdlib.h>
11#include <string.h>
11 12
12#define ptrtype( iitype, iiname ) \ 13#define ptrtype( iitype, iiname ) \
13 Bu::ParamProc::ParamPtr::ParamPtr( iitype *iiname ) : \ 14 Bu::ParamProc::ParamPtr::ParamPtr( iitype *iiname ) : \
diff --git a/src/protocolhttp.h b/src/protocolhttp.h
index 6632a65..eae525a 100644
--- a/src/protocolhttp.h
+++ b/src/protocolhttp.h
@@ -14,6 +14,7 @@
14#include "bu/protocol.h" 14#include "bu/protocol.h"
15#include "bu/client.h" 15#include "bu/client.h"
16#include "bu/fstring.h" 16#include "bu/fstring.h"
17#include "bu/hash.h"
17 18
18namespace Bu 19namespace Bu
19{ 20{
diff --git a/src/server.cpp b/src/server.cpp
index bfa7880..804ec70 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -7,6 +7,7 @@
7 7
8#include "bu/server.h" 8#include "bu/server.h"
9#include <errno.h> 9#include <errno.h>
10#include <unistd.h>
10#include "bu/serversocket.h" 11#include "bu/serversocket.h"
11#include "bu/client.h" 12#include "bu/client.h"
12#include "bu/socket.h" 13#include "bu/socket.h"
diff --git a/src/server.h b/src/server.h
index 315248b..1e317a4 100644
--- a/src/server.h
+++ b/src/server.h
@@ -16,6 +16,7 @@
16 16
17#include "bu/clientlink.h" 17#include "bu/clientlink.h"
18#include "bu/clientlinkfactory.h" 18#include "bu/clientlinkfactory.h"
19#include "bu/hash.h"
19 20
20namespace Bu 21namespace Bu
21{ 22{
diff --git a/src/set.h b/src/set.h
index aec5781..d5593a2 100644
--- a/src/set.h
+++ b/src/set.h
@@ -16,6 +16,7 @@
16#include <utility> 16#include <utility>
17#include "bu/exceptionbase.h" 17#include "bu/exceptionbase.h"
18#include "bu/list.h" 18#include "bu/list.h"
19#include "bu/archive.h"
19 20
20#define bitsToBytes( n ) (n/32+(n%32>0 ? 1 : 0)) 21#define bitsToBytes( n ) (n/32+(n%32>0 ? 1 : 0))
21 22
@@ -763,6 +764,35 @@ namespace Bu
763 challoc ca; 764 challoc ca;
764 sizecalc szCalc; 765 sizecalc szCalc;
765 }; 766 };
767
768 template<typename key, typename b, typename c, typename d>
769 Archive &operator<<( Archive &ar, const Set<key, b, c, d> &h )
770 {
771 ar << h.getSize();
772 for( typename Set<key, b, c, d>::const_iterator i = h.begin(); i != h.end(); i++ )
773 {
774 ar << (*i);
775 }
776
777 return ar;
778 }
779
780 template<typename key, typename b, typename c, typename d>
781 Archive &operator>>( Archive &ar, Set<key, b, c, d> &h )
782 {
783 h.clear();
784 long nSize;
785 ar >> nSize;
786
787 for( long j = 0; j < nSize; j++ )
788 {
789 key v;
790 ar >> v;
791 h.insert( v );
792 }
793
794 return ar;
795 }
766} 796}
767 797
768#endif 798#endif
diff --git a/src/tests/archive.cpp b/src/tests/archive.cpp
index 131d4de..8a5f6ee 100644
--- a/src/tests/archive.cpp
+++ b/src/tests/archive.cpp
@@ -7,6 +7,7 @@
7 7
8#include "bu/archive.h" 8#include "bu/archive.h"
9#include "bu/file.h" 9#include "bu/file.h"
10#include "bu/fstring.h"
10 11
11using namespace Bu; 12using namespace Bu;
12 13
@@ -15,7 +16,7 @@ int main()
15 File f("test.dat", File::Write ); 16 File f("test.dat", File::Write );
16 Archive ar( f, Archive::save ); 17 Archive ar( f, Archive::save );
17 18
18 std::string s("Hello there"); 19 Bu::FString s("Hello there");
19 ar << s; 20 ar << s;
20 21
21 return 0; 22 return 0;
diff --git a/src/tests/archive2.cpp b/src/tests/archive2.cpp
index fddb91b..3d95c2f 100644
--- a/src/tests/archive2.cpp
+++ b/src/tests/archive2.cpp
@@ -23,7 +23,7 @@ public:
23 { 23 {
24 } 24 }
25 25
26 virtual void archive( Bu::Archive &ar ) 26 virtual void archive( Bu::ArchiveBase &ar )
27 { 27 {
28 ar && iId; 28 ar && iId;
29 } 29 }
@@ -47,7 +47,7 @@ public:
47 delete a2; 47 delete a2;
48 } 48 }
49 49
50 virtual void archive( Bu::Archive &ar ) 50 virtual void archive( Bu::ArchiveBase &ar )
51 { 51 {
52 //ar && iId && a1 && a2; 52 //ar && iId && a1 && a2;
53 ar << iId << a1 << a2; 53 ar << iId << a1 << a2;
@@ -73,7 +73,7 @@ public:
73 delete b; 73 delete b;
74 } 74 }
75 75
76 virtual void archive( Bu::Archive &ar ) 76 virtual void archive( Bu::ArchiveBase &ar )
77 { 77 {
78 //ar && iId && a && b; 78 //ar && iId && a && b;
79 ar << iId; 79 ar << iId;
diff --git a/src/tests/cache.cpp b/src/tests/cache.cpp
index 3fcc34c..a098145 100644
--- a/src/tests/cache.cpp
+++ b/src/tests/cache.cpp
@@ -10,6 +10,7 @@
10#include <sys/stat.h> 10#include <sys/stat.h>
11#include <sys/types.h> 11#include <sys/types.h>
12#include <errno.h> 12#include <errno.h>
13#include <unistd.h>
13 14
14#include "bu/cache.h" 15#include "bu/cache.h"
15#include "bu/file.h" 16#include "bu/file.h"
diff --git a/src/tests/fastcgi.cpp b/src/tests/fastcgi.cpp
index cd6cdda..46a7d62 100644
--- a/src/tests/fastcgi.cpp
+++ b/src/tests/fastcgi.cpp
@@ -7,6 +7,8 @@
7 7
8#include "bu/fastcgi.h" 8#include "bu/fastcgi.h"
9 9
10#include <unistd.h>
11
10class Cgi : public Bu::FastCgi 12class Cgi : public Bu::FastCgi
11{ 13{
12public: 14public:
diff --git a/src/tests/heap.cpp b/src/tests/heap.cpp
index daa0356..ae130ec 100644
--- a/src/tests/heap.cpp
+++ b/src/tests/heap.cpp
@@ -8,7 +8,10 @@
8#include <stdlib.h> 8#include <stdlib.h>
9#include <stdio.h> 9#include <stdio.h>
10 10
11#include "bu/formatter.h"
11#include "bu/heap.h" 12#include "bu/heap.h"
13#include "bu/fstring.h"
14#include "bu/file.h"
12 15
13typedef struct num 16typedef struct num
14{ 17{
@@ -35,8 +38,18 @@ typedef struct num
35 } 38 }
36} num; 39} num;
37 40
41void printHeap( Bu::Heap<Bu::FString> &h, int j )
42{
43 Bu::FString sFName;
44 sFName.format("graph-step-%02d.dot", j );
45 Bu::File fOut( sFName, Bu::File::WriteNew );
46 Bu::Formatter f( Bu::File );
47 //h.print( f );
48}
49
38int main() 50int main()
39{ 51{
52 /*
40 Bu::Heap<num> hNum; 53 Bu::Heap<num> hNum;
41 54
42 for( int j = 0; j < 30; j++ ) 55 for( int j = 0; j < 30; j++ )
@@ -53,6 +66,46 @@ int main()
53 hNum.dequeue(); 66 hNum.dequeue();
54 } 67 }
55 printf("\n"); 68 printf("\n");
69*/
70 Bu::Heap<Bu::FString> hStr;
71 int j = 0;
72
73 hStr.enqueue("George");
74 printHeap( hStr, j++ );
75 hStr.enqueue("Sam");
76 printHeap( hStr, j++ );
77 hStr.enqueue("Abby");
78 printHeap( hStr, j++ );
79 hStr.enqueue("Zorro");
80 printHeap( hStr, j++ );
81 hStr.enqueue("Brianna");
82 printHeap( hStr, j++ );
83 hStr.enqueue("Kate");
84 printHeap( hStr, j++ );
85 hStr.enqueue("Soggy");
86 printHeap( hStr, j++ );
87
88 while( !hStr.isEmpty() )
89 {
90 printf("\"%s\" ", hStr.dequeue().getStr() );
91 printHeap( hStr, j++ );
92 }
93 printf("\n");
94
95 Bu::List<Bu::FString> lStr;
96
97 lStr.insertSorted("George");
98 lStr.insertSorted("Sam");
99 lStr.insertSorted("Abby");
100 lStr.insertSorted("Zorro");
101 lStr.insertSorted("Brianna");
102 lStr.insertSorted("Kate");
103 lStr.insertSorted("Soggy");
104 for( Bu::List<Bu::FString>::iterator i = lStr.begin(); i; i++ )
105 {
106 printf("\"%s\" ", (*i).getStr() );
107 }
108 printf("\n");
56 109
57 return 0; 110 return 0;
58} 111}
diff --git a/src/tests/itoheap.cpp b/src/tests/itoheap.cpp
index 9016d86..c5816b2 100644
--- a/src/tests/itoheap.cpp
+++ b/src/tests/itoheap.cpp
@@ -7,6 +7,7 @@
7 7
8#include <stdio.h> 8#include <stdio.h>
9#include <stdlib.h> 9#include <stdlib.h>
10#include <unistd.h>
10 11
11#include "bu/itoheap.h" 12#include "bu/itoheap.h"
12#include "bu/ito.h" 13#include "bu/ito.h"
diff --git a/src/tests/listsort.cpp b/src/tests/listsort.cpp
new file mode 100644
index 0000000..f9236e6
--- /dev/null
+++ b/src/tests/listsort.cpp
@@ -0,0 +1,60 @@
1#include <bu/list.h>
2#include <bu/sio.h>
3#include <bu/fstring.h>
4
5using namespace Bu;
6
7int main()
8{
9 FString a("Soggy"), b("Sam");
10
11 if( a < b )
12 {
13 sio << "Bad" << sio.nl;
14 }
15 else
16 {
17 sio << "Good" << sio.nl;
18 }
19
20 typedef List<FString> StrList;
21
22 StrList lNames;
23
24 lNames.append("George");
25 lNames.append("Sam");
26 lNames.append("Abby");
27 lNames.append("Zorro");
28 lNames.append("Brianna");
29 lNames.append("Kate");
30 lNames.append("Soggy");
31
32 sio << "Names: " << lNames << sio.nl;
33 lNames.sort();
34
35 sio << "Names: " << lNames << sio.nl;
36
37 StrList lNames2;
38
39 lNames2.insertSorted("George");
40 lNames2.insertSorted("Sam");
41 lNames2.insertSorted("Abby");
42 lNames2.insertSorted("Zorro");
43 lNames2.insertSorted("Brianna");
44 lNames2.insertSorted("Kate");
45 lNames2.insertSorted("Soggy");
46
47 sio << "Names: " << lNames2 << sio.nl;
48
49 if( lNames == lNames2 )
50 {
51 sio << "They're the same." << sio.nl;
52 }
53 else
54 {
55 sio << "They're different." << sio.nl;
56 }
57
58 return 0;
59}
60
diff --git a/src/tests/ringbuffer.cpp b/src/tests/ringbuffer.cpp
index 46c515b..9489b30 100644
--- a/src/tests/ringbuffer.cpp
+++ b/src/tests/ringbuffer.cpp
@@ -7,6 +7,8 @@
7 7
8#include "bu/ringbuffer.h" 8#include "bu/ringbuffer.h"
9#include <stdlib.h> 9#include <stdlib.h>
10#include <stdint.h>
11#include <stdio.h>
10 12
11int main() 13int main()
12{ 14{
diff --git a/src/tests/serverticks.cpp b/src/tests/serverticks.cpp
index e599444..3aad746 100644
--- a/src/tests/serverticks.cpp
+++ b/src/tests/serverticks.cpp
@@ -8,6 +8,7 @@
8#include "bu/server.h" 8#include "bu/server.h"
9#include "bu/client.h" 9#include "bu/client.h"
10#include "bu/protocol.h" 10#include "bu/protocol.h"
11#include <unistd.h>
11 12
12class TickProtocol : public Bu::Protocol 13class TickProtocol : public Bu::Protocol
13{ 14{
diff --git a/src/tests/socketblock.cpp b/src/tests/socketblock.cpp
index 2a7dfdc..5dad46c 100644
--- a/src/tests/socketblock.cpp
+++ b/src/tests/socketblock.cpp
@@ -9,6 +9,7 @@
9#include "bu/socket.h" 9#include "bu/socket.h"
10#include "bu/serversocket.h" 10#include "bu/serversocket.h"
11#include <stdio.h> 11#include <stdio.h>
12#include <unistd.h>
12 13
13class TstServer : public Bu::Ito 14class TstServer : public Bu::Ito
14{ 15{
diff --git a/src/tests/socketbreak.cpp b/src/tests/socketbreak.cpp
index e77ae4f..b873830 100644
--- a/src/tests/socketbreak.cpp
+++ b/src/tests/socketbreak.cpp
@@ -7,6 +7,7 @@
7 7
8#include "bu/serversocket.h" 8#include "bu/serversocket.h"
9#include "bu/socket.h" 9#include "bu/socket.h"
10#include <unistd.h>
10 11
11int main() 12int main()
12{ 13{
diff --git a/src/tests/uuid.cpp b/src/tests/uuid.cpp
new file mode 100644
index 0000000..4544543
--- /dev/null
+++ b/src/tests/uuid.cpp
@@ -0,0 +1,14 @@
1#include <bu/uuid.h>
2#include <bu/sio.h>
3
4using namespace Bu;
5
6int main()
7{
8 Uuid i = Uuid::gen();
9
10 sio << i.toString() << sio.nl;
11
12 return 0;
13}
14
diff --git a/src/unit/archive.unit b/src/unit/archive.unit
index ecc589b..266784f 100644
--- a/src/unit/archive.unit
+++ b/src/unit/archive.unit
@@ -7,14 +7,18 @@
7 */ 7 */
8 8
9#include "bu/membuf.h" 9#include "bu/membuf.h"
10#include "bu/array.h"
11#include "bu/archive.h"
12
13using namespace Bu;
10 14
11{=Init} 15{=Init}
12 16
13{%testPrimitives} 17{%testPrimitives}
14{ 18{
15 Bu::MemBuf mb; 19 MemBuf mb;
16 { 20 {
17 Bu::Archive ar( mb, Bu::Archive::save ); 21 Archive ar( mb, Archive::save );
18 ar << (int8_t)1; 22 ar << (int8_t)1;
19 ar << (uint8_t)2; 23 ar << (uint8_t)2;
20 ar << (int16_t)3; 24 ar << (int16_t)3;
@@ -37,7 +41,7 @@
37 } 41 }
38 mb.setPos( 0 ); 42 mb.setPos( 0 );
39 { 43 {
40 Bu::Archive ar( mb, Bu::Archive::load ); 44 Archive ar( mb, Archive::load );
41 int8_t p1; 45 int8_t p1;
42 uint8_t p2; 46 uint8_t p2;
43 int16_t p3; 47 int16_t p3;
@@ -96,13 +100,13 @@
96 } 100 }
97} 101}
98 102
99{%testContainers} 103{%testContainers1}
100{ 104{
101 Bu::MemBuf mb; 105 MemBuf mb;
102 { 106 {
103 Bu::Archive ar( mb, Bu::Archive::save ); 107 Archive ar( mb, Archive::save );
104 Bu::FString sStr("This is a test string."); 108 FString sStr("This is a test string.");
105 Bu::List<int> lList; 109 List<int> lList;
106 lList.append( 10 ); 110 lList.append( 10 );
107 lList.append( 20 ); 111 lList.append( 20 );
108 lList.append( 30 ); 112 lList.append( 30 );
@@ -113,14 +117,47 @@
113 } 117 }
114 mb.setPos( 0 ); 118 mb.setPos( 0 );
115 { 119 {
116 Bu::Archive ar( mb, Bu::Archive::load ); 120 Archive ar( mb, Archive::load );
117 Bu::FString sStr; 121 FString sStr;
118 Bu::List<int> lList; 122 List<int> lList;
119 ar >> sStr; 123 ar >> sStr;
120 ar >> lList; 124 ar >> lList;
121 unitTest( sStr == "This is a test string." ); 125 unitTest( sStr == "This is a test string." );
122 unitTest( lList.getSize() == 4 ); 126 unitTest( lList.getSize() == 4 );
123 Bu::List<int>::iterator i = lList.begin(); 127 List<int>::iterator i = lList.begin();
128 unitTest( *i == 10 ); i++;
129 unitTest( *i == 20 ); i++;
130 unitTest( *i == 30 ); i++;
131 unitTest( *i == 40 );
132 ar.close();
133 }
134}
135
136{%testContainers2}
137{
138 MemBuf mb;
139 {
140 Archive ar( mb, Archive::save );
141 FString sStr("This is a test string.");
142 Array<int> lArray;
143 lArray.append( 10 );
144 lArray.append( 20 );
145 lArray.append( 30 );
146 lArray.append( 40 );
147 ar << sStr;
148 ar << lArray;
149 ar.close();
150 }
151 mb.setPos( 0 );
152 {
153 Archive ar( mb, Archive::load );
154 FString sStr;
155 Array<int> lArray;
156 ar >> sStr;
157 ar >> lArray;
158 unitTest( sStr == "This is a test string." );
159 unitTest( lArray.getSize() == 4 );
160 Array<int>::iterator i = lArray.begin();
124 unitTest( *i == 10 ); i++; 161 unitTest( *i == 10 ); i++;
125 unitTest( *i == 20 ); i++; 162 unitTest( *i == 20 ); i++;
126 unitTest( *i == 30 ); i++; 163 unitTest( *i == 30 ); i++;
@@ -128,3 +165,31 @@
128 ar.close(); 165 ar.close();
129 } 166 }
130} 167}
168
169{%testContainers3}
170{
171 MemBuf mb;
172 {
173 Archive ar( mb, Archive::save );
174 Array<FString> lArray;
175 lArray.append( "10" );
176 lArray.append( "20" );
177 lArray.append( "30" );
178 lArray.append( "40" );
179 ar << lArray;
180 ar.close();
181 }
182 mb.setPos( 0 );
183 {
184 Archive ar( mb, Archive::load );
185 Array<FString> lArray;
186 ar >> lArray;
187 unitTest( lArray.getSize() == 4 );
188 Array<FString>::iterator i = lArray.begin();
189 unitTest( *i == "10" ); i++;
190 unitTest( *i == "20" ); i++;
191 unitTest( *i == "30" ); i++;
192 unitTest( *i == "40" );
193 ar.close();
194 }
195}
diff --git a/src/unit/file.unit b/src/unit/file.unit
index 911d8f6..e0d2005 100644
--- a/src/unit/file.unit
+++ b/src/unit/file.unit
@@ -16,7 +16,7 @@
16 16
17{%writeFull} 17{%writeFull}
18{ 18{
19 Bu::File sf("testfile1", Bu::File::Write ); 19 Bu::File sf("testfile1", Bu::File::WriteNew );
20 for( int c = 0; c < 256; c++ ) 20 for( int c = 0; c < 256; c++ )
21 { 21 {
22 unsigned char ch = (unsigned char)c; 22 unsigned char ch = (unsigned char)c;
diff --git a/src/unit/fstring.unit b/src/unit/fstring.unit
index 3e4456d..d218a07 100644
--- a/src/unit/fstring.unit
+++ b/src/unit/fstring.unit
@@ -312,3 +312,24 @@
312 bob = ""; 312 bob = "";
313 unitTest( bob.isSet() == false ); 313 unitTest( bob.isSet() == false );
314} 314}
315
316{%swap1}
317{
318 Bu::FString a, b;
319 a = "Goodbye";
320 b = "Hello";
321 Bu::swap( a, b );
322 unitTest( a == "Hello" );
323 unitTest( b == "Goodbye" );
324}
325
326{%swap2}
327{
328 Bu::FString a, b;
329 a = "Goodbye";
330 b = "Hello";
331 std::swap( a, b );
332 unitTest( a == "Hello" );
333 unitTest( b == "Goodbye" );
334}
335
diff --git a/src/unit/list.unit b/src/unit/list.unit
index 9da0342..9f66f54 100644
--- a/src/unit/list.unit
+++ b/src/unit/list.unit
@@ -66,3 +66,83 @@ typedef Bu::List<int> IntList;
66 } 66 }
67} 67}
68 68
69{%sort1}
70{
71 IntList lst;
72
73 lst.insertSorted( 5 );
74 lst.insertSorted( 1 );
75 lst.insertSorted( 10 );
76 lst.insertSorted( 3 );
77
78 unitTest( lst == IntList(1).append(3).append(5).append(10) );
79}
80
81{%sort2}
82{
83 IntList lst;
84
85 lst.insertSorted<Bu::__basicGTCmp<int> >( 5 );
86 lst.insertSorted<Bu::__basicGTCmp<int> >( 1 );
87 lst.insertSorted<Bu::__basicGTCmp<int> >( 10 );
88 lst.insertSorted<Bu::__basicGTCmp<int> >( 3 );
89
90 unitTest( lst == IntList(10).append(5).append(3).append(1) );
91}
92
93{%sort3}
94{
95 IntList lst;
96 Bu::__basicGTCmp<int> cmp;
97
98 lst.insertSorted( cmp, 5 );
99 lst.insertSorted( cmp, 1 );
100 lst.insertSorted( cmp, 10 );
101 lst.insertSorted( cmp, 3 );
102
103 unitTest( lst == IntList(10).append(5).append(3).append(1) );
104}
105
106{%sort4}
107{
108 IntList lst;
109
110 lst.append( 5 );
111 lst.append( 1 );
112 lst.append( 10 );
113 lst.append( 3 );
114
115 lst.sort();
116
117 unitTest( lst == IntList(1).append(3).append(5).append(10) );
118}
119
120{%sort5}
121{
122 IntList lst;
123
124 lst.append( 5 );
125 lst.append( 1 );
126 lst.append( 10 );
127 lst.append( 3 );
128
129 lst.sort<Bu::__basicGTCmp<int> >();
130
131 unitTest( lst == IntList(10).append(5).append(3).append(1) );
132}
133
134{%sort6}
135{
136 IntList lst;
137
138 lst.append( 5 );
139 lst.append( 1 );
140 lst.append( 10 );
141 lst.append( 3 );
142
143 Bu::__basicGTCmp<int> x;
144 lst.sort( x );
145
146 unitTest( lst == IntList(10).append(5).append(3).append(1) );
147}
148
diff --git a/src/util.cpp b/src/util.cpp
index 3ca711d..6107bdb 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -35,7 +35,24 @@ int Bu::getDaysInMonth( int iMonth, int iYear )
35 return 29; 35 return 29;
36 return 28; 36 return 28;
37 break; 37 break;
38 }
39 38
39 default:
40 return -1;
41 }
42}
43void Bu::memcpy( void *pDest, const void *pSrc, size_t iBytes )
44{
45#ifdef VALTEST
46 const char *src = (const char *)pSrc;
47 char *dest = (char *)pDest;
48 for( int j = 0; j < count; j++ )
49 {
50 *dest = *src;
51 dest++;
52 src++;
53 }
54#else
55 ::memcpy( pDest, pSrc, iBytes );
56#endif
40} 57}
41 58
diff --git a/src/util.h b/src/util.h
index c284880..6f2f930 100644
--- a/src/util.h
+++ b/src/util.h
@@ -9,18 +9,20 @@
9#define BU_UTIL_H 9#define BU_UTIL_H
10 10
11#ifndef NULL 11#ifndef NULL
12#define NULL 0 12# define NULL 0
13#endif 13#endif
14 14
15/* I borrowed this from someone who borrowed it from glib who borrowed it 15/* I borrowed this from someone who borrowed it from glib who borrowed it
16 * from... 16 * from...
17 */ 17 */
18#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) 18#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
19#define DEPRECATED __attribute__((__deprecated__)) 19# define DEPRECATED __attribute__((__deprecated__))
20#else 20#else
21#define DEPRECATED 21# define DEPRECATED
22#endif /* __GNUC__ */ 22#endif /* __GNUC__ */
23 23
24#include <string.h>
25
24namespace Bu 26namespace Bu
25{ 27{
26 /** 28 /**
@@ -173,6 +175,8 @@ namespace Bu
173 * leap years into account. 175 * leap years into account.
174 */ 176 */
175 int getDaysInMonth( int iMonth, int iYear ); 177 int getDaysInMonth( int iMonth, int iYear );
178
179 void memcpy( void *pDest, const void *pSrc, size_t iBytes );
176}; 180};
177 181
178#endif 182#endif