diff options
Diffstat (limited to '')
-rw-r--r-- | src/unit/blobbuilder.unit | 13 | ||||
-rw-r--r-- | src/unstable/blobbuilder.cpp | 37 | ||||
-rw-r--r-- | src/unstable/blobbuilder.h | 6 |
3 files changed, 55 insertions, 1 deletions
diff --git a/src/unit/blobbuilder.unit b/src/unit/blobbuilder.unit index 84bf549..7f3fb93 100644 --- a/src/unit/blobbuilder.unit +++ b/src/unit/blobbuilder.unit | |||
@@ -17,6 +17,7 @@ suite BlobBuilder | |||
17 | { | 17 | { |
18 | test append | 18 | test append |
19 | { | 19 | { |
20 | /* | ||
20 | Bu::BlobBuilder a; | 21 | Bu::BlobBuilder a; |
21 | a.append("a"); | 22 | a.append("a"); |
22 | a.append("bc"); | 23 | a.append("bc"); |
@@ -24,5 +25,17 @@ suite BlobBuilder | |||
24 | Bu::println(">%1<\n\n").arg( a.getBlob() ); | 25 | Bu::println(">%1<\n\n").arg( a.getBlob() ); |
25 | a.append("abcdef"); | 26 | a.append("abcdef"); |
26 | Bu::println(">%1<\n\n").arg( a.getBlob() ); | 27 | Bu::println(">%1<\n\n").arg( a.getBlob() ); |
28 | */ | ||
29 | } | ||
30 | |||
31 | test appendChar | ||
32 | { | ||
33 | Bu::BlobBuilder a; | ||
34 | for( int j = 0; j < 20; j++ ) | ||
35 | { | ||
36 | a += 'A'; | ||
37 | } | ||
38 | Bu::println("%1").arg( a.getBlob() ); | ||
39 | unitTest( a.getBlob() == "AAAAAAAAAAAAAAAAAAAA" ); | ||
27 | } | 40 | } |
28 | } | 41 | } |
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 | ||
219 | char 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 | ||
246 | void Bu::BlobBuilder::set( const char *pSrc ) | 263 | void 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 | ||
263 | void Bu::BlobBuilder::append( const char *pSrc ) | 281 | void 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 | ||
280 | void Bu::BlobBuilder::prepend( const char *pSrc ) | 299 | void 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 | ||
298 | void Bu::BlobBuilder::insert( int32_t iBefore, const char *pSrc ) | 318 | void 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 | ||
345 | char Bu::BlobBuilder::operator[]( int32_t iIndex ) const | ||
346 | { | ||
347 | return core->getAt( iIndex ); | ||
348 | } | ||
349 | |||
324 | Bu::BlobBuilder &Bu::BlobBuilder::operator=( const Blob &rSrc ) | 350 | Bu::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 | ||
362 | Bu::BlobBuilder &Bu::BlobBuilder::operator=( const char chr ) | ||
363 | { | ||
364 | set( &chr, 1 ); | ||
365 | return *this; | ||
366 | } | ||
367 | |||
336 | Bu::BlobBuilder &Bu::BlobBuilder::operator+=( const Blob &rSrc ) | 368 | Bu::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 | ||
380 | Bu::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 | }; |