aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2010-05-12 20:40:20 +0000
committerMike Buland <eichlan@xagasoft.com>2010-05-12 20:40:20 +0000
commit6acfc972c2d5734e62c45b4803ef18101fc1dcb2 (patch)
treefd77ca5eced12a3fe09ed6fe32e5df09682f4326 /src
parent1300301a52bba102fed8b08bdcb668d246973af5 (diff)
downloadlibbu++-6acfc972c2d5734e62c45b4803ef18101fc1dcb2.tar.gz
libbu++-6acfc972c2d5734e62c45b4803ef18101fc1dcb2.tar.bz2
libbu++-6acfc972c2d5734e62c45b4803ef18101fc1dcb2.tar.xz
libbu++-6acfc972c2d5734e62c45b4803ef18101fc1dcb2.zip
The Bu::Archive class now supports arbitrary, named properties via variants.
Diffstat (limited to 'src')
-rw-r--r--src/archive.h18
-rw-r--r--src/tests/archive.cpp5
2 files changed, 22 insertions, 1 deletions
diff --git a/src/archive.h b/src/archive.h
index 7b74999..bd85113 100644
--- a/src/archive.h
+++ b/src/archive.h
@@ -12,6 +12,7 @@
12#include "bu/archivebase.h" 12#include "bu/archivebase.h"
13#include "bu/hash.h" 13#include "bu/hash.h"
14#include "bu/util.h" 14#include "bu/util.h"
15#include "bu/variant.h"
15 16
16namespace Bu 17namespace Bu
17{ 18{
@@ -109,11 +110,28 @@ namespace Bu
109 */ 110 */
110 void readID( const void *ptr, uint32_t id ); 111 void readID( const void *ptr, uint32_t id );
111 112
113 template<typename t>
114 void setProp( const Bu::FString &sId, const t &val )
115 {
116 if( !hProps.has( sId ) )
117 {
118 hProps.insert( sId, Variant() );
119 }
120 hProps.get( sId ) = val;
121 }
122
123 template<typename t>
124 t getProp( const Bu::FString &sId )
125 {
126 return hProps.get( sId );
127 }
128
112 private: 129 private:
113 Stream &rStream; 130 Stream &rStream;
114 uint32_t nNextID; 131 uint32_t nNextID;
115 Hash<uint32_t,uint32_t> hPtrID; 132 Hash<uint32_t,uint32_t> hPtrID;
116 Hash<uint32_t,List<void **> > hPtrDest; 133 Hash<uint32_t,List<void **> > hPtrDest;
134 Hash<Bu::FString, Variant> hProps;
117 }; 135 };
118} 136}
119 137
diff --git a/src/tests/archive.cpp b/src/tests/archive.cpp
index a0bc78a..08e3b17 100644
--- a/src/tests/archive.cpp
+++ b/src/tests/archive.cpp
@@ -13,12 +13,15 @@ using namespace Bu;
13 13
14int main() 14int main()
15{ 15{
16 File f("test.dat", File::Write ); 16 File f("test.dat", File::WriteNew );
17 Archive ar( f, Archive::save ); 17 Archive ar( f, Archive::save );
18 18
19 Bu::FString s("Hello there"); 19 Bu::FString s("Hello there");
20 ar << s; 20 ar << s;
21 21
22 ar.setProp("hi", 45 );
23 printf("Hi: %d", ar.getProp<int>("hi") );
24
22 return 0; 25 return 0;
23} 26}
24 27