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/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 ++--- 6 files changed, 51 insertions(+), 197 deletions(-) delete mode 100644 src/unstable/archivestream.cpp delete mode 100644 src/unstable/archivestream.h (limited to 'src/unstable') 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