From db7474e0facd82577edfc1cc4883bce3fa588584 Mon Sep 17 00:00:00 2001 From: Tobias Hoffmann Date: Mon, 18 Jun 2012 22:38:59 +0200 Subject: Added additional array mutators Added methods to append to arrays, insert items into arrays, and replace array contents with a vector of items. --- libqpdf/QPDF_Array.cc | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'libqpdf/QPDF_Array.cc') diff --git a/libqpdf/QPDF_Array.cc b/libqpdf/QPDF_Array.cc index 91e34eec..9f720287 100644 --- a/libqpdf/QPDF_Array.cc +++ b/libqpdf/QPDF_Array.cc @@ -64,3 +64,35 @@ QPDF_Array::setItem(int n, QPDFObjectHandle const& oh) (void) getItem(n); this->items[n] = oh; } + +void +QPDF_Array::setFromVector(std::vector 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); +} -- cgit v1.2.3-54-g00ecf