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;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
QPDF_Array::getNItems() const
|
|
|
|
{
|
2012-06-20 15:20:57 +00:00
|
|
|
return (int)this->items.size();
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPDFObjectHandle
|
|
|
|
QPDF_Array::getItem(int n) const
|
|
|
|
{
|
|
|
|
if ((n < 0) || (n >= (int)this->items.size()))
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
return this->items[n];
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
this->items[n] = oh;
|
|
|
|
}
|
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
|
|
|
|
if ((at < 0) || (at > (int)this->items.size()))
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|