From 23d88aa2812c361d30abefeeb296548698409bf5 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 21 Apr 2022 10:32:35 -0700 Subject: More progress, mostly planning and playing. I'm trying to find the right design usage patterns for using the archive system with tagging and lists and dictionaries. Also, are there other structures that I'm missing? --- src/stable/archivebinary.cpp | 41 +------------------------ src/stable/archivebinary.h | 72 -------------------------------------------- src/tests/archivetags.cpp | 6 ++-- 3 files changed, 4 insertions(+), 115 deletions(-) diff --git a/src/stable/archivebinary.cpp b/src/stable/archivebinary.cpp index 04e80d2..f46bd28 100644 --- a/src/stable/archivebinary.cpp +++ b/src/stable/archivebinary.cpp @@ -13,8 +13,7 @@ Bu::ArchiveBinary::ArchiveBinary( Stream &rStream, bool bLoading ) : bLoading( bLoading ), - rStream( rStream ), - nNextID( 1 ) + rStream( rStream ) { } @@ -236,44 +235,6 @@ bool Bu::ArchiveBinary::isLoading() return bLoading; } -uint32_t Bu::ArchiveBinary::getID( const void *ptr ) -{ - if( hPtrID.has( (ptrdiff_t)ptr ) ) - return hPtrID.get( (ptrdiff_t)ptr ); - hPtrID.insert( (ptrdiff_t)ptr, nNextID ); - return nNextID++; -} - -void Bu::ArchiveBinary::assocPtrID( void **ptr, uint32_t id ) -{ - if( hPtrID.has( id ) ) - { - *ptr = (void *)hPtrID.get( id ); - return; - } - - if( !hPtrDest.has( id ) ) - hPtrDest.insert( id, List() ); - - hPtrDest[id].getValue().append( ptr ); -} - -void Bu::ArchiveBinary::readID( const void *ptr, uint32_t id ) -{ - hPtrID.insert( id, (ptrdiff_t)ptr ); - - if( hPtrDest.has( id ) ) - { - Bu::List &l = hPtrDest.get( id ); - for( Bu::List::iterator i = l.begin(); i != l.end(); i++ ) - { - *(*i) = (void *)ptr; - } - - hPtrDest.erase( id ); - } -} - void Bu::ArchiveBinary::setProperty( const Bu::Blob &rKey, const Bu::Variant &rValue ) { hProps.insert( rKey, rValue ); diff --git a/src/stable/archivebinary.h b/src/stable/archivebinary.h index d28e5e7..d917249 100644 --- a/src/stable/archivebinary.h +++ b/src/stable/archivebinary.h @@ -20,51 +20,6 @@ namespace Bu class Stream; /** - * Provides a framework for serialization of objects and primitives. The - * archive will handle any basic primitive, a few special types, like char * - * strings, as well as STL classes and anything that inherits from the - * Archival class. Each ArchiveBinary operates on a Stream, so you can send the - * data using an ArchiveBinary almost anywhere. - * - * In order to use an ArchiveBinary to store something to a file, try something - * like: - *@code - * File sOut("output", "wb"); // This is a stream subclass - * ArchiveBinary ar( sOut, ArchiveBinary::save ); - * ar << myClass; - @endcode - * In this example myClass is any class that inherits from Archival. When - * the storage operator is called, the Archival::archive() function in the - * myClass object is called with a reference to the ArchiveBinary. This can be - * handled in one of two ways: - *@code - * void MyClass::archive( ArchiveBinary &ar ) - * { - * ar && sName && nAge && sJob; - * } - @endcode - * Here we don't worry about weather we're loading or saving by using the - * smart && operator. This allows us to write very consistent, very simple - * archive functions that really do a lot of work. If we wanted to do - * something different in the case of loading or saving we would do: - *@code - * void MyClass::archive( ArchiveBinary &ar ) - * { - * if( ar.isLoading() ) - * { - * ar >> sName >> nAge >> sJob; - * } else - * { - * ar << sName << nAge << sJob; - * } - * } - @endcode - * ArchiveBinary currently does not provide facility to make fully portable - * archives. For example, it will not convert between endianness for you, - * nor will it take into account differences between primitive sizes on - * different platforms. This, at the moment, is up to the user to ensure. - * One way of dealing with the latter problem is to make sure and use - * explicit primitive types from the stdint.h header, i.e. int32_t. */ class ArchiveBinary : public Archive { @@ -116,39 +71,12 @@ namespace Bu virtual void read( Bu::Blob &rData ); virtual void read( Bu::Text &rData ); - /** - * For storage, get an ID for the pointer to the object you're going to - * write. - */ - uint32_t getID( const void *ptr ); - - /** - * For loading. Assosiates an empty pointer with an id. When you wind - * up loading an id reference to a pointer for an object that may or - * may not have loaded yet, call this with the id, if it has been loaded - * already, you'll immediately get a pointer, if not, it will write one - * for you when the time comes. - */ - void assocPtrID( void **ptr, uint32_t id ); - - /** - * For loading. Call this when you load an object that other things may - * have pointers to. It will assosiate every pointer that's been - * registered with assocPtrID to the pointer passed in, and id passed - * in. It will also set things up so future calls to assocPtrID will - * automatically succeed immediately. - */ - void readID( const void *ptr, uint32_t id ); - 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; }; } diff --git a/src/tests/archivetags.cpp b/src/tests/archivetags.cpp index f0587fd..5c8e0fa 100644 --- a/src/tests/archivetags.cpp +++ b/src/tests/archivetags.cpp @@ -25,9 +25,9 @@ Bu::Archive &operator<<( Bu::Archive &ar, const SubThing &st ) { Bu::Archive::Dictionary ds( ar ); - return ar - << ar.tag("data") << st.bData - << ar.tag("name") << st.tName; + ar.tag("data") << st.bData + ar.tag("name") << st.tName; + return ar; } Bu::Archive &operator>>( Bu::Archive &ar, SubThing &st ) -- cgit v1.2.3