diff options
author | m-holger <m-holger@kubitscheck.org> | 2022-08-06 20:52:07 +0200 |
---|---|---|
committer | m-holger <m-holger@kubitscheck.org> | 2022-08-28 23:15:59 +0200 |
commit | c53d54b13dc6ad369646a09c64d392549effac38 (patch) | |
tree | c26a8d6477b5a175f483affed2782a969d39142d /include | |
parent | cef6425bcac678157f58e9eafabb7e63c5831d18 (diff) | |
download | qpdf-c53d54b13dc6ad369646a09c64d392549effac38.tar.zst |
Add optional parameter allow_nullptr to QPDFObjectHandle::getOwningQPDF
Also, inline method and add optional parameter error_msg.
Diffstat (limited to 'include')
-rw-r--r-- | include/qpdf/QPDFObjectHandle.hh | 19 |
1 files changed, 17 insertions, 2 deletions
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<std::string>* 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 |