Modified BDataBuffer's copy constructor to let the user specify whether to create a copy of the buffer or just a reference. Also changed all void* params to be const.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8888 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
ejakowatz 2004-09-07 23:00:30 +00:00
parent 9fa0302ad0
commit e4265bfbfe
2 changed files with 22 additions and 10 deletions

View File

@ -25,8 +25,8 @@ class BDataBuffer
{
public:
BDataBuffer(size_t len);
BDataBuffer(void* data, size_t len, bool copy = false);
BDataBuffer(const BDataBuffer& rhs);
BDataBuffer(const void* data, size_t len, bool copy = false);
BDataBuffer(const BDataBuffer& rhs, bool copy = false);
~BDataBuffer();
BDataBuffer& operator=(const BDataBuffer& rhs);
@ -45,12 +45,12 @@ class BDataBuffer
size_t Size() const { return fSize; }
int32 Count() { return fCount; }
static void Create(void* data, size_t len, BDataReference*& ref,
bool copy = false);
static void Create(const void* data, size_t len,
BDataReference*& ref, bool copy = false);
static void Create(size_t len, BDataReference*& ref);
private:
BDataReference(void* data, size_t len, bool copy = false);
BDataReference(const void* data, size_t len, bool copy = false);
BDataReference(size_t len);
~BDataReference();

View File

@ -49,14 +49,25 @@ BDataBuffer::BDataBuffer(size_t len)
BDataReference::Create(len, fDataRef);
}
//------------------------------------------------------------------------------
BDataBuffer::BDataBuffer(void* data, size_t len, bool copy)
BDataBuffer::BDataBuffer(const void* data, size_t len, bool copy)
{
BDataReference::Create(data, len, fDataRef, copy);
}
//------------------------------------------------------------------------------
BDataBuffer::BDataBuffer(const BDataBuffer& rhs)
BDataBuffer::BDataBuffer(const BDataBuffer& rhs, bool copy)
{
*this = rhs;
if (this != &rhs)
{
if (copy)
{
BDataReference::Create(rhs.Buffer(), rhs.BufferSize(),
fDataRef, copy);
}
else
{
rhs.fDataRef->Acquire(fDataRef);
}
}
}
//------------------------------------------------------------------------------
BDataBuffer::~BDataBuffer()
@ -90,7 +101,7 @@ const void* BDataBuffer::Buffer() const
//------------------------------------------------------------------------------
void BDataBuffer::BDataReference::Create(void* data, size_t len,
void BDataBuffer::BDataReference::Create(const void* data, size_t len,
BDataReference*& ref, bool copy)
{
BDataReference* temp = new BDataReference(data, len, copy);
@ -119,7 +130,8 @@ void BDataBuffer::BDataReference::Release(BDataReference*& ref)
}
}
//------------------------------------------------------------------------------
BDataBuffer::BDataReference::BDataReference(void* data, size_t len, bool copy)
BDataBuffer::BDataReference::BDataReference(const void* data, size_t len,
bool copy)
: fData(NULL), fSize(len), fCount(0)
{
if (copy)