From 00cef0e9a21e1ee07d622bb05c3a7e4e56425723 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sat, 25 May 2019 00:19:04 -0700 Subject: Started Bu::Text and Bu::Blob. These will someday replace Bu::String and Bu::UtfString. The plan is to support more encodings in the Text class than just Unicode, Blob and Text will not be shared core, but the Builders will be, making Text and Blob objects much safer in multi-threaded programs. --- src/unstable/blob.h | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 src/unstable/blob.h (limited to 'src/unstable/blob.h') diff --git a/src/unstable/blob.h b/src/unstable/blob.h new file mode 100644 index 0000000..5b8cabd --- /dev/null +++ b/src/unstable/blob.h @@ -0,0 +1,125 @@ +/* + * 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_H +#define BU_BLOB_H + +#include + +namespace Bu +{ + /** + * Blob contans a sequence of binary values. This is basically the + * replacement for the old libbu++ Bu::String, std::string classes, or the + * tradition C char * string. The Blob is static and immutable, and a good + * choice when dealing with any sequence of binary data that you don't + * need to interpret further. + * + * If you're dealing with data that contains language, such as human text, + * then use the Bu::Text class instead. + */ + class Blob + { + public: + Blob(); + Blob( const Blob &rSrc ); + Blob( const char *pSrc ); + Blob( const void *pSrc, int32_t iSize ); + virtual ~Blob(); + + int32_t getSize() const; + char *getData() const; + + char *c_str() const; + + Blob &operator=( const Blob &rRhs ); + Blob &operator=( const char *pRhs ); + + class const_iterator; + class iterator + { + friend class Blob; + friend class const_iterator; + private: + iterator( Blob *pBlob, bool bForward ); + + public: + iterator(); + iterator( const iterator &rSrc ); + + bool isValid() const; + operator bool() const; + char &operator *(); + + iterator &operator++( int ); + iterator &operator++(); + iterator &operator--( int ); + iterator &operator--(); + bool operator==( const iterator &rRhs ); + bool operator==( const const_iterator &rRhs ); + bool operator!=( const iterator &rRhs ); + bool operator!=( const const_iterator &rRhs ); + + iterator &operator=( iterator &rRhs ); + + private: + Blob *pBlob; + int32_t iIndex; + bool bForward; + }; + + class const_iterator + { + friend class Blob; + friend class iterator; + private: + const_iterator( const Blob *pBlob, bool bForward ); + + public: + const_iterator(); + const_iterator( const const_iterator &rSrc ); + const_iterator( const iterator &rSrc ); + + bool isValid() const; + operator bool() const; + char operator *() const; + + const_iterator &operator++( int ); + const_iterator &operator++(); + const_iterator &operator--( int ); + const_iterator &operator--(); + bool operator==( const iterator &rRhs ); + bool operator==( const const_iterator &rRhs ); + bool operator!=( const iterator &rRhs ); + bool operator!=( const const_iterator &rRhs ); + + const_iterator &operator=( iterator &rRhs ); + const_iterator &operator=( const_iterator &rRhs ); + + private: + const Blob *pBlob; + int32_t iIndex; + bool bForward; + }; + + iterator begin(); + const_iterator begin() const; + iterator end(); + const_iterator end() const; + iterator rbegin(); + const_iterator rbegin() const; + iterator rend(); + const_iterator rend() const; + + private: + char *pData; + int32_t iSize; + }; +} + +#endif + -- cgit v1.2.3