mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-23 11:28:56 +00:00
9f444ffef3
git-svn-id: svn+q:///qpdf/trunk@1034 71b93d88-0707-0410-a8cf-f5a4172ac649
95 lines
1.2 KiB
C++
95 lines
1.2 KiB
C++
#include <qpdf/Buffer.hh>
|
|
|
|
#include <string.h>
|
|
|
|
Buffer::Buffer()
|
|
{
|
|
init(0, 0, true);
|
|
}
|
|
|
|
Buffer::Buffer(unsigned long size)
|
|
{
|
|
init(size, 0, true);
|
|
}
|
|
|
|
Buffer::Buffer(unsigned char* buf, unsigned long size)
|
|
{
|
|
init(size, buf, false);
|
|
}
|
|
|
|
Buffer::Buffer(Buffer const& rhs)
|
|
{
|
|
init(0, 0, true);
|
|
copy(rhs);
|
|
}
|
|
|
|
Buffer&
|
|
Buffer::operator=(Buffer const& rhs)
|
|
{
|
|
copy(rhs);
|
|
return *this;
|
|
}
|
|
|
|
Buffer::~Buffer()
|
|
{
|
|
destroy();
|
|
}
|
|
|
|
void
|
|
Buffer::init(unsigned long size, unsigned char* buf, bool own_memory)
|
|
{
|
|
this->own_memory = own_memory;
|
|
this->size = size;
|
|
if (own_memory)
|
|
{
|
|
this->buf = (size ? new unsigned char[size] : 0);
|
|
}
|
|
else
|
|
{
|
|
this->buf = buf;
|
|
}
|
|
}
|
|
|
|
void
|
|
Buffer::copy(Buffer const& rhs)
|
|
{
|
|
if (this != &rhs)
|
|
{
|
|
this->destroy();
|
|
this->init(rhs.size, 0, true);
|
|
if (this->size)
|
|
{
|
|
memcpy(this->buf, rhs.buf, this->size);
|
|
}
|
|
}
|
|
}
|
|
|
|
void
|
|
Buffer::destroy()
|
|
{
|
|
if (this->own_memory)
|
|
{
|
|
delete [] this->buf;
|
|
}
|
|
this->size = 0;
|
|
this->buf = 0;
|
|
}
|
|
|
|
unsigned long
|
|
Buffer::getSize() const
|
|
{
|
|
return this->size;
|
|
}
|
|
|
|
unsigned char const*
|
|
Buffer::getBuffer() const
|
|
{
|
|
return this->buf;
|
|
}
|
|
|
|
unsigned char*
|
|
Buffer::getBuffer()
|
|
{
|
|
return this->buf;
|
|
}
|