aboutsummaryrefslogtreecommitdiff
path: root/src/unstable/blob.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/unstable/blob.cpp161
1 files changed, 115 insertions, 46 deletions
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 ) :
34 memcpy( pData, pSrc, iSize+1 ); 34 memcpy( pData, pSrc, iSize+1 );
35} 35}
36 36
37Bu::Blob::Blob( const void *pSrc, int32_t iSize ) 37Bu::Blob::Blob( const void *pSrc, int32_t iSize ) :
38 pData( 0 ),
39 iSize( iSize )
38{ 40{
39 this->iSize = iSize;
40 pData = new char[iSize+1]; 41 pData = new char[iSize+1];
41 memcpy( pData, pSrc, iSize ); 42 memcpy( pData, pSrc, iSize );
42 pData[iSize] = '\0'; 43 pData[iSize] = '\0';
43} 44}
44 45
46Bu::Blob::Blob( const Bu::Blob::const_iterator &iStart ) :
47 pData( 0 ),
48 iSize( -1 )
49{
50 if( !iStart )
51 return;
52
53 iSize = iStart.pBlob->iSize - iStart.iIndex;
54 pData = new char[iSize+1];
55 memcpy( pData, iStart.pBlob->pData+iStart.iIndex, iSize );
56}
57
58Bu::Blob::Blob( const Bu::Blob::const_iterator &iStart,
59 const Bu::Blob::const_iterator &iEnd ) :
60 pData( 0 ),
61 iSize( -1 )
62{
63 if( !iStart )
64 return;
65
66 if( iEnd )
67 {
68 iSize = iEnd.iIndex - iStart.iIndex;
69 }
70 else
71 {
72 iSize = iStart.pBlob->iSize - iStart.iIndex;
73 }
74
75 pData = new char[iSize+1];
76 memcpy( pData, iStart.pBlob->pData+iStart.iIndex, iSize );
77}
78
45Bu::Blob::~Blob() 79Bu::Blob::~Blob()
46{ 80{
47 delete[] pData; 81 delete[] pData;
@@ -316,6 +350,45 @@ bool Bu::Blob::operator>=( const char *pRhs ) const
316 return true; 350 return true;
317} 351}
318 352
353Bu::Blob::iterator Bu::Blob::begin()
354{
355 return iterator( this, true );
356}
357
358Bu::Blob::const_iterator Bu::Blob::begin() const
359{
360 return const_iterator( this, true );
361}
362
363Bu::Blob::iterator Bu::Blob::end()
364{
365 return iterator();
366}
367
368Bu::Blob::const_iterator Bu::Blob::end() const
369{
370 return const_iterator();
371}
372
373Bu::Blob::iterator Bu::Blob::rbegin()
374{
375 return iterator( this, false );
376}
377
378Bu::Blob::const_iterator Bu::Blob::rbegin() const
379{
380 return const_iterator( this, false );
381}
382
383Bu::Blob::iterator Bu::Blob::rend()
384{
385 return iterator();
386}
387
388Bu::Blob::const_iterator Bu::Blob::rend() const
389{
390 return const_iterator();
391}
319 392
320///// 393/////
321// Iterators 394// Iterators
@@ -328,6 +401,13 @@ Bu::Blob::iterator::iterator( Bu::Blob *pBlob, bool bForward ) :
328{ 401{
329} 402}
330 403
404Bu::Blob::iterator::iterator( Bu::Blob *pBlob, int32_t iIndex, bool bForward ) :
405 pBlob( pBlob ),
406 iIndex( iIndex ),
407 bForward( bForward )
408{
409}
410
331Bu::Blob::iterator::iterator() : 411Bu::Blob::iterator::iterator() :
332 pBlob( NULL ), 412 pBlob( NULL ),
333 iIndex( -1 ), 413 iIndex( -1 ),
@@ -366,7 +446,7 @@ char &Bu::Blob::iterator::operator *()
366 return pBlob->pData[iIndex]; 446 return pBlob->pData[iIndex];
367} 447}
368 448
369Bu::Blob::iterator &Bu::Blob::iterator::operator++( int ) 449Bu::Blob::iterator &Bu::Blob::iterator::operator++( int32_t )
370{ 450{
371 if( bForward ) 451 if( bForward )
372 ++iIndex; 452 ++iIndex;
@@ -386,7 +466,7 @@ Bu::Blob::iterator &Bu::Blob::iterator::operator++()
386 return *this; 466 return *this;
387} 467}
388 468
389Bu::Blob::iterator &Bu::Blob::iterator::operator--( int ) 469Bu::Blob::iterator &Bu::Blob::iterator::operator--( int32_t )
390{ 470{
391 if( bForward ) 471 if( bForward )
392 --iIndex; 472 --iIndex;
@@ -406,6 +486,16 @@ Bu::Blob::iterator &Bu::Blob::iterator::operator--()
406 return *this; 486 return *this;
407} 487}
408 488
489Bu::Blob::iterator Bu::Blob::iterator::operator+( int32_t iDelta ) const
490{
491 return iterator( pBlob, iIndex + iDelta, bForward );
492}
493
494Bu::Blob::iterator Bu::Blob::iterator::operator-( int32_t iDelta ) const
495{
496 return iterator( pBlob, iIndex - iDelta, bForward );
497}
498
409bool Bu::Blob::iterator::operator==( const Bu::Blob::iterator &rRhs ) 499bool Bu::Blob::iterator::operator==( const Bu::Blob::iterator &rRhs )
410{ 500{
411 if( isValid() == false && rRhs.isValid() == false ) 501 if( isValid() == false && rRhs.isValid() == false )
@@ -454,6 +544,13 @@ Bu::Blob::const_iterator::const_iterator( const Blob *pBlob, bool bForward ) :
454 bForward( bForward ) 544 bForward( bForward )
455{ 545{
456} 546}
547Bu::Blob::const_iterator::const_iterator( const Blob *pBlob, int32_t iIndex,
548 bool bForward ) :
549 pBlob( pBlob ),
550 iIndex( iIndex ),
551 bForward( bForward )
552{
553}
457 554
458Bu::Blob::const_iterator::const_iterator() : 555Bu::Blob::const_iterator::const_iterator() :
459 pBlob( NULL ), 556 pBlob( NULL ),
@@ -541,6 +638,18 @@ Bu::Blob::const_iterator &Bu::Blob::const_iterator::operator--()
541 return *this; 638 return *this;
542} 639}
543 640
641Bu::Blob::const_iterator Bu::Blob::const_iterator::operator+( int32_t iDelta )
642 const
643{
644 return const_iterator( pBlob, iIndex + iDelta, bForward );
645}
646
647Bu::Blob::const_iterator Bu::Blob::const_iterator::operator-( int32_t iDelta )
648 const
649{
650 return const_iterator( pBlob, iIndex - iDelta, bForward );
651}
652
544bool Bu::Blob::const_iterator::operator==( const Bu::Blob::iterator &rRhs ) 653bool Bu::Blob::const_iterator::operator==( const Bu::Blob::iterator &rRhs )
545{ 654{
546 if( isValid() == false && rRhs.isValid() == false ) 655 if( isValid() == false && rRhs.isValid() == false )
@@ -595,50 +704,10 @@ Bu::Blob::const_iterator &Bu::Blob::const_iterator::operator=(
595 return *this; 704 return *this;
596} 705}
597 706
598 707/////
599Bu::Blob::iterator Bu::Blob::begin()
600{
601 return iterator( this, true );
602}
603
604Bu::Blob::const_iterator Bu::Blob::begin() const
605{
606 return const_iterator( this, true );
607}
608
609Bu::Blob::iterator Bu::Blob::end()
610{
611 return iterator();
612}
613
614Bu::Blob::const_iterator Bu::Blob::end() const
615{
616 return const_iterator();
617}
618
619Bu::Blob::iterator Bu::Blob::rbegin()
620{
621 return iterator( this, false );
622}
623
624Bu::Blob::const_iterator Bu::Blob::rbegin() const
625{
626 return const_iterator( this, false );
627}
628
629Bu::Blob::iterator Bu::Blob::rend()
630{
631 return iterator();
632}
633
634Bu::Blob::const_iterator Bu::Blob::rend() const
635{
636 return const_iterator();
637}
638
639////
640// Helper functions 708// Helper functions
641// 709//
710
642template<> uint32_t Bu::__calcHashCode<Bu::Blob>( const Bu::Blob &k ) 711template<> uint32_t Bu::__calcHashCode<Bu::Blob>( const Bu::Blob &k )
643{ 712{
644 int32_t sz = k.getSize(); 713 int32_t sz = k.getSize();