2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-23 03:18:59 +00:00
qpdf/libqpdf/Buffer.cc
Jay Berkenbilt cb769c62e5 WHITESPACE ONLY -- expand tabs in source code
This comment expands all tabs using an 8-character tab-width. You
should ignore this commit when using git blame or use git blame -w.

In the early days, I used to use tabs where possible for indentation,
since emacs did this automatically. In recent years, I have switched
to only using spaces, which means qpdf source code has been a mixture
of spaces and tabs. I have avoided cleaning this up because of not
wanting gratuitous whitespaces change to cloud the output of git
blame, but I changed my mind after discussing with users who view qpdf
source code in editors/IDEs that have other tab widths by default and
in light of the fact that I am planning to start applying automatic
code formatting soon.
2022-02-08 11:51:15 -05:00

85 lines
1.2 KiB
C++

#include <qpdf/Buffer.hh>
#include <cstring>
Buffer::Members::Members(size_t size, unsigned char* buf, bool own_memory) :
own_memory(own_memory),
size(size),
buf(0)
{
if (own_memory)
{
this->buf = (size ? new unsigned char[size] : 0);
}
else
{
this->buf = buf;
}
}
Buffer::Members::~Members()
{
if (this->own_memory)
{
delete [] this->buf;
}
}
Buffer::Buffer() :
m(new Members(0, 0, true))
{
}
Buffer::Buffer(size_t size) :
m(new Members(size, 0, true))
{
}
Buffer::Buffer(unsigned char* buf, size_t size) :
m(new Members(size, buf, false))
{
}
Buffer::Buffer(Buffer const& rhs)
{
copy(rhs);
}
Buffer&
Buffer::operator=(Buffer const& rhs)
{
copy(rhs);
return *this;
}
void
Buffer::copy(Buffer const& rhs)
{
if (this != &rhs)
{
this->m = PointerHolder<Members>(new Members(rhs.m->size, 0, true));
if (this->m->size)
{
memcpy(this->m->buf, rhs.m->buf, this->m->size);
}
}
}
size_t
Buffer::getSize() const
{
return this->m->size;
}
unsigned char const*
Buffer::getBuffer() const
{
return this->m->buf;
}
unsigned char*
Buffer::getBuffer()
{
return this->m->buf;
}