aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/QPDFObjectHandle.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-04-30 02:09:10 +0200
committerJay Berkenbilt <ejb@ql.org>2022-04-30 02:09:10 +0200
commite80fad86e95af978ada2a6cc5c4b209a1f65f7c0 (patch)
treeda7c15233d63e22789350e2fde12086e14f00730 /libqpdf/QPDFObjectHandle.cc
parentff73d71ec8cfd5915a711e1b071ee183515705bd (diff)
downloadqpdf-e80fad86e95af978ada2a6cc5c4b209a1f65f7c0.tar.zst
Add new QPDFObjectHandle methods for more fluent programming
Diffstat (limited to 'libqpdf/QPDFObjectHandle.cc')
-rw-r--r--libqpdf/QPDFObjectHandle.cc59
1 files changed, 54 insertions, 5 deletions
diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc
index 297221df..68849f46 100644
--- a/libqpdf/QPDFObjectHandle.cc
+++ b/libqpdf/QPDFObjectHandle.cc
@@ -959,7 +959,7 @@ QPDFObjectHandle::setArrayFromVector(std::vector<QPDFObjectHandle> const& items)
}
}
-void
+QPDFObjectHandle&
QPDFObjectHandle::insertItem(int at, QPDFObjectHandle const& item)
{
if (isArray()) {
@@ -968,9 +968,17 @@ QPDFObjectHandle::insertItem(int at, QPDFObjectHandle const& item)
typeWarning("array", "ignoring attempt to insert item");
QTC::TC("qpdf", "QPDFObjectHandle array ignoring insert item");
}
+ return *this;
}
-void
+QPDFObjectHandle
+QPDFObjectHandle::insertItemAndGet(int at, QPDFObjectHandle const& item)
+{
+ insertItem(at, item);
+ return item;
+}
+
+QPDFObjectHandle&
QPDFObjectHandle::appendItem(QPDFObjectHandle const& item)
{
if (isArray()) {
@@ -980,9 +988,17 @@ QPDFObjectHandle::appendItem(QPDFObjectHandle const& item)
typeWarning("array", "ignoring attempt to append item");
QTC::TC("qpdf", "QPDFObjectHandle array ignoring append item");
}
+ return *this;
}
-void
+QPDFObjectHandle
+QPDFObjectHandle::appendItemAndGet(QPDFObjectHandle const& item)
+{
+ appendItem(item);
+ return item;
+}
+
+QPDFObjectHandle&
QPDFObjectHandle::eraseItem(int at)
{
if (isArray() && (at < getArrayNItems()) && (at >= 0)) {
@@ -996,6 +1012,18 @@ QPDFObjectHandle::eraseItem(int at)
QTC::TC("qpdf", "QPDFObjectHandle array ignoring erase item");
}
}
+ return *this;
+}
+
+QPDFObjectHandle
+QPDFObjectHandle::eraseItemAndGet(int at)
+{
+ auto result = QPDFObjectHandle::newNull();
+ if (isArray() && (at < getArrayNItems()) && (at >= 0)) {
+ result = getArrayItem(at);
+ }
+ eraseItem(at);
+ return result;
}
// Dictionary accessors
@@ -1267,7 +1295,7 @@ QPDFObjectHandle::getOwningQPDF()
// Dictionary mutators
-void
+QPDFObjectHandle&
QPDFObjectHandle::replaceKey(
std::string const& key, QPDFObjectHandle const& value)
{
@@ -1278,9 +1306,18 @@ QPDFObjectHandle::replaceKey(
typeWarning("dictionary", "ignoring key replacement request");
QTC::TC("qpdf", "QPDFObjectHandle dictionary ignoring replaceKey");
}
+ return *this;
}
-void
+QPDFObjectHandle
+QPDFObjectHandle::replaceKeyAndGet(
+ std::string const& key, QPDFObjectHandle const& value)
+{
+ replaceKey(key, value);
+ return value;
+}
+
+QPDFObjectHandle&
QPDFObjectHandle::removeKey(std::string const& key)
{
if (isDictionary()) {
@@ -1289,6 +1326,18 @@ QPDFObjectHandle::removeKey(std::string const& key)
typeWarning("dictionary", "ignoring key removal request");
QTC::TC("qpdf", "QPDFObjectHandle dictionary ignoring removeKey");
}
+ return *this;
+}
+
+QPDFObjectHandle
+QPDFObjectHandle::removeKeyAndGet(std::string const& key)
+{
+ auto result = QPDFObjectHandle::newNull();
+ if (isDictionary()) {
+ result = getKey(key);
+ }
+ removeKey(key);
+ return result;
}
void