2008-04-29 12:55:25 +00:00
|
|
|
#include <qpdf/QPDF_Array.hh>
|
2022-02-04 21:31:31 +00:00
|
|
|
|
2019-06-21 03:35:23 +00:00
|
|
|
#include <qpdf/QIntC.hh>
|
2022-04-02 21:14:10 +00:00
|
|
|
#include <qpdf/QUtil.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)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-06-16 16:45:04 +00:00
|
|
|
std::shared_ptr<QPDFObject>
|
|
|
|
QPDF_Array::create(std::vector<QPDFObjectHandle> const& items)
|
|
|
|
{
|
|
|
|
return do_create(new QPDF_Array(items));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<QPDFObject>
|
|
|
|
QPDF_Array::create(SparseOHArray const& items)
|
|
|
|
{
|
|
|
|
return do_create(new QPDF_Array(items));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<QPDFObject>
|
|
|
|
QPDF_Array::shallowCopy()
|
|
|
|
{
|
|
|
|
return create(elements);
|
|
|
|
}
|
|
|
|
|
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();
|
2022-04-02 21:14:10 +00:00
|
|
|
for (size_t i = 0; i < size; ++i) {
|
2022-02-08 14:18:08 +00:00
|
|
|
result += this->elements.at(i).unparse();
|
|
|
|
result += " ";
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
result += "]";
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-12-17 22:40:29 +00:00
|
|
|
JSON
|
2022-05-07 11:53:45 +00:00
|
|
|
QPDF_Array::getJSON(int json_version)
|
2018-12-17 22:40:29 +00:00
|
|
|
{
|
|
|
|
JSON j = JSON::makeArray();
|
2019-08-18 02:13:37 +00:00
|
|
|
size_t size = this->elements.size();
|
2022-04-02 21:14:10 +00:00
|
|
|
for (size_t i = 0; i < size; ++i) {
|
2022-05-07 11:53:45 +00:00
|
|
|
j.addArrayElement(this->elements.at(i).getJSON(json_version));
|
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";
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
{
|
2022-04-02 21:14:10 +00:00
|
|
|
if ((n < 0) || (n >= QIntC::to_int(elements.size()))) {
|
2022-02-08 14:18:08 +00:00
|
|
|
throw std::logic_error(
|
|
|
|
"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();
|
2022-04-02 21:14:10 +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();
|
2022-04-30 17:23:18 +00:00
|
|
|
for (auto const& iter: v) {
|
|
|
|
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
|
2022-04-02 21:14:10 +00:00
|
|
|
if ((at < 0) || (at > QIntC::to_int(this->elements.size()))) {
|
2022-02-08 14:18:08 +00:00
|
|
|
throw std::logic_error(
|
|
|
|
"INTERNAL ERROR: bounds error accessing QPDF_Array element");
|
2012-06-18 20:38:59 +00:00
|
|
|
}
|
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
|
|
|
}
|
2019-08-18 02:27:55 +00:00
|
|
|
|
2019-08-18 02:28:19 +00:00
|
|
|
void
|
|
|
|
QPDF_Array::addExplicitElementsToList(std::list<QPDFObjectHandle>& l) const
|
|
|
|
{
|
2022-04-30 13:43:07 +00:00
|
|
|
for (auto const& iter: this->elements) {
|
2020-04-09 00:14:04 +00:00
|
|
|
l.push_back(iter.second);
|
2019-08-18 02:28:19 +00:00
|
|
|
}
|
|
|
|
}
|