2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-11-01 03:12:29 +00:00

Change QPDF_Unresolved::create method to take QPDF* and QPDFObjGen parameters

This commit is contained in:
m-holger 2022-08-12 15:14:11 +01:00
parent ae6e484e23
commit 89061d5b33
4 changed files with 38 additions and 12 deletions

View File

@ -25,6 +25,7 @@
#include <qpdf/Constants.h> #include <qpdf/Constants.h>
#include <qpdf/DLL.h> #include <qpdf/DLL.h>
#include <qpdf/JSON.hh> #include <qpdf/JSON.hh>
#include <qpdf/QPDFObjGen.hh>
#include <qpdf/Types.h> #include <qpdf/Types.h>
#include <string> #include <string>
@ -73,11 +74,21 @@ class QPDFValue
{ {
return parsed_offset; return parsed_offset;
} }
QPDF*
getQPDF()
{
return qpdf;
}
QPDFObjGen
getObjGen()
{
return og;
}
protected: protected:
QPDFValue() : QPDFValue() :
type_code(::ot_uninitialized), type_code(::ot_uninitialized),
type_name("uninitilized") type_name("uninitialized")
{ {
} }
QPDFValue(qpdf_object_type_e type_code, char const* type_name) : QPDFValue(qpdf_object_type_e type_code, char const* type_name) :
@ -85,7 +96,17 @@ class QPDFValue
type_name(type_name) type_name(type_name)
{ {
} }
QPDFValue(
qpdf_object_type_e type_code,
char const* type_name,
QPDF* qpdf,
QPDFObjGen const& og) :
type_code(type_code),
type_name(type_name),
qpdf(qpdf),
og(og)
{
}
virtual void virtual void
releaseResolved() releaseResolved()
{ {
@ -100,6 +121,10 @@ class QPDFValue
qpdf_offset_t parsed_offset{-1}; qpdf_offset_t parsed_offset{-1};
const qpdf_object_type_e type_code; const qpdf_object_type_e type_code;
char const* type_name; char const* type_name;
protected:
QPDF* qpdf{nullptr};
QPDFObjGen og;
}; };
#endif // QPDFVALUE_HH #endif // QPDFVALUE_HH

View File

@ -2183,9 +2183,8 @@ QPDF::getObject(QPDFObjGen const& og)
if (!og.isIndirect()) { if (!og.isIndirect()) {
return QPDFObjectHandle::newNull(); return QPDFObjectHandle::newNull();
} }
// auto obj = (og.getObj() != 0) ? resolve(og) : QPDF_Null::create(); if (!isCached(og)) {
if (!m->obj_cache.count(og)) { m->obj_cache[og] = ObjCache(QPDF_Unresolved::create(this, og), -1, -1);
m->obj_cache[og] = ObjCache(QPDF_Unresolved::create(), -1, -1);
} }
return newIndirect(og, m->obj_cache[og].object); return newIndirect(og, m->obj_cache[og].object);
} }

View File

@ -2,21 +2,23 @@
#include <stdexcept> #include <stdexcept>
QPDF_Unresolved::QPDF_Unresolved() : QPDF_Unresolved::QPDF_Unresolved(QPDF* qpdf, QPDFObjGen const& og) :
QPDFValue(::ot_unresolved, "unresolved") QPDFValue(::ot_unresolved, "unresolved", qpdf, og)
{ {
} }
std::shared_ptr<QPDFObject> std::shared_ptr<QPDFObject>
QPDF_Unresolved::create() QPDF_Unresolved::create(QPDF* qpdf, QPDFObjGen const& og)
{ {
return do_create(new QPDF_Unresolved()); return do_create(new QPDF_Unresolved(qpdf, og));
} }
std::shared_ptr<QPDFObject> std::shared_ptr<QPDFObject>
QPDF_Unresolved::shallowCopy() QPDF_Unresolved::shallowCopy()
{ {
return create(); throw std::logic_error(
"attempted to shallow copy unresolved QPDFObjectHandle");
return create(qpdf, og);
} }
std::string std::string

View File

@ -7,13 +7,13 @@ class QPDF_Unresolved: public QPDFValue
{ {
public: public:
virtual ~QPDF_Unresolved() = default; virtual ~QPDF_Unresolved() = default;
static std::shared_ptr<QPDFObject> create(); static std::shared_ptr<QPDFObject> create(QPDF* qpdf, QPDFObjGen const& og);
virtual std::shared_ptr<QPDFObject> shallowCopy(); virtual std::shared_ptr<QPDFObject> shallowCopy();
virtual std::string unparse(); virtual std::string unparse();
virtual JSON getJSON(int json_version); virtual JSON getJSON(int json_version);
private: private:
QPDF_Unresolved(); QPDF_Unresolved(QPDF* qpdf, QPDFObjGen const& og);
}; };
#endif // QPDF_UNRESOLVED_HH #endif // QPDF_UNRESOLVED_HH