From 6acfc972c2d5734e62c45b4803ef18101fc1dcb2 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 12 May 2010 20:40:20 +0000 Subject: The Bu::Archive class now supports arbitrary, named properties via variants. --- src/archive.h | 18 ++++++++++++++++++ src/tests/archive.cpp | 5 ++++- 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'src') 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 @@ #include "bu/archivebase.h" #include "bu/hash.h" #include "bu/util.h" +#include "bu/variant.h" namespace Bu { @@ -109,11 +110,28 @@ namespace Bu */ void readID( const void *ptr, uint32_t id ); + template + void setProp( const Bu::FString &sId, const t &val ) + { + if( !hProps.has( sId ) ) + { + hProps.insert( sId, Variant() ); + } + hProps.get( sId ) = val; + } + + template + t getProp( const Bu::FString &sId ) + { + return hProps.get( sId ); + } + private: Stream &rStream; uint32_t nNextID; Hash hPtrID; Hash > hPtrDest; + Hash hProps; }; } 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; int main() { - File f("test.dat", File::Write ); + File f("test.dat", File::WriteNew ); Archive ar( f, Archive::save ); Bu::FString s("Hello there"); ar << s; + ar.setProp("hi", 45 ); + printf("Hi: %d", ar.getProp("hi") ); + return 0; } -- cgit v1.2.3