From fd56cdd21a7c9c944ad189cf91ff24d3c2b0f975 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 20 Apr 2022 14:04:47 -0700 Subject: Gradually moving to better archive structure. It's dragging other new API changes along with it, including use of Blob and Text. --- src/stable/archive.cpp | 84 +++++++++++------- src/stable/archive.h | 46 +++++++++- src/stable/archivebinary.cpp | 190 ++++++++++++++++++++++++++++++++++++++++- src/stable/archivebinary.h | 40 ++++++++- src/stable/crypt.cpp | 4 +- src/stable/membuf.cpp | 5 ++ src/stable/membuf.h | 2 + src/stable/string.cpp | 12 ++- src/tests/archivetags.cpp | 73 ++++++++++++++++ src/unstable/archivestream.cpp | 127 --------------------------- src/unstable/archivestream.h | 49 ----------- src/unstable/blob.cpp | 20 +++++ src/unstable/blob.h | 3 + src/unstable/uuid.cpp | 34 +++++--- src/unstable/uuid.h | 15 ++-- 15 files changed, 463 insertions(+), 241 deletions(-) create mode 100644 src/tests/archivetags.cpp delete mode 100644 src/unstable/archivestream.cpp delete mode 100644 src/unstable/archivestream.h (limited to 'src') diff --git a/src/stable/archive.cpp b/src/stable/archive.cpp index df9b1ff..829e7eb 100644 --- a/src/stable/archive.cpp +++ b/src/stable/archive.cpp @@ -17,181 +17,205 @@ Bu::Archive::~Archive() Bu::Archive &Bu::operator<<( Bu::Archive &ar, bool p) { - ar.write( &p, sizeof(p) ); + ar.write( p ); return ar; } Bu::Archive &Bu::operator<<( Bu::Archive &ar, char p) { - ar.write( &p, sizeof(p) ); + ar.write( p ); return ar; } Bu::Archive &Bu::operator<<( Bu::Archive &ar, signed char p) { - ar.write( &p, sizeof(p) ); + ar.write( p ); return ar; } Bu::Archive &Bu::operator<<( Bu::Archive &ar, unsigned char p) { - ar.write( &p, sizeof(p) ); + ar.write( p ); return ar; } Bu::Archive &Bu::operator<<( Bu::Archive &ar, signed short p) { - ar.write( &p, sizeof(p) ); + ar.write( p ); return ar; } Bu::Archive &Bu::operator<<( Bu::Archive &ar, unsigned short p) { - ar.write( &p, sizeof(p) ); + ar.write( p ); return ar; } Bu::Archive &Bu::operator<<( Bu::Archive &ar, signed int p) { - ar.write( &p, sizeof(p) ); + ar.write( p ); return ar; } Bu::Archive &Bu::operator<<( Bu::Archive &ar, unsigned int p) { - ar.write( &p, sizeof(p) ); + ar.write( p ); return ar; } Bu::Archive &Bu::operator<<( Bu::Archive &ar, signed long p) { - ar.write( &p, sizeof(p) ); + ar.write( p ); return ar; } Bu::Archive &Bu::operator<<( Bu::Archive &ar, unsigned long p) { - ar.write( &p, sizeof(p) ); + ar.write( p ); return ar; } Bu::Archive &Bu::operator<<( Bu::Archive &ar, signed long long p) { - ar.write( &p, sizeof(p) ); + ar.write( p ); return ar; } Bu::Archive &Bu::operator<<( Bu::Archive &ar, unsigned long long p) { - ar.write( &p, sizeof(p) ); + ar.write( p ); return ar; } Bu::Archive &Bu::operator<<( Bu::Archive &ar, float p) { - ar.write( &p, sizeof(p) ); + ar.write( p ); return ar; } Bu::Archive &Bu::operator<<( Bu::Archive &ar, double p) { - ar.write( &p, sizeof(p) ); + ar.write( p ); return ar; } Bu::Archive &Bu::operator<<( Bu::Archive &ar, long double p) { - ar.write( &p, sizeof(p) ); + ar.write( p ); + return ar; +} + +Bu::Archive &Bu::operator<<( Bu::Archive &ar, const Bu::Blob &p) +{ + ar.write( p ); + return ar; +} + +Bu::Archive &Bu::operator<<( Bu::Archive &ar, const Bu::Text &p) +{ + ar.write( p ); return ar; } Bu::Archive &Bu::operator>>( Bu::Archive &ar, bool &p) { - ar.read( &p, sizeof(p) ); + ar.read( p ); return ar; } Bu::Archive &Bu::operator>>( Bu::Archive &ar, char &p) { - ar.read( &p, sizeof(p) ); + ar.read( p ); return ar; } Bu::Archive &Bu::operator>>( Bu::Archive &ar, signed char &p) { - ar.read( &p, sizeof(p) ); + ar.read( p ); return ar; } Bu::Archive &Bu::operator>>( Bu::Archive &ar, unsigned char &p) { - ar.read( &p, sizeof(p) ); + ar.read( p ); return ar; } Bu::Archive &Bu::operator>>( Bu::Archive &ar, signed short &p) { - ar.read( &p, sizeof(p) ); + ar.read( p ); return ar; } Bu::Archive &Bu::operator>>( Bu::Archive &ar, unsigned short &p) { - ar.read( &p, sizeof(p) ); + ar.read( p ); return ar; } Bu::Archive &Bu::operator>>( Bu::Archive &ar, signed int &p) { - ar.read( &p, sizeof(p) ); + ar.read( p ); return ar; } Bu::Archive &Bu::operator>>( Bu::Archive &ar, unsigned int &p) { - ar.read( &p, sizeof(p) ); + ar.read( p ); return ar; } Bu::Archive &Bu::operator>>( Bu::Archive &ar, signed long &p) { - ar.read( &p, sizeof(p) ); + ar.read( p ); return ar; } Bu::Archive &Bu::operator>>( Bu::Archive &ar, unsigned long &p) { - ar.read( &p, sizeof(p) ); + ar.read( p ); return ar; } Bu::Archive &Bu::operator>>( Bu::Archive &ar, signed long long &p) { - ar.read( &p, sizeof(p) ); + ar.read( p ); return ar; } Bu::Archive &Bu::operator>>( Bu::Archive &ar, unsigned long long &p) { - ar.read( &p, sizeof(p) ); + ar.read( p ); return ar; } Bu::Archive &Bu::operator>>( Bu::Archive &ar, float &p) { - ar.read( &p, sizeof(p) ); + ar.read( p ); return ar; } Bu::Archive &Bu::operator>>( Bu::Archive &ar, double &p) { - ar.read( &p, sizeof(p) ); + ar.read( p ); return ar; } Bu::Archive &Bu::operator>>( Bu::Archive &ar, long double &p) { - ar.read( &p, sizeof(p) ); + ar.read( p ); + return ar; +} + +Bu::Archive &Bu::operator>>( Bu::Archive &ar, Bu::Blob &p) +{ + ar.read( p ); + return ar; +} + +Bu::Archive &Bu::operator>>( Bu::Archive &ar, Bu::Text &p) +{ + ar.read( p ); return ar; } diff --git a/src/stable/archive.h b/src/stable/archive.h index 45d9af6..2cd340c 100644 --- a/src/stable/archive.h +++ b/src/stable/archive.h @@ -16,6 +16,8 @@ namespace Bu { + class Text; + class Archive { public: @@ -29,10 +31,46 @@ namespace Bu }; virtual void close()=0; - virtual void write( const void *pData, size_t iLength )=0; - virtual void read( void *pData, size_t iLength )=0; +// 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 write( bool rData )=0; + virtual void write( unsigned char rData )=0; + virtual void write( char rData )=0; + virtual void write( signed char rData )=0; + virtual void write( unsigned short rData )=0; + virtual void write( signed short rData )=0; + virtual void write( unsigned int rData )=0; + virtual void write( signed int rData )=0; + virtual void write( unsigned long rData )=0; + virtual void write( signed long rData )=0; + virtual void write( unsigned long long rData )=0; + virtual void write( signed long long rData )=0; + virtual void write( float rData )=0; + virtual void write( double rData )=0; + virtual void write( long double rData )=0; + virtual void write( const Bu::Blob &rData )=0; + virtual void write( const Bu::Text &rData )=0; + + virtual void read( bool &rData )=0; + virtual void read( unsigned char &rData )=0; + virtual void read( char &rData )=0; + virtual void read( signed char &rData )=0; + virtual void read( unsigned short &rData )=0; + virtual void read( signed short &rData )=0; + virtual void read( unsigned int &rData )=0; + virtual void read( signed int &rData )=0; + virtual void read( unsigned long &rData )=0; + virtual void read( signed long &rData )=0; + virtual void read( unsigned long long &rData )=0; + virtual void read( signed long long &rData )=0; + virtual void read( float &rData )=0; + virtual void read( double &rData )=0; + virtual void read( long double &rData )=0; + virtual void read( Bu::Blob &rData )=0; + virtual void read( Bu::Text &rData )=0; + virtual void setProperty( const Bu::Blob &rKey, const Bu::Variant &rValue )=0; virtual Bu::Variant getProperty( const Bu::Blob &rKey ) const=0; @@ -65,6 +103,8 @@ namespace Bu Archive &operator<<( Archive &ar, float p ); Archive &operator<<( Archive &ar, double p ); Archive &operator<<( Archive &ar, long double p ); + Archive &operator<<( Archive &ar, const Bu::Blob &p ); + Archive &operator<<( Archive &ar, const Bu::Text &p ); Archive &operator>>( Archive &ar, bool &p ); Archive &operator>>( Archive &ar, char &p ); @@ -81,6 +121,8 @@ namespace Bu Archive &operator>>( Archive &ar, float &p ); Archive &operator>>( Archive &ar, double &p ); Archive &operator>>( Archive &ar, long double &p ); + Archive &operator>>( Archive &ar, Bu::Blob &p ); + Archive &operator>>( Archive &ar, Bu::Text &p ); }; #endif diff --git a/src/stable/archivebinary.cpp b/src/stable/archivebinary.cpp index 3f05947..04e80d2 100644 --- a/src/stable/archivebinary.cpp +++ b/src/stable/archivebinary.cpp @@ -9,6 +9,7 @@ #include "bu/stream.h" #include "bu/sio.h" +#include "bu/text.h" Bu::ArchiveBinary::ArchiveBinary( Stream &rStream, bool bLoading ) : bLoading( bLoading ), @@ -20,7 +21,7 @@ Bu::ArchiveBinary::ArchiveBinary( Stream &rStream, bool bLoading ) : Bu::ArchiveBinary::~ArchiveBinary() { } - +/* void Bu::ArchiveBinary::write( const void *pData, size_t nSize ) { if( nSize == 0 || pData == NULL ) @@ -36,6 +37,193 @@ void Bu::ArchiveBinary::read( void *pData, size_t nSize ) 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() diff --git a/src/stable/archivebinary.h b/src/stable/archivebinary.h index 4c12e02..d28e5e7 100644 --- a/src/stable/archivebinary.h +++ b/src/stable/archivebinary.h @@ -77,8 +77,44 @@ namespace Bu virtual ~ArchiveBinary(); virtual void close(); - virtual void write( const void *pData, size_t iSize ); - virtual void read( void *pData, size_t iSize ); + //virtual void write( const void *pData, size_t iSize ); + //virtual void read( void *pData, size_t iSize ); + + virtual void write( bool rData ); + virtual void write( unsigned char rData ); + virtual void write( char rData ); + virtual void write( signed char rData ); + virtual void write( unsigned short rData ); + virtual void write( signed short rData ); + virtual void write( unsigned int rData ); + virtual void write( signed int rData ); + virtual void write( unsigned long rData ); + virtual void write( signed long rData ); + virtual void write( unsigned long long rData ); + virtual void write( signed long long rData ); + virtual void write( float rData ); + virtual void write( double rData ); + virtual void write( long double rData ); + virtual void write( const Bu::Blob &rData ); + virtual void write( const Bu::Text &rData ); + + virtual void read( bool &rData ); + virtual void read( unsigned char &rData ); + virtual void read( char &rData ); + virtual void read( signed char &rData ); + virtual void read( unsigned short &rData ); + virtual void read( signed short &rData ); + virtual void read( unsigned int &rData ); + virtual void read( signed int &rData ); + virtual void read( unsigned long &rData ); + virtual void read( signed long &rData ); + virtual void read( unsigned long long &rData ); + virtual void read( signed long long &rData ); + virtual void read( float &rData ); + virtual void read( double &rData ); + virtual void read( long double &rData ); + 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 diff --git a/src/stable/crypt.cpp b/src/stable/crypt.cpp index 085d460..0dbe2d5 100644 --- a/src/stable/crypt.cpp +++ b/src/stable/crypt.cpp @@ -26,7 +26,7 @@ Bu::String Bu::cryptPass( const Bu::String &sPass, const Bu::String &sSalt ) b64Out.stop(); - return sSaltSml + "$" + mbOut.getString(); + return sSaltSml + "$" + mbOut.getBlob(); } Bu::String Bu::cryptPass( const Bu::String &sPass ) @@ -42,6 +42,6 @@ Bu::String Bu::cryptPass( const Bu::String &sPass ) b64Salt.stop(); - return cryptPass( sPass, mbSalt.getString() ); + return cryptPass( sPass, mbSalt.getBlob() ); } diff --git a/src/stable/membuf.cpp b/src/stable/membuf.cpp index 040c0c6..fff3027 100644 --- a/src/stable/membuf.cpp +++ b/src/stable/membuf.cpp @@ -169,6 +169,11 @@ Bu::String &Bu::MemBuf::getString() return sBuf; } +Bu::Blob Bu::MemBuf::getBlob() +{ + return Bu::Blob( sBuf.getStr(), sBuf.getSize() ); +} + void Bu::MemBuf::setString( const Bu::String &sNewData ) { sBuf = sNewData; diff --git a/src/stable/membuf.h b/src/stable/membuf.h index fc9be1f..f42cc2d 100644 --- a/src/stable/membuf.h +++ b/src/stable/membuf.h @@ -13,6 +13,7 @@ #include "bu/config.h" #include "bu/stream.h" #include "bu/string.h" +#include "bu/blob.h" namespace Bu { @@ -57,6 +58,7 @@ namespace Bu virtual Bu::String getLocation() const; Bu::String &getString(); + Bu::Blob getBlob(); void setString( const Bu::String &sNewData ); private: diff --git a/src/stable/string.cpp b/src/stable/string.cpp index c36b768..81f2c7f 100644 --- a/src/stable/string.cpp +++ b/src/stable/string.cpp @@ -1520,20 +1520,18 @@ Bu::String &Bu::operator<<( Bu::String &dst, const Bu::String &sIn ) return dst; } +#include "bu/blob.h" + Bu::Archive &Bu::operator<<( Bu::Archive &ar, const Bu::String &s ) { - long n = s.getSize(); - ar << n; - ar.write( s.getConstStr(), n ); + ar << Bu::Blob( s.getStr(), s.getSize() ); return ar; } Bu::Archive &Bu::operator>>( Bu::Archive &ar, Bu::String &s ) { - long n; - ar >> n; - s.setSize( n ); - ar.read( s.getStr(), n ); + Bu::Blob b; + ar >> b; return ar; } diff --git a/src/tests/archivetags.cpp b/src/tests/archivetags.cpp new file mode 100644 index 0000000..f0587fd --- /dev/null +++ b/src/tests/archivetags.cpp @@ -0,0 +1,73 @@ + +class SubThing +{ +public: + SubThing(); + virtual ~SubThing(); + + Bu::Blob bData; + Bu::Text tName; +}; + +class Something +{ +pubilc: + Something(); + virtual ~Something(); + + int iAge; + int iSize; + int *aiNumber; + SubThing xThing; +}; + +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; +} + +Bu::Archive &operator>>( Bu::Archive &ar, SubThing &st ) +{ + Bu::Archive::Dictionary ds( ar ); + + return ar + >> ar.tag("data") >> st.bData + >> ar.tag("name") >> st.tName; +} + +Bu::Archive &operator<<( Bu::Archive &ar, const Something &st ) +{ + Bu::Archive::Dictionary ds( ar ); + ar << ar.tag("age") << st.iAge; + + ar.startList("number", st.iSize ); + for( int j = 0; j < st.iSize; j++ ) + { + ar << st.aiNumber[j]; + } + ar.endList(); + ar << ar.tag("thing") << st.xThing; + return ar; +} + +Bu::Archive &operator>>( Bu::Archive &ar, Something &st ) +{ + Bu::Archive::Dictionary ds( ar ); + ar >> ar.tag("age") >> st.iAge; + + ar.startList("number"); + int iSize = ar.getListSize(); + for( int j = 0; j < iSize; j++ ) + { + ar >> st.aiNumber[j]; + } + ar.endList(); + + ar >> ar.tag("thing") >> st.xThing; + return ar; +} + diff --git a/src/unstable/archivestream.cpp b/src/unstable/archivestream.cpp deleted file mode 100644 index 90a9599..0000000 --- a/src/unstable/archivestream.cpp +++ /dev/null @@ -1,127 +0,0 @@ -/* - * 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/archivestream.h" - -Bu::ArchiveStream::ArchiveStream( Bu::Archive &ar ) : - ar( ar ), - iPos( 0 ) -{ -} - -Bu::ArchiveStream::~ArchiveStream() -{ -} - -void Bu::ArchiveStream::close() -{ - ar.close(); -} - -Bu::size Bu::ArchiveStream::read( void *pBuf, size iBytes ) -{ - ar.read( pBuf, iBytes ); - iPos += iBytes; - return iBytes; -} - -Bu::size Bu::ArchiveStream::write( const void *pBuf, size iBytes ) -{ - ar.write( pBuf, iBytes ); - iPos += iBytes; - return iBytes; -} - -Bu::size Bu::ArchiveStream::tell() -{ - return iPos; -} - -void Bu::ArchiveStream::seek( Bu::size ) -{ - throw Bu::UnsupportedException(); -} - -void Bu::ArchiveStream::setPos( Bu::size ) -{ - throw Bu::UnsupportedException(); -} - -void Bu::ArchiveStream::setPosEnd( Bu::size ) -{ - throw Bu::UnsupportedException(); -} - -bool Bu::ArchiveStream::isEos() -{ - return false; -} - -bool Bu::ArchiveStream::isOpen() -{ - return true; -} - -void Bu::ArchiveStream::flush() -{ -} - -bool Bu::ArchiveStream::canRead() -{ - return true; -} - -bool Bu::ArchiveStream::canWrite() -{ - return true; -} - -bool Bu::ArchiveStream::isReadable() -{ - return true; -} - -bool Bu::ArchiveStream::isWritable() -{ - return true; -} - -bool Bu::ArchiveStream::isSeekable() -{ - return false; -} - -bool Bu::ArchiveStream::isBlocking() -{ - return false; -} - -void Bu::ArchiveStream::setBlocking( bool ) -{ - throw Bu::UnsupportedException(); -} - -void Bu::ArchiveStream::setSize( Bu::size ) -{ - throw Bu::UnsupportedException(); -} - -Bu::size Bu::ArchiveStream::getSize() const -{ - return iPos; -} - -Bu::size Bu::ArchiveStream::getBlockSize() const -{ - return 1; -} - -Bu::String Bu::ArchiveStream::getLocation() const -{ - return "Archive"; -} - diff --git a/src/unstable/archivestream.h b/src/unstable/archivestream.h deleted file mode 100644 index da6c6b0..0000000 --- a/src/unstable/archivestream.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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. - */ -#ifndef BU_ARCHIVE_STREAM_H -#define BU_ARCHIVE_STREAM_H - -#include "bu/archive.h" -#include "bu/stream.h" - -namespace Bu -{ - class ArchiveStream : public Stream - { - public: - ArchiveStream( Bu::Archive &ar ); - virtual ~ArchiveStream(); - - virtual void close(); - virtual size read( void *pBuf, size iBytes ); - virtual size write( const void *pBuf, size iBytes ); - virtual size tell(); - virtual void seek( size offset ); - virtual void setPos( size pos ); - virtual void setPosEnd( size pos ); - virtual bool isEos(); - virtual bool isOpen(); - virtual void flush(); - virtual bool canRead(); - virtual bool canWrite(); - virtual bool isReadable(); - virtual bool isWritable(); - virtual bool isSeekable(); - virtual bool isBlocking(); - virtual void setBlocking( bool bBlocking=true ); - virtual void setSize( size iSize ); - virtual size getSize() const; - virtual size getBlockSize() const; - virtual Bu::String getLocation() const; - - private: - Bu::Archive &ar; - size iPos; - }; -} - -#endif diff --git a/src/unstable/blob.cpp b/src/unstable/blob.cpp index e72e265..51e74ff 100644 --- a/src/unstable/blob.cpp +++ b/src/unstable/blob.cpp @@ -142,6 +142,26 @@ bool Bu::Blob::isNullOrEmpty() const return pData == NULL || iSize == 0; } +void Bu::Blob::set( const Blob &rRhs ) +{ + *this = rRhs; +} + +void Bu::Blob::set( const char *pRhs ) +{ + *this = pRhs; +} + +void Bu::Blob::set( const char *pRhs, int32_t iSize ) +{ + delete[] pData; + + this->iSize = iSize; + pData = new char[iSize+1]; + memcpy( pData, pRhs, iSize ); + pData[iSize] = '\0'; +} + Bu::Blob &Bu::Blob::operator=( const Bu::Blob &rRhs ) { delete[] pData; diff --git a/src/unstable/blob.h b/src/unstable/blob.h index d6c40e3..214ab41 100644 --- a/src/unstable/blob.h +++ b/src/unstable/blob.h @@ -55,6 +55,9 @@ namespace Bu bool isNull() const; bool isNullOrEmpty() const; + void set( const Blob &rRhs ); + void set( const char *pRhs ); + void set( const char *pRhs, int32_t iSize ); Blob &operator=( const Blob &rRhs ); Blob &operator=( const char *pRhs ); diff --git a/src/unstable/uuid.cpp b/src/unstable/uuid.cpp index 6642d75..9708423 100644 --- a/src/unstable/uuid.cpp +++ b/src/unstable/uuid.cpp @@ -10,6 +10,8 @@ #include "bu/formatter.h" #include "bu/membuf.h" #include "bu/random.h" +#include "bu/archive.h" +#include "bu/blobbuilder.h" #include #ifdef WIN32 @@ -27,11 +29,11 @@ Bu::Uuid::Uuid( const Uuid &src ) memcpy( data, src.data, 16 ); } -Bu::Uuid::Uuid( const Bu::String &sSrc ) +Bu::Uuid::Uuid( const Bu::Blob &sSrc ) { if( sSrc.getSize() == 16 ) { - memcpy( data, sSrc.getStr(), 16 ); + memcpy( data, sSrc.getData(), 16 ); } else if( sSrc.getSize() == 36 ) { @@ -44,12 +46,12 @@ Bu::Uuid::~Uuid() { } -Bu::String Bu::Uuid::toRawString() const +Bu::Blob Bu::Uuid::toRawBlob() const { - return Bu::String( (char *)data, 16 ); + return Bu::Blob( (char *)data, 16 ); } -Bu::String Bu::Uuid::toString() const +Bu::Blob Bu::Uuid::toBlob() const { Bu::MemBuf mb; Bu::Formatter f( mb ); @@ -61,12 +63,14 @@ Bu::String Bu::Uuid::toString() const f << Bu::Fmt::hex(2).caps(false) << (unsigned int)data[j]; } - return mb.getString(); + return mb.getBlob(); } -Bu::String Bu::Uuid::toUrn() const +Bu::Blob Bu::Uuid::toUrn() const { - return "urn:uuid:" + toString(); + BlobBuilder bb("urn:uuid:"); + bb.append( toBlob() ); + return bb.getBlob(); } int Bu::Uuid::getVersion() @@ -129,9 +133,9 @@ Bu::Uuid Bu::Uuid::generate( Bu::Uuid::Type eType ) return id; } -void Bu::Uuid::set( const Bu::String &sSrc ) +void Bu::Uuid::set( const Bu::Blob &sSrc ) { - const char *dat = sSrc.getStr(); + const char *dat = sSrc.getData(); int iNibble = 0; memset( data, 0, 16 ); for( int j = 0; j < 36; j++ ) @@ -162,7 +166,7 @@ Bu::Uuid &Bu::Uuid::operator=( const Uuid &rhs ) template<> uint32_t Bu::__calcHashCode( const Bu::Uuid &k ) { - return __calcHashCode( k.toRawString() ); + return __calcHashCode( k.toRawBlob() ); } template<> bool Bu::__cmpHashKeys( const Bu::Uuid &a, const Bu::Uuid &b ) @@ -172,18 +176,20 @@ template<> bool Bu::__cmpHashKeys( const Bu::Uuid &a, const Bu::Uuid & Bu::Archive &Bu::operator>>( Bu::Archive &ar, Bu::Uuid &u ) { - ar.read( u.data, 16 ); + Bu::Blob b; + ar >> b; + memcpy( b.getData(), u.data, 16 ); return ar; } Bu::Archive &Bu::operator<<( Bu::Archive &ar, const Bu::Uuid &u ) { - ar.write( u.data, 16 ); + ar << u.toRawBlob(); return ar; } Bu::Formatter &Bu::operator<<( Bu::Formatter &f, const Bu::Uuid &u ) { - return f << u.toString(); + return f << u.toBlob(); } diff --git a/src/unstable/uuid.h b/src/unstable/uuid.h index d61a928..902942e 100644 --- a/src/unstable/uuid.h +++ b/src/unstable/uuid.h @@ -9,10 +9,11 @@ #define BU_UUID_H #include "bu/util.h" -#include "bu/string.h" +#include "bu/blob.h" namespace Bu { + class Archive; class Uuid { friend Bu::Archive &operator>>( Bu::Archive &ar, Uuid &u ); @@ -20,12 +21,12 @@ namespace Bu public: Uuid(); Uuid( const Uuid &src ); - Uuid( const Bu::String &sSrc ); + Uuid( const Bu::Blob &sSrc ); virtual ~Uuid(); - Bu::String toRawString() const; - Bu::String toString() const; - Bu::String toUrn() const; + Bu::Blob toRawBlob() const; + Bu::Blob toBlob() const; + Bu::Blob toUrn() const; enum Type { @@ -43,11 +44,11 @@ namespace Bu DEPRECATED static Uuid gen() { return generate(); } void clear(); - void set( const Bu::String &sSrc ); + void set( const Bu::Blob &sSrc ); bool operator==( const Uuid &rhs ) const; bool operator!=( const Uuid &rhs ) const; - Uuid &operator=( const Bu::String &rhs ) { set( rhs ); return *this; } + Uuid &operator=( const Bu::Blob &rhs ) { set( rhs ); return *this; } Uuid &operator=( const Uuid &rhs ); private: -- cgit v1.2.3