9#include <Pt/SmartPtr.h>
10#include <Pt/RefCounted.h>
21class IBlob :
public RefCounted
30 virtual void assign(
const char*
data, std::size_t len) = 0;
54 return _size == other._size &&
55 ( std::strncmp(_data, other._data, _size) == 0 );
70class BlobImpl :
public IBlob
91 if( len > this->
size() )
94 _data =
new char[len];
97 std::memcpy(_data,
data, len);
102 {
return new BlobImpl(); }
114 BlobImpl(std::size_t n)
115 { RefCounted::addRef(); }
121static struct BlobStaticInitializer
123 BlobStaticInitializer()
125 BlobImpl::emptyInstance();
127} pt_blob_static_initializer;
145 template <
typename T>
148 void destroy(T* blob)
158 : m_data(
BlobImpl::emptyInstance() )
166 m_data->assign(
data, len);
180 if ( m_data->refs() > 1 )
182 m_data.reset( m_data->create() );
185 m_data->assign(
data, len);
192 return *m_data == *b.m_data;
206 return m_data->data();
213 return m_data->size();
Default blob implementation using new and delete.
Definition Blob.h:71
virtual void assign(const char *data, std::size_t len)
Copies len bytes from data into this blob.
Definition Blob.h:81
virtual void destroy()
Destroys an instance created by create().
Definition Blob.h:104
virtual IBlob * create() const
Creates a new implementation of the same type.
Definition Blob.h:101
bool operator==(const Blob &b) const
Returns true if both blobs contain the same data.
Definition Blob.h:190
Blob()
Creates an empty blob.
Definition Blob.h:157
Blob(const char *data, std::size_t len)
Copies len bytes from data.
Definition Blob.h:163
void assign(const char *data, std::size_t len)
Replaces the bytes with len bytes from data.
Definition Blob.h:177
Blob(IBlob *b)
Takes ownership of the implementation b.
Definition Blob.h:171
const char * data() const
Returns a pointer to the data, or 0 if empty.
Definition Blob.h:204
bool operator!=(const Blob &b) const
Returns true if the blobs do not contain the same data.
Definition Blob.h:197
std::size_t size() const
Returns the size of the data.
Definition Blob.h:211
Shared implementation of blob data.
Definition Blob.h:22
virtual ~IBlob()
Destructor.
Definition Blob.h:26
virtual void assign(const char *data, std::size_t len)=0
Copies len bytes from data into this blob.
const char * data() const
Returns a pointer to the blob data, or 0 if empty.
Definition Blob.h:47
std::size_t size() const
Returns the size of the blob data.
Definition Blob.h:42
virtual IBlob * create() const =0
Creates a new implementation of the same type.
bool operator==(const IBlob &other) const
Returns true if both instances contain the same data.
Definition Blob.h:52
virtual void destroy()=0
Destroys an instance created by create().
Policy based smart pointer.
Definition SmartPtr.h:462
Portable SQL database access.
Core module.
Definition Allocator.h:33