From 9fc845c1746a83afc4e847895913851576945000 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 9 Aug 2023 13:00:19 -0700 Subject: Added a temporory String -> Blob constructor. Just to ease the transition. --- src/unstable/blob.cpp | 27 +++++++++++++++++++++++++++ src/unstable/blob.h | 5 +++++ 2 files changed, 32 insertions(+) (limited to 'src/unstable') diff --git a/src/unstable/blob.cpp b/src/unstable/blob.cpp index d343963..bf8cb5a 100644 --- a/src/unstable/blob.cpp +++ b/src/unstable/blob.cpp @@ -10,6 +10,9 @@ #include "bu/exceptioninvaliditerator.h" #include "bu/exceptionindexoutofbounds.h" +// Temporary +#include "bu/string.h" + #include Bu::Blob::Blob() : @@ -97,6 +100,14 @@ Bu::Blob::Blob( const Bu::Blob::const_iterator &iStart, pData[iSize] = 0; } +Bu::Blob::Blob( const Bu::String &rSrc ) : + pData( 0 ), + iSize( rSrc.getSize() ) +{ + pData = new char[rSrc.getSize()+1]; + memcpy( pData, rSrc.getStr(), iSize+1 ); +} + Bu::Blob::~Blob() { delete[] pData; @@ -117,6 +128,15 @@ int32_t Bu::Blob::getSize() const return iSize; } +void Bu::Blob::setData( const char *pSrc, int32_t iSize ) +{ + delete[] pData; + pData = new char[iSize+1]; + memset( pData, iSize, 1 ); + this->iSize = iSize; + memcpy( pData, pSrc, iSize ); +} + char *Bu::Blob::getData() const { return pData; @@ -817,6 +837,13 @@ Bu::Formatter &Bu::operator<<( Bu::Formatter &rOut, const Bu::Blob &b ) return rOut; } +Bu::Formatter &Bu::operator>>( Bu::Formatter &fIn, Bu::Blob &b ) +{ + Bu::String sTmp = fIn.readToken(); + b.setData( sTmp.getStr(), sTmp.getSize() ); + return fIn; +} + Bu::ArchiveBase &Bu::operator<<( Bu::ArchiveBase &ar, const Bu::Blob &b ) { int32_t iSize = b.getSize(); diff --git a/src/unstable/blob.h b/src/unstable/blob.h index 2866ab2..2a665ad 100644 --- a/src/unstable/blob.h +++ b/src/unstable/blob.h @@ -46,10 +46,14 @@ namespace Bu Blob( int32_t iSize ); Blob( const const_iterator &iStart ); Blob( const const_iterator &iStart, const const_iterator &iEnd ); + + // Obviously temporary + Blob( const Bu::String &rSrc ); virtual ~Blob(); void setSize( int32_t iSize ); int32_t getSize() const; + void setData( const char *pSrc, int32_t iSize ); char *getData() const; char *c_str() const; @@ -184,6 +188,7 @@ namespace Bu class Formatter; Formatter &operator<<( Formatter &rOut, const Blob &b ); + Formatter &operator>>( Formatter &fIn, Blob &b ); } #endif -- cgit v1.2.3