diff options
author | Mike Buland <eichlan@xagasoft.com> | 2007-03-19 18:44:25 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2007-03-19 18:44:25 +0000 |
commit | 2b8255fabce194b35f7b2a350fd08f43d1e698a6 (patch) | |
tree | 61ef7a7918b603d37d022bd0cb599b238615816b /src/hash.h | |
parent | 5a345983b99ecf8528d58ddca2ab5f52d87d9a95 (diff) | |
download | libbu++-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.h | 47 |
1 files changed, 46 insertions, 1 deletions
@@ -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 | |||
667 | template<> uint32_t __calcHashCode<Hashable>( const Hashable &k ); | 669 | template<> uint32_t __calcHashCode<Hashable>( const Hashable &k ); |
668 | template<> bool __cmpHashKeys<Hashable>( const Hashable &a, const Hashable &b ); | 670 | template<> bool __cmpHashKeys<Hashable>( const Hashable &a, const Hashable &b ); |
669 | 671 | ||
672 | template<typename key, typename value> | ||
673 | Serializer &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 | |||
685 | template<typename key, typename value> | ||
686 | Serializer &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 | |||
702 | template<typename key, typename value> | ||
703 | Serializer &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 |