diff options
author | Mike Buland <eichlan@xagasoft.com> | 2010-05-12 20:40:20 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2010-05-12 20:40:20 +0000 |
commit | 6acfc972c2d5734e62c45b4803ef18101fc1dcb2 (patch) | |
tree | fd77ca5eced12a3fe09ed6fe32e5df09682f4326 | |
parent | 1300301a52bba102fed8b08bdcb668d246973af5 (diff) | |
download | libbu++-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 '')
-rw-r--r-- | src/archive.h | 18 | ||||
-rw-r--r-- | src/tests/archive.cpp | 5 |
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 | ||
16 | namespace Bu | 17 | namespace 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 | ||
14 | int main() | 14 | int 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 | ||