mirror of
https://github.com/qpdf/qpdf.git
synced 2025-01-24 07:38:28 +00:00
Added additional array mutators
Added methods to append to arrays, insert items into arrays, and replace array contents with a vector of items.
This commit is contained in:
parent
b2e6818935
commit
db7474e0fa
@ -200,6 +200,19 @@ class QPDFObjectHandle
|
|||||||
// Mutator methods for array objects
|
// Mutator methods for array objects
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
void setArrayItem(int, QPDFObjectHandle const&);
|
void setArrayItem(int, QPDFObjectHandle const&);
|
||||||
|
QPDF_DLL
|
||||||
|
void setArrayFromVector(std::vector<QPDFObjectHandle> const& items);
|
||||||
|
// Insert an item before the item at the given position ("at") so
|
||||||
|
// that it has that position after insertion. If "at" is equal to
|
||||||
|
// the size of the array, insert the item at the end.
|
||||||
|
QPDF_DLL
|
||||||
|
void insertItem(int at, QPDFObjectHandle const& item);
|
||||||
|
QPDF_DLL
|
||||||
|
void appendItem(QPDFObjectHandle const& item);
|
||||||
|
// Remove the item at that position, reducing the size of the
|
||||||
|
// array by one.
|
||||||
|
QPDF_DLL
|
||||||
|
void eraseItem(int at);
|
||||||
|
|
||||||
// Mutator methods for dictionary objects
|
// Mutator methods for dictionary objects
|
||||||
|
|
||||||
|
@ -262,6 +262,34 @@ QPDFObjectHandle::setArrayItem(int n, QPDFObjectHandle const& item)
|
|||||||
return dynamic_cast<QPDF_Array*>(obj.getPointer())->setItem(n, item);
|
return dynamic_cast<QPDF_Array*>(obj.getPointer())->setItem(n, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
QPDFObjectHandle::setArrayFromVector(std::vector<QPDFObjectHandle> const& items)
|
||||||
|
{
|
||||||
|
assertType("Array", isArray());
|
||||||
|
return dynamic_cast<QPDF_Array*>(obj.getPointer())->setFromVector(items);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
QPDFObjectHandle::insertItem(int at, QPDFObjectHandle const& item)
|
||||||
|
{
|
||||||
|
assertType("Array", isArray());
|
||||||
|
return dynamic_cast<QPDF_Array*>(obj.getPointer())->insertItem(at, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
QPDFObjectHandle::appendItem(QPDFObjectHandle const& item)
|
||||||
|
{
|
||||||
|
assertType("Array", isArray());
|
||||||
|
return dynamic_cast<QPDF_Array*>(obj.getPointer())->appendItem(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
QPDFObjectHandle::eraseItem(int at)
|
||||||
|
{
|
||||||
|
assertType("Array", isArray());
|
||||||
|
return dynamic_cast<QPDF_Array*>(obj.getPointer())->eraseItem(at);
|
||||||
|
}
|
||||||
|
|
||||||
// Dictionary accessors
|
// Dictionary accessors
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -64,3 +64,35 @@ QPDF_Array::setItem(int n, QPDFObjectHandle const& oh)
|
|||||||
(void) getItem(n);
|
(void) getItem(n);
|
||||||
this->items[n] = oh;
|
this->items[n] = oh;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
@ -12,10 +12,16 @@ class QPDF_Array: public QPDFObject
|
|||||||
QPDF_Array(std::vector<QPDFObjectHandle> const& items);
|
QPDF_Array(std::vector<QPDFObjectHandle> const& items);
|
||||||
virtual ~QPDF_Array();
|
virtual ~QPDF_Array();
|
||||||
virtual std::string unparse();
|
virtual std::string unparse();
|
||||||
|
|
||||||
int getNItems() const;
|
int getNItems() const;
|
||||||
QPDFObjectHandle getItem(int n) const;
|
QPDFObjectHandle getItem(int n) const;
|
||||||
std::vector<QPDFObjectHandle> const& getAsVector() const;
|
std::vector<QPDFObjectHandle> const& getAsVector() const;
|
||||||
|
|
||||||
void setItem(int, QPDFObjectHandle const&);
|
void setItem(int, QPDFObjectHandle const&);
|
||||||
|
void setFromVector(std::vector<QPDFObjectHandle> const& items);
|
||||||
|
void insertItem(int at, QPDFObjectHandle const& item);
|
||||||
|
void appendItem(QPDFObjectHandle const& item);
|
||||||
|
void eraseItem(int at);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void releaseResolved();
|
virtual void releaseResolved();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user