/* * Copyright (C) 2007-2019 Xagasoft, All rights reserved. * * This file is part of the libbu++ library and is released under the * 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 Blob; class BlobBuilder; /** @cond DEVEL */ class BlobBuilderCore { friend class BlobBuilder; friend class SharedCore; private: class Chunk { public: Chunk( const char *pSrc, int32_t iLength ); ~Chunk(); void append( const char *&pSrc, int32_t &iLength ); /** * Splits this chunk into two chunks, and fixes the links. *@param iIndex The first byte to be in the new chunk, if this is * zero or less then it has no effect. *@returns A pointer to the new chunk, or null if no work was * done. */ Chunk *split( int32_t iIndex ); int32_t iLength; char *pData; Chunk *pNext; }; BlobBuilderCore(); BlobBuilderCore( const BlobBuilderCore &rSrc ); virtual ~BlobBuilderCore(); void clear(); void append( const char *pSrc, int32_t iLength ); void prepend( const char *pSrc, int32_t iLength ); void insert( int32_t iBefore, const char *pSrc, int32_t iLength ); void set( const char *pSrc, int32_t iLength ); void copyTo( void *pDestRaw, int32_t iLength ) const; Chunk *pFirst; Chunk *pLast; int32_t iLength; }; /** @endcond */ class BlobBuilder : public Bu::SharedCore { protected: using SharedCore::core; using SharedCore::_hardCopy; public: BlobBuilder(); BlobBuilder( const Blob &rSrc ); BlobBuilder( const BlobBuilder &rSrc ); virtual ~BlobBuilder(); void set( const Blob &rSrc ); void set( const char *pSrc, int32_t iLength ); void set( const char *pSrc ); void append( const Blob &rSrc ); void append( const char *pSrc, int32_t iLength ); void append( const char *pSrc ); void prepend( const Blob &rSrc ); void prepend( const char *pSrc, int32_t iLength ); void prepend( const char *pSrc ); void insert( int32_t iBefore, const Blob &rSrc ); void insert( int32_t iBefore, const char *pSrc, int32_t iLength ); void insert( int32_t iBefore, const char *pSrc ); void clear(); int32_t getSize() const; Blob getBlob() const; void copyTo( void *pDestRaw, int32_t iDestSize ) const; BlobBuilder &operator=( const Blob &rSrc ); BlobBuilder &operator=( const char *pSrc ); BlobBuilder &operator+=( const Blob &rSrc ); BlobBuilder &operator+=( const char *pSrc ); private: }; }; #endif