From d7b470761b3fe6895888f44c15655e880e5afaa0 Mon Sep 17 00:00:00 2001 From: m-holger Date: Thu, 29 Dec 2022 15:12:04 +0000 Subject: Remove QPDFObjectHandle::Factory and ObjAccessor --- include/qpdf/QPDFObjectHandle.hh | 43 ---------------------------------------- libqpdf/QPDF.cc | 31 ++++++++++++----------------- 2 files changed, 13 insertions(+), 61 deletions(-) diff --git a/include/qpdf/QPDFObjectHandle.hh b/include/qpdf/QPDFObjectHandle.hh index 51530ee5..3c597adc 100644 --- a/include/qpdf/QPDFObjectHandle.hh +++ b/include/qpdf/QPDFObjectHandle.hh @@ -1490,49 +1490,6 @@ class QPDFObjectHandle QPDF_DLL void warnIfPossible(std::string const& warning); - // Initializers for objects. This Factory class gives the QPDF - // class specific permission to call factory methods without - // making it a friend of the whole QPDFObjectHandle class. - class Factory - { - friend class QPDF; - - private: - static QPDFObjectHandle - newIndirect(std::shared_ptr const& obj) - { - return QPDFObjectHandle(obj); - } - }; - - // Accessor for raw underlying object -- only QPDF is allowed to - // call this. - class ObjAccessor - { - friend class QPDF; - - private: - static std::shared_ptr - getObject(QPDFObjectHandle& o) - { - if (!o.dereference()) { - throw std::logic_error("attempted to dereference an" - " uninitialized QPDFObjectHandle"); - }; - return o.obj; - } - static QPDF_Array* - asArray(QPDFObjectHandle& oh) - { - return oh.asArray(); - } - static QPDF_Stream* - asStream(QPDFObjectHandle& oh) - { - return oh.asStream(); - } - }; - // Provide access to specific classes for recursive // disconnected(). class DisconnectAccess diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index b1eefd3b..f2c80539 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -1775,11 +1775,7 @@ QPDF::readObjectAtOffset( // skip_cache_if_in_xref. QTC::TC("qpdf", "QPDF skipping cache for known unchecked object"); } else { - updateCache( - og, - QPDFObjectHandle::ObjAccessor::getObject(oh), - end_before_space, - end_after_space); + updateCache(og, oh.getObj(), end_before_space, end_after_space); } } @@ -1930,11 +1926,7 @@ QPDF::resolveObjectsInStream(int obj_stream_number) int offset = iter.second; input->seek(offset, SEEK_SET); QPDFObjectHandle oh = readObject(input, "", og, true); - updateCache( - og, - QPDFObjectHandle::ObjAccessor::getObject(oh), - end_before_space, - end_after_space); + updateCache(og, oh.getObj(), end_before_space, end_after_space); } else { QTC::TC("qpdf", "QPDF not caching overridden objstm object"); } @@ -1945,7 +1937,7 @@ QPDFObjectHandle QPDF::newIndirect(QPDFObjGen const& og, std::shared_ptr const& obj) { obj->setDefaultDescription(this, og); - return QPDFObjectHandle::Factory::newIndirect(obj); + return {obj}; } void @@ -2000,8 +1992,11 @@ QPDF::makeIndirectFromQPDFObject(std::shared_ptr const& obj) QPDFObjectHandle QPDF::makeIndirectObject(QPDFObjectHandle oh) { - return makeIndirectFromQPDFObject( - QPDFObjectHandle::ObjAccessor::getObject(oh)); + if (!oh.isInitialized()) { + throw std::logic_error( + "attempted to make an uninitialized QPDFObjectHandle indirect"); + } + return makeIndirectFromQPDFObject(oh.getObj()); } QPDFObjectHandle @@ -2043,8 +2038,8 @@ QPDF::reserveObjectIfNotExists(QPDFObjGen const& og) QPDFObjectHandle QPDF::reserveStream(QPDFObjGen const& og) { - return QPDFObjectHandle::Factory::newIndirect( - QPDF_Stream::create(this, og, QPDFObjectHandle::newDictionary(), 0, 0)); + return { + QPDF_Stream::create(this, og, QPDFObjectHandle::newDictionary(), 0, 0)}; } QPDFObjectHandle @@ -2085,12 +2080,12 @@ QPDF::replaceObject(int objid, int generation, QPDFObjectHandle oh) void QPDF::replaceObject(QPDFObjGen const& og, QPDFObjectHandle oh) { - if (oh.isIndirect()) { + if (oh.isIndirect() || !oh.isInitialized()) { QTC::TC("qpdf", "QPDF replaceObject called with indirect object"); throw std::logic_error( "QPDF::replaceObject called with indirect object handle"); } - updateCache(og, QPDFObjectHandle::ObjAccessor::getObject(oh), -1, -1); + updateCache(og, oh.getObj(), -1, -1); } void @@ -2347,7 +2342,7 @@ QPDF::copyStreamData(QPDFObjectHandle result, QPDFObjectHandle foreign) QPDF& foreign_stream_qpdf = foreign.getQPDF("unable to retrieve owning qpdf from foreign stream"); - auto stream = QPDFObjectHandle::ObjAccessor::asStream(foreign); + auto stream = foreign.getObjectPtr()->as(); if (stream == nullptr) { throw std::logic_error("unable to retrieve underlying" " stream object from foreign stream"); -- cgit v1.2.3-54-g00ecf