/* * Copyright (C) 2007-2019 Xagasoft, All rights reserved. * * This file is part of the libbu++ library and is released under the * terms of the license contained in the file LICENSE. */ #include "bu/archivebinary.h" #include "bu/stream.h" #include "bu/sio.h" #include "bu/text.h" Bu::ArchiveBinary::ArchiveBinary( Stream &rStream, bool bLoading ) : bLoading( bLoading ), rStream( rStream ) { } Bu::ArchiveBinary::~ArchiveBinary() { } /* void Bu::ArchiveBinary::write( const void *pData, size_t nSize ) { if( nSize == 0 || pData == NULL ) return; rStream.write( (const char *)pData, nSize ); } void Bu::ArchiveBinary::read( void *pData, size_t nSize ) { if( nSize == 0 || pData == NULL ) return; if( (size_t)rStream.read( (char *)pData, nSize ) < nSize ) throw Bu::ExceptionBase("Insufficient data to unarchive object."); }*/ void Bu::ArchiveBinary::write( bool rData ) { rStream.write( &rData, sizeof(rData) ); } void Bu::ArchiveBinary::write( const unsigned char rData ) { rStream.write( &rData, sizeof(rData) ); } void Bu::ArchiveBinary::write( char rData ) { rStream.write( &rData, sizeof(rData) ); } void Bu::ArchiveBinary::write( signed char rData ) { rStream.write( &rData, sizeof(rData) ); } void Bu::ArchiveBinary::write( unsigned short rData ) { rStream.write( &rData, sizeof(rData) ); } void Bu::ArchiveBinary::write( signed short rData ) { rStream.write( &rData, sizeof(rData) ); } void Bu::ArchiveBinary::write( unsigned int rData ) { rStream.write( &rData, sizeof(rData) ); } void Bu::ArchiveBinary::write( signed int rData ) { rStream.write( &rData, sizeof(rData) ); } void Bu::ArchiveBinary::write( unsigned long rData ) { rStream.write( &rData, sizeof(rData) ); } void Bu::ArchiveBinary::write( signed long rData ) { rStream.write( &rData, sizeof(rData) ); } void Bu::ArchiveBinary::write( unsigned long long rData ) { rStream.write( &rData, sizeof(rData) ); } void Bu::ArchiveBinary::write( signed long long rData ) { rStream.write( &rData, sizeof(rData) ); } void Bu::ArchiveBinary::write( float rData ) { rStream.write( &rData, sizeof(rData) ); } void Bu::ArchiveBinary::write( double rData ) { rStream.write( &rData, sizeof(rData) ); } void Bu::ArchiveBinary::write( long double rData ) { rStream.write( &rData, sizeof(rData) ); } void Bu::ArchiveBinary::write( const Bu::Blob &rData ) { int32_t iSize = rData.getSize(); write( iSize ); rStream.write( rData.getData(), iSize ); } void Bu::ArchiveBinary::write( const Bu::Text &rData ) { int32_t iSize = rData.getSize(); write( iSize ); rStream.write( rData.getData(), iSize ); } void Bu::ArchiveBinary::read( bool &rData ) { rStream.read( &rData, sizeof(rData) ); } void Bu::ArchiveBinary::read( unsigned char &rData ) { rStream.read( &rData, sizeof(rData) ); } void Bu::ArchiveBinary::read( char &rData ) { rStream.read( &rData, sizeof(rData) ); } void Bu::ArchiveBinary::read( signed char &rData ) { rStream.read( &rData, sizeof(rData) ); } void Bu::ArchiveBinary::read( unsigned short &rData ) { rStream.read( &rData, sizeof(rData) ); } void Bu::ArchiveBinary::read( signed short &rData ) { rStream.read( &rData, sizeof(rData) ); } void Bu::ArchiveBinary::read( unsigned int &rData ) { rStream.read( &rData, sizeof(rData) ); } void Bu::ArchiveBinary::read( signed int &rData ) { rStream.read( &rData, sizeof(rData) ); } void Bu::ArchiveBinary::read( unsigned long &rData ) { rStream.read( &rData, sizeof(rData) ); } void Bu::ArchiveBinary::read( signed long &rData ) { rStream.read( &rData, sizeof(rData) ); } void Bu::ArchiveBinary::read( unsigned long long &rData ) { rStream.read( &rData, sizeof(rData) ); } void Bu::ArchiveBinary::read( signed long long &rData ) { rStream.read( &rData, sizeof(rData) ); } void Bu::ArchiveBinary::read( float &rData ) { rStream.read( &rData, sizeof(rData) ); } void Bu::ArchiveBinary::read( double &rData ) { rStream.read( &rData, sizeof(rData) ); } void Bu::ArchiveBinary::read( long double &rData ) { rStream.read( &rData, sizeof(rData) ); } void Bu::ArchiveBinary::read( Bu::Blob &rData ) { int32_t iSize; read( iSize ); char *pBuf = new char[iSize]; rStream.read( pBuf, iSize ); rData.set( pBuf, iSize ); delete[] pBuf; } void Bu::ArchiveBinary::read( Bu::Text &rData ) { /* int32_t iSize; read( iSize ); char *pBuf = new char[iSize]; rStream.read( pBuf, iSize ); rData.set( pBuf, iSize ); delete[] pBuf; */ throw Bu::ExceptionBase("Cannot read Bu::Text objects yet."); } void Bu::ArchiveBinary::close() { rStream.close(); } bool Bu::ArchiveBinary::isLoading() { return bLoading; } void Bu::ArchiveBinary::setProperty( const Bu::Blob &rKey, const Bu::Variant &rValue ) { hProps.insert( rKey, rValue ); } Bu::Variant Bu::ArchiveBinary::getProperty( const Bu::Blob &rKey ) const { return hProps.get( rKey ); }