diff options
author | Jay Berkenbilt <jberkenbilt@users.noreply.github.com> | 2022-08-29 22:33:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-29 22:33:19 +0200 |
commit | 0adfd74f8b5dc96091cd0b4251b08401f54df2ed (patch) | |
tree | 9ff07be139c118dc5bf02f98afeda41162066bfc /include | |
parent | 2b01a79e876d60df7ec330a60cb213f3ecc3559f (diff) | |
parent | c53d54b13dc6ad369646a09c64d392549effac38 (diff) | |
download | qpdf-0adfd74f8b5dc96091cd0b4251b08401f54df2ed.tar.zst |
Merge pull request #747 from m-holger/new_stream
Add optional parameter allow_nullptr to QPDFObjectHandle::getOwningQPDF
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 |