diff options
Diffstat (limited to 'src/unstable')
| -rw-r--r-- | src/unstable/blob.cpp | 161 | ||||
| -rw-r--r-- | src/unstable/blob.h | 39 |
2 files changed, 140 insertions, 60 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 | ||
| 37 | Bu::Blob::Blob( const void *pSrc, int32_t iSize ) | 37 | Bu::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 | ||
| 46 | Bu::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 | |||
| 58 | Bu::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 | |||
| 45 | Bu::Blob::~Blob() | 79 | Bu::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 | ||
| 353 | Bu::Blob::iterator Bu::Blob::begin() | ||
| 354 | { | ||
| 355 | return iterator( this, true ); | ||
| 356 | } | ||
| 357 | |||
| 358 | Bu::Blob::const_iterator Bu::Blob::begin() const | ||
| 359 | { | ||
| 360 | return const_iterator( this, true ); | ||
| 361 | } | ||
| 362 | |||
| 363 | Bu::Blob::iterator Bu::Blob::end() | ||
| 364 | { | ||
| 365 | return iterator(); | ||
| 366 | } | ||
| 367 | |||
| 368 | Bu::Blob::const_iterator Bu::Blob::end() const | ||
| 369 | { | ||
| 370 | return const_iterator(); | ||
| 371 | } | ||
| 372 | |||
| 373 | Bu::Blob::iterator Bu::Blob::rbegin() | ||
| 374 | { | ||
| 375 | return iterator( this, false ); | ||
| 376 | } | ||
| 377 | |||
| 378 | Bu::Blob::const_iterator Bu::Blob::rbegin() const | ||
| 379 | { | ||
| 380 | return const_iterator( this, false ); | ||
| 381 | } | ||
| 382 | |||
| 383 | Bu::Blob::iterator Bu::Blob::rend() | ||
| 384 | { | ||
| 385 | return iterator(); | ||
| 386 | } | ||
| 387 | |||
| 388 | Bu::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 | ||
| 404 | Bu::Blob::iterator::iterator( Bu::Blob *pBlob, int32_t iIndex, bool bForward ) : | ||
| 405 | pBlob( pBlob ), | ||
| 406 | iIndex( iIndex ), | ||
| 407 | bForward( bForward ) | ||
| 408 | { | ||
| 409 | } | ||
| 410 | |||
| 331 | Bu::Blob::iterator::iterator() : | 411 | Bu::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 | ||
| 369 | Bu::Blob::iterator &Bu::Blob::iterator::operator++( int ) | 449 | Bu::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 | ||
| 389 | Bu::Blob::iterator &Bu::Blob::iterator::operator--( int ) | 469 | Bu::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 | ||
| 489 | Bu::Blob::iterator Bu::Blob::iterator::operator+( int32_t iDelta ) const | ||
| 490 | { | ||
| 491 | return iterator( pBlob, iIndex + iDelta, bForward ); | ||
| 492 | } | ||
| 493 | |||
| 494 | Bu::Blob::iterator Bu::Blob::iterator::operator-( int32_t iDelta ) const | ||
| 495 | { | ||
| 496 | return iterator( pBlob, iIndex - iDelta, bForward ); | ||
| 497 | } | ||
| 498 | |||
| 409 | bool Bu::Blob::iterator::operator==( const Bu::Blob::iterator &rRhs ) | 499 | bool 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 | } |
| 547 | Bu::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 | ||
| 458 | Bu::Blob::const_iterator::const_iterator() : | 555 | Bu::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 | ||
| 641 | Bu::Blob::const_iterator Bu::Blob::const_iterator::operator+( int32_t iDelta ) | ||
| 642 | const | ||
| 643 | { | ||
| 644 | return const_iterator( pBlob, iIndex + iDelta, bForward ); | ||
| 645 | } | ||
| 646 | |||
| 647 | Bu::Blob::const_iterator Bu::Blob::const_iterator::operator-( int32_t iDelta ) | ||
| 648 | const | ||
| 649 | { | ||
| 650 | return const_iterator( pBlob, iIndex - iDelta, bForward ); | ||
| 651 | } | ||
| 652 | |||
| 544 | bool Bu::Blob::const_iterator::operator==( const Bu::Blob::iterator &rRhs ) | 653 | bool 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 | ///// | |
| 599 | Bu::Blob::iterator Bu::Blob::begin() | ||
| 600 | { | ||
| 601 | return iterator( this, true ); | ||
| 602 | } | ||
| 603 | |||
| 604 | Bu::Blob::const_iterator Bu::Blob::begin() const | ||
| 605 | { | ||
| 606 | return const_iterator( this, true ); | ||
| 607 | } | ||
| 608 | |||
| 609 | Bu::Blob::iterator Bu::Blob::end() | ||
| 610 | { | ||
| 611 | return iterator(); | ||
| 612 | } | ||
| 613 | |||
| 614 | Bu::Blob::const_iterator Bu::Blob::end() const | ||
| 615 | { | ||
| 616 | return const_iterator(); | ||
| 617 | } | ||
| 618 | |||
| 619 | Bu::Blob::iterator Bu::Blob::rbegin() | ||
| 620 | { | ||
| 621 | return iterator( this, false ); | ||
| 622 | } | ||
| 623 | |||
| 624 | Bu::Blob::const_iterator Bu::Blob::rbegin() const | ||
| 625 | { | ||
| 626 | return const_iterator( this, false ); | ||
| 627 | } | ||
| 628 | |||
| 629 | Bu::Blob::iterator Bu::Blob::rend() | ||
| 630 | { | ||
| 631 | return iterator(); | ||
| 632 | } | ||
| 633 | |||
| 634 | Bu::Blob::const_iterator Bu::Blob::rend() const | ||
| 635 | { | ||
| 636 | return const_iterator(); | ||
| 637 | } | ||
| 638 | |||
| 639 | //// | ||
| 640 | // Helper functions | 708 | // Helper functions |
| 641 | // | 709 | // |
| 710 | |||
| 642 | template<> uint32_t Bu::__calcHashCode<Bu::Blob>( const Bu::Blob &k ) | 711 | template<> uint32_t Bu::__calcHashCode<Bu::Blob>( const Bu::Blob &k ) |
| 643 | { | 712 | { |
| 644 | int32_t sz = k.getSize(); | 713 | int32_t sz = k.getSize(); |
diff --git a/src/unstable/blob.h b/src/unstable/blob.h index 6ce0c67..daee5f9 100644 --- a/src/unstable/blob.h +++ b/src/unstable/blob.h | |||
| @@ -25,10 +25,16 @@ namespace Bu | |||
| 25 | class Blob | 25 | class Blob |
| 26 | { | 26 | { |
| 27 | public: | 27 | public: |
| 28 | class iterator; | ||
| 29 | class const_iterator; | ||
| 30 | |||
| 31 | public: | ||
| 28 | Blob(); | 32 | Blob(); |
| 29 | Blob( const Blob &rSrc ); | 33 | Blob( const Blob &rSrc ); |
| 30 | Blob( const char *pSrc ); | 34 | Blob( const char *pSrc ); |
| 31 | Blob( const void *pSrc, int32_t iSize ); | 35 | Blob( const void *pSrc, int32_t iSize ); |
| 36 | Blob( const const_iterator &iStart ); | ||
| 37 | Blob( const const_iterator &iStart, const const_iterator &iEnd ); | ||
| 32 | virtual ~Blob(); | 38 | virtual ~Blob(); |
| 33 | 39 | ||
| 34 | int32_t getSize() const; | 40 | int32_t getSize() const; |
| @@ -58,13 +64,22 @@ namespace Bu | |||
| 58 | bool operator>=( const Blob &rRhs ) const; | 64 | bool operator>=( const Blob &rRhs ) const; |
| 59 | bool operator>=( const char *rRhs ) const; | 65 | bool operator>=( const char *rRhs ) const; |
| 60 | 66 | ||
| 61 | class const_iterator; | 67 | iterator begin(); |
| 68 | const_iterator begin() const; | ||
| 69 | iterator end(); | ||
| 70 | const_iterator end() const; | ||
| 71 | iterator rbegin(); | ||
| 72 | const_iterator rbegin() const; | ||
| 73 | iterator rend(); | ||
| 74 | const_iterator rend() const; | ||
| 75 | |||
| 62 | class iterator | 76 | class iterator |
| 63 | { | 77 | { |
| 64 | friend class Blob; | 78 | friend class Blob; |
| 65 | friend class const_iterator; | 79 | friend class const_iterator; |
| 66 | private: | 80 | private: |
| 67 | iterator( Blob *pBlob, bool bForward ); | 81 | iterator( Blob *pBlob, bool bForward ); |
| 82 | iterator( Blob *pBlob, int32_t iIndex, bool bForward ); | ||
| 68 | 83 | ||
| 69 | public: | 84 | public: |
| 70 | iterator(); | 85 | iterator(); |
| @@ -74,10 +89,12 @@ namespace Bu | |||
| 74 | operator bool() const; | 89 | operator bool() const; |
| 75 | char &operator *(); | 90 | char &operator *(); |
| 76 | 91 | ||
| 77 | iterator &operator++( int ); | 92 | iterator &operator++( int32_t ); |
| 78 | iterator &operator++(); | 93 | iterator &operator++(); |
| 79 | iterator &operator--( int ); | 94 | iterator &operator--( int32_t ); |
| 80 | iterator &operator--(); | 95 | iterator &operator--(); |
| 96 | iterator operator+( int32_t iDelta ) const; | ||
| 97 | iterator operator-( int32_t iDelta ) const; | ||
| 81 | bool operator==( const iterator &rRhs ); | 98 | bool operator==( const iterator &rRhs ); |
| 82 | bool operator==( const const_iterator &rRhs ); | 99 | bool operator==( const const_iterator &rRhs ); |
| 83 | bool operator!=( const iterator &rRhs ); | 100 | bool operator!=( const iterator &rRhs ); |
| @@ -97,6 +114,7 @@ namespace Bu | |||
| 97 | friend class iterator; | 114 | friend class iterator; |
| 98 | private: | 115 | private: |
| 99 | const_iterator( const Blob *pBlob, bool bForward ); | 116 | const_iterator( const Blob *pBlob, bool bForward ); |
| 117 | const_iterator( const Blob *pBlob, int32_t iIndex, bool bForward ); | ||
| 100 | 118 | ||
| 101 | public: | 119 | public: |
| 102 | const_iterator(); | 120 | const_iterator(); |
| @@ -107,10 +125,12 @@ namespace Bu | |||
| 107 | operator bool() const; | 125 | operator bool() const; |
| 108 | char operator *() const; | 126 | char operator *() const; |
| 109 | 127 | ||
| 110 | const_iterator &operator++( int ); | 128 | const_iterator &operator++( int32_t ); |
| 111 | const_iterator &operator++(); | 129 | const_iterator &operator++(); |
| 112 | const_iterator &operator--( int ); | 130 | const_iterator &operator--( int32_t ); |
| 113 | const_iterator &operator--(); | 131 | const_iterator &operator--(); |
| 132 | const_iterator operator+( int32_t iDelta ) const; | ||
| 133 | const_iterator operator-( int32_t iDelta ) const; | ||
| 114 | bool operator==( const iterator &rRhs ); | 134 | bool operator==( const iterator &rRhs ); |
| 115 | bool operator==( const const_iterator &rRhs ); | 135 | bool operator==( const const_iterator &rRhs ); |
| 116 | bool operator!=( const iterator &rRhs ); | 136 | bool operator!=( const iterator &rRhs ); |
| @@ -125,15 +145,6 @@ namespace Bu | |||
| 125 | bool bForward; | 145 | bool bForward; |
| 126 | }; | 146 | }; |
| 127 | 147 | ||
| 128 | iterator begin(); | ||
| 129 | const_iterator begin() const; | ||
| 130 | iterator end(); | ||
| 131 | const_iterator end() const; | ||
| 132 | iterator rbegin(); | ||
| 133 | const_iterator rbegin() const; | ||
| 134 | iterator rend(); | ||
| 135 | const_iterator rend() const; | ||
| 136 | |||
| 137 | private: | 148 | private: |
| 138 | char *pData; | 149 | char *pData; |
| 139 | int32_t iSize; | 150 | int32_t iSize; |
