summaryrefslogtreecommitdiff
path: root/src/hash.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-03-19 18:44:25 +0000
committerMike Buland <eichlan@xagasoft.com>2007-03-19 18:44:25 +0000
commit2b8255fabce194b35f7b2a350fd08f43d1e698a6 (patch)
tree61ef7a7918b603d37d022bd0cb599b238615816b /src/hash.h
parent5a345983b99ecf8528d58ddca2ab5f52d87d9a95 (diff)
downloadlibbu++-2b8255fabce194b35f7b2a350fd08f43d1e698a6.tar.gz
libbu++-2b8255fabce194b35f7b2a350fd08f43d1e698a6.tar.bz2
libbu++-2b8255fabce194b35f7b2a350fd08f43d1e698a6.tar.xz
libbu++-2b8255fabce194b35f7b2a350fd08f43d1e698a6.zip
Fixed some bugs and added some new goo. You can serialize FStrings and Heshes
now.
Diffstat (limited to 'src/hash.h')
-rw-r--r--src/hash.h47
1 files changed, 46 insertions, 1 deletions
diff --git a/src/hash.h b/src/hash.h
index 6671ae6..c37cfba 100644
--- a/src/hash.h
+++ b/src/hash.h
@@ -7,6 +7,8 @@
7#include <iostream> 7#include <iostream>
8#include "exceptionbase.h" 8#include "exceptionbase.h"
9#include "hashable.h" 9#include "hashable.h"
10#include "serializable.h"
11#include "serializer.h"
10 12
11#define bitsToBytes( n ) (n/32+(n%32>0 ? 1 : 0)) 13#define bitsToBytes( n ) (n/32+(n%32>0 ? 1 : 0))
12 14
@@ -241,7 +243,7 @@ public:
241 243
242 uint32_t size() 244 uint32_t size()
243 { 245 {
244 return nFilled; 246 return nFilled-nDeleted;
245 } 247 }
246 248
247 uint32_t getDeleted() 249 uint32_t getDeleted()
@@ -667,4 +669,47 @@ template<> bool __cmpHashKeys<std::string>( const std::string &a, const std::str
667template<> uint32_t __calcHashCode<Hashable>( const Hashable &k ); 669template<> uint32_t __calcHashCode<Hashable>( const Hashable &k );
668template<> bool __cmpHashKeys<Hashable>( const Hashable &a, const Hashable &b ); 670template<> bool __cmpHashKeys<Hashable>( const Hashable &a, const Hashable &b );
669 671
672template<typename key, typename value>
673Serializer &operator<<( Serializer &ar, Hash<key,value> &h )
674{
675 ar << h.size();
676 for( typename Hash<key,value>::iterator i = h.begin(); i != h.end(); i++ )
677 {
678 std::pair<key,value> p = *i;
679 ar << p.first << p.second;
680 }
681
682 return ar;
683}
684
685template<typename key, typename value>
686Serializer &operator>>( Serializer &ar, Hash<key,value> &h )
687{
688 h.clear();
689 uint32_t nSize;
690 ar >> nSize;
691
692 for( uint32_t j = 0; j < nSize; j++ )
693 {
694 key k; value v;
695 ar >> k >> v;
696 h.insert( k, v );
697 }
698
699 return ar;
700}
701
702template<typename key, typename value>
703Serializer &operator&&( Serializer &ar, Hash<key,value> &h )
704{
705 if( ar.isLoading() )
706 {
707 return ar >> h;
708 }
709 else
710 {
711 return ar << h;
712 }
713}
714
670#endif 715#endif