From 6c61be00e8366d467e7e4c82a6d91a4d074a1181 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Mon, 5 Sep 2022 09:15:14 -0400 Subject: Rename QPDFObject -> QPDFValueProxy This is in preparation for restoring a QPDFObject.hh to ease the transition on qpdf_object_type_e. This commit was created by * Renaming QPDFObject.cc and QPDFObject.hh * Replacing QPDFObject\b with QPDFValueProxy (where \b is word boundary) * Running format-code * Manually resorting files in libqpdf/CMakeLists.txt * Manually refilling the comment in QPDF.hh near class Resolver --- cSpell.json | 2 + include/qpdf/QPDF.hh | 14 ++-- include/qpdf/QPDFObjectHandle.hh | 10 +-- libqpdf/CMakeLists.txt | 2 +- libqpdf/QPDF.cc | 7 +- libqpdf/QPDFObject.cc | 10 --- libqpdf/QPDFObjectHandle.cc | 4 +- libqpdf/QPDFValue.cc | 6 +- libqpdf/QPDFValueProxy.cc | 10 +++ libqpdf/QPDF_Array.cc | 6 +- libqpdf/QPDF_Bool.cc | 4 +- libqpdf/QPDF_Dictionary.cc | 4 +- libqpdf/QPDF_InlineImage.cc | 4 +- libqpdf/QPDF_Integer.cc | 4 +- libqpdf/QPDF_Name.cc | 4 +- libqpdf/QPDF_Null.cc | 4 +- libqpdf/QPDF_Operator.cc | 4 +- libqpdf/QPDF_Real.cc | 6 +- libqpdf/QPDF_Reserved.cc | 4 +- libqpdf/QPDF_Stream.cc | 4 +- libqpdf/QPDF_String.cc | 6 +- libqpdf/QPDF_Unresolved.cc | 4 +- libqpdf/qpdf/QPDFObject.hh | 146 --------------------------------------- libqpdf/qpdf/QPDFValue.hh | 8 +-- libqpdf/qpdf/QPDFValueProxy.hh | 146 +++++++++++++++++++++++++++++++++++++++ libqpdf/qpdf/QPDF_Array.hh | 6 +- libqpdf/qpdf/QPDF_Bool.hh | 4 +- libqpdf/qpdf/QPDF_Dictionary.hh | 4 +- libqpdf/qpdf/QPDF_InlineImage.hh | 4 +- libqpdf/qpdf/QPDF_Integer.hh | 4 +- libqpdf/qpdf/QPDF_Name.hh | 4 +- libqpdf/qpdf/QPDF_Null.hh | 4 +- libqpdf/qpdf/QPDF_Operator.hh | 4 +- libqpdf/qpdf/QPDF_Real.hh | 6 +- libqpdf/qpdf/QPDF_Reserved.hh | 4 +- libqpdf/qpdf/QPDF_Stream.hh | 4 +- libqpdf/qpdf/QPDF_String.hh | 6 +- libqpdf/qpdf/QPDF_Unresolved.hh | 5 +- 38 files changed, 243 insertions(+), 239 deletions(-) delete mode 100644 libqpdf/QPDFObject.cc create mode 100644 libqpdf/QPDFValueProxy.cc delete mode 100644 libqpdf/qpdf/QPDFObject.hh create mode 100644 libqpdf/qpdf/QPDFValueProxy.hh diff --git a/cSpell.json b/cSpell.json index 655cd141..918d186c 100644 --- a/cSpell.json +++ b/cSpell.json @@ -300,6 +300,7 @@ "nodefaultlib", "noout", "notfound", + "nowarn", "npages", "nproc", "nrounds", @@ -423,6 +424,7 @@ "qpdftypes", "qpdfusage", "qpdfvalue", + "qpdfvalueproxy", "qpdfwriter", "qpdfx", "qpdfxrefentry", diff --git a/include/qpdf/QPDF.hh b/include/qpdf/QPDF.hh index 567817f1..c7ac5281 100644 --- a/include/qpdf/QPDF.hh +++ b/include/qpdf/QPDF.hh @@ -842,11 +842,11 @@ class QPDF } }; - // Resolver class is restricted to QPDFObject so that only it can - // resolve indirect references. + // Resolver class is restricted to QPDFValueProxy so that only it + // can resolve indirect references. class Resolver { - friend class QPDFObject; + friend class QPDFValueProxy; private: static void @@ -952,7 +952,7 @@ class QPDF { } ObjCache( - std::shared_ptr object, + std::shared_ptr object, qpdf_offset_t end_before_space, qpdf_offset_t end_after_space) : object(object), @@ -961,7 +961,7 @@ class QPDF { } - std::shared_ptr object; + std::shared_ptr object; qpdf_offset_t end_before_space; qpdf_offset_t end_after_space; }; @@ -1186,12 +1186,12 @@ class QPDF QPDFObjectHandle reserveObjectIfNotExists(QPDFObjGen const& og); QPDFObjectHandle reserveStream(QPDFObjGen const& og); QPDFObjectHandle - newIndirect(QPDFObjGen const&, std::shared_ptr const&); + newIndirect(QPDFObjGen const&, std::shared_ptr const&); bool isCached(QPDFObjGen const& og); bool isUnresolved(QPDFObjGen const& og); void updateCache( QPDFObjGen const& og, - std::shared_ptr const& object, + std::shared_ptr const& object, qpdf_offset_t end_before_space, qpdf_offset_t end_after_space); diff --git a/include/qpdf/QPDFObjectHandle.hh b/include/qpdf/QPDFObjectHandle.hh index 8f1858a1..de085bb6 100644 --- a/include/qpdf/QPDFObjectHandle.hh +++ b/include/qpdf/QPDFObjectHandle.hh @@ -54,7 +54,7 @@ class QPDF_Real; class QPDF_Reserved; class QPDF_Stream; class QPDF_String; -class QPDFObject; +class QPDFValueProxy; class QPDFTokenizer; class QPDFExc; class Pl_QPDFTokenizer; @@ -1453,7 +1453,7 @@ class QPDFObjectHandle private: static QPDFObjectHandle - newIndirect(std::shared_ptr const& obj) + newIndirect(std::shared_ptr const& obj) { return QPDFObjectHandle(obj); } @@ -1478,7 +1478,7 @@ class QPDFObjectHandle friend class QPDF; private: - static std::shared_ptr + static std::shared_ptr getObject(QPDFObjectHandle& o) { if (!o.dereference()) { @@ -1560,7 +1560,7 @@ class QPDFObjectHandle bool isImage(bool exclude_imagemask = true); private: - QPDFObjectHandle(std::shared_ptr const& obj) : + QPDFObjectHandle(std::shared_ptr const& obj) : obj(obj) { } @@ -1613,7 +1613,7 @@ class QPDFObjectHandle // Moving members of QPDFObjectHandle into a smart pointer incurs // a substantial performance penalty since QPDFObjectHandle // objects are copied around so frequently. - std::shared_ptr obj; + std::shared_ptr obj; }; #ifndef QPDF_NO_QPDF_STRING diff --git a/libqpdf/CMakeLists.txt b/libqpdf/CMakeLists.txt index 686ea04a..95024c64 100644 --- a/libqpdf/CMakeLists.txt +++ b/libqpdf/CMakeLists.txt @@ -72,7 +72,6 @@ set(libqpdf_SOURCES QPDFMatrix.cc QPDFNameTreeObjectHelper.cc QPDFNumberTreeObjectHelper.cc - QPDFObject.cc QPDFObjectHandle.cc QPDFObjGen.cc QPDFOutlineDocumentHelper.cc @@ -86,6 +85,7 @@ set(libqpdf_SOURCES QPDFTokenizer.cc QPDFUsage.cc QPDFValue.cc + QPDFValueProxy.cc QPDFWriter.cc QPDFXRefEntry.cc QPDF_Array.cc diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index 15636d34..aa97de4b 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include #include @@ -2114,7 +2114,8 @@ QPDF::resolveObjectsInStream(int obj_stream_number) } QPDFObjectHandle -QPDF::newIndirect(QPDFObjGen const& og, std::shared_ptr const& obj) +QPDF::newIndirect( + QPDFObjGen const& og, std::shared_ptr const& obj) { obj->setObjGen(this, og); if (!obj->hasDescription()) { @@ -2126,7 +2127,7 @@ QPDF::newIndirect(QPDFObjGen const& og, std::shared_ptr const& obj) void QPDF::updateCache( QPDFObjGen const& og, - std::shared_ptr const& object, + std::shared_ptr const& object, qpdf_offset_t end_before_space, qpdf_offset_t end_after_space) { diff --git a/libqpdf/QPDFObject.cc b/libqpdf/QPDFObject.cc deleted file mode 100644 index 8b538021..00000000 --- a/libqpdf/QPDFObject.cc +++ /dev/null @@ -1,10 +0,0 @@ -#include - -#include - -void -QPDFObject::doResolve() -{ - auto og = value->og; - QPDF::Resolver::resolve(value->qpdf, og); -} diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index 4b1ebe43..838d389f 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -7,9 +7,9 @@ #include #include #include -#include #include #include +#include #include #include #include @@ -2257,7 +2257,7 @@ QPDFObjectHandle::copyObject( " reserved object handle direct"); } - std::shared_ptr new_obj; + std::shared_ptr new_obj; if (isBool() || isInteger() || isName() || isNull() || isReal() || isString()) { diff --git a/libqpdf/QPDFValue.cc b/libqpdf/QPDFValue.cc index 8a6222d2..957cc350 100644 --- a/libqpdf/QPDFValue.cc +++ b/libqpdf/QPDFValue.cc @@ -1,11 +1,11 @@ #include -#include +#include -std::shared_ptr +std::shared_ptr QPDFValue::do_create(QPDFValue* object) { - std::shared_ptr obj(new QPDFObject()); + std::shared_ptr obj(new QPDFValueProxy()); obj->value = std::shared_ptr(object); return obj; } diff --git a/libqpdf/QPDFValueProxy.cc b/libqpdf/QPDFValueProxy.cc new file mode 100644 index 00000000..461d8177 --- /dev/null +++ b/libqpdf/QPDFValueProxy.cc @@ -0,0 +1,10 @@ +#include + +#include + +void +QPDFValueProxy::doResolve() +{ + auto og = value->og; + QPDF::Resolver::resolve(value->qpdf, og); +} diff --git a/libqpdf/QPDF_Array.cc b/libqpdf/QPDF_Array.cc index 7d42508c..5cce8909 100644 --- a/libqpdf/QPDF_Array.cc +++ b/libqpdf/QPDF_Array.cc @@ -16,19 +16,19 @@ QPDF_Array::QPDF_Array(SparseOHArray const& items) : { } -std::shared_ptr +std::shared_ptr QPDF_Array::create(std::vector const& items) { return do_create(new QPDF_Array(items)); } -std::shared_ptr +std::shared_ptr QPDF_Array::create(SparseOHArray const& items) { return do_create(new QPDF_Array(items)); } -std::shared_ptr +std::shared_ptr QPDF_Array::shallowCopy() { return create(elements); diff --git a/libqpdf/QPDF_Bool.cc b/libqpdf/QPDF_Bool.cc index efbfd6c9..8b4c6a7a 100644 --- a/libqpdf/QPDF_Bool.cc +++ b/libqpdf/QPDF_Bool.cc @@ -6,13 +6,13 @@ QPDF_Bool::QPDF_Bool(bool val) : { } -std::shared_ptr +std::shared_ptr QPDF_Bool::create(bool value) { return do_create(new QPDF_Bool(value)); } -std::shared_ptr +std::shared_ptr QPDF_Bool::shallowCopy() { return create(val); diff --git a/libqpdf/QPDF_Dictionary.cc b/libqpdf/QPDF_Dictionary.cc index be0104d0..41760993 100644 --- a/libqpdf/QPDF_Dictionary.cc +++ b/libqpdf/QPDF_Dictionary.cc @@ -9,13 +9,13 @@ QPDF_Dictionary::QPDF_Dictionary( { } -std::shared_ptr +std::shared_ptr QPDF_Dictionary::create(std::map const& items) { return do_create(new QPDF_Dictionary(items)); } -std::shared_ptr +std::shared_ptr QPDF_Dictionary::shallowCopy() { return create(items); diff --git a/libqpdf/QPDF_InlineImage.cc b/libqpdf/QPDF_InlineImage.cc index 76318196..a675514a 100644 --- a/libqpdf/QPDF_InlineImage.cc +++ b/libqpdf/QPDF_InlineImage.cc @@ -6,13 +6,13 @@ QPDF_InlineImage::QPDF_InlineImage(std::string const& val) : { } -std::shared_ptr +std::shared_ptr QPDF_InlineImage::create(std::string const& val) { return do_create(new QPDF_InlineImage(val)); } -std::shared_ptr +std::shared_ptr QPDF_InlineImage::shallowCopy() { return create(val); diff --git a/libqpdf/QPDF_Integer.cc b/libqpdf/QPDF_Integer.cc index 24812573..cb9066bd 100644 --- a/libqpdf/QPDF_Integer.cc +++ b/libqpdf/QPDF_Integer.cc @@ -8,13 +8,13 @@ QPDF_Integer::QPDF_Integer(long long val) : { } -std::shared_ptr +std::shared_ptr QPDF_Integer::create(long long value) { return do_create(new QPDF_Integer(value)); } -std::shared_ptr +std::shared_ptr QPDF_Integer::shallowCopy() { return create(val); diff --git a/libqpdf/QPDF_Name.cc b/libqpdf/QPDF_Name.cc index c86d34b4..e793affb 100644 --- a/libqpdf/QPDF_Name.cc +++ b/libqpdf/QPDF_Name.cc @@ -10,13 +10,13 @@ QPDF_Name::QPDF_Name(std::string const& name) : { } -std::shared_ptr +std::shared_ptr QPDF_Name::create(std::string const& name) { return do_create(new QPDF_Name(name)); } -std::shared_ptr +std::shared_ptr QPDF_Name::shallowCopy() { return create(name); diff --git a/libqpdf/QPDF_Null.cc b/libqpdf/QPDF_Null.cc index f60dda1f..0b824828 100644 --- a/libqpdf/QPDF_Null.cc +++ b/libqpdf/QPDF_Null.cc @@ -5,13 +5,13 @@ QPDF_Null::QPDF_Null() : { } -std::shared_ptr +std::shared_ptr QPDF_Null::create() { return do_create(new QPDF_Null()); } -std::shared_ptr +std::shared_ptr QPDF_Null::shallowCopy() { return create(); diff --git a/libqpdf/QPDF_Operator.cc b/libqpdf/QPDF_Operator.cc index 547ff40a..f29ab23d 100644 --- a/libqpdf/QPDF_Operator.cc +++ b/libqpdf/QPDF_Operator.cc @@ -6,13 +6,13 @@ QPDF_Operator::QPDF_Operator(std::string const& val) : { } -std::shared_ptr +std::shared_ptr QPDF_Operator::create(std::string const& val) { return do_create(new QPDF_Operator(val)); } -std::shared_ptr +std::shared_ptr QPDF_Operator::shallowCopy() { return create(val); diff --git a/libqpdf/QPDF_Real.cc b/libqpdf/QPDF_Real.cc index 85c9ceeb..32c03b63 100644 --- a/libqpdf/QPDF_Real.cc +++ b/libqpdf/QPDF_Real.cc @@ -15,20 +15,20 @@ QPDF_Real::QPDF_Real( { } -std::shared_ptr +std::shared_ptr QPDF_Real::create(std::string const& val) { return do_create(new QPDF_Real(val)); } -std::shared_ptr +std::shared_ptr QPDF_Real::create(double value, int decimal_places, bool trim_trailing_zeroes) { return do_create( new QPDF_Real(value, decimal_places, trim_trailing_zeroes)); } -std::shared_ptr +std::shared_ptr QPDF_Real::shallowCopy() { return create(val); diff --git a/libqpdf/QPDF_Reserved.cc b/libqpdf/QPDF_Reserved.cc index f5af4688..420cf765 100644 --- a/libqpdf/QPDF_Reserved.cc +++ b/libqpdf/QPDF_Reserved.cc @@ -7,13 +7,13 @@ QPDF_Reserved::QPDF_Reserved() : { } -std::shared_ptr +std::shared_ptr QPDF_Reserved::create() { return do_create(new QPDF_Reserved()); } -std::shared_ptr +std::shared_ptr QPDF_Reserved::shallowCopy() { return create(); diff --git a/libqpdf/QPDF_Stream.cc b/libqpdf/QPDF_Stream.cc index 4e5e2013..bf11bd92 100644 --- a/libqpdf/QPDF_Stream.cc +++ b/libqpdf/QPDF_Stream.cc @@ -130,7 +130,7 @@ QPDF_Stream::QPDF_Stream( qpdf, qpdf->getFilename() + ", stream object " + og.unparse(' ')); } -std::shared_ptr +std::shared_ptr QPDF_Stream::create( QPDF* qpdf, QPDFObjGen const& og, @@ -141,7 +141,7 @@ QPDF_Stream::create( return do_create(new QPDF_Stream(qpdf, og, stream_dict, offset, length)); } -std::shared_ptr +std::shared_ptr QPDF_Stream::shallowCopy() { throw std::logic_error("stream objects cannot be cloned"); diff --git a/libqpdf/QPDF_String.cc b/libqpdf/QPDF_String.cc index c6cb6c41..a9819325 100644 --- a/libqpdf/QPDF_String.cc +++ b/libqpdf/QPDF_String.cc @@ -26,13 +26,13 @@ QPDF_String::QPDF_String(std::string const& val) : { } -std::shared_ptr +std::shared_ptr QPDF_String::create(std::string const& val) { return do_create(new QPDF_String(val)); } -std::shared_ptr +std::shared_ptr QPDF_String::create_utf16(std::string const& utf8_val) { std::string result; @@ -42,7 +42,7 @@ QPDF_String::create_utf16(std::string const& utf8_val) return do_create(new QPDF_String(result)); } -std::shared_ptr +std::shared_ptr QPDF_String::shallowCopy() { return create(val); diff --git a/libqpdf/QPDF_Unresolved.cc b/libqpdf/QPDF_Unresolved.cc index f824a9a6..f72281c0 100644 --- a/libqpdf/QPDF_Unresolved.cc +++ b/libqpdf/QPDF_Unresolved.cc @@ -7,13 +7,13 @@ QPDF_Unresolved::QPDF_Unresolved(QPDF* qpdf, QPDFObjGen const& og) : { } -std::shared_ptr +std::shared_ptr QPDF_Unresolved::create(QPDF* qpdf, QPDFObjGen const& og) { return do_create(new QPDF_Unresolved(qpdf, og)); } -std::shared_ptr +std::shared_ptr QPDF_Unresolved::shallowCopy() { throw std::logic_error( diff --git a/libqpdf/qpdf/QPDFObject.hh b/libqpdf/qpdf/QPDFObject.hh deleted file mode 100644 index 9d3c1fec..00000000 --- a/libqpdf/qpdf/QPDFObject.hh +++ /dev/null @@ -1,146 +0,0 @@ -#ifndef QPDFOBJECT_HH -#define QPDFOBJECT_HH - -#include -#include -#include -#include -#include - -#include - -class QPDF; -class QPDFObjectHandle; - -class QPDFObject -{ - friend class QPDFValue; - - public: - QPDFObject() = default; - - std::shared_ptr - shallowCopy() - { - return value->shallowCopy(); - } - std::string - unparse() - { - return value->unparse(); - } - JSON - getJSON(int json_version) - { - return value->getJSON(json_version); - } - - // Return a unique type code for the object - qpdf_object_type_e - getTypeCode() const - { - return value->type_code; - } - - // Return a string literal that describes the type, useful for - // debugging and testing - char const* - getTypeName() const - { - return value->type_name; - } - // Returns nullptr for direct objects - QPDF* - getQPDF() const - { - return value->qpdf; - } - QPDFObjGen - getObjGen() const - { - return value->og; - } - - void - setDescription(QPDF* qpdf, std::string const& description) - { - return value->setDescription(qpdf, description); - } - bool - getDescription(QPDF*& qpdf, std::string& description) - { - return value->getDescription(qpdf, description); - } - bool - hasDescription() - { - return value->hasDescription(); - } - void - setParsedOffset(qpdf_offset_t offset) - { - value->setParsedOffset(offset); - } - qpdf_offset_t - getParsedOffset() - { - return value->getParsedOffset(); - } - void - assign(std::shared_ptr o) - { - value = o->value; - } - void - swapWith(std::shared_ptr o) - { - auto v = value; - value = o->value; - o->value = v; - auto og = value->og; - value->og = o->value->og; - o->value->og = og; - } - - // The following two methods are for use by class QPDF only - void - setObjGen(QPDF* qpdf, QPDFObjGen const& og) - { - value->qpdf = qpdf; - value->og = og; - } - void - resetObjGen() - { - value->qpdf = nullptr; - value->og = QPDFObjGen(); - } - - bool - isUnresolved() const - { - return value->type_code == ::ot_unresolved; - } - void - resolve() - { - if (isUnresolved()) { - doResolve(); - } - } - void doResolve(); - - template - T* - as() - { - return dynamic_cast(value.get()); - } - - private: - QPDFObject(QPDFObject const&) = delete; - QPDFObject& operator=(QPDFObject const&) = delete; - std::shared_ptr value; -}; - -#endif // QPDFOBJECT_HH diff --git a/libqpdf/qpdf/QPDFValue.hh b/libqpdf/qpdf/QPDFValue.hh index abcd02fc..bac573d6 100644 --- a/libqpdf/qpdf/QPDFValue.hh +++ b/libqpdf/qpdf/QPDFValue.hh @@ -11,16 +11,16 @@ class QPDF; class QPDFObjectHandle; -class QPDFObject; +class QPDFValueProxy; class QPDFValue { - friend class QPDFObject; + friend class QPDFValueProxy; public: virtual ~QPDFValue() = default; - virtual std::shared_ptr shallowCopy() = 0; + virtual std::shared_ptr shallowCopy() = 0; virtual std::string unparse() = 0; virtual JSON getJSON(int json_version) = 0; virtual void @@ -87,7 +87,7 @@ class QPDFValue { } - static std::shared_ptr do_create(QPDFValue*); + static std::shared_ptr do_create(QPDFValue*); private: QPDFValue(QPDFValue const&) = delete; diff --git a/libqpdf/qpdf/QPDFValueProxy.hh b/libqpdf/qpdf/QPDFValueProxy.hh new file mode 100644 index 00000000..e190318c --- /dev/null +++ b/libqpdf/qpdf/QPDFValueProxy.hh @@ -0,0 +1,146 @@ +#ifndef QPDFVALUEPROXY_HH +#define QPDFVALUEPROXY_HH + +#include +#include +#include +#include +#include + +#include + +class QPDF; +class QPDFObjectHandle; + +class QPDFValueProxy +{ + friend class QPDFValue; + + public: + QPDFValueProxy() = default; + + std::shared_ptr + shallowCopy() + { + return value->shallowCopy(); + } + std::string + unparse() + { + return value->unparse(); + } + JSON + getJSON(int json_version) + { + return value->getJSON(json_version); + } + + // Return a unique type code for the object + qpdf_object_type_e + getTypeCode() const + { + return value->type_code; + } + + // Return a string literal that describes the type, useful for + // debugging and testing + char const* + getTypeName() const + { + return value->type_name; + } + // Returns nullptr for direct objects + QPDF* + getQPDF() const + { + return value->qpdf; + } + QPDFObjGen + getObjGen() const + { + return value->og; + } + + void + setDescription(QPDF* qpdf, std::string const& description) + { + return value->setDescription(qpdf, description); + } + bool + getDescription(QPDF*& qpdf, std::string& description) + { + return value->getDescription(qpdf, description); + } + bool + hasDescription() + { + return value->hasDescription(); + } + void + setParsedOffset(qpdf_offset_t offset) + { + value->setParsedOffset(offset); + } + qpdf_offset_t + getParsedOffset() + { + return value->getParsedOffset(); + } + void + assign(std::shared_ptr o) + { + value = o->value; + } + void + swapWith(std::shared_ptr o) + { + auto v = value; + value = o->value; + o->value = v; + auto og = value->og; + value->og = o->value->og; + o->value->og = og; + } + + // The following two methods are for use by class QPDF only + void + setObjGen(QPDF* qpdf, QPDFObjGen const& og) + { + value->qpdf = qpdf; + value->og = og; + } + void + resetObjGen() + { + value->qpdf = nullptr; + value->og = QPDFObjGen(); + } + + bool + isUnresolved() const + { + return value->type_code == ::ot_unresolved; + } + void + resolve() + { + if (isUnresolved()) { + doResolve(); + } + } + void doResolve(); + + template + T* + as() + { + return dynamic_cast(value.get()); + } + + private: + QPDFValueProxy(QPDFValueProxy const&) = delete; + QPDFValueProxy& operator=(QPDFValueProxy const&) = delete; + std::shared_ptr value; +}; + +#endif // QPDFVALUEPROXY_HH diff --git a/libqpdf/qpdf/QPDF_Array.hh b/libqpdf/qpdf/QPDF_Array.hh index 672e87f6..4bae85f7 100644 --- a/libqpdf/qpdf/QPDF_Array.hh +++ b/libqpdf/qpdf/QPDF_Array.hh @@ -11,10 +11,10 @@ class QPDF_Array: public QPDFValue { public: virtual ~QPDF_Array() = default; - static std::shared_ptr + static std::shared_ptr create(std::vector const& items); - static std::shared_ptr create(SparseOHArray const& items); - virtual std::shared_ptr shallowCopy(); + static std::shared_ptr create(SparseOHArray const& items); + virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); virtual JSON getJSON(int json_version); diff --git a/libqpdf/qpdf/QPDF_Bool.hh b/libqpdf/qpdf/QPDF_Bool.hh index 3e45cd8e..33704176 100644 --- a/libqpdf/qpdf/QPDF_Bool.hh +++ b/libqpdf/qpdf/QPDF_Bool.hh @@ -7,8 +7,8 @@ class QPDF_Bool: public QPDFValue { public: virtual ~QPDF_Bool() = default; - static std::shared_ptr create(bool val); - virtual std::shared_ptr shallowCopy(); + static std::shared_ptr create(bool val); + virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); virtual JSON getJSON(int json_version); bool getVal() const; diff --git a/libqpdf/qpdf/QPDF_Dictionary.hh b/libqpdf/qpdf/QPDF_Dictionary.hh index 00de85e9..11970161 100644 --- a/libqpdf/qpdf/QPDF_Dictionary.hh +++ b/libqpdf/qpdf/QPDF_Dictionary.hh @@ -12,9 +12,9 @@ class QPDF_Dictionary: public QPDFValue { public: virtual ~QPDF_Dictionary() = default; - static std::shared_ptr + static std::shared_ptr create(std::map const& items); - virtual std::shared_ptr shallowCopy(); + virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); virtual JSON getJSON(int json_version); diff --git a/libqpdf/qpdf/QPDF_InlineImage.hh b/libqpdf/qpdf/QPDF_InlineImage.hh index b7bea9c7..9c21c183 100644 --- a/libqpdf/qpdf/QPDF_InlineImage.hh +++ b/libqpdf/qpdf/QPDF_InlineImage.hh @@ -7,8 +7,8 @@ class QPDF_InlineImage: public QPDFValue { public: virtual ~QPDF_InlineImage() = default; - static std::shared_ptr create(std::string const& val); - virtual std::shared_ptr shallowCopy(); + static std::shared_ptr create(std::string const& val); + virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); virtual JSON getJSON(int json_version); std::string getVal() const; diff --git a/libqpdf/qpdf/QPDF_Integer.hh b/libqpdf/qpdf/QPDF_Integer.hh index 7e09673c..448bc059 100644 --- a/libqpdf/qpdf/QPDF_Integer.hh +++ b/libqpdf/qpdf/QPDF_Integer.hh @@ -7,8 +7,8 @@ class QPDF_Integer: public QPDFValue { public: virtual ~QPDF_Integer() = default; - static std::shared_ptr create(long long value); - virtual std::shared_ptr shallowCopy(); + static std::shared_ptr create(long long value); + virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); virtual JSON getJSON(int json_version); long long getVal() const; diff --git a/libqpdf/qpdf/QPDF_Name.hh b/libqpdf/qpdf/QPDF_Name.hh index 74fc7e44..bf46ee14 100644 --- a/libqpdf/qpdf/QPDF_Name.hh +++ b/libqpdf/qpdf/QPDF_Name.hh @@ -7,8 +7,8 @@ class QPDF_Name: public QPDFValue { public: virtual ~QPDF_Name() = default; - static std::shared_ptr create(std::string const& name); - virtual std::shared_ptr shallowCopy(); + static std::shared_ptr create(std::string const& name); + virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); virtual JSON getJSON(int json_version); std::string getName() const; diff --git a/libqpdf/qpdf/QPDF_Null.hh b/libqpdf/qpdf/QPDF_Null.hh index 68973de9..90ccda38 100644 --- a/libqpdf/qpdf/QPDF_Null.hh +++ b/libqpdf/qpdf/QPDF_Null.hh @@ -7,8 +7,8 @@ class QPDF_Null: public QPDFValue { public: virtual ~QPDF_Null() = default; - static std::shared_ptr create(); - virtual std::shared_ptr shallowCopy(); + static std::shared_ptr create(); + virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); virtual JSON getJSON(int json_version); diff --git a/libqpdf/qpdf/QPDF_Operator.hh b/libqpdf/qpdf/QPDF_Operator.hh index 767c0ba0..30c40070 100644 --- a/libqpdf/qpdf/QPDF_Operator.hh +++ b/libqpdf/qpdf/QPDF_Operator.hh @@ -7,8 +7,8 @@ class QPDF_Operator: public QPDFValue { public: virtual ~QPDF_Operator() = default; - static std::shared_ptr create(std::string const& val); - virtual std::shared_ptr shallowCopy(); + static std::shared_ptr create(std::string const& val); + virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); virtual JSON getJSON(int json_version); std::string getVal() const; diff --git a/libqpdf/qpdf/QPDF_Real.hh b/libqpdf/qpdf/QPDF_Real.hh index dc0f3ff8..2e5bfa02 100644 --- a/libqpdf/qpdf/QPDF_Real.hh +++ b/libqpdf/qpdf/QPDF_Real.hh @@ -7,10 +7,10 @@ class QPDF_Real: public QPDFValue { public: virtual ~QPDF_Real() = default; - static std::shared_ptr create(std::string const& val); - static std::shared_ptr + static std::shared_ptr create(std::string const& val); + static std::shared_ptr create(double value, int decimal_places, bool trim_trailing_zeroes); - virtual std::shared_ptr shallowCopy(); + virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); virtual JSON getJSON(int json_version); std::string getVal(); diff --git a/libqpdf/qpdf/QPDF_Reserved.hh b/libqpdf/qpdf/QPDF_Reserved.hh index f90242a9..23b72ec3 100644 --- a/libqpdf/qpdf/QPDF_Reserved.hh +++ b/libqpdf/qpdf/QPDF_Reserved.hh @@ -7,8 +7,8 @@ class QPDF_Reserved: public QPDFValue { public: virtual ~QPDF_Reserved() = default; - static std::shared_ptr create(); - virtual std::shared_ptr shallowCopy(); + static std::shared_ptr create(); + virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); virtual JSON getJSON(int json_version); diff --git a/libqpdf/qpdf/QPDF_Stream.hh b/libqpdf/qpdf/QPDF_Stream.hh index 6430ae58..2f38e486 100644 --- a/libqpdf/qpdf/QPDF_Stream.hh +++ b/libqpdf/qpdf/QPDF_Stream.hh @@ -17,13 +17,13 @@ class QPDF_Stream: public QPDFValue { public: virtual ~QPDF_Stream() = default; - static std::shared_ptr create( + static std::shared_ptr create( QPDF*, QPDFObjGen const& og, QPDFObjectHandle stream_dict, qpdf_offset_t offset, size_t length); - virtual std::shared_ptr shallowCopy(); + virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); virtual JSON getJSON(int json_version); virtual void setDescription(QPDF*, std::string const&); diff --git a/libqpdf/qpdf/QPDF_String.hh b/libqpdf/qpdf/QPDF_String.hh index a92427e3..a2cf9246 100644 --- a/libqpdf/qpdf/QPDF_String.hh +++ b/libqpdf/qpdf/QPDF_String.hh @@ -11,10 +11,10 @@ class QPDF_String: public QPDFValue public: virtual ~QPDF_String() = default; - static std::shared_ptr create(std::string const& val); - static std::shared_ptr + static std::shared_ptr create(std::string const& val); + static std::shared_ptr create_utf16(std::string const& utf8_val); - virtual std::shared_ptr shallowCopy(); + virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); std::string unparse(bool force_binary); virtual JSON getJSON(int json_version); diff --git a/libqpdf/qpdf/QPDF_Unresolved.hh b/libqpdf/qpdf/QPDF_Unresolved.hh index efcf4e3d..80d27102 100644 --- a/libqpdf/qpdf/QPDF_Unresolved.hh +++ b/libqpdf/qpdf/QPDF_Unresolved.hh @@ -7,8 +7,9 @@ class QPDF_Unresolved: public QPDFValue { public: virtual ~QPDF_Unresolved() = default; - static std::shared_ptr create(QPDF* qpdf, QPDFObjGen const& og); - virtual std::shared_ptr shallowCopy(); + static std::shared_ptr + create(QPDF* qpdf, QPDFObjGen const& og); + virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); virtual JSON getJSON(int json_version); -- cgit v1.2.3-54-g00ecf