From d10e6a5ca0905f0ef2836cd98aebfb48e7f1e8a3 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 20 Apr 2022 11:14:47 -0700 Subject: ArchiveBase/Archive renamed. More to come. --- src/stable/archive.cpp | 200 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 149 insertions(+), 51 deletions(-) (limited to 'src/stable/archive.cpp') diff --git a/src/stable/archive.cpp b/src/stable/archive.cpp index 69447fb..df9b1ff 100644 --- a/src/stable/archive.cpp +++ b/src/stable/archive.cpp @@ -6,15 +6,8 @@ */ #include "bu/archive.h" -#include "bu/stream.h" -#include "bu/archival.h" -#include "bu/sio.h" - -Bu::Archive::Archive( Stream &rStream, bool bLoading ) : - bLoading( bLoading ), - rStream( rStream ), - nNextID( 1 ) +Bu::Archive::Archive() { } @@ -22,78 +15,183 @@ Bu::Archive::~Archive() { } -void Bu::Archive::write( const void *pData, size_t nSize ) +Bu::Archive &Bu::operator<<( Bu::Archive &ar, bool p) +{ + ar.write( &p, sizeof(p) ); + return ar; +} + +Bu::Archive &Bu::operator<<( Bu::Archive &ar, char p) +{ + ar.write( &p, sizeof(p) ); + return ar; +} + +Bu::Archive &Bu::operator<<( Bu::Archive &ar, signed char p) +{ + ar.write( &p, sizeof(p) ); + return ar; +} + +Bu::Archive &Bu::operator<<( Bu::Archive &ar, unsigned char p) +{ + ar.write( &p, sizeof(p) ); + return ar; +} + +Bu::Archive &Bu::operator<<( Bu::Archive &ar, signed short p) +{ + ar.write( &p, sizeof(p) ); + return ar; +} + +Bu::Archive &Bu::operator<<( Bu::Archive &ar, unsigned short p) { - if( nSize == 0 || pData == NULL ) - return; + ar.write( &p, sizeof(p) ); + return ar; +} - rStream.write( (const char *)pData, nSize ); +Bu::Archive &Bu::operator<<( Bu::Archive &ar, signed int p) +{ + ar.write( &p, sizeof(p) ); + return ar; } -void Bu::Archive::read( void *pData, size_t nSize ) +Bu::Archive &Bu::operator<<( Bu::Archive &ar, unsigned int p) { - if( nSize == 0 || pData == NULL ) - return; + ar.write( &p, sizeof(p) ); + return ar; +} - if( (size_t)rStream.read( (char *)pData, nSize ) < nSize ) - throw Bu::ExceptionBase("Insufficient data to unarchive object."); +Bu::Archive &Bu::operator<<( Bu::Archive &ar, signed long p) +{ + ar.write( &p, sizeof(p) ); + return ar; } -void Bu::Archive::close() +Bu::Archive &Bu::operator<<( Bu::Archive &ar, unsigned long p) { - rStream.close(); + ar.write( &p, sizeof(p) ); + return ar; } -bool Bu::Archive::isLoading() +Bu::Archive &Bu::operator<<( Bu::Archive &ar, signed long long p) { - return bLoading; + ar.write( &p, sizeof(p) ); + return ar; } -uint32_t Bu::Archive::getID( const void *ptr ) +Bu::Archive &Bu::operator<<( Bu::Archive &ar, unsigned long long p) { - if( hPtrID.has( (ptrdiff_t)ptr ) ) - return hPtrID.get( (ptrdiff_t)ptr ); - hPtrID.insert( (ptrdiff_t)ptr, nNextID ); - return nNextID++; + ar.write( &p, sizeof(p) ); + return ar; } -void Bu::Archive::assocPtrID( void **ptr, uint32_t id ) +Bu::Archive &Bu::operator<<( Bu::Archive &ar, float p) { - if( hPtrID.has( id ) ) - { - *ptr = (void *)hPtrID.get( id ); - return; - } + ar.write( &p, sizeof(p) ); + return ar; +} - if( !hPtrDest.has( id ) ) - hPtrDest.insert( id, List() ); - - hPtrDest[id].getValue().append( ptr ); +Bu::Archive &Bu::operator<<( Bu::Archive &ar, double p) +{ + ar.write( &p, sizeof(p) ); + return ar; } -void Bu::Archive::readID( const void *ptr, uint32_t id ) +Bu::Archive &Bu::operator<<( Bu::Archive &ar, long double p) { - hPtrID.insert( id, (ptrdiff_t)ptr ); + ar.write( &p, sizeof(p) ); + return ar; +} - if( hPtrDest.has( id ) ) - { - Bu::List &l = hPtrDest.get( id ); - for( Bu::List::iterator i = l.begin(); i != l.end(); i++ ) - { - *(*i) = (void *)ptr; - } +Bu::Archive &Bu::operator>>( Bu::Archive &ar, bool &p) +{ + ar.read( &p, sizeof(p) ); + return ar; +} - hPtrDest.erase( id ); - } +Bu::Archive &Bu::operator>>( Bu::Archive &ar, char &p) +{ + ar.read( &p, sizeof(p) ); + return ar; +} + +Bu::Archive &Bu::operator>>( Bu::Archive &ar, signed char &p) +{ + ar.read( &p, sizeof(p) ); + return ar; +} + +Bu::Archive &Bu::operator>>( Bu::Archive &ar, unsigned char &p) +{ + ar.read( &p, sizeof(p) ); + return ar; +} + +Bu::Archive &Bu::operator>>( Bu::Archive &ar, signed short &p) +{ + ar.read( &p, sizeof(p) ); + return ar; +} + +Bu::Archive &Bu::operator>>( Bu::Archive &ar, unsigned short &p) +{ + ar.read( &p, sizeof(p) ); + return ar; +} + +Bu::Archive &Bu::operator>>( Bu::Archive &ar, signed int &p) +{ + ar.read( &p, sizeof(p) ); + return ar; +} + +Bu::Archive &Bu::operator>>( Bu::Archive &ar, unsigned int &p) +{ + ar.read( &p, sizeof(p) ); + return ar; +} + +Bu::Archive &Bu::operator>>( Bu::Archive &ar, signed long &p) +{ + ar.read( &p, sizeof(p) ); + return ar; +} + +Bu::Archive &Bu::operator>>( Bu::Archive &ar, unsigned long &p) +{ + ar.read( &p, sizeof(p) ); + return ar; +} + +Bu::Archive &Bu::operator>>( Bu::Archive &ar, signed long long &p) +{ + ar.read( &p, sizeof(p) ); + return ar; +} + +Bu::Archive &Bu::operator>>( Bu::Archive &ar, unsigned long long &p) +{ + ar.read( &p, sizeof(p) ); + return ar; +} + +Bu::Archive &Bu::operator>>( Bu::Archive &ar, float &p) +{ + ar.read( &p, sizeof(p) ); + return ar; } -void Bu::Archive::setProperty( const Bu::Blob &rKey, const Bu::Variant &rValue ) +Bu::Archive &Bu::operator>>( Bu::Archive &ar, double &p) { - hProps.insert( rKey, rValue ); + ar.read( &p, sizeof(p) ); + return ar; } -Bu::Variant Bu::Archive::getProperty( const Bu::Blob &rKey ) const +Bu::Archive &Bu::operator>>( Bu::Archive &ar, long double &p) { - return hProps.get( rKey ); + ar.read( &p, sizeof(p) ); + return ar; } -- cgit v1.2.3