2008-04-29 12:55:25 +00:00
|
|
|
#include <qpdf/QPDF_Array.hh>
|
2009-09-26 18:36:04 +00:00
|
|
|
#include <stdexcept>
|
2008-04-29 12:55:25 +00:00
|
|
|
|
|
|
|
QPDF_Array::QPDF_Array(std::vector<QPDFObjectHandle> const& items) :
|
|
|
|
items(items)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_Array::~QPDF_Array()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-06-06 13:32:08 +00:00
|
|
|
void
|
|
|
|
QPDF_Array::releaseResolved()
|
|
|
|
{
|
|
|
|
for (std::vector<QPDFObjectHandle>::iterator iter = this->items.begin();
|
|
|
|
iter != this->items.end(); ++iter)
|
|
|
|
{
|
|
|
|
QPDFObjectHandle::ReleaseResolver::releaseResolved(*iter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-29 12:55:25 +00:00
|
|
|
std::string
|
|
|
|
QPDF_Array::unparse()
|
|
|
|
{
|
|
|
|
std::string result = "[ ";
|
|
|
|
for (std::vector<QPDFObjectHandle>::iterator iter = this->items.begin();
|
|
|
|
iter != this->items.end(); ++iter)
|
|
|
|
{
|
|
|
|
result += (*iter).unparse();
|
|
|
|
result += " ";
|
|
|
|
}
|
|
|
|
result += "]";
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
{
|
2013-02-24 02:46:21 +00:00
|
|
|
return this->items.size();
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPDFObjectHandle
|
|
|
|
QPDF_Array::getItem(int n) const
|
|
|
|
{
|
2013-02-24 02:46:21 +00:00
|
|
|
if ((n < 0) || (n >= static_cast<int>(this->items.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
|
|
|
}
|
2013-10-05 23:42:39 +00:00
|
|
|
return this->items.at(n);
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
|
2011-08-10 17:33:58 +00:00
|
|
|
std::vector<QPDFObjectHandle> const&
|
|
|
|
QPDF_Array::getAsVector() const
|
|
|
|
{
|
|
|
|
return this->items;
|
|
|
|
}
|
|
|
|
|
2008-04-29 12:55:25 +00:00
|
|
|
void
|
|
|
|
QPDF_Array::setItem(int n, QPDFObjectHandle const& oh)
|
|
|
|
{
|
|
|
|
// Call getItem for bounds checking
|
|
|
|
(void) getItem(n);
|
2013-10-05 23:42:39 +00:00
|
|
|
this->items.at(n) = oh;
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
2012-06-18 20:38:59 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
QPDF_Array::setFromVector(std::vector<QPDFObjectHandle> const& items)
|
|
|
|
{
|
|
|
|
this->items = items;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
QPDF_Array::insertItem(int at, QPDFObjectHandle const& item)
|
|
|
|
{
|
|
|
|
// As special case, also allow insert beyond the end
|
2013-02-24 02:46:21 +00:00
|
|
|
if ((at < 0) || (at > static_cast<int>(this->items.size())))
|
2012-06-18 20:38:59 +00:00
|
|
|
{
|
|
|
|
throw std::logic_error(
|
|
|
|
"INTERNAL ERROR: bounds error accessing QPDF_Array element");
|
|
|
|
}
|
|
|
|
this->items.insert(this->items.begin() + at, item);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
QPDF_Array::appendItem(QPDFObjectHandle const& item)
|
|
|
|
{
|
|
|
|
this->items.push_back(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
QPDF_Array::eraseItem(int at)
|
|
|
|
{
|
|
|
|
// Call getItem for bounds checking
|
|
|
|
(void) getItem(at);
|
|
|
|
this->items.erase(this->items.begin() + at);
|
|
|
|
}
|