Commit 906034d9b38dd74b06f0609fa95eb51a54dd705d
1 parent
08d49887
Refactor `QPDFObjectHandle`: replace `getObj` with `BaseHandle::obj_sp` for impr…
…oved shared pointer handling, remove deprecated object methods, and update all references.
Showing
8 changed files
with
26 additions
and
26 deletions
include/qpdf/ObjectHandle.hh
| @@ -105,6 +105,9 @@ namespace qpdf | @@ -105,6 +105,9 @@ namespace qpdf | ||
| 105 | void warn(QPDFExc&&) const; | 105 | void warn(QPDFExc&&) const; |
| 106 | void warn(std::string const& warning) const; | 106 | void warn(std::string const& warning) const; |
| 107 | 107 | ||
| 108 | + inline std::shared_ptr<QPDFObject> const& obj_sp() const; | ||
| 109 | + inline QPDFObjectHandle oh() const; | ||
| 110 | + | ||
| 108 | protected: | 111 | protected: |
| 109 | BaseHandle() = default; | 112 | BaseHandle() = default; |
| 110 | BaseHandle(std::shared_ptr<QPDFObject> const& obj) : | 113 | BaseHandle(std::shared_ptr<QPDFObject> const& obj) : |
include/qpdf/QPDFObjectHandle.hh
| @@ -1321,21 +1321,6 @@ class QPDFObjectHandle: public qpdf::BaseHandle | @@ -1321,21 +1321,6 @@ class QPDFObjectHandle: public qpdf::BaseHandle | ||
| 1321 | { | 1321 | { |
| 1322 | return obj; | 1322 | return obj; |
| 1323 | } | 1323 | } |
| 1324 | - std::shared_ptr<QPDFObject> | ||
| 1325 | - getObj() const | ||
| 1326 | - { | ||
| 1327 | - return obj; | ||
| 1328 | - } | ||
| 1329 | - QPDFObject* | ||
| 1330 | - getObjectPtr() | ||
| 1331 | - { | ||
| 1332 | - return obj.get(); | ||
| 1333 | - } | ||
| 1334 | - QPDFObject* const | ||
| 1335 | - getObjectPtr() const | ||
| 1336 | - { | ||
| 1337 | - return obj.get(); | ||
| 1338 | - } | ||
| 1339 | 1324 | ||
| 1340 | void writeJSON(int json_version, JSON::Writer& p, bool dereference_indirect = false) const; | 1325 | void writeJSON(int json_version, JSON::Writer& p, bool dereference_indirect = false) const; |
| 1341 | 1326 |
libqpdf/QPDFFormFieldObjectHelper.cc
| @@ -765,7 +765,7 @@ QPDFFormFieldObjectHelper::generateTextAppearance(QPDFAnnotationObjectHelper& ao | @@ -765,7 +765,7 @@ QPDFFormFieldObjectHelper::generateTextAppearance(QPDFAnnotationObjectHelper& ao | ||
| 765 | return; | 765 | return; |
| 766 | } | 766 | } |
| 767 | 767 | ||
| 768 | - if (AS.getObj().use_count() > 4) { | 768 | + if (AS.obj_sp().use_count() > 3) { |
| 769 | aoh.warn("unable to generate text appearance from shared appearance stream for update"); | 769 | aoh.warn("unable to generate text appearance from shared appearance stream for update"); |
| 770 | return; | 770 | return; |
| 771 | } | 771 | } |
libqpdf/QPDFObjectHandle.cc
| @@ -318,7 +318,7 @@ BaseHandle::copy(bool shallow) const | @@ -318,7 +318,7 @@ BaseHandle::copy(bool shallow) const | ||
| 318 | throw std::logic_error("attempted to shallow copy QPDFObjectHandle from destroyed QPDF"); | 318 | throw std::logic_error("attempted to shallow copy QPDFObjectHandle from destroyed QPDF"); |
| 319 | return {}; // does not return | 319 | return {}; // does not return |
| 320 | case ::ot_reference: | 320 | case ::ot_reference: |
| 321 | - return obj->qpdf->getObject(obj->og).getObj(); | 321 | + return obj->qpdf->getObject(obj->og).obj_sp(); |
| 322 | } | 322 | } |
| 323 | return {}; // unreachable | 323 | return {}; // unreachable |
| 324 | } | 324 | } |
| @@ -470,7 +470,7 @@ BaseHandle::write_json(int json_version, JSON::Writer& p) const | @@ -470,7 +470,7 @@ BaseHandle::write_json(int json_version, JSON::Writer& p) const | ||
| 470 | p.writeNext() << "null"; | 470 | p.writeNext() << "null"; |
| 471 | } | 471 | } |
| 472 | p.writeNext(); | 472 | p.writeNext(); |
| 473 | - auto item_og = value.getObj()->getObjGen(); | 473 | + auto item_og = value.id_gen(); |
| 474 | if (item_og.isIndirect()) { | 474 | if (item_og.isIndirect()) { |
| 475 | p << "\"" << item_og.unparse(' ') << " R\""; | 475 | p << "\"" << item_og.unparse(' ') << " R\""; |
| 476 | } else { | 476 | } else { |
libqpdf/QPDFParser.cc
| @@ -626,8 +626,8 @@ QPDFParser::fixMissingKeys() | @@ -626,8 +626,8 @@ QPDFParser::fixMissingKeys() | ||
| 626 | { | 626 | { |
| 627 | std::set<std::string> names; | 627 | std::set<std::string> names; |
| 628 | for (auto& obj: frame->olist) { | 628 | for (auto& obj: frame->olist) { |
| 629 | - if (obj.getObj()->getTypeCode() == ::ot_name) { | ||
| 630 | - names.insert(obj.getObj()->getStringValue()); | 629 | + if (obj.raw_type_code() == ::ot_name) { |
| 630 | + names.insert(obj.obj_sp()->getStringValue()); | ||
| 631 | } | 631 | } |
| 632 | } | 632 | } |
| 633 | int next_fake_key = 1; | 633 | int next_fake_key = 1; |
libqpdf/QPDF_json.cc
| @@ -693,7 +693,7 @@ QPDF::JSONReactor::setObjectDescription(QPDFObjectHandle& oh, JSON const& value) | @@ -693,7 +693,7 @@ QPDF::JSONReactor::setObjectDescription(QPDFObjectHandle& oh, JSON const& value) | ||
| 693 | QPDFObject::JSON_Descr(j_descr.input, cur_object)); | 693 | QPDFObject::JSON_Descr(j_descr.input, cur_object)); |
| 694 | } | 694 | } |
| 695 | 695 | ||
| 696 | - oh.getObjectPtr()->setDescription(&pdf, descr, value.getStart()); | 696 | + oh.obj_sp()->setDescription(&pdf, descr, value.getStart()); |
| 697 | } | 697 | } |
| 698 | 698 | ||
| 699 | QPDFObjectHandle | 699 | QPDFObjectHandle |
libqpdf/QPDF_objects.cc
| @@ -1554,7 +1554,7 @@ Objects::readObjectAtOffset( | @@ -1554,7 +1554,7 @@ Objects::readObjectAtOffset( | ||
| 1554 | break; | 1554 | break; |
| 1555 | } | 1555 | } |
| 1556 | } | 1556 | } |
| 1557 | - m->objects.updateCache(og, oh.getObj(), end_before_space, m->file->tell()); | 1557 | + m->objects.updateCache(og, oh.obj_sp(), end_before_space, m->file->tell()); |
| 1558 | } | 1558 | } |
| 1559 | 1559 | ||
| 1560 | QPDFObjectHandle | 1560 | QPDFObjectHandle |
| @@ -1613,7 +1613,7 @@ Objects::readObjectAtOffset( | @@ -1613,7 +1613,7 @@ Objects::readObjectAtOffset( | ||
| 1613 | break; | 1613 | break; |
| 1614 | } | 1614 | } |
| 1615 | } | 1615 | } |
| 1616 | - m->objects.updateCache(og, oh.getObj(), end_before_space, m->file->tell()); | 1616 | + m->objects.updateCache(og, oh.obj_sp(), end_before_space, m->file->tell()); |
| 1617 | 1617 | ||
| 1618 | return oh; | 1618 | return oh; |
| 1619 | } | 1619 | } |
| @@ -1805,7 +1805,7 @@ Objects::resolveObjectsInStream(int obj_stream_number) | @@ -1805,7 +1805,7 @@ Objects::resolveObjectsInStream(int obj_stream_number) | ||
| 1805 | entry->second.getObjStreamNumber() == obj_stream_number) { | 1805 | entry->second.getObjStreamNumber() == obj_stream_number) { |
| 1806 | is::OffsetBuffer in("", {b_start + obj_offset, obj_size}, obj_offset); | 1806 | is::OffsetBuffer in("", {b_start + obj_offset, obj_size}, obj_offset); |
| 1807 | auto oh = readObjectInStream(in, obj_stream_number, obj_id); | 1807 | auto oh = readObjectInStream(in, obj_stream_number, obj_id); |
| 1808 | - updateCache(og, oh.getObj(), end_before_space, end_after_space); | 1808 | + updateCache(og, oh.obj_sp(), end_before_space, end_after_space); |
| 1809 | } else { | 1809 | } else { |
| 1810 | QTC::TC("qpdf", "QPDF not caching overridden objstm object"); | 1810 | QTC::TC("qpdf", "QPDF not caching overridden objstm object"); |
| 1811 | } | 1811 | } |
| @@ -1874,7 +1874,7 @@ QPDF::makeIndirectObject(QPDFObjectHandle oh) | @@ -1874,7 +1874,7 @@ QPDF::makeIndirectObject(QPDFObjectHandle oh) | ||
| 1874 | if (!oh) { | 1874 | if (!oh) { |
| 1875 | throw std::logic_error("attempted to make an uninitialized QPDFObjectHandle indirect"); | 1875 | throw std::logic_error("attempted to make an uninitialized QPDFObjectHandle indirect"); |
| 1876 | } | 1876 | } |
| 1877 | - return m->objects.makeIndirectFromQPDFObject(oh.getObj()); | 1877 | + return m->objects.makeIndirectFromQPDFObject(oh.obj_sp()); |
| 1878 | } | 1878 | } |
| 1879 | 1879 | ||
| 1880 | std::shared_ptr<QPDFObject> | 1880 | std::shared_ptr<QPDFObject> |
| @@ -1935,7 +1935,7 @@ QPDF::replaceObject(QPDFObjGen og, QPDFObjectHandle oh) | @@ -1935,7 +1935,7 @@ QPDF::replaceObject(QPDFObjGen og, QPDFObjectHandle oh) | ||
| 1935 | if (!oh || (oh.isIndirect() && !(oh.isStream() && oh.getObjGen() == og))) { | 1935 | if (!oh || (oh.isIndirect() && !(oh.isStream() && oh.getObjGen() == og))) { |
| 1936 | throw std::logic_error("QPDF::replaceObject called with indirect object handle"); | 1936 | throw std::logic_error("QPDF::replaceObject called with indirect object handle"); |
| 1937 | } | 1937 | } |
| 1938 | - m->objects.updateCache(og, oh.getObj(), -1, -1, false); | 1938 | + m->objects.updateCache(og, oh.obj_sp(), -1, -1, false); |
| 1939 | } | 1939 | } |
| 1940 | 1940 | ||
| 1941 | void | 1941 | void |
libqpdf/qpdf/QPDFObjectHandle_private.hh
| @@ -621,6 +621,18 @@ namespace qpdf | @@ -621,6 +621,18 @@ namespace qpdf | ||
| 621 | { | 621 | { |
| 622 | } | 622 | } |
| 623 | 623 | ||
| 624 | + inline std::shared_ptr<QPDFObject> const& | ||
| 625 | + BaseHandle::obj_sp() const | ||
| 626 | + { | ||
| 627 | + return obj; | ||
| 628 | + } | ||
| 629 | + | ||
| 630 | + inline QPDFObjectHandle | ||
| 631 | + BaseHandle::oh() const | ||
| 632 | + { | ||
| 633 | + return {obj}; | ||
| 634 | + } | ||
| 635 | + | ||
| 624 | inline void | 636 | inline void |
| 625 | BaseHandle::assign(qpdf_object_type_e required, BaseHandle const& other) | 637 | BaseHandle::assign(qpdf_object_type_e required, BaseHandle const& other) |
| 626 | { | 638 | { |