From 819ff3d27012b4ec4a0a21c150c112a4dd28b14d Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 18 Apr 2022 21:58:01 -0700 Subject: ArchiveBase has getProperty and setProperty. I kind of want to re-engineer the entire archive system...The root should be able to track a stateful stack of containers such as arrays and dictionaries as well as support non-binary reads and writes in a more robust way. It also still bothers me that it's the only thing in the system with base in the base class name. I should just change it...it's going to impact many programs, though. --- src/stable/archive.cpp | 10 ++++++++++ src/stable/archive.h | 21 +++++---------------- src/stable/archivebase.h | 9 +++++++-- 3 files changed, 22 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/stable/archive.cpp b/src/stable/archive.cpp index 31a4ba7..69447fb 100644 --- a/src/stable/archive.cpp +++ b/src/stable/archive.cpp @@ -87,3 +87,13 @@ void Bu::Archive::readID( const void *ptr, uint32_t id ) } } +void Bu::Archive::setProperty( const Bu::Blob &rKey, const Bu::Variant &rValue ) +{ + hProps.insert( rKey, rValue ); +} + +Bu::Variant Bu::Archive::getProperty( const Bu::Blob &rKey ) const +{ + return hProps.get( rKey ); +} + diff --git a/src/stable/archive.h b/src/stable/archive.h index 7f988eb..b6cc2a9 100644 --- a/src/stable/archive.h +++ b/src/stable/archive.h @@ -13,6 +13,7 @@ #include "bu/hash.h" #include "bu/util.h" #include "bu/variant.h" +#include "bu/blob.h" namespace Bu { @@ -110,28 +111,16 @@ namespace Bu */ void readID( const void *ptr, uint32_t id ); - template - void setProp( const Bu::String &sId, const t &val ) - { - if( !hProps.has( sId ) ) - { - hProps.insert( sId, Variant() ); - } - hProps.get( sId ) = val; - } - - template - t getProp( const Bu::String &sId ) - { - return hProps.get( sId ); - } + virtual void setProperty( const Bu::Blob &rKey, + const Bu::Variant &rValue ); + virtual Bu::Variant getProperty( const Bu::Blob &rKey ) const; private: Stream &rStream; uint32_t nNextID; Hash hPtrID; Hash > hPtrDest; - Hash hProps; + Hash hProps; }; } diff --git a/src/stable/archivebase.h b/src/stable/archivebase.h index e3d2b60..d846c27 100644 --- a/src/stable/archivebase.h +++ b/src/stable/archivebase.h @@ -11,6 +11,9 @@ #include #include +#include "bu/variant.h" +#include "bu/blob.h" + namespace Bu { class ArchiveBase @@ -23,6 +26,10 @@ namespace Bu virtual void write( const void *pData, size_t iLength )=0; virtual void read( void *pData, size_t iLength )=0; virtual bool isLoading()=0; + + virtual void setProperty( const Bu::Blob &rKey, + const Bu::Variant &rValue )=0; + virtual Bu::Variant getProperty( const Bu::Blob &rKey ) const=0; }; template ArchiveBase &operator&&( ArchiveBase &ar, T &dat ) @@ -68,8 +75,6 @@ namespace Bu ArchiveBase &operator>>( ArchiveBase &ar, float &p ); ArchiveBase &operator>>( ArchiveBase &ar, double &p ); ArchiveBase &operator>>( ArchiveBase &ar, long double &p ); - - }; #endif -- cgit v1.2.3