From 5033e3b215c36457106cc2dd0150f2322655360c Mon Sep 17 00:00:00 2001 From: m-holger Date: Sun, 14 Aug 2022 11:19:00 +0100 Subject: Add method QPDFObject::getQPDF and remove QPDFObjectHandle::qpdf --- include/qpdf/QPDFObject.hh | 6 ++++++ include/qpdf/QPDFObjectHandle.hh | 13 ++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/include/qpdf/QPDFObject.hh b/include/qpdf/QPDFObject.hh index 751a5736..6801cd5b 100644 --- a/include/qpdf/QPDFObject.hh +++ b/include/qpdf/QPDFObject.hh @@ -97,6 +97,12 @@ class QPDFObject { return value->type_name; } + // Returns nullptr for direct objects + QPDF* + getQPDF() const + { + return value->qpdf; + } void setDescription(QPDF* qpdf, std::string const& description) { diff --git a/include/qpdf/QPDFObjectHandle.hh b/include/qpdf/QPDFObjectHandle.hh index 0dc474cd..d23d0fd4 100644 --- a/include/qpdf/QPDFObjectHandle.hh +++ b/include/qpdf/QPDFObjectHandle.hh @@ -973,8 +973,8 @@ class QPDFObjectHandle // null for a direct object if allow_nullptr is set to true or // throws a runtime error otherwise. QPDF_DLL - inline QPDF* - getOwningQPDF(bool allow_nullptr = true, std::string const& error_msg = ""); + inline QPDF* getOwningQPDF( + bool allow_nullptr = true, std::string const& error_msg = "") const; // Create a shallow copy of an object as a direct object, but do not // traverse across indirect object boundaries. That means that, @@ -1584,7 +1584,6 @@ class QPDFObjectHandle QPDF* qpdf, QPDFObjGen const& og, std::shared_ptr const& obj) : - qpdf(qpdf), og(og), obj(obj) { @@ -1641,7 +1640,6 @@ class QPDFObjectHandle // Moving members of QPDFObjectHandle into a smart pointer incurs // a substantial performance penalty since QPDFObjectHandle // objects are copied around so frequently. - QPDF* qpdf; QPDFObjGen og; std::shared_ptr obj; }; @@ -1896,14 +1894,15 @@ QPDFObjectHandle::isInitialized() const // Indirect object accessors inline QPDF* QPDFObjectHandle::getOwningQPDF( - bool allow_nullptr, std::string const& error_msg) + bool allow_nullptr, std::string const& error_msg) const { // Will be null for direct objects - if (!allow_nullptr && (this->qpdf == nullptr)) { + auto result = isInitialized() ? this->obj->getQPDF() : nullptr; + if (!allow_nullptr && (result == nullptr)) { throw std::runtime_error( error_msg == "" ? "attempt to use a null qpdf object" : error_msg); } - return this->qpdf; + return result; } inline void -- cgit v1.2.3-70-g09d2