aboutsummaryrefslogtreecommitdiff
path: root/src/unstable/blobbuilder.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/unstable/blobbuilder.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/unstable/blobbuilder.cpp b/src/unstable/blobbuilder.cpp
index 497a1a1..43c0779 100644
--- a/src/unstable/blobbuilder.cpp
+++ b/src/unstable/blobbuilder.cpp
@@ -7,6 +7,7 @@
7 7
8#include "bu/blobbuilder.h" 8#include "bu/blobbuilder.h"
9#include "bu/blob.h" 9#include "bu/blob.h"
10#include "bu/exceptionbase.h"
10 11
11#define PAGE_SIZE 8 12#define PAGE_SIZE 8
12 13
@@ -132,6 +133,7 @@ void Bu::BlobBuilderCore::append( const char *pSrc, int32_t iLength )
132 if( iLength > 0 ) 133 if( iLength > 0 )
133 { 134 {
134 pLast->pNext = new Chunk( pSrc, iLength ); 135 pLast->pNext = new Chunk( pSrc, iLength );
136 pLast = pLast->pNext;
135 } 137 }
136} 138}
137 139
@@ -214,6 +216,21 @@ void Bu::BlobBuilderCore::copyTo( void *pDestRaw, int32_t iLength ) const
214 } 216 }
215} 217}
216 218
219char Bu::BlobBuilderCore::getAt( int32_t iIndex ) const
220{
221 if( iIndex < 0 || iIndex >= iLength )
222 throw Bu::ExceptionBase("Requseted index is out of range.");
223
224 Chunk *pCur = pFirst;
225 while( iIndex >= pCur->iLength )
226 {
227 iIndex -= pCur->iLength;
228 pCur = pCur->pNext;
229 }
230
231 return pCur->pData[iIndex];
232}
233
217////// 234//////
218// BlobBuilder 235// BlobBuilder
219// 236//
@@ -245,6 +262,7 @@ void Bu::BlobBuilder::set( const char *pSrc, int32_t iLength )
245 262
246void Bu::BlobBuilder::set( const char *pSrc ) 263void Bu::BlobBuilder::set( const char *pSrc )
247{ 264{
265 _hardCopy();
248 set( pSrc, strlen( pSrc ) ); 266 set( pSrc, strlen( pSrc ) );
249} 267}
250 268
@@ -262,6 +280,7 @@ void Bu::BlobBuilder::append( const char *pSrc, int32_t iLength )
262 280
263void Bu::BlobBuilder::append( const char *pSrc ) 281void Bu::BlobBuilder::append( const char *pSrc )
264{ 282{
283 _hardCopy();
265 append( pSrc, strlen( pSrc ) ); 284 append( pSrc, strlen( pSrc ) );
266} 285}
267 286
@@ -279,6 +298,7 @@ void Bu::BlobBuilder::prepend( const char *pSrc, int32_t iLength )
279 298
280void Bu::BlobBuilder::prepend( const char *pSrc ) 299void Bu::BlobBuilder::prepend( const char *pSrc )
281{ 300{
301 _hardCopy();
282 prepend( pSrc, strlen( pSrc ) ); 302 prepend( pSrc, strlen( pSrc ) );
283} 303}
284 304
@@ -297,6 +317,7 @@ void Bu::BlobBuilder::insert( int32_t iBefore, const char *pSrc,
297 317
298void Bu::BlobBuilder::insert( int32_t iBefore, const char *pSrc ) 318void Bu::BlobBuilder::insert( int32_t iBefore, const char *pSrc )
299{ 319{
320 _hardCopy();
300 insert( iBefore, pSrc, strlen( pSrc ) ); 321 insert( iBefore, pSrc, strlen( pSrc ) );
301} 322}
302 323
@@ -321,6 +342,11 @@ void Bu::BlobBuilder::copyTo( void *pDestRaw, int32_t iDestSize ) const
321 core->copyTo( pDestRaw, iDestSize ); 342 core->copyTo( pDestRaw, iDestSize );
322} 343}
323 344
345char Bu::BlobBuilder::operator[]( int32_t iIndex ) const
346{
347 return core->getAt( iIndex );
348}
349
324Bu::BlobBuilder &Bu::BlobBuilder::operator=( const Blob &rSrc ) 350Bu::BlobBuilder &Bu::BlobBuilder::operator=( const Blob &rSrc )
325{ 351{
326 set( rSrc ); 352 set( rSrc );
@@ -333,6 +359,12 @@ Bu::BlobBuilder &Bu::BlobBuilder::operator=( const char *pSrc )
333 return *this; 359 return *this;
334} 360}
335 361
362Bu::BlobBuilder &Bu::BlobBuilder::operator=( const char chr )
363{
364 set( &chr, 1 );
365 return *this;
366}
367
336Bu::BlobBuilder &Bu::BlobBuilder::operator+=( const Blob &rSrc ) 368Bu::BlobBuilder &Bu::BlobBuilder::operator+=( const Blob &rSrc )
337{ 369{
338 append( rSrc ); 370 append( rSrc );
@@ -345,4 +377,9 @@ Bu::BlobBuilder &Bu::BlobBuilder::operator+=( const char *pSrc )
345 return *this; 377 return *this;
346} 378}
347 379
380Bu::BlobBuilder &Bu::BlobBuilder::operator+=( const char chr )
381{
382 append( &chr, 1 );
383 return *this;
384}
348 385