From c53d54b13dc6ad369646a09c64d392549effac38 Mon Sep 17 00:00:00 2001 From: m-holger Date: Sat, 6 Aug 2022 19:52:07 +0100 Subject: Add optional parameter allow_nullptr to QPDFObjectHandle::getOwningQPDF Also, inline method and add optional parameter error_msg. --- include/qpdf/QPDFObjectHandle.hh | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/qpdf/QPDFObjectHandle.hh b/include/qpdf/QPDFObjectHandle.hh index 5d9f52d5..4b054928 100644 --- a/include/qpdf/QPDFObjectHandle.hh +++ b/include/qpdf/QPDFObjectHandle.hh @@ -957,9 +957,11 @@ class QPDFObjectHandle std::set* resource_names = nullptr); // Return the QPDF object that owns an indirect object. Returns - // null for a direct object. + // null for a direct object if allow_nullptr is set to true or + // throws a runtime error otherwise. QPDF_DLL - QPDF* getOwningQPDF(); + inline QPDF* + getOwningQPDF(bool allow_nullptr = true, std::string const& error_msg = ""); // Create a shallow copy of an object as a direct object, but do not // traverse across indirect object boundaries. That means that, @@ -1876,4 +1878,17 @@ QPDFObjectHandle::isInitialized() const return initialized; } +// Indirect object accessors +inline QPDF* +QPDFObjectHandle::getOwningQPDF( + bool allow_nullptr, std::string const& error_msg) +{ + // Will be null for direct objects + if (!allow_nullptr && (this->qpdf == nullptr)) { + throw std::runtime_error( + error_msg == "" ? "attempt to use a null qpdf object" : error_msg); + } + return this->qpdf; +} + #endif // QPDFOBJECTHANDLE_HH -- cgit v1.2.3-54-g00ecf