2008-04-29 12:55:25 +00:00
|
|
|
#include <qpdf/QPDF_Array.hh>
|
2018-02-16 22:25:27 +00:00
|
|
|
#include <qpdf/QUtil.hh>
|
2019-06-21 03:35:23 +00:00
|
|
|
#include <qpdf/QIntC.hh>
|
2009-09-26 18:36:04 +00:00
|
|
|
#include <stdexcept>
|
2008-04-29 12:55:25 +00:00
|
|
|
|
2019-08-17 23:01:32 +00:00
|
|
|
QPDF_Array::QPDF_Array(std::vector<QPDFObjectHandle> const& v)
|
2008-04-29 12:55:25 +00:00
|
|
|
{
|
2019-08-17 23:01:32 +00:00
|
|
|
setFromVector(v);
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
|
2019-08-18 02:13:37 +00:00
|
|
|
QPDF_Array::QPDF_Array(SparseOHArray const& items) :
|
|
|
|
elements(items)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-04-29 12:55:25 +00:00
|
|
|
QPDF_Array::~QPDF_Array()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-06-06 13:32:08 +00:00
|
|
|
void
|
|
|
|
QPDF_Array::releaseResolved()
|
|
|
|
{
|
2019-08-18 02:13:37 +00:00
|
|
|
this->elements.releaseResolved();
|
2010-06-06 13:32:08 +00:00
|
|
|
}
|
|
|
|
|
2008-04-29 12:55:25 +00:00
|
|
|
std::string
|
|
|
|
QPDF_Array::unparse()
|
|
|
|
{
|
|
|
|
std::string result = "[ ";
|
2019-08-18 02:13:37 +00:00
|
|
|
size_t size = this->elements.size();
|
2019-08-17 23:01:32 +00:00
|
|
|
for (size_t i = 0; i < size; ++i)
|
2008-04-29 12:55:25 +00:00
|
|
|
{
|
2019-08-18 02:13:37 +00:00
|
|
|
result += this->elements.at(i).unparse();
|
2008-04-29 12:55:25 +00:00
|
|
|
result += " ";
|
|
|
|
}
|
|
|
|
result += "]";
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-12-17 22:40:29 +00:00
|
|
|
JSON
|
|
|
|
QPDF_Array::getJSON()
|
|
|
|
{
|
|
|
|
JSON j = JSON::makeArray();
|
2019-08-18 02:13:37 +00:00
|
|
|
size_t size = this->elements.size();
|
2019-08-17 23:01:32 +00:00
|
|
|
for (size_t i = 0; i < size; ++i)
|
2018-12-17 22:40:29 +00:00
|
|
|
{
|
2019-08-18 02:13:37 +00:00
|
|
|
j.addArrayElement(this->elements.at(i).getJSON());
|
2018-12-17 22:40:29 +00:00
|
|
|
}
|
|
|
|
return j;
|
|
|
|
}
|
|
|
|
|
2013-01-22 14:57:07 +00:00
|
|
|
QPDFObject::object_type_e
|
|
|
|
QPDF_Array::getTypeCode() const
|
|
|
|
{
|
|
|
|
return QPDFObject::ot_array;
|
|
|
|
}
|
|
|
|
|
|
|
|
char const*
|
|
|
|
QPDF_Array::getTypeName() const
|
|
|
|
{
|
|
|
|
return "array";
|
|
|
|
}
|
|
|
|
|
2018-02-16 22:25:27 +00:00
|
|
|
void
|
|
|
|
QPDF_Array::setDescription(QPDF* qpdf, std::string const& description)
|
|
|
|
{
|
|
|
|
this->QPDFObject::setDescription(qpdf, description);
|
|
|
|
}
|
|
|
|
|
2008-04-29 12:55:25 +00:00
|
|
|
int
|
|
|
|
QPDF_Array::getNItems() const
|
|
|
|
{
|
2019-06-21 03:35:23 +00:00
|
|
|
// This should really return a size_t, but changing it would break
|
|
|
|
// a lot of code.
|
2019-08-18 02:13:37 +00:00
|
|
|
return QIntC::to_int(this->elements.size());
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPDFObjectHandle
|
|
|
|
QPDF_Array::getItem(int n) const
|
|
|
|
{
|
2019-08-18 02:13:37 +00:00
|
|
|
if ((n < 0) || (n >= QIntC::to_int(elements.size())))
|
2008-04-29 12:55:25 +00:00
|
|
|
{
|
2009-09-26 18:36:04 +00:00
|
|
|
throw std::logic_error(
|
2012-06-20 11:36:47 +00:00
|
|
|
"INTERNAL ERROR: bounds error accessing QPDF_Array element");
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
2019-08-18 02:13:37 +00:00
|
|
|
return this->elements.at(QIntC::to_size(n));
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
|
2019-08-17 23:01:32 +00:00
|
|
|
void
|
|
|
|
QPDF_Array::getAsVector(std::vector<QPDFObjectHandle>& v) const
|
2011-08-10 17:33:58 +00:00
|
|
|
{
|
2019-08-18 02:13:37 +00:00
|
|
|
size_t size = this->elements.size();
|
2019-08-17 23:01:32 +00:00
|
|
|
for (size_t i = 0; i < size; ++i)
|
|
|
|
{
|
2019-08-18 02:13:37 +00:00
|
|
|
v.push_back(this->elements.at(i));
|
2019-08-17 23:01:32 +00:00
|
|
|
}
|
2011-08-10 17:33:58 +00:00
|
|
|
}
|
|
|
|
|
2008-04-29 12:55:25 +00:00
|
|
|
void
|
|
|
|
QPDF_Array::setItem(int n, QPDFObjectHandle const& oh)
|
|
|
|
{
|
2019-08-18 02:13:37 +00:00
|
|
|
this->elements.setAt(QIntC::to_size(n), oh);
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
2012-06-18 20:38:59 +00:00
|
|
|
|
|
|
|
void
|
2019-08-17 23:01:32 +00:00
|
|
|
QPDF_Array::setFromVector(std::vector<QPDFObjectHandle> const& v)
|
2012-06-18 20:38:59 +00:00
|
|
|
{
|
2019-08-18 02:13:37 +00:00
|
|
|
this->elements = SparseOHArray();
|
2019-08-17 23:01:32 +00:00
|
|
|
for (std::vector<QPDFObjectHandle>::const_iterator iter = v.begin();
|
|
|
|
iter != v.end(); ++iter)
|
|
|
|
{
|
2019-08-18 02:13:37 +00:00
|
|
|
this->elements.append(*iter);
|
2019-08-17 23:01:32 +00:00
|
|
|
}
|
2012-06-18 20:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
QPDF_Array::insertItem(int at, QPDFObjectHandle const& item)
|
|
|
|
{
|
|
|
|
// As special case, also allow insert beyond the end
|
2019-08-18 02:13:37 +00:00
|
|
|
if ((at < 0) || (at > QIntC::to_int(this->elements.size())))
|
2012-06-18 20:38:59 +00:00
|
|
|
{
|
|
|
|
throw std::logic_error(
|
|
|
|
"INTERNAL ERROR: bounds error accessing QPDF_Array element");
|
|
|
|
}
|
2019-08-18 02:13:37 +00:00
|
|
|
this->elements.insert(QIntC::to_size(at), item);
|
2012-06-18 20:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
QPDF_Array::appendItem(QPDFObjectHandle const& item)
|
|
|
|
{
|
2019-08-18 02:13:37 +00:00
|
|
|
this->elements.append(item);
|
2012-06-18 20:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
QPDF_Array::eraseItem(int at)
|
|
|
|
{
|
2019-08-18 02:13:37 +00:00
|
|
|
this->elements.erase(QIntC::to_size(at));
|
2012-06-18 20:38:59 +00:00
|
|
|
}
|