From 3a27454dca4a16d021a4d418f0725adccc5baabb Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sat, 25 May 2019 20:34:29 -0700 Subject: Just about everything that Blob needs is in. --- src/unstable/blob.cpp | 161 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 115 insertions(+), 46 deletions(-) (limited to 'src/unstable/blob.cpp') diff --git a/src/unstable/blob.cpp b/src/unstable/blob.cpp index f8cf1b0..3f7d9d9 100644 --- a/src/unstable/blob.cpp +++ b/src/unstable/blob.cpp @@ -34,14 +34,48 @@ Bu::Blob::Blob( const char *pSrc ) : memcpy( pData, pSrc, iSize+1 ); } -Bu::Blob::Blob( const void *pSrc, int32_t iSize ) +Bu::Blob::Blob( const void *pSrc, int32_t iSize ) : + pData( 0 ), + iSize( iSize ) { - this->iSize = iSize; pData = new char[iSize+1]; memcpy( pData, pSrc, iSize ); pData[iSize] = '\0'; } +Bu::Blob::Blob( const Bu::Blob::const_iterator &iStart ) : + pData( 0 ), + iSize( -1 ) +{ + if( !iStart ) + return; + + iSize = iStart.pBlob->iSize - iStart.iIndex; + pData = new char[iSize+1]; + memcpy( pData, iStart.pBlob->pData+iStart.iIndex, iSize ); +} + +Bu::Blob::Blob( const Bu::Blob::const_iterator &iStart, + const Bu::Blob::const_iterator &iEnd ) : + pData( 0 ), + iSize( -1 ) +{ + if( !iStart ) + return; + + if( iEnd ) + { + iSize = iEnd.iIndex - iStart.iIndex; + } + else + { + iSize = iStart.pBlob->iSize - iStart.iIndex; + } + + pData = new char[iSize+1]; + memcpy( pData, iStart.pBlob->pData+iStart.iIndex, iSize ); +} + Bu::Blob::~Blob() { delete[] pData; @@ -316,6 +350,45 @@ bool Bu::Blob::operator>=( const char *pRhs ) const return true; } +Bu::Blob::iterator Bu::Blob::begin() +{ + return iterator( this, true ); +} + +Bu::Blob::const_iterator Bu::Blob::begin() const +{ + return const_iterator( this, true ); +} + +Bu::Blob::iterator Bu::Blob::end() +{ + return iterator(); +} + +Bu::Blob::const_iterator Bu::Blob::end() const +{ + return const_iterator(); +} + +Bu::Blob::iterator Bu::Blob::rbegin() +{ + return iterator( this, false ); +} + +Bu::Blob::const_iterator Bu::Blob::rbegin() const +{ + return const_iterator( this, false ); +} + +Bu::Blob::iterator Bu::Blob::rend() +{ + return iterator(); +} + +Bu::Blob::const_iterator Bu::Blob::rend() const +{ + return const_iterator(); +} ///// // Iterators @@ -328,6 +401,13 @@ Bu::Blob::iterator::iterator( Bu::Blob *pBlob, bool bForward ) : { } +Bu::Blob::iterator::iterator( Bu::Blob *pBlob, int32_t iIndex, bool bForward ) : + pBlob( pBlob ), + iIndex( iIndex ), + bForward( bForward ) +{ +} + Bu::Blob::iterator::iterator() : pBlob( NULL ), iIndex( -1 ), @@ -366,7 +446,7 @@ char &Bu::Blob::iterator::operator *() return pBlob->pData[iIndex]; } -Bu::Blob::iterator &Bu::Blob::iterator::operator++( int ) +Bu::Blob::iterator &Bu::Blob::iterator::operator++( int32_t ) { if( bForward ) ++iIndex; @@ -386,7 +466,7 @@ Bu::Blob::iterator &Bu::Blob::iterator::operator++() return *this; } -Bu::Blob::iterator &Bu::Blob::iterator::operator--( int ) +Bu::Blob::iterator &Bu::Blob::iterator::operator--( int32_t ) { if( bForward ) --iIndex; @@ -406,6 +486,16 @@ Bu::Blob::iterator &Bu::Blob::iterator::operator--() return *this; } +Bu::Blob::iterator Bu::Blob::iterator::operator+( int32_t iDelta ) const +{ + return iterator( pBlob, iIndex + iDelta, bForward ); +} + +Bu::Blob::iterator Bu::Blob::iterator::operator-( int32_t iDelta ) const +{ + return iterator( pBlob, iIndex - iDelta, bForward ); +} + bool Bu::Blob::iterator::operator==( const Bu::Blob::iterator &rRhs ) { if( isValid() == false && rRhs.isValid() == false ) @@ -454,6 +544,13 @@ Bu::Blob::const_iterator::const_iterator( const Blob *pBlob, bool bForward ) : bForward( bForward ) { } +Bu::Blob::const_iterator::const_iterator( const Blob *pBlob, int32_t iIndex, + bool bForward ) : + pBlob( pBlob ), + iIndex( iIndex ), + bForward( bForward ) +{ +} Bu::Blob::const_iterator::const_iterator() : pBlob( NULL ), @@ -541,6 +638,18 @@ Bu::Blob::const_iterator &Bu::Blob::const_iterator::operator--() return *this; } +Bu::Blob::const_iterator Bu::Blob::const_iterator::operator+( int32_t iDelta ) + const +{ + return const_iterator( pBlob, iIndex + iDelta, bForward ); +} + +Bu::Blob::const_iterator Bu::Blob::const_iterator::operator-( int32_t iDelta ) + const +{ + return const_iterator( pBlob, iIndex - iDelta, bForward ); +} + bool Bu::Blob::const_iterator::operator==( const Bu::Blob::iterator &rRhs ) { if( isValid() == false && rRhs.isValid() == false ) @@ -595,50 +704,10 @@ Bu::Blob::const_iterator &Bu::Blob::const_iterator::operator=( return *this; } - -Bu::Blob::iterator Bu::Blob::begin() -{ - return iterator( this, true ); -} - -Bu::Blob::const_iterator Bu::Blob::begin() const -{ - return const_iterator( this, true ); -} - -Bu::Blob::iterator Bu::Blob::end() -{ - return iterator(); -} - -Bu::Blob::const_iterator Bu::Blob::end() const -{ - return const_iterator(); -} - -Bu::Blob::iterator Bu::Blob::rbegin() -{ - return iterator( this, false ); -} - -Bu::Blob::const_iterator Bu::Blob::rbegin() const -{ - return const_iterator( this, false ); -} - -Bu::Blob::iterator Bu::Blob::rend() -{ - return iterator(); -} - -Bu::Blob::const_iterator Bu::Blob::rend() const -{ - return const_iterator(); -} - -//// +///// // Helper functions // + template<> uint32_t Bu::__calcHashCode( const Bu::Blob &k ) { int32_t sz = k.getSize(); -- cgit v1.2.3