From 26aa4bd668a2f2358b03634bce78c58085f14164 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sat, 25 May 2019 23:04:09 -0700 Subject: Started work on the SharedCore BlobBuilder. This will contain everything that made Bu::String flexible and fast when building, and a nightmare for multi-threaded programming. --- src/unstable/blob.h | 8 +++++- src/unstable/blobbuilder.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++++ src/unstable/blobbuilder.h | 53 +++++++++++++++++++++++++++++++++++++ 3 files changed, 123 insertions(+), 1 deletion(-) diff --git a/src/unstable/blob.h b/src/unstable/blob.h index daee5f9..b48f488 100644 --- a/src/unstable/blob.h +++ b/src/unstable/blob.h @@ -8,7 +8,7 @@ #ifndef BU_BLOB_H #define BU_BLOB_H -#include +#include "bu/config.h" namespace Bu { @@ -19,6 +19,12 @@ namespace Bu * choice when dealing with any sequence of binary data that you don't * need to interpret further. * + * You may note that Blob doesn't have any append, prepend, etc. methods. + * This is because Blobs are designed to be more or less immutable. If you + * need that functionality (which is quite likely), check out + * Bu::BlobBuilder which offers a flexible, fast interface to build Blobs + * dynamically, piece at a time. + * * If you're dealing with data that contains language, such as human text, * then use the Bu::Text class instead. */ diff --git a/src/unstable/blobbuilder.cpp b/src/unstable/blobbuilder.cpp index 73271f8..b98476b 100644 --- a/src/unstable/blobbuilder.cpp +++ b/src/unstable/blobbuilder.cpp @@ -5,4 +5,67 @@ * terms of the license contained in the file LICENSE. */ +#include "blobbuilder.h" + +///// +// BlobBuilderCore::Chunk +// + +Bu::BlobBuilderCore::Chunk::Chunk() : + iFill( 0 ), + iLength( 0 ), + pData( 0 ), + pNext( 0 ) +{ +} + +Bu::BlobBuilderCore::Chunk::~Chunk() +{ + delete[] pData; + pData = 0; + delete pNext; + pNext = 0; +} + +///// +// BlobBuilderCore +// + +Bu::BlobBuilderCore::BlobBuilderCore() : + pFirst( 0 ), + pLast( 0 ), + iLength( 0 ) +{ +} + +Bu::BlobBuilderCore::BlobBuilderCore( const Bu::BlobBuilderCore &rSrc ) : + iLength( rSrc.iLength ), + pFirst( 0 ), + pLast( 0 ) +{ + +} + +Bu::BlobBuilderCore::~BlobBuilderCore() +{ + delete pFirst; + pFirst = pLast = 0; +} + +////// +// BlobBuilder +// + +Bu::BlobBuilder::BlobBuilder() +{ +} + +Bu::BlobBuilder::BlobBuilder( const Bu::BlobBuilder &rSrc ) : + Bu::SharedCore( rSrc ) +{ +} + +Bu::BlobBuilder::~BlobBuilder() +{ +} diff --git a/src/unstable/blobbuilder.h b/src/unstable/blobbuilder.h index 73271f8..8cc2a24 100644 --- a/src/unstable/blobbuilder.h +++ b/src/unstable/blobbuilder.h @@ -5,4 +5,57 @@ * terms of the license contained in the file LICENSE. */ +#ifndef BU_BLOB_BUILDER_H +#define BU_BLOB_BUILDER_H +#include "bu/config.h" +#include "bu/sharedcore.h" + +namespace Bu +{ + class BlobBuilder; + + class BlobBuilderCore + { + friend class BlobBuilder; + friend class SharedCore; + private: + class Chunk + { + public: + Chunk(); + ~Chunk(); + + int16_t iFill; + int16_t iLength; + char *pData; + Chunk *pNext; + }; + + BlobBuilderCore(); + BlobBuilderCore( const BlobBuilderCore &rSrc ); + virtual ~BlobBuilderCore(); + + void clear(); + + Chunk *pFirst; + Chunk *pLast; + int32_t iLength; + }; + + class BlobBuilder : public Bu::SharedCore + { + protected: + using SharedCore::core; + using SharedCore::_hardCopy; + + public: + BlobBuilder(); + BlobBuilder( const BlobBuilder &rSrc ); + virtual ~BlobBuilder(); + + private: + }; +}; + +#endif -- cgit v1.2.3