Commit d7b470761b3fe6895888f44c15655e880e5afaa0

Authored by m-holger
Committed by Jay Berkenbilt
1 parent 432f4174

Remove QPDFObjectHandle::Factory and ObjAccessor

include/qpdf/QPDFObjectHandle.hh
... ... @@ -1490,49 +1490,6 @@ class QPDFObjectHandle
1490 1490 QPDF_DLL
1491 1491 void warnIfPossible(std::string const& warning);
1492 1492  
1493   - // Initializers for objects. This Factory class gives the QPDF
1494   - // class specific permission to call factory methods without
1495   - // making it a friend of the whole QPDFObjectHandle class.
1496   - class Factory
1497   - {
1498   - friend class QPDF;
1499   -
1500   - private:
1501   - static QPDFObjectHandle
1502   - newIndirect(std::shared_ptr<QPDFObject> const& obj)
1503   - {
1504   - return QPDFObjectHandle(obj);
1505   - }
1506   - };
1507   -
1508   - // Accessor for raw underlying object -- only QPDF is allowed to
1509   - // call this.
1510   - class ObjAccessor
1511   - {
1512   - friend class QPDF;
1513   -
1514   - private:
1515   - static std::shared_ptr<QPDFObject>
1516   - getObject(QPDFObjectHandle& o)
1517   - {
1518   - if (!o.dereference()) {
1519   - throw std::logic_error("attempted to dereference an"
1520   - " uninitialized QPDFObjectHandle");
1521   - };
1522   - return o.obj;
1523   - }
1524   - static QPDF_Array*
1525   - asArray(QPDFObjectHandle& oh)
1526   - {
1527   - return oh.asArray();
1528   - }
1529   - static QPDF_Stream*
1530   - asStream(QPDFObjectHandle& oh)
1531   - {
1532   - return oh.asStream();
1533   - }
1534   - };
1535   -
1536 1493 // Provide access to specific classes for recursive
1537 1494 // disconnected().
1538 1495 class DisconnectAccess
... ...
libqpdf/QPDF.cc
... ... @@ -1775,11 +1775,7 @@ QPDF::readObjectAtOffset(
1775 1775 // skip_cache_if_in_xref.
1776 1776 QTC::TC("qpdf", "QPDF skipping cache for known unchecked object");
1777 1777 } else {
1778   - updateCache(
1779   - og,
1780   - QPDFObjectHandle::ObjAccessor::getObject(oh),
1781   - end_before_space,
1782   - end_after_space);
  1778 + updateCache(og, oh.getObj(), end_before_space, end_after_space);
1783 1779 }
1784 1780 }
1785 1781  
... ... @@ -1930,11 +1926,7 @@ QPDF::resolveObjectsInStream(int obj_stream_number)
1930 1926 int offset = iter.second;
1931 1927 input->seek(offset, SEEK_SET);
1932 1928 QPDFObjectHandle oh = readObject(input, "", og, true);
1933   - updateCache(
1934   - og,
1935   - QPDFObjectHandle::ObjAccessor::getObject(oh),
1936   - end_before_space,
1937   - end_after_space);
  1929 + updateCache(og, oh.getObj(), end_before_space, end_after_space);
1938 1930 } else {
1939 1931 QTC::TC("qpdf", "QPDF not caching overridden objstm object");
1940 1932 }
... ... @@ -1945,7 +1937,7 @@ QPDFObjectHandle
1945 1937 QPDF::newIndirect(QPDFObjGen const& og, std::shared_ptr<QPDFObject> const& obj)
1946 1938 {
1947 1939 obj->setDefaultDescription(this, og);
1948   - return QPDFObjectHandle::Factory::newIndirect(obj);
  1940 + return {obj};
1949 1941 }
1950 1942  
1951 1943 void
... ... @@ -2000,8 +1992,11 @@ QPDF::makeIndirectFromQPDFObject(std::shared_ptr&lt;QPDFObject&gt; const&amp; obj)
2000 1992 QPDFObjectHandle
2001 1993 QPDF::makeIndirectObject(QPDFObjectHandle oh)
2002 1994 {
2003   - return makeIndirectFromQPDFObject(
2004   - QPDFObjectHandle::ObjAccessor::getObject(oh));
  1995 + if (!oh.isInitialized()) {
  1996 + throw std::logic_error(
  1997 + "attempted to make an uninitialized QPDFObjectHandle indirect");
  1998 + }
  1999 + return makeIndirectFromQPDFObject(oh.getObj());
2005 2000 }
2006 2001  
2007 2002 QPDFObjectHandle
... ... @@ -2043,8 +2038,8 @@ QPDF::reserveObjectIfNotExists(QPDFObjGen const&amp; og)
2043 2038 QPDFObjectHandle
2044 2039 QPDF::reserveStream(QPDFObjGen const& og)
2045 2040 {
2046   - return QPDFObjectHandle::Factory::newIndirect(
2047   - QPDF_Stream::create(this, og, QPDFObjectHandle::newDictionary(), 0, 0));
  2041 + return {
  2042 + QPDF_Stream::create(this, og, QPDFObjectHandle::newDictionary(), 0, 0)};
2048 2043 }
2049 2044  
2050 2045 QPDFObjectHandle
... ... @@ -2085,12 +2080,12 @@ QPDF::replaceObject(int objid, int generation, QPDFObjectHandle oh)
2085 2080 void
2086 2081 QPDF::replaceObject(QPDFObjGen const& og, QPDFObjectHandle oh)
2087 2082 {
2088   - if (oh.isIndirect()) {
  2083 + if (oh.isIndirect() || !oh.isInitialized()) {
2089 2084 QTC::TC("qpdf", "QPDF replaceObject called with indirect object");
2090 2085 throw std::logic_error(
2091 2086 "QPDF::replaceObject called with indirect object handle");
2092 2087 }
2093   - updateCache(og, QPDFObjectHandle::ObjAccessor::getObject(oh), -1, -1);
  2088 + updateCache(og, oh.getObj(), -1, -1);
2094 2089 }
2095 2090  
2096 2091 void
... ... @@ -2347,7 +2342,7 @@ QPDF::copyStreamData(QPDFObjectHandle result, QPDFObjectHandle foreign)
2347 2342 QPDF& foreign_stream_qpdf =
2348 2343 foreign.getQPDF("unable to retrieve owning qpdf from foreign stream");
2349 2344  
2350   - auto stream = QPDFObjectHandle::ObjAccessor::asStream(foreign);
  2345 + auto stream = foreign.getObjectPtr()->as<QPDF_Stream>();
2351 2346 if (stream == nullptr) {
2352 2347 throw std::logic_error("unable to retrieve underlying"
2353 2348 " stream object from foreign stream");
... ...