mirror of
https://github.com/qpdf/qpdf.git
synced 2024-11-10 23:20:58 +00:00
cb769c62e5
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.
155 lines
3.0 KiB
C++
155 lines
3.0 KiB
C++
#include <qpdf/QPDF_Array.hh>
|
|
|
|
#include <qpdf/QUtil.hh>
|
|
#include <qpdf/QIntC.hh>
|
|
#include <stdexcept>
|
|
|
|
QPDF_Array::QPDF_Array(std::vector<QPDFObjectHandle> const& v)
|
|
{
|
|
setFromVector(v);
|
|
}
|
|
|
|
QPDF_Array::QPDF_Array(SparseOHArray const& items) :
|
|
elements(items)
|
|
{
|
|
}
|
|
|
|
QPDF_Array::~QPDF_Array()
|
|
{
|
|
}
|
|
|
|
void
|
|
QPDF_Array::releaseResolved()
|
|
{
|
|
this->elements.releaseResolved();
|
|
}
|
|
|
|
std::string
|
|
QPDF_Array::unparse()
|
|
{
|
|
std::string result = "[ ";
|
|
size_t size = this->elements.size();
|
|
for (size_t i = 0; i < size; ++i)
|
|
{
|
|
result += this->elements.at(i).unparse();
|
|
result += " ";
|
|
}
|
|
result += "]";
|
|
return result;
|
|
}
|
|
|
|
JSON
|
|
QPDF_Array::getJSON()
|
|
{
|
|
JSON j = JSON::makeArray();
|
|
size_t size = this->elements.size();
|
|
for (size_t i = 0; i < size; ++i)
|
|
{
|
|
j.addArrayElement(this->elements.at(i).getJSON());
|
|
}
|
|
return j;
|
|
}
|
|
|
|
QPDFObject::object_type_e
|
|
QPDF_Array::getTypeCode() const
|
|
{
|
|
return QPDFObject::ot_array;
|
|
}
|
|
|
|
char const*
|
|
QPDF_Array::getTypeName() const
|
|
{
|
|
return "array";
|
|
}
|
|
|
|
void
|
|
QPDF_Array::setDescription(QPDF* qpdf, std::string const& description)
|
|
{
|
|
this->QPDFObject::setDescription(qpdf, description);
|
|
}
|
|
|
|
int
|
|
QPDF_Array::getNItems() const
|
|
{
|
|
// This should really return a size_t, but changing it would break
|
|
// a lot of code.
|
|
return QIntC::to_int(this->elements.size());
|
|
}
|
|
|
|
QPDFObjectHandle
|
|
QPDF_Array::getItem(int n) const
|
|
{
|
|
if ((n < 0) || (n >= QIntC::to_int(elements.size())))
|
|
{
|
|
throw std::logic_error(
|
|
"INTERNAL ERROR: bounds error accessing QPDF_Array element");
|
|
}
|
|
return this->elements.at(QIntC::to_size(n));
|
|
}
|
|
|
|
void
|
|
QPDF_Array::getAsVector(std::vector<QPDFObjectHandle>& v) const
|
|
{
|
|
size_t size = this->elements.size();
|
|
for (size_t i = 0; i < size; ++i)
|
|
{
|
|
v.push_back(this->elements.at(i));
|
|
}
|
|
}
|
|
|
|
void
|
|
QPDF_Array::setItem(int n, QPDFObjectHandle const& oh)
|
|
{
|
|
this->elements.setAt(QIntC::to_size(n), oh);
|
|
}
|
|
|
|
void
|
|
QPDF_Array::setFromVector(std::vector<QPDFObjectHandle> const& v)
|
|
{
|
|
this->elements = SparseOHArray();
|
|
for (std::vector<QPDFObjectHandle>::const_iterator iter = v.begin();
|
|
iter != v.end(); ++iter)
|
|
{
|
|
this->elements.append(*iter);
|
|
}
|
|
}
|
|
|
|
void
|
|
QPDF_Array::insertItem(int at, QPDFObjectHandle const& item)
|
|
{
|
|
// As special case, also allow insert beyond the end
|
|
if ((at < 0) || (at > QIntC::to_int(this->elements.size())))
|
|
{
|
|
throw std::logic_error(
|
|
"INTERNAL ERROR: bounds error accessing QPDF_Array element");
|
|
}
|
|
this->elements.insert(QIntC::to_size(at), item);
|
|
}
|
|
|
|
void
|
|
QPDF_Array::appendItem(QPDFObjectHandle const& item)
|
|
{
|
|
this->elements.append(item);
|
|
}
|
|
|
|
void
|
|
QPDF_Array::eraseItem(int at)
|
|
{
|
|
this->elements.erase(QIntC::to_size(at));
|
|
}
|
|
|
|
SparseOHArray const&
|
|
QPDF_Array::getElementsForShallowCopy() const
|
|
{
|
|
return this->elements;
|
|
}
|
|
|
|
void
|
|
QPDF_Array::addExplicitElementsToList(std::list<QPDFObjectHandle>& l) const
|
|
{
|
|
for (auto const& iter: this->elements)
|
|
{
|
|
l.push_back(iter.second);
|
|
}
|
|
}
|