aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/QPDF_Array.cc
diff options
context:
space:
mode:
authorm-holger <m-holger@kubitscheck.org>2022-11-17 18:35:13 +0100
committerm-holger <m-holger@kubitscheck.org>2023-04-01 14:54:44 +0200
commitc6179da9615057a14e74180f640e2e77fdcbf234 (patch)
treead9b30de5571cf75efd29bfb86c21bab030c0c1f /libqpdf/QPDF_Array.cc
parenta1a8f35b63bcad7e0cac31a205e109d6a0d70622 (diff)
downloadqpdf-c6179da9615057a14e74180f640e2e77fdcbf234.tar.zst
Add new method QPDFValue::checkOwnership
Diffstat (limited to 'libqpdf/QPDF_Array.cc')
-rw-r--r--libqpdf/QPDF_Array.cc20
1 files changed, 20 insertions, 0 deletions
diff --git a/libqpdf/QPDF_Array.cc b/libqpdf/QPDF_Array.cc
index e9d216a5..def40e9b 100644
--- a/libqpdf/QPDF_Array.cc
+++ b/libqpdf/QPDF_Array.cc
@@ -7,6 +7,26 @@
static const QPDFObjectHandle null_oh = QPDFObjectHandle::newNull();
+inline void
+QPDF_Array::checkOwnership(QPDFObjectHandle const& item) const
+{
+ if (auto obj = item.getObjectPtr()) {
+ if (qpdf) {
+ if (auto item_qpdf = obj->getQPDF()) {
+ if (qpdf != item_qpdf) {
+ throw std::logic_error(
+ "Attempting to add an object from a different QPDF. "
+ "Use QPDF::copyForeignObject to add objects from "
+ "another file.");
+ }
+ }
+ }
+ } else {
+ throw std::logic_error(
+ "Attempting to add an uninitialized object to a QPDF_Array.");
+ }
+}
+
QPDF_Array::QPDF_Array(std::vector<QPDFObjectHandle> const& v) :
QPDFValue(::ot_array, "array")
{