2008-04-29 12:55:25 +00:00
|
|
|
#include <qpdf/Buffer.hh>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
Buffer::Buffer()
|
|
|
|
{
|
2010-10-01 10:20:38 +00:00
|
|
|
init(0, 0, true);
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
|
2012-06-20 15:20:57 +00:00
|
|
|
Buffer::Buffer(size_t size)
|
2008-04-29 12:55:25 +00:00
|
|
|
{
|
2010-10-01 10:20:38 +00:00
|
|
|
init(size, 0, true);
|
|
|
|
}
|
|
|
|
|
2012-06-20 15:20:57 +00:00
|
|
|
Buffer::Buffer(unsigned char* buf, size_t size)
|
2010-10-01 10:20:38 +00:00
|
|
|
{
|
|
|
|
init(size, buf, false);
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Buffer::Buffer(Buffer const& rhs)
|
|
|
|
{
|
2010-10-01 10:20:38 +00:00
|
|
|
init(0, 0, true);
|
2008-04-29 12:55:25 +00:00
|
|
|
copy(rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
Buffer&
|
|
|
|
Buffer::operator=(Buffer const& rhs)
|
|
|
|
{
|
|
|
|
copy(rhs);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
Buffer::~Buffer()
|
|
|
|
{
|
|
|
|
destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-06-20 15:20:57 +00:00
|
|
|
Buffer::init(size_t size, unsigned char* buf, bool own_memory)
|
2008-04-29 12:55:25 +00:00
|
|
|
{
|
2010-10-01 10:20:38 +00:00
|
|
|
this->own_memory = own_memory;
|
2008-04-29 12:55:25 +00:00
|
|
|
this->size = size;
|
2010-10-01 10:20:38 +00:00
|
|
|
if (own_memory)
|
|
|
|
{
|
|
|
|
this->buf = (size ? new unsigned char[size] : 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->buf = buf;
|
|
|
|
}
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Buffer::copy(Buffer const& rhs)
|
|
|
|
{
|
|
|
|
if (this != &rhs)
|
|
|
|
{
|
|
|
|
this->destroy();
|
2010-10-01 10:20:38 +00:00
|
|
|
this->init(rhs.size, 0, true);
|
2008-04-29 12:55:25 +00:00
|
|
|
if (this->size)
|
|
|
|
{
|
|
|
|
memcpy(this->buf, rhs.buf, this->size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Buffer::destroy()
|
|
|
|
{
|
2010-10-01 10:20:38 +00:00
|
|
|
if (this->own_memory)
|
|
|
|
{
|
|
|
|
delete [] this->buf;
|
|
|
|
}
|
2008-04-29 12:55:25 +00:00
|
|
|
this->size = 0;
|
|
|
|
this->buf = 0;
|
|
|
|
}
|
|
|
|
|
2012-06-20 15:20:57 +00:00
|
|
|
size_t
|
2008-04-29 12:55:25 +00:00
|
|
|
Buffer::getSize() const
|
|
|
|
{
|
|
|
|
return this->size;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char const*
|
|
|
|
Buffer::getBuffer() const
|
|
|
|
{
|
|
|
|
return this->buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char*
|
|
|
|
Buffer::getBuffer()
|
|
|
|
{
|
|
|
|
return this->buf;
|
|
|
|
}
|