aboutsummaryrefslogtreecommitdiff
path: root/src/unstable
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/unstable/blobbuilder.cpp37
-rw-r--r--src/unstable/blobbuilder.h6
2 files changed, 42 insertions, 1 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
diff --git a/src/unstable/blobbuilder.h b/src/unstable/blobbuilder.h
index 744212a..c343a4f 100644
--- a/src/unstable/blobbuilder.h
+++ b/src/unstable/blobbuilder.h
@@ -53,7 +53,8 @@ namespace Bu
53 void prepend( const char *pSrc, int32_t iLength ); 53 void prepend( const char *pSrc, int32_t iLength );
54 void insert( int32_t iBefore, const char *pSrc, int32_t iLength ); 54 void insert( int32_t iBefore, const char *pSrc, int32_t iLength );
55 void set( const char *pSrc, int32_t iLength ); 55 void set( const char *pSrc, int32_t iLength );
56 void copyTo( void *pDestRaw, int32_t iLength ) const; 56 void copyTo( void *pDestRaw, int32_t iLength ) const;
57 char getAt( int32_t iIndex ) const;
57 58
58 Chunk *pFirst; 59 Chunk *pFirst;
59 Chunk *pLast; 60 Chunk *pLast;
@@ -110,11 +111,14 @@ namespace Bu
110 int32_t getSize() const; 111 int32_t getSize() const;
111 Blob getBlob() const; 112 Blob getBlob() const;
112 void copyTo( void *pDestRaw, int32_t iDestSize ) const; 113 void copyTo( void *pDestRaw, int32_t iDestSize ) const;
114 char operator[]( int32_t iIndex ) const;
113 115
114 BlobBuilder &operator=( const Blob &rSrc ); 116 BlobBuilder &operator=( const Blob &rSrc );
115 BlobBuilder &operator=( const char *pSrc ); 117 BlobBuilder &operator=( const char *pSrc );
118 BlobBuilder &operator=( const char chr );
116 BlobBuilder &operator+=( const Blob &rSrc ); 119 BlobBuilder &operator+=( const Blob &rSrc );
117 BlobBuilder &operator+=( const char *pSrc ); 120 BlobBuilder &operator+=( const char *pSrc );
121 BlobBuilder &operator+=( const char chr );
118 private: 122 private:
119 }; 123 };
120}; 124};