Commit 5033e3b215c36457106cc2dd0150f2322655360c
1 parent
4a851591
Add method QPDFObject::getQPDF and remove QPDFObjectHandle::qpdf
Showing
3 changed files
with
16 additions
and
13 deletions
include/qpdf/QPDFObject.hh
| @@ -97,6 +97,12 @@ class QPDFObject | @@ -97,6 +97,12 @@ class QPDFObject | ||
| 97 | { | 97 | { |
| 98 | return value->type_name; | 98 | return value->type_name; |
| 99 | } | 99 | } |
| 100 | + // Returns nullptr for direct objects | ||
| 101 | + QPDF* | ||
| 102 | + getQPDF() const | ||
| 103 | + { | ||
| 104 | + return value->qpdf; | ||
| 105 | + } | ||
| 100 | void | 106 | void |
| 101 | setDescription(QPDF* qpdf, std::string const& description) | 107 | setDescription(QPDF* qpdf, std::string const& description) |
| 102 | { | 108 | { |
include/qpdf/QPDFObjectHandle.hh
| @@ -973,8 +973,8 @@ class QPDFObjectHandle | @@ -973,8 +973,8 @@ class QPDFObjectHandle | ||
| 973 | // null for a direct object if allow_nullptr is set to true or | 973 | // null for a direct object if allow_nullptr is set to true or |
| 974 | // throws a runtime error otherwise. | 974 | // throws a runtime error otherwise. |
| 975 | QPDF_DLL | 975 | QPDF_DLL |
| 976 | - inline QPDF* | ||
| 977 | - getOwningQPDF(bool allow_nullptr = true, std::string const& error_msg = ""); | 976 | + inline QPDF* getOwningQPDF( |
| 977 | + bool allow_nullptr = true, std::string const& error_msg = "") const; | ||
| 978 | 978 | ||
| 979 | // Create a shallow copy of an object as a direct object, but do not | 979 | // Create a shallow copy of an object as a direct object, but do not |
| 980 | // traverse across indirect object boundaries. That means that, | 980 | // traverse across indirect object boundaries. That means that, |
| @@ -1584,7 +1584,6 @@ class QPDFObjectHandle | @@ -1584,7 +1584,6 @@ class QPDFObjectHandle | ||
| 1584 | QPDF* qpdf, | 1584 | QPDF* qpdf, |
| 1585 | QPDFObjGen const& og, | 1585 | QPDFObjGen const& og, |
| 1586 | std::shared_ptr<QPDFObject> const& obj) : | 1586 | std::shared_ptr<QPDFObject> const& obj) : |
| 1587 | - qpdf(qpdf), | ||
| 1588 | og(og), | 1587 | og(og), |
| 1589 | obj(obj) | 1588 | obj(obj) |
| 1590 | { | 1589 | { |
| @@ -1641,7 +1640,6 @@ class QPDFObjectHandle | @@ -1641,7 +1640,6 @@ class QPDFObjectHandle | ||
| 1641 | // Moving members of QPDFObjectHandle into a smart pointer incurs | 1640 | // Moving members of QPDFObjectHandle into a smart pointer incurs |
| 1642 | // a substantial performance penalty since QPDFObjectHandle | 1641 | // a substantial performance penalty since QPDFObjectHandle |
| 1643 | // objects are copied around so frequently. | 1642 | // objects are copied around so frequently. |
| 1644 | - QPDF* qpdf; | ||
| 1645 | QPDFObjGen og; | 1643 | QPDFObjGen og; |
| 1646 | std::shared_ptr<QPDFObject> obj; | 1644 | std::shared_ptr<QPDFObject> obj; |
| 1647 | }; | 1645 | }; |
| @@ -1896,14 +1894,15 @@ QPDFObjectHandle::isInitialized() const | @@ -1896,14 +1894,15 @@ QPDFObjectHandle::isInitialized() const | ||
| 1896 | // Indirect object accessors | 1894 | // Indirect object accessors |
| 1897 | inline QPDF* | 1895 | inline QPDF* |
| 1898 | QPDFObjectHandle::getOwningQPDF( | 1896 | QPDFObjectHandle::getOwningQPDF( |
| 1899 | - bool allow_nullptr, std::string const& error_msg) | 1897 | + bool allow_nullptr, std::string const& error_msg) const |
| 1900 | { | 1898 | { |
| 1901 | // Will be null for direct objects | 1899 | // Will be null for direct objects |
| 1902 | - if (!allow_nullptr && (this->qpdf == nullptr)) { | 1900 | + auto result = isInitialized() ? this->obj->getQPDF() : nullptr; |
| 1901 | + if (!allow_nullptr && (result == nullptr)) { | ||
| 1903 | throw std::runtime_error( | 1902 | throw std::runtime_error( |
| 1904 | error_msg == "" ? "attempt to use a null qpdf object" : error_msg); | 1903 | error_msg == "" ? "attempt to use a null qpdf object" : error_msg); |
| 1905 | } | 1904 | } |
| 1906 | - return this->qpdf; | 1905 | + return result; |
| 1907 | } | 1906 | } |
| 1908 | 1907 | ||
| 1909 | inline void | 1908 | inline void |
libqpdf/QPDFObjectHandle.cc
| @@ -235,13 +235,11 @@ LastChar::getLastChar() | @@ -235,13 +235,11 @@ LastChar::getLastChar() | ||
| 235 | return this->last_char; | 235 | return this->last_char; |
| 236 | } | 236 | } |
| 237 | 237 | ||
| 238 | -QPDFObjectHandle::QPDFObjectHandle() : | ||
| 239 | - qpdf(nullptr) | 238 | +QPDFObjectHandle::QPDFObjectHandle() |
| 240 | { | 239 | { |
| 241 | } | 240 | } |
| 242 | 241 | ||
| 243 | QPDFObjectHandle::QPDFObjectHandle(std::shared_ptr<QPDFObject> const& data) : | 242 | QPDFObjectHandle::QPDFObjectHandle(std::shared_ptr<QPDFObject> const& data) : |
| 244 | - qpdf(nullptr), | ||
| 245 | obj(data) | 243 | obj(data) |
| 246 | { | 244 | { |
| 247 | } | 245 | } |
| @@ -2284,7 +2282,6 @@ QPDFObjectHandle::copyObject( | @@ -2284,7 +2282,6 @@ QPDFObjectHandle::copyObject( | ||
| 2284 | " reserved object handle direct"); | 2282 | " reserved object handle direct"); |
| 2285 | } | 2283 | } |
| 2286 | 2284 | ||
| 2287 | - qpdf = nullptr; | ||
| 2288 | og = QPDFObjGen(); | 2285 | og = QPDFObjGen(); |
| 2289 | 2286 | ||
| 2290 | std::shared_ptr<QPDFObject> new_obj; | 2287 | std::shared_ptr<QPDFObject> new_obj; |
| @@ -2572,8 +2569,9 @@ QPDFObjectHandle::isImage(bool exclude_imagemask) | @@ -2572,8 +2569,9 @@ QPDFObjectHandle::isImage(bool exclude_imagemask) | ||
| 2572 | void | 2569 | void |
| 2573 | QPDFObjectHandle::checkOwnership(QPDFObjectHandle const& item) const | 2570 | QPDFObjectHandle::checkOwnership(QPDFObjectHandle const& item) const |
| 2574 | { | 2571 | { |
| 2575 | - if ((this->qpdf != nullptr) && (item.qpdf != nullptr) && | ||
| 2576 | - (this->qpdf != item.qpdf)) { | 2572 | + auto qpdf = getOwningQPDF(); |
| 2573 | + auto item_qpdf = item.getOwningQPDF(); | ||
| 2574 | + if ((qpdf != nullptr) && (item_qpdf != nullptr) && (qpdf != item_qpdf)) { | ||
| 2577 | QTC::TC("qpdf", "QPDFObjectHandle check ownership"); | 2575 | QTC::TC("qpdf", "QPDFObjectHandle check ownership"); |
| 2578 | throw std::logic_error( | 2576 | throw std::logic_error( |
| 2579 | "Attempting to add an object from a different QPDF." | 2577 | "Attempting to add an object from a different QPDF." |