2008-04-29 12:55:25 +00:00
|
|
|
#include <qpdf/Buffer.hh>
|
|
|
|
|
2019-06-22 01:32:47 +00:00
|
|
|
#include <cstring>
|
2008-04-29 12:55:25 +00:00
|
|
|
|
2019-06-22 01:32:47 +00:00
|
|
|
Buffer::Members::Members(size_t size, unsigned char* buf, bool own_memory) :
|
|
|
|
own_memory(own_memory),
|
|
|
|
size(size),
|
|
|
|
buf(0)
|
2008-04-29 12:55:25 +00:00
|
|
|
{
|
2022-04-02 21:14:10 +00:00
|
|
|
if (own_memory) {
|
2022-02-08 14:18:08 +00:00
|
|
|
this->buf = (size ? new unsigned char[size] : 0);
|
2022-04-02 21:14:10 +00:00
|
|
|
} else {
|
2022-02-08 14:18:08 +00:00
|
|
|
this->buf = buf;
|
2019-06-22 01:32:47 +00:00
|
|
|
}
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
|
2019-06-22 01:32:47 +00:00
|
|
|
Buffer::Members::~Members()
|
2008-04-29 12:55:25 +00:00
|
|
|
{
|
2022-04-02 21:14:10 +00:00
|
|
|
if (this->own_memory) {
|
|
|
|
delete[] this->buf;
|
2019-06-22 01:32:47 +00:00
|
|
|
}
|
2010-10-01 10:20:38 +00:00
|
|
|
}
|
|
|
|
|
2019-06-22 01:32:47 +00:00
|
|
|
Buffer::Buffer() :
|
|
|
|
m(new Members(0, 0, true))
|
2010-10-01 10:20:38 +00:00
|
|
|
{
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
|
2019-06-22 01:32:47 +00:00
|
|
|
Buffer::Buffer(size_t size) :
|
|
|
|
m(new Members(size, 0, true))
|
2008-04-29 12:55:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-06-22 01:32:47 +00:00
|
|
|
Buffer::Buffer(unsigned char* buf, size_t size) :
|
|
|
|
m(new Members(size, buf, false))
|
2008-04-29 12:55:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-06-22 01:32:47 +00:00
|
|
|
Buffer::Buffer(Buffer const& rhs)
|
2008-04-29 12:55:25 +00:00
|
|
|
{
|
2019-06-22 01:32:47 +00:00
|
|
|
copy(rhs);
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
|
2019-06-22 01:32:47 +00:00
|
|
|
Buffer&
|
|
|
|
Buffer::operator=(Buffer const& rhs)
|
2008-04-29 12:55:25 +00:00
|
|
|
{
|
2019-06-22 01:32:47 +00:00
|
|
|
copy(rhs);
|
|
|
|
return *this;
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Buffer::copy(Buffer const& rhs)
|
|
|
|
{
|
2022-04-02 21:14:10 +00:00
|
|
|
if (this != &rhs) {
|
2022-04-09 18:35:56 +00:00
|
|
|
this->m = std::shared_ptr<Members>(new Members(rhs.m->size, 0, true));
|
2022-04-02 21:14:10 +00:00
|
|
|
if (this->m->size) {
|
2022-02-08 14:18:08 +00:00
|
|
|
memcpy(this->m->buf, rhs.m->buf, this->m->size);
|
|
|
|
}
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-20 15:20:57 +00:00
|
|
|
size_t
|
2008-04-29 12:55:25 +00:00
|
|
|
Buffer::getSize() const
|
|
|
|
{
|
2019-06-22 01:32:47 +00:00
|
|
|
return this->m->size;
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char const*
|
|
|
|
Buffer::getBuffer() const
|
|
|
|
{
|
2019-06-22 01:32:47 +00:00
|
|
|
return this->m->buf;
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char*
|
|
|
|
Buffer::getBuffer()
|
|
|
|
{
|
2019-06-22 01:32:47 +00:00
|
|
|
return this->m->buf;
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|