From 7248cab71b69efe1e5efa3f1400d4d3970271a77 Mon Sep 17 00:00:00 2001 From: m-holger Date: Tue, 2 Aug 2022 13:12:17 +0100 Subject: Add class QPDF_Unresolved Allow QPDFObjectHandle::obj to be set prior resolving object. ot_unresolved has been appended to the list object types in order to preserve the output of existing test cases. --- libqpdf/QPDF_Unresolved.cc | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 libqpdf/QPDF_Unresolved.cc (limited to 'libqpdf/QPDF_Unresolved.cc') diff --git a/libqpdf/QPDF_Unresolved.cc b/libqpdf/QPDF_Unresolved.cc new file mode 100644 index 00000000..f348ec36 --- /dev/null +++ b/libqpdf/QPDF_Unresolved.cc @@ -0,0 +1,41 @@ +#include + +#include + +std::shared_ptr +QPDF_Unresolved::create() +{ + return do_create(new QPDF_Unresolved()); +} + +std::shared_ptr +QPDF_Unresolved::shallowCopy() +{ + return create(); +} + +std::string +QPDF_Unresolved::unparse() +{ + throw std::logic_error( + "attempted to unparse an unresolveded QPDFObjectHandle"); + return ""; +} + +JSON +QPDF_Unresolved::getJSON(int json_version) +{ + return JSON::makeNull(); +} + +QPDFObject::object_type_e +QPDF_Unresolved::getTypeCode() const +{ + return QPDFObject::ot_unresolved; +} + +char const* +QPDF_Unresolved::getTypeName() const +{ + return "unresolved"; +} -- cgit v1.2.3-54-g00ecf From 431bd666c0504af0c8a016a96a73b7efbf9737c9 Mon Sep 17 00:00:00 2001 From: m-holger Date: Tue, 2 Aug 2022 21:35:04 +0100 Subject: Split QPDFObject into QPDFObject and QPDFValue --- include/qpdf/QPDFObject.hh | 97 ++++++++++++++++++++++++++++++++-------- include/qpdf/QPDFValue.hh | 93 ++++++++++++++++++++++++++++++++++++++ libqpdf/CMakeLists.txt | 1 + libqpdf/QPDFObject.cc | 46 ------------------- libqpdf/QPDFObjectHandle.cc | 33 ++++++-------- libqpdf/QPDFValue.cc | 11 +++++ libqpdf/QPDF_Array.cc | 4 +- libqpdf/QPDF_Bool.cc | 4 +- libqpdf/QPDF_Dictionary.cc | 5 +-- libqpdf/QPDF_InlineImage.cc | 4 +- libqpdf/QPDF_Integer.cc | 4 +- libqpdf/QPDF_Name.cc | 4 +- libqpdf/QPDF_Null.cc | 4 +- libqpdf/QPDF_Operator.cc | 6 +-- libqpdf/QPDF_Real.cc | 4 +- libqpdf/QPDF_Reserved.cc | 4 +- libqpdf/QPDF_Stream.cc | 6 +-- libqpdf/QPDF_String.cc | 4 +- libqpdf/QPDF_Unresolved.cc | 6 +-- libqpdf/qpdf/QPDF_Array.hh | 6 +-- libqpdf/qpdf/QPDF_Bool.hh | 6 +-- libqpdf/qpdf/QPDF_Dictionary.hh | 6 +-- libqpdf/qpdf/QPDF_InlineImage.hh | 6 +-- libqpdf/qpdf/QPDF_Integer.hh | 6 +-- libqpdf/qpdf/QPDF_Name.hh | 6 +-- libqpdf/qpdf/QPDF_Null.hh | 6 +-- libqpdf/qpdf/QPDF_Operator.hh | 6 +-- libqpdf/qpdf/QPDF_Real.hh | 6 +-- libqpdf/qpdf/QPDF_Reserved.hh | 6 +-- libqpdf/qpdf/QPDF_Stream.hh | 6 +-- libqpdf/qpdf/QPDF_String.hh | 6 +-- libqpdf/qpdf/QPDF_Unresolved.hh | 6 +-- 32 files changed, 264 insertions(+), 154 deletions(-) create mode 100644 include/qpdf/QPDFValue.hh create mode 100644 libqpdf/QPDFValue.cc (limited to 'libqpdf/QPDF_Unresolved.cc') diff --git a/include/qpdf/QPDFObject.hh b/include/qpdf/QPDFObject.hh index 8b6f7403..db6efa4c 100644 --- a/include/qpdf/QPDFObject.hh +++ b/include/qpdf/QPDFObject.hh @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -34,9 +35,9 @@ class QPDFObjectHandle; class QPDFObject { - public: - QPDFObject(); + friend class QPDFValue; + public: // Objects derived from QPDFObject are accessible through // QPDFObjectHandle. Each object returns a unique type code that // has one of the valid qpdf_object_type_e values. As new object @@ -63,17 +64,84 @@ class QPDFObject static constexpr object_type_e ot_inlineimage = ::ot_inlineimage; static constexpr object_type_e ot_unresolved = ::ot_unresolved; + QPDFObject() = default; virtual ~QPDFObject() = default; - virtual std::shared_ptr shallowCopy() = 0; - virtual std::string unparse() = 0; - virtual JSON getJSON(int json_version) = 0; + + 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 - virtual object_type_e getTypeCode() const = 0; + object_type_e + getTypeCode() const + { + return value->getTypeCode(); + } // Return a string literal that describes the type, useful for // debugging and testing - virtual char const* getTypeName() const = 0; + char const* + getTypeName() const + { + return value->getTypeName(); + } + + 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; + } + + template + T* + as() + { + return dynamic_cast(value.get()); + } // Accessor to give specific access to non-public methods class ObjAccessor @@ -90,29 +158,20 @@ class QPDFObject } } }; - friend class ObjAccessor; - - virtual void setDescription(QPDF*, std::string const&); - bool getDescription(QPDF*&, std::string&); - bool hasDescription(); - void setParsedOffset(qpdf_offset_t offset); - qpdf_offset_t getParsedOffset(); + friend class ObjAccessor; protected: virtual void releaseResolved() { + value->releaseResolved(); } - static std::shared_ptr do_create(QPDFObject*); private: QPDFObject(QPDFObject const&) = delete; QPDFObject& operator=(QPDFObject const&) = delete; - - QPDF* owning_qpdf; - std::string object_description; - qpdf_offset_t parsed_offset; + std::shared_ptr value; }; #endif // QPDFOBJECT_HH diff --git a/include/qpdf/QPDFValue.hh b/include/qpdf/QPDFValue.hh new file mode 100644 index 00000000..b957b813 --- /dev/null +++ b/include/qpdf/QPDFValue.hh @@ -0,0 +1,93 @@ +// Copyright (c) 2005-2022 Jay Berkenbilt +// +// This file is part of qpdf. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Versions of qpdf prior to version 7 were released under the terms +// of version 2.0 of the Artistic License. At your option, you may +// continue to consider qpdf to be licensed under those terms. Please +// see the manual for additional information. + +#ifndef QPDFVALUE_HH +#define QPDFVALUE_HH + +#include +#include +#include +#include + +#include + +class QPDF; +class QPDFObjectHandle; +class QPDFObject; + +class QPDFValue +{ + friend class QPDFObject; + + public: + virtual ~QPDFValue() = default; + + virtual std::shared_ptr shallowCopy() = 0; + virtual std::string unparse() = 0; + virtual JSON getJSON(int json_version) = 0; + virtual qpdf_object_type_e getTypeCode() const = 0; + virtual char const* getTypeName() const = 0; + virtual void + setDescription(QPDF* qpdf, std::string const& description) + { + owning_qpdf = qpdf; + object_description = description; + } + bool + getDescription(QPDF*& qpdf, std::string& description) + { + qpdf = owning_qpdf; + description = object_description; + return owning_qpdf != nullptr; + } + bool + hasDescription() + { + return owning_qpdf != nullptr; + } + void + setParsedOffset(qpdf_offset_t offset) + { + parsed_offset = offset; + } + qpdf_offset_t + getParsedOffset() + { + return parsed_offset; + } + + protected: + QPDFValue() = default; + virtual void + releaseResolved() + { + } + static std::shared_ptr do_create(QPDFValue*); + + private: + QPDFValue(QPDFValue const&) = delete; + QPDFValue& operator=(QPDFValue const&) = delete; + QPDF* owning_qpdf{nullptr}; + std::string object_description; + qpdf_offset_t parsed_offset{-1}; +}; + +#endif // QPDFVALUE_HH diff --git a/libqpdf/CMakeLists.txt b/libqpdf/CMakeLists.txt index 7a4ef333..686ea04a 100644 --- a/libqpdf/CMakeLists.txt +++ b/libqpdf/CMakeLists.txt @@ -85,6 +85,7 @@ set(libqpdf_SOURCES QPDFSystemError.cc QPDFTokenizer.cc QPDFUsage.cc + QPDFValue.cc QPDFWriter.cc QPDFXRefEntry.cc QPDF_Array.cc diff --git a/libqpdf/QPDFObject.cc b/libqpdf/QPDFObject.cc index 382dd6c6..8df2b480 100644 --- a/libqpdf/QPDFObject.cc +++ b/libqpdf/QPDFObject.cc @@ -1,47 +1 @@ #include - -QPDFObject::QPDFObject() : - owning_qpdf(nullptr), - parsed_offset(-1) -{ -} - -std::shared_ptr -QPDFObject::do_create(QPDFObject* object) -{ - std::shared_ptr obj(object); - return obj; -} - -void -QPDFObject::setDescription(QPDF* qpdf, std::string const& description) -{ - this->owning_qpdf = qpdf; - this->object_description = description; -} - -bool -QPDFObject::getDescription(QPDF*& qpdf, std::string& description) -{ - qpdf = this->owning_qpdf; - description = this->object_description; - return this->owning_qpdf != nullptr; -} - -bool -QPDFObject::hasDescription() -{ - return this->owning_qpdf != nullptr; -} - -void -QPDFObject::setParsedOffset(qpdf_offset_t offset) -{ - this->parsed_offset = offset; -} - -qpdf_offset_t -QPDFObject::getParsedOffset() -{ - return this->parsed_offset; -} diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index e0e0e50a..72a35390 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -280,68 +280,67 @@ QPDFObjectHandle::getTypeName() QPDF_Array* QPDFObjectHandle::asArray() { - return isArray() ? dynamic_cast(obj.get()) : nullptr; + return dereference() ? obj->as() : nullptr; } QPDF_Bool* QPDFObjectHandle::asBool() { - return isBool() ? dynamic_cast(obj.get()) : nullptr; + return dereference() ? obj->as() : nullptr; } QPDF_Dictionary* QPDFObjectHandle::asDictionary() { - return isDictionary() ? dynamic_cast(obj.get()) : nullptr; + return dereference() ? obj->as() : nullptr; } QPDF_InlineImage* QPDFObjectHandle::asInlineImage() { - return isInlineImage() ? dynamic_cast(obj.get()) - : nullptr; + return dereference() ? obj->as() : nullptr; } QPDF_Integer* QPDFObjectHandle::asInteger() { - return isInteger() ? dynamic_cast(obj.get()) : nullptr; + return dereference() ? obj->as() : nullptr; } QPDF_Name* QPDFObjectHandle::asName() { - return isName() ? dynamic_cast(obj.get()) : nullptr; + return dereference() ? obj->as() : nullptr; } QPDF_Null* QPDFObjectHandle::asNull() { - return isNull() ? dynamic_cast(obj.get()) : nullptr; + return dereference() ? obj->as() : nullptr; } QPDF_Operator* QPDFObjectHandle::asOperator() { - return isOperator() ? dynamic_cast(obj.get()) : nullptr; + return dereference() ? obj->as() : nullptr; } QPDF_Real* QPDFObjectHandle::asReal() { - return isReal() ? dynamic_cast(obj.get()) : nullptr; + return dereference() ? obj->as() : nullptr; } QPDF_Reserved* QPDFObjectHandle::asReserved() { - return isReserved() ? dynamic_cast(obj.get()) : nullptr; + return dereference() ? obj->as() : nullptr; } QPDF_Stream* QPDFObjectHandle::asStream() { - return isStream() ? dynamic_cast(obj.get()) : nullptr; + return dereference() ? obj->as() : nullptr; } QPDF_Stream* @@ -355,7 +354,7 @@ QPDFObjectHandle::asStreamWithAssert() QPDF_String* QPDFObjectHandle::asString() { - return isString() ? dynamic_cast(obj.get()) : nullptr; + return dereference() ? obj->as() : nullptr; } bool @@ -1716,11 +1715,8 @@ QPDFObjectHandle::unparseResolved() if (!dereference()) { throw std::logic_error( "attempted to dereference an uninitialized QPDFObjectHandle"); - } else if (isReserved()) { - throw std::logic_error( - "QPDFObjectHandle: attempting to unparse a reserved object"); } - return this->obj->unparse(); + return obj->unparse(); } std::string @@ -1749,9 +1745,6 @@ QPDFObjectHandle::getJSON(int json_version, bool dereference_indirect) } else if (!dereference()) { throw std::logic_error( "attempted to dereference an uninitialized QPDFObjectHandle"); - } else if (isReserved()) { - throw std::logic_error( - "QPDFObjectHandle: attempting to unparse a reserved object"); } else { return obj->getJSON(json_version); } diff --git a/libqpdf/QPDFValue.cc b/libqpdf/QPDFValue.cc new file mode 100644 index 00000000..8a6222d2 --- /dev/null +++ b/libqpdf/QPDFValue.cc @@ -0,0 +1,11 @@ +#include + +#include + +std::shared_ptr +QPDFValue::do_create(QPDFValue* object) +{ + std::shared_ptr obj(new QPDFObject()); + obj->value = std::shared_ptr(object); + return obj; +} diff --git a/libqpdf/QPDF_Array.cc b/libqpdf/QPDF_Array.cc index 55e4d20a..ff35e9a3 100644 --- a/libqpdf/QPDF_Array.cc +++ b/libqpdf/QPDF_Array.cc @@ -62,10 +62,10 @@ QPDF_Array::getJSON(int json_version) return j; } -QPDFObject::object_type_e +qpdf_object_type_e QPDF_Array::getTypeCode() const { - return QPDFObject::ot_array; + return ::ot_array; } char const* diff --git a/libqpdf/QPDF_Bool.cc b/libqpdf/QPDF_Bool.cc index f26325c3..e58eb62b 100644 --- a/libqpdf/QPDF_Bool.cc +++ b/libqpdf/QPDF_Bool.cc @@ -29,10 +29,10 @@ QPDF_Bool::getJSON(int json_version) return JSON::makeBool(this->val); } -QPDFObject::object_type_e +qpdf_object_type_e QPDF_Bool::getTypeCode() const { - return QPDFObject::ot_boolean; + return ::ot_boolean; } char const* diff --git a/libqpdf/QPDF_Dictionary.cc b/libqpdf/QPDF_Dictionary.cc index 60b2339f..7f374f81 100644 --- a/libqpdf/QPDF_Dictionary.cc +++ b/libqpdf/QPDF_Dictionary.cc @@ -1,7 +1,6 @@ #include #include -#include QPDF_Dictionary::QPDF_Dictionary( std::map const& items) : @@ -58,10 +57,10 @@ QPDF_Dictionary::getJSON(int json_version) return j; } -QPDFObject::object_type_e +qpdf_object_type_e QPDF_Dictionary::getTypeCode() const { - return QPDFObject::ot_dictionary; + return ::ot_dictionary; } char const* diff --git a/libqpdf/QPDF_InlineImage.cc b/libqpdf/QPDF_InlineImage.cc index c3c656e0..494363f6 100644 --- a/libqpdf/QPDF_InlineImage.cc +++ b/libqpdf/QPDF_InlineImage.cc @@ -29,10 +29,10 @@ QPDF_InlineImage::getJSON(int json_version) return JSON::makeNull(); } -QPDFObject::object_type_e +qpdf_object_type_e QPDF_InlineImage::getTypeCode() const { - return QPDFObject::ot_inlineimage; + return ::ot_inlineimage; } char const* diff --git a/libqpdf/QPDF_Integer.cc b/libqpdf/QPDF_Integer.cc index e8d23e4a..68f97420 100644 --- a/libqpdf/QPDF_Integer.cc +++ b/libqpdf/QPDF_Integer.cc @@ -31,10 +31,10 @@ QPDF_Integer::getJSON(int json_version) return JSON::makeInt(this->val); } -QPDFObject::object_type_e +qpdf_object_type_e QPDF_Integer::getTypeCode() const { - return QPDFObject::ot_integer; + return ::ot_integer; } char const* diff --git a/libqpdf/QPDF_Name.cc b/libqpdf/QPDF_Name.cc index 73990775..6831bcba 100644 --- a/libqpdf/QPDF_Name.cc +++ b/libqpdf/QPDF_Name.cc @@ -61,10 +61,10 @@ QPDF_Name::getJSON(int json_version) } } -QPDFObject::object_type_e +qpdf_object_type_e QPDF_Name::getTypeCode() const { - return QPDFObject::ot_name; + return ::ot_name; } char const* diff --git a/libqpdf/QPDF_Null.cc b/libqpdf/QPDF_Null.cc index b015ed8b..67b564c8 100644 --- a/libqpdf/QPDF_Null.cc +++ b/libqpdf/QPDF_Null.cc @@ -24,10 +24,10 @@ QPDF_Null::getJSON(int json_version) return JSON::makeNull(); } -QPDFObject::object_type_e +qpdf_object_type_e QPDF_Null::getTypeCode() const { - return QPDFObject::ot_null; + return ::ot_null; } char const* diff --git a/libqpdf/QPDF_Operator.cc b/libqpdf/QPDF_Operator.cc index cd5009ae..84bde381 100644 --- a/libqpdf/QPDF_Operator.cc +++ b/libqpdf/QPDF_Operator.cc @@ -20,7 +20,7 @@ QPDF_Operator::shallowCopy() std::string QPDF_Operator::unparse() { - return this->val; + return val; } JSON @@ -29,10 +29,10 @@ QPDF_Operator::getJSON(int json_version) return JSON::makeNull(); } -QPDFObject::object_type_e +qpdf_object_type_e QPDF_Operator::getTypeCode() const { - return QPDFObject::ot_operator; + return ::ot_operator; } char const* diff --git a/libqpdf/QPDF_Real.cc b/libqpdf/QPDF_Real.cc index 138bbb3c..1604d4ba 100644 --- a/libqpdf/QPDF_Real.cc +++ b/libqpdf/QPDF_Real.cc @@ -60,10 +60,10 @@ QPDF_Real::getJSON(int json_version) return JSON::makeNumber(result); } -QPDFObject::object_type_e +qpdf_object_type_e QPDF_Real::getTypeCode() const { - return QPDFObject::ot_real; + return ::ot_real; } char const* diff --git a/libqpdf/QPDF_Reserved.cc b/libqpdf/QPDF_Reserved.cc index d5009674..14f82a62 100644 --- a/libqpdf/QPDF_Reserved.cc +++ b/libqpdf/QPDF_Reserved.cc @@ -30,10 +30,10 @@ QPDF_Reserved::getJSON(int json_version) return JSON::makeNull(); } -QPDFObject::object_type_e +qpdf_object_type_e QPDF_Reserved::getTypeCode() const { - return QPDFObject::ot_reserved; + return ::ot_reserved; } char const* diff --git a/libqpdf/QPDF_Stream.cc b/libqpdf/QPDF_Stream.cc index 1b7f9461..7a74512f 100644 --- a/libqpdf/QPDF_Stream.cc +++ b/libqpdf/QPDF_Stream.cc @@ -291,10 +291,10 @@ QPDF_Stream::getStreamJSON( return result; } -QPDFObject::object_type_e +qpdf_object_type_e QPDF_Stream::getTypeCode() const { - return QPDFObject::ot_stream; + return ::ot_stream; } char const* @@ -306,7 +306,7 @@ QPDF_Stream::getTypeName() const void QPDF_Stream::setDescription(QPDF* qpdf, std::string const& description) { - this->QPDFObject::setDescription(qpdf, description); + this->QPDFValue::setDescription(qpdf, description); setDictDescription(); } diff --git a/libqpdf/QPDF_String.cc b/libqpdf/QPDF_String.cc index b038366b..c8e21463 100644 --- a/libqpdf/QPDF_String.cc +++ b/libqpdf/QPDF_String.cc @@ -84,10 +84,10 @@ QPDF_String::getJSON(int json_version) return JSON::makeString(result); } -QPDFObject::object_type_e +qpdf_object_type_e QPDF_String::getTypeCode() const { - return QPDFObject::ot_string; + return ::ot_string; } char const* diff --git a/libqpdf/QPDF_Unresolved.cc b/libqpdf/QPDF_Unresolved.cc index f348ec36..b51075f7 100644 --- a/libqpdf/QPDF_Unresolved.cc +++ b/libqpdf/QPDF_Unresolved.cc @@ -18,7 +18,7 @@ std::string QPDF_Unresolved::unparse() { throw std::logic_error( - "attempted to unparse an unresolveded QPDFObjectHandle"); + "attempted to unparse an unresolved QPDFObjectHandle"); return ""; } @@ -28,10 +28,10 @@ QPDF_Unresolved::getJSON(int json_version) return JSON::makeNull(); } -QPDFObject::object_type_e +qpdf_object_type_e QPDF_Unresolved::getTypeCode() const { - return QPDFObject::ot_unresolved; + return ::ot_unresolved; } char const* diff --git a/libqpdf/qpdf/QPDF_Array.hh b/libqpdf/qpdf/QPDF_Array.hh index 3e095637..b0207115 100644 --- a/libqpdf/qpdf/QPDF_Array.hh +++ b/libqpdf/qpdf/QPDF_Array.hh @@ -1,13 +1,13 @@ #ifndef QPDF_ARRAY_HH #define QPDF_ARRAY_HH -#include +#include #include #include #include -class QPDF_Array: public QPDFObject +class QPDF_Array: public QPDFValue { public: virtual ~QPDF_Array() = default; @@ -17,7 +17,7 @@ class QPDF_Array: public QPDFObject virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); virtual JSON getJSON(int json_version); - virtual QPDFObject::object_type_e getTypeCode() const; + virtual qpdf_object_type_e getTypeCode() const; virtual char const* getTypeName() const; int getNItems() const; diff --git a/libqpdf/qpdf/QPDF_Bool.hh b/libqpdf/qpdf/QPDF_Bool.hh index dbedc70a..2de585cb 100644 --- a/libqpdf/qpdf/QPDF_Bool.hh +++ b/libqpdf/qpdf/QPDF_Bool.hh @@ -1,9 +1,9 @@ #ifndef QPDF_BOOL_HH #define QPDF_BOOL_HH -#include +#include -class QPDF_Bool: public QPDFObject +class QPDF_Bool: public QPDFValue { public: virtual ~QPDF_Bool() = default; @@ -11,7 +11,7 @@ class QPDF_Bool: public QPDFObject virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); virtual JSON getJSON(int json_version); - virtual QPDFObject::object_type_e getTypeCode() const; + virtual qpdf_object_type_e getTypeCode() const; virtual char const* getTypeName() const; bool getVal() const; diff --git a/libqpdf/qpdf/QPDF_Dictionary.hh b/libqpdf/qpdf/QPDF_Dictionary.hh index cacc8961..5761b030 100644 --- a/libqpdf/qpdf/QPDF_Dictionary.hh +++ b/libqpdf/qpdf/QPDF_Dictionary.hh @@ -1,14 +1,14 @@ #ifndef QPDF_DICTIONARY_HH #define QPDF_DICTIONARY_HH -#include +#include #include #include #include -class QPDF_Dictionary: public QPDFObject +class QPDF_Dictionary: public QPDFValue { public: virtual ~QPDF_Dictionary() = default; @@ -17,7 +17,7 @@ class QPDF_Dictionary: public QPDFObject virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); virtual JSON getJSON(int json_version); - virtual QPDFObject::object_type_e getTypeCode() const; + virtual qpdf_object_type_e getTypeCode() const; virtual char const* getTypeName() const; // hasKey() and getKeys() treat keys with null values as if they diff --git a/libqpdf/qpdf/QPDF_InlineImage.hh b/libqpdf/qpdf/QPDF_InlineImage.hh index caaeaf87..31f7529a 100644 --- a/libqpdf/qpdf/QPDF_InlineImage.hh +++ b/libqpdf/qpdf/QPDF_InlineImage.hh @@ -1,9 +1,9 @@ #ifndef QPDF_INLINEIMAGE_HH #define QPDF_INLINEIMAGE_HH -#include +#include -class QPDF_InlineImage: public QPDFObject +class QPDF_InlineImage: public QPDFValue { public: virtual ~QPDF_InlineImage() = default; @@ -11,7 +11,7 @@ class QPDF_InlineImage: public QPDFObject virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); virtual JSON getJSON(int json_version); - virtual QPDFObject::object_type_e getTypeCode() const; + virtual qpdf_object_type_e getTypeCode() const; virtual char const* getTypeName() const; std::string getVal() const; diff --git a/libqpdf/qpdf/QPDF_Integer.hh b/libqpdf/qpdf/QPDF_Integer.hh index 2c17daf0..cf201021 100644 --- a/libqpdf/qpdf/QPDF_Integer.hh +++ b/libqpdf/qpdf/QPDF_Integer.hh @@ -1,9 +1,9 @@ #ifndef QPDF_INTEGER_HH #define QPDF_INTEGER_HH -#include +#include -class QPDF_Integer: public QPDFObject +class QPDF_Integer: public QPDFValue { public: virtual ~QPDF_Integer() = default; @@ -11,7 +11,7 @@ class QPDF_Integer: public QPDFObject virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); virtual JSON getJSON(int json_version); - virtual QPDFObject::object_type_e getTypeCode() const; + virtual qpdf_object_type_e getTypeCode() const; virtual char const* getTypeName() const; long long getVal() const; diff --git a/libqpdf/qpdf/QPDF_Name.hh b/libqpdf/qpdf/QPDF_Name.hh index cf653b2e..438b118e 100644 --- a/libqpdf/qpdf/QPDF_Name.hh +++ b/libqpdf/qpdf/QPDF_Name.hh @@ -1,9 +1,9 @@ #ifndef QPDF_NAME_HH #define QPDF_NAME_HH -#include +#include -class QPDF_Name: public QPDFObject +class QPDF_Name: public QPDFValue { public: virtual ~QPDF_Name() = default; @@ -11,7 +11,7 @@ class QPDF_Name: public QPDFObject virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); virtual JSON getJSON(int json_version); - virtual QPDFObject::object_type_e getTypeCode() const; + virtual qpdf_object_type_e getTypeCode() const; virtual char const* getTypeName() const; std::string getName() const; diff --git a/libqpdf/qpdf/QPDF_Null.hh b/libqpdf/qpdf/QPDF_Null.hh index 16833424..7f722a3a 100644 --- a/libqpdf/qpdf/QPDF_Null.hh +++ b/libqpdf/qpdf/QPDF_Null.hh @@ -1,9 +1,9 @@ #ifndef QPDF_NULL_HH #define QPDF_NULL_HH -#include +#include -class QPDF_Null: public QPDFObject +class QPDF_Null: public QPDFValue { public: virtual ~QPDF_Null() = default; @@ -11,7 +11,7 @@ class QPDF_Null: public QPDFObject virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); virtual JSON getJSON(int json_version); - virtual QPDFObject::object_type_e getTypeCode() const; + virtual qpdf_object_type_e getTypeCode() const; virtual char const* getTypeName() const; private: diff --git a/libqpdf/qpdf/QPDF_Operator.hh b/libqpdf/qpdf/QPDF_Operator.hh index 1da43d72..d17f1629 100644 --- a/libqpdf/qpdf/QPDF_Operator.hh +++ b/libqpdf/qpdf/QPDF_Operator.hh @@ -1,9 +1,9 @@ #ifndef QPDF_OPERATOR_HH #define QPDF_OPERATOR_HH -#include +#include -class QPDF_Operator: public QPDFObject +class QPDF_Operator: public QPDFValue { public: virtual ~QPDF_Operator() = default; @@ -11,7 +11,7 @@ class QPDF_Operator: public QPDFObject virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); virtual JSON getJSON(int json_version); - virtual QPDFObject::object_type_e getTypeCode() const; + virtual qpdf_object_type_e getTypeCode() const; virtual char const* getTypeName() const; std::string getVal() const; diff --git a/libqpdf/qpdf/QPDF_Real.hh b/libqpdf/qpdf/QPDF_Real.hh index f5ab4bd6..97375c73 100644 --- a/libqpdf/qpdf/QPDF_Real.hh +++ b/libqpdf/qpdf/QPDF_Real.hh @@ -1,9 +1,9 @@ #ifndef QPDF_REAL_HH #define QPDF_REAL_HH -#include +#include -class QPDF_Real: public QPDFObject +class QPDF_Real: public QPDFValue { public: virtual ~QPDF_Real() = default; @@ -13,7 +13,7 @@ class QPDF_Real: public QPDFObject virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); virtual JSON getJSON(int json_version); - virtual QPDFObject::object_type_e getTypeCode() const; + virtual qpdf_object_type_e getTypeCode() const; virtual char const* getTypeName() const; std::string getVal(); diff --git a/libqpdf/qpdf/QPDF_Reserved.hh b/libqpdf/qpdf/QPDF_Reserved.hh index 243a1728..e9f8313a 100644 --- a/libqpdf/qpdf/QPDF_Reserved.hh +++ b/libqpdf/qpdf/QPDF_Reserved.hh @@ -1,9 +1,9 @@ #ifndef QPDF_RESERVED_HH #define QPDF_RESERVED_HH -#include +#include -class QPDF_Reserved: public QPDFObject +class QPDF_Reserved: public QPDFValue { public: virtual ~QPDF_Reserved() = default; @@ -11,7 +11,7 @@ class QPDF_Reserved: public QPDFObject virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); virtual JSON getJSON(int json_version); - virtual QPDFObject::object_type_e getTypeCode() const; + virtual qpdf_object_type_e getTypeCode() const; virtual char const* getTypeName() const; private: diff --git a/libqpdf/qpdf/QPDF_Stream.hh b/libqpdf/qpdf/QPDF_Stream.hh index 8980c751..639d5298 100644 --- a/libqpdf/qpdf/QPDF_Stream.hh +++ b/libqpdf/qpdf/QPDF_Stream.hh @@ -3,9 +3,9 @@ #include -#include #include #include +#include #include #include @@ -13,7 +13,7 @@ class Pipeline; class QPDF; -class QPDF_Stream: public QPDFObject +class QPDF_Stream: public QPDFValue { public: virtual ~QPDF_Stream() = default; @@ -26,7 +26,7 @@ class QPDF_Stream: public QPDFObject virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); virtual JSON getJSON(int json_version); - virtual QPDFObject::object_type_e getTypeCode() const; + virtual qpdf_object_type_e getTypeCode() const; virtual char const* getTypeName() const; virtual void setDescription(QPDF*, std::string const&); QPDFObjectHandle getDict() const; diff --git a/libqpdf/qpdf/QPDF_String.hh b/libqpdf/qpdf/QPDF_String.hh index b6d77637..9b6fc95c 100644 --- a/libqpdf/qpdf/QPDF_String.hh +++ b/libqpdf/qpdf/QPDF_String.hh @@ -1,11 +1,11 @@ #ifndef QPDF_STRING_HH #define QPDF_STRING_HH -#include +#include // QPDF_Strings may included embedded null characters. -class QPDF_String: public QPDFObject +class QPDF_String: public QPDFValue { friend class QPDFWriter; @@ -16,7 +16,7 @@ class QPDF_String: public QPDFObject create_utf16(std::string const& utf8_val); virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); - virtual QPDFObject::object_type_e getTypeCode() const; + virtual qpdf_object_type_e getTypeCode() const; virtual char const* getTypeName() const; 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 4f1c5238..c17748b5 100644 --- a/libqpdf/qpdf/QPDF_Unresolved.hh +++ b/libqpdf/qpdf/QPDF_Unresolved.hh @@ -1,9 +1,9 @@ #ifndef QPDF_UNRESOLVED_HH #define QPDF_UNRESOLVED_HH -#include +#include -class QPDF_Unresolved: public QPDFObject +class QPDF_Unresolved: public QPDFValue { public: virtual ~QPDF_Unresolved() = default; @@ -11,7 +11,7 @@ class QPDF_Unresolved: public QPDFObject virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); virtual JSON getJSON(int json_version); - virtual QPDFObject::object_type_e getTypeCode() const; + virtual qpdf_object_type_e getTypeCode() const; virtual char const* getTypeName() const; private: -- cgit v1.2.3-54-g00ecf From c7005e8a6d626d1c66bd780314c2520d12b0ca9a Mon Sep 17 00:00:00 2001 From: m-holger Date: Tue, 2 Aug 2022 22:57:33 +0100 Subject: Remove virtual methods QPDFValue::getTypeCode and getTypeName --- include/qpdf/QPDFObject.hh | 5 ++--- include/qpdf/QPDFValue.hh | 16 +++++++++++++--- libqpdf/QPDF_Array.cc | 16 +++------------- libqpdf/QPDF_Bool.cc | 13 +------------ libqpdf/QPDF_Dictionary.cc | 13 +------------ libqpdf/QPDF_InlineImage.cc | 13 +------------ libqpdf/QPDF_Integer.cc | 13 +------------ libqpdf/QPDF_Name.cc | 13 +------------ libqpdf/QPDF_Null.cc | 17 +++++------------ libqpdf/QPDF_Operator.cc | 13 +------------ libqpdf/QPDF_Real.cc | 14 ++------------ libqpdf/QPDF_Reserved.cc | 17 +++++------------ libqpdf/QPDF_Stream.cc | 13 +------------ libqpdf/QPDF_String.cc | 13 +------------ libqpdf/QPDF_Unresolved.cc | 17 +++++------------ libqpdf/qpdf/QPDF_Array.hh | 2 -- libqpdf/qpdf/QPDF_Bool.hh | 2 -- libqpdf/qpdf/QPDF_Dictionary.hh | 2 -- libqpdf/qpdf/QPDF_InlineImage.hh | 2 -- libqpdf/qpdf/QPDF_Integer.hh | 2 -- libqpdf/qpdf/QPDF_Name.hh | 2 -- libqpdf/qpdf/QPDF_Null.hh | 4 +--- libqpdf/qpdf/QPDF_Operator.hh | 2 -- libqpdf/qpdf/QPDF_Real.hh | 2 -- libqpdf/qpdf/QPDF_Reserved.hh | 4 +--- libqpdf/qpdf/QPDF_Stream.hh | 2 -- libqpdf/qpdf/QPDF_String.hh | 2 -- libqpdf/qpdf/QPDF_Unresolved.hh | 4 +--- 28 files changed, 46 insertions(+), 192 deletions(-) (limited to 'libqpdf/QPDF_Unresolved.cc') diff --git a/include/qpdf/QPDFObject.hh b/include/qpdf/QPDFObject.hh index db6efa4c..a1930168 100644 --- a/include/qpdf/QPDFObject.hh +++ b/include/qpdf/QPDFObject.hh @@ -87,7 +87,7 @@ class QPDFObject object_type_e getTypeCode() const { - return value->getTypeCode(); + return value->type_code; } // Return a string literal that describes the type, useful for @@ -95,9 +95,8 @@ class QPDFObject char const* getTypeName() const { - return value->getTypeName(); + return value->type_name; } - void setDescription(QPDF* qpdf, std::string const& description) { diff --git a/include/qpdf/QPDFValue.hh b/include/qpdf/QPDFValue.hh index b957b813..33558f1b 100644 --- a/include/qpdf/QPDFValue.hh +++ b/include/qpdf/QPDFValue.hh @@ -43,8 +43,6 @@ class QPDFValue virtual std::shared_ptr shallowCopy() = 0; virtual std::string unparse() = 0; virtual JSON getJSON(int json_version) = 0; - virtual qpdf_object_type_e getTypeCode() const = 0; - virtual char const* getTypeName() const = 0; virtual void setDescription(QPDF* qpdf, std::string const& description) { @@ -75,7 +73,17 @@ class QPDFValue } protected: - QPDFValue() = default; + QPDFValue() : + type_code(::ot_uninitialized), + type_name("uninitilized") + { + } + QPDFValue(qpdf_object_type_e type_code, char const* type_name) : + type_code(type_code), + type_name(type_name) + { + } + virtual void releaseResolved() { @@ -88,6 +96,8 @@ class QPDFValue QPDF* owning_qpdf{nullptr}; std::string object_description; qpdf_offset_t parsed_offset{-1}; + const qpdf_object_type_e type_code; + char const* type_name; }; #endif // QPDFVALUE_HH diff --git a/libqpdf/QPDF_Array.cc b/libqpdf/QPDF_Array.cc index ff35e9a3..63fe98d4 100644 --- a/libqpdf/QPDF_Array.cc +++ b/libqpdf/QPDF_Array.cc @@ -4,12 +4,14 @@ #include #include -QPDF_Array::QPDF_Array(std::vector const& v) +QPDF_Array::QPDF_Array(std::vector const& v) : + QPDFValue(::ot_array, "array") { setFromVector(v); } QPDF_Array::QPDF_Array(SparseOHArray const& items) : + QPDFValue(::ot_array, "array"), elements(items) { } @@ -62,18 +64,6 @@ QPDF_Array::getJSON(int json_version) return j; } -qpdf_object_type_e -QPDF_Array::getTypeCode() const -{ - return ::ot_array; -} - -char const* -QPDF_Array::getTypeName() const -{ - return "array"; -} - int QPDF_Array::getNItems() const { diff --git a/libqpdf/QPDF_Bool.cc b/libqpdf/QPDF_Bool.cc index e58eb62b..efbfd6c9 100644 --- a/libqpdf/QPDF_Bool.cc +++ b/libqpdf/QPDF_Bool.cc @@ -1,6 +1,7 @@ #include QPDF_Bool::QPDF_Bool(bool val) : + QPDFValue(::ot_boolean, "boolean"), val(val) { } @@ -29,18 +30,6 @@ QPDF_Bool::getJSON(int json_version) return JSON::makeBool(this->val); } -qpdf_object_type_e -QPDF_Bool::getTypeCode() const -{ - return ::ot_boolean; -} - -char const* -QPDF_Bool::getTypeName() const -{ - return "boolean"; -} - bool QPDF_Bool::getVal() const { diff --git a/libqpdf/QPDF_Dictionary.cc b/libqpdf/QPDF_Dictionary.cc index 7f374f81..845bcad8 100644 --- a/libqpdf/QPDF_Dictionary.cc +++ b/libqpdf/QPDF_Dictionary.cc @@ -4,6 +4,7 @@ QPDF_Dictionary::QPDF_Dictionary( std::map const& items) : + QPDFValue(::ot_dictionary, "dictionary"), items(items) { } @@ -57,18 +58,6 @@ QPDF_Dictionary::getJSON(int json_version) return j; } -qpdf_object_type_e -QPDF_Dictionary::getTypeCode() const -{ - return ::ot_dictionary; -} - -char const* -QPDF_Dictionary::getTypeName() const -{ - return "dictionary"; -} - bool QPDF_Dictionary::hasKey(std::string const& key) { diff --git a/libqpdf/QPDF_InlineImage.cc b/libqpdf/QPDF_InlineImage.cc index 494363f6..76318196 100644 --- a/libqpdf/QPDF_InlineImage.cc +++ b/libqpdf/QPDF_InlineImage.cc @@ -1,6 +1,7 @@ #include QPDF_InlineImage::QPDF_InlineImage(std::string const& val) : + QPDFValue(::ot_inlineimage, "inline-image"), val(val) { } @@ -29,18 +30,6 @@ QPDF_InlineImage::getJSON(int json_version) return JSON::makeNull(); } -qpdf_object_type_e -QPDF_InlineImage::getTypeCode() const -{ - return ::ot_inlineimage; -} - -char const* -QPDF_InlineImage::getTypeName() const -{ - return "inline-image"; -} - std::string QPDF_InlineImage::getVal() const { diff --git a/libqpdf/QPDF_Integer.cc b/libqpdf/QPDF_Integer.cc index 68f97420..24812573 100644 --- a/libqpdf/QPDF_Integer.cc +++ b/libqpdf/QPDF_Integer.cc @@ -3,6 +3,7 @@ #include QPDF_Integer::QPDF_Integer(long long val) : + QPDFValue(::ot_integer, "integer"), val(val) { } @@ -31,18 +32,6 @@ QPDF_Integer::getJSON(int json_version) return JSON::makeInt(this->val); } -qpdf_object_type_e -QPDF_Integer::getTypeCode() const -{ - return ::ot_integer; -} - -char const* -QPDF_Integer::getTypeName() const -{ - return "integer"; -} - long long QPDF_Integer::getVal() const { diff --git a/libqpdf/QPDF_Name.cc b/libqpdf/QPDF_Name.cc index 6831bcba..c86d34b4 100644 --- a/libqpdf/QPDF_Name.cc +++ b/libqpdf/QPDF_Name.cc @@ -5,6 +5,7 @@ #include QPDF_Name::QPDF_Name(std::string const& name) : + QPDFValue(::ot_name, "name"), name(name) { } @@ -61,18 +62,6 @@ QPDF_Name::getJSON(int json_version) } } -qpdf_object_type_e -QPDF_Name::getTypeCode() const -{ - return ::ot_name; -} - -char const* -QPDF_Name::getTypeName() const -{ - return "name"; -} - std::string QPDF_Name::getName() const { diff --git a/libqpdf/QPDF_Null.cc b/libqpdf/QPDF_Null.cc index 67b564c8..f60dda1f 100644 --- a/libqpdf/QPDF_Null.cc +++ b/libqpdf/QPDF_Null.cc @@ -1,5 +1,10 @@ #include +QPDF_Null::QPDF_Null() : + QPDFValue(::ot_null, "null") +{ +} + std::shared_ptr QPDF_Null::create() { @@ -23,15 +28,3 @@ QPDF_Null::getJSON(int json_version) { return JSON::makeNull(); } - -qpdf_object_type_e -QPDF_Null::getTypeCode() const -{ - return ::ot_null; -} - -char const* -QPDF_Null::getTypeName() const -{ - return "null"; -} diff --git a/libqpdf/QPDF_Operator.cc b/libqpdf/QPDF_Operator.cc index 84bde381..547ff40a 100644 --- a/libqpdf/QPDF_Operator.cc +++ b/libqpdf/QPDF_Operator.cc @@ -1,6 +1,7 @@ #include QPDF_Operator::QPDF_Operator(std::string const& val) : + QPDFValue(::ot_operator, "operator"), val(val) { } @@ -29,18 +30,6 @@ QPDF_Operator::getJSON(int json_version) return JSON::makeNull(); } -qpdf_object_type_e -QPDF_Operator::getTypeCode() const -{ - return ::ot_operator; -} - -char const* -QPDF_Operator::getTypeName() const -{ - return "operator"; -} - std::string QPDF_Operator::getVal() const { diff --git a/libqpdf/QPDF_Real.cc b/libqpdf/QPDF_Real.cc index 1604d4ba..85c9ceeb 100644 --- a/libqpdf/QPDF_Real.cc +++ b/libqpdf/QPDF_Real.cc @@ -3,12 +3,14 @@ #include QPDF_Real::QPDF_Real(std::string const& val) : + QPDFValue(::ot_real, "real"), val(val) { } QPDF_Real::QPDF_Real( double value, int decimal_places, bool trim_trailing_zeroes) : + QPDFValue(::ot_real, "real"), val(QUtil::double_to_string(value, decimal_places, trim_trailing_zeroes)) { } @@ -60,18 +62,6 @@ QPDF_Real::getJSON(int json_version) return JSON::makeNumber(result); } -qpdf_object_type_e -QPDF_Real::getTypeCode() const -{ - return ::ot_real; -} - -char const* -QPDF_Real::getTypeName() const -{ - return "real"; -} - std::string QPDF_Real::getVal() { diff --git a/libqpdf/QPDF_Reserved.cc b/libqpdf/QPDF_Reserved.cc index 14f82a62..f5af4688 100644 --- a/libqpdf/QPDF_Reserved.cc +++ b/libqpdf/QPDF_Reserved.cc @@ -2,6 +2,11 @@ #include +QPDF_Reserved::QPDF_Reserved() : + QPDFValue(::ot_reserved, "reserved") +{ +} + std::shared_ptr QPDF_Reserved::create() { @@ -29,15 +34,3 @@ QPDF_Reserved::getJSON(int json_version) "QPDFObjectHandle: attempting to unparse a reserved object"); return JSON::makeNull(); } - -qpdf_object_type_e -QPDF_Reserved::getTypeCode() const -{ - return ::ot_reserved; -} - -char const* -QPDF_Reserved::getTypeName() const -{ - return "reserved"; -} diff --git a/libqpdf/QPDF_Stream.cc b/libqpdf/QPDF_Stream.cc index 7a74512f..9932c15d 100644 --- a/libqpdf/QPDF_Stream.cc +++ b/libqpdf/QPDF_Stream.cc @@ -114,6 +114,7 @@ QPDF_Stream::QPDF_Stream( QPDFObjectHandle stream_dict, qpdf_offset_t offset, size_t length) : + QPDFValue(::ot_stream, "stream"), qpdf(qpdf), og(og), filter_on_write(true), @@ -291,18 +292,6 @@ QPDF_Stream::getStreamJSON( return result; } -qpdf_object_type_e -QPDF_Stream::getTypeCode() const -{ - return ::ot_stream; -} - -char const* -QPDF_Stream::getTypeName() const -{ - return "stream"; -} - void QPDF_Stream::setDescription(QPDF* qpdf, std::string const& description) { diff --git a/libqpdf/QPDF_String.cc b/libqpdf/QPDF_String.cc index c8e21463..c6cb6c41 100644 --- a/libqpdf/QPDF_String.cc +++ b/libqpdf/QPDF_String.cc @@ -21,6 +21,7 @@ is_iso_latin1_printable(char ch) } QPDF_String::QPDF_String(std::string const& val) : + QPDFValue(::ot_string, "string"), val(val) { } @@ -84,18 +85,6 @@ QPDF_String::getJSON(int json_version) return JSON::makeString(result); } -qpdf_object_type_e -QPDF_String::getTypeCode() const -{ - return ::ot_string; -} - -char const* -QPDF_String::getTypeName() const -{ - return "string"; -} - bool QPDF_String::useHexString() const { diff --git a/libqpdf/QPDF_Unresolved.cc b/libqpdf/QPDF_Unresolved.cc index b51075f7..40d4874e 100644 --- a/libqpdf/QPDF_Unresolved.cc +++ b/libqpdf/QPDF_Unresolved.cc @@ -2,6 +2,11 @@ #include +QPDF_Unresolved::QPDF_Unresolved() : + QPDFValue(::ot_unresolved, "unresolved") +{ +} + std::shared_ptr QPDF_Unresolved::create() { @@ -27,15 +32,3 @@ QPDF_Unresolved::getJSON(int json_version) { return JSON::makeNull(); } - -qpdf_object_type_e -QPDF_Unresolved::getTypeCode() const -{ - return ::ot_unresolved; -} - -char const* -QPDF_Unresolved::getTypeName() const -{ - return "unresolved"; -} diff --git a/libqpdf/qpdf/QPDF_Array.hh b/libqpdf/qpdf/QPDF_Array.hh index b0207115..426efe36 100644 --- a/libqpdf/qpdf/QPDF_Array.hh +++ b/libqpdf/qpdf/QPDF_Array.hh @@ -17,8 +17,6 @@ class QPDF_Array: public QPDFValue virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); virtual JSON getJSON(int json_version); - virtual qpdf_object_type_e getTypeCode() const; - virtual char const* getTypeName() const; int getNItems() const; QPDFObjectHandle getItem(int n) const; diff --git a/libqpdf/qpdf/QPDF_Bool.hh b/libqpdf/qpdf/QPDF_Bool.hh index 2de585cb..3e45cd8e 100644 --- a/libqpdf/qpdf/QPDF_Bool.hh +++ b/libqpdf/qpdf/QPDF_Bool.hh @@ -11,8 +11,6 @@ class QPDF_Bool: public QPDFValue virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); virtual JSON getJSON(int json_version); - virtual qpdf_object_type_e getTypeCode() const; - virtual char const* getTypeName() const; bool getVal() const; private: diff --git a/libqpdf/qpdf/QPDF_Dictionary.hh b/libqpdf/qpdf/QPDF_Dictionary.hh index 5761b030..19ab8d9b 100644 --- a/libqpdf/qpdf/QPDF_Dictionary.hh +++ b/libqpdf/qpdf/QPDF_Dictionary.hh @@ -17,8 +17,6 @@ class QPDF_Dictionary: public QPDFValue virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); virtual JSON getJSON(int json_version); - virtual qpdf_object_type_e getTypeCode() const; - virtual char const* getTypeName() const; // hasKey() and getKeys() treat keys with null values as if they // aren't there. getKey() returns null for the value of a diff --git a/libqpdf/qpdf/QPDF_InlineImage.hh b/libqpdf/qpdf/QPDF_InlineImage.hh index 31f7529a..b7bea9c7 100644 --- a/libqpdf/qpdf/QPDF_InlineImage.hh +++ b/libqpdf/qpdf/QPDF_InlineImage.hh @@ -11,8 +11,6 @@ class QPDF_InlineImage: public QPDFValue virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); virtual JSON getJSON(int json_version); - virtual qpdf_object_type_e getTypeCode() const; - virtual char const* getTypeName() const; std::string getVal() const; private: diff --git a/libqpdf/qpdf/QPDF_Integer.hh b/libqpdf/qpdf/QPDF_Integer.hh index cf201021..7e09673c 100644 --- a/libqpdf/qpdf/QPDF_Integer.hh +++ b/libqpdf/qpdf/QPDF_Integer.hh @@ -11,8 +11,6 @@ class QPDF_Integer: public QPDFValue virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); virtual JSON getJSON(int json_version); - virtual qpdf_object_type_e getTypeCode() const; - virtual char const* getTypeName() const; long long getVal() const; private: diff --git a/libqpdf/qpdf/QPDF_Name.hh b/libqpdf/qpdf/QPDF_Name.hh index 438b118e..74fc7e44 100644 --- a/libqpdf/qpdf/QPDF_Name.hh +++ b/libqpdf/qpdf/QPDF_Name.hh @@ -11,8 +11,6 @@ class QPDF_Name: public QPDFValue virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); virtual JSON getJSON(int json_version); - virtual qpdf_object_type_e getTypeCode() const; - virtual char const* getTypeName() const; std::string getName() const; // Put # into strings with characters unsuitable for name token diff --git a/libqpdf/qpdf/QPDF_Null.hh b/libqpdf/qpdf/QPDF_Null.hh index 7f722a3a..68973de9 100644 --- a/libqpdf/qpdf/QPDF_Null.hh +++ b/libqpdf/qpdf/QPDF_Null.hh @@ -11,11 +11,9 @@ class QPDF_Null: public QPDFValue virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); virtual JSON getJSON(int json_version); - virtual qpdf_object_type_e getTypeCode() const; - virtual char const* getTypeName() const; private: - QPDF_Null() = default; + QPDF_Null(); }; #endif // QPDF_NULL_HH diff --git a/libqpdf/qpdf/QPDF_Operator.hh b/libqpdf/qpdf/QPDF_Operator.hh index d17f1629..767c0ba0 100644 --- a/libqpdf/qpdf/QPDF_Operator.hh +++ b/libqpdf/qpdf/QPDF_Operator.hh @@ -11,8 +11,6 @@ class QPDF_Operator: public QPDFValue virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); virtual JSON getJSON(int json_version); - virtual qpdf_object_type_e getTypeCode() const; - virtual char const* getTypeName() const; std::string getVal() const; private: diff --git a/libqpdf/qpdf/QPDF_Real.hh b/libqpdf/qpdf/QPDF_Real.hh index 97375c73..dc0f3ff8 100644 --- a/libqpdf/qpdf/QPDF_Real.hh +++ b/libqpdf/qpdf/QPDF_Real.hh @@ -13,8 +13,6 @@ class QPDF_Real: public QPDFValue virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); virtual JSON getJSON(int json_version); - virtual qpdf_object_type_e getTypeCode() const; - virtual char const* getTypeName() const; std::string getVal(); private: diff --git a/libqpdf/qpdf/QPDF_Reserved.hh b/libqpdf/qpdf/QPDF_Reserved.hh index e9f8313a..f90242a9 100644 --- a/libqpdf/qpdf/QPDF_Reserved.hh +++ b/libqpdf/qpdf/QPDF_Reserved.hh @@ -11,11 +11,9 @@ class QPDF_Reserved: public QPDFValue virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); virtual JSON getJSON(int json_version); - virtual qpdf_object_type_e getTypeCode() const; - virtual char const* getTypeName() const; private: - QPDF_Reserved() = default; + QPDF_Reserved(); }; #endif // QPDF_RESERVED_HH diff --git a/libqpdf/qpdf/QPDF_Stream.hh b/libqpdf/qpdf/QPDF_Stream.hh index 639d5298..3a16160e 100644 --- a/libqpdf/qpdf/QPDF_Stream.hh +++ b/libqpdf/qpdf/QPDF_Stream.hh @@ -26,8 +26,6 @@ class QPDF_Stream: public QPDFValue virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); virtual JSON getJSON(int json_version); - virtual qpdf_object_type_e getTypeCode() const; - virtual char const* getTypeName() const; virtual void setDescription(QPDF*, std::string const&); QPDFObjectHandle getDict() const; bool isDataModified() const; diff --git a/libqpdf/qpdf/QPDF_String.hh b/libqpdf/qpdf/QPDF_String.hh index 9b6fc95c..a92427e3 100644 --- a/libqpdf/qpdf/QPDF_String.hh +++ b/libqpdf/qpdf/QPDF_String.hh @@ -16,8 +16,6 @@ class QPDF_String: public QPDFValue create_utf16(std::string const& utf8_val); virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); - virtual qpdf_object_type_e getTypeCode() const; - virtual char const* getTypeName() const; std::string unparse(bool force_binary); virtual JSON getJSON(int json_version); std::string getVal() const; diff --git a/libqpdf/qpdf/QPDF_Unresolved.hh b/libqpdf/qpdf/QPDF_Unresolved.hh index c17748b5..c1231590 100644 --- a/libqpdf/qpdf/QPDF_Unresolved.hh +++ b/libqpdf/qpdf/QPDF_Unresolved.hh @@ -11,11 +11,9 @@ class QPDF_Unresolved: public QPDFValue virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); virtual JSON getJSON(int json_version); - virtual qpdf_object_type_e getTypeCode() const; - virtual char const* getTypeName() const; private: - QPDF_Unresolved() = default; + QPDF_Unresolved(); }; #endif // QPDF_UNRESOLVED_HH -- cgit v1.2.3-54-g00ecf From 89061d5b33baa7e8f4e3486d0c7ccf2447500b13 Mon Sep 17 00:00:00 2001 From: m-holger Date: Fri, 12 Aug 2022 15:14:11 +0100 Subject: Change QPDF_Unresolved::create method to take QPDF* and QPDFObjGen parameters --- include/qpdf/QPDFValue.hh | 29 +++++++++++++++++++++++++++-- libqpdf/QPDF.cc | 5 ++--- libqpdf/QPDF_Unresolved.cc | 12 +++++++----- libqpdf/qpdf/QPDF_Unresolved.hh | 4 ++-- 4 files changed, 38 insertions(+), 12 deletions(-) (limited to 'libqpdf/QPDF_Unresolved.cc') diff --git a/include/qpdf/QPDFValue.hh b/include/qpdf/QPDFValue.hh index 4ed3a0de..8b4f53b5 100644 --- a/include/qpdf/QPDFValue.hh +++ b/include/qpdf/QPDFValue.hh @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -73,11 +74,21 @@ class QPDFValue { return parsed_offset; } + QPDF* + getQPDF() + { + return qpdf; + } + QPDFObjGen + getObjGen() + { + return og; + } protected: QPDFValue() : type_code(::ot_uninitialized), - type_name("uninitilized") + type_name("uninitialized") { } QPDFValue(qpdf_object_type_e type_code, char const* type_name) : @@ -85,7 +96,17 @@ class QPDFValue 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 releaseResolved() { @@ -100,6 +121,10 @@ class QPDFValue qpdf_offset_t parsed_offset{-1}; const qpdf_object_type_e type_code; char const* type_name; + + protected: + QPDF* qpdf{nullptr}; + QPDFObjGen og; }; #endif // QPDFVALUE_HH diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index 553c1a41..f33e2920 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -2183,9 +2183,8 @@ QPDF::getObject(QPDFObjGen const& og) if (!og.isIndirect()) { return QPDFObjectHandle::newNull(); } - // auto obj = (og.getObj() != 0) ? resolve(og) : QPDF_Null::create(); - if (!m->obj_cache.count(og)) { - m->obj_cache[og] = ObjCache(QPDF_Unresolved::create(), -1, -1); + if (!isCached(og)) { + m->obj_cache[og] = ObjCache(QPDF_Unresolved::create(this, og), -1, -1); } return newIndirect(og, m->obj_cache[og].object); } diff --git a/libqpdf/QPDF_Unresolved.cc b/libqpdf/QPDF_Unresolved.cc index 40d4874e..f824a9a6 100644 --- a/libqpdf/QPDF_Unresolved.cc +++ b/libqpdf/QPDF_Unresolved.cc @@ -2,21 +2,23 @@ #include -QPDF_Unresolved::QPDF_Unresolved() : - QPDFValue(::ot_unresolved, "unresolved") +QPDF_Unresolved::QPDF_Unresolved(QPDF* qpdf, QPDFObjGen const& og) : + QPDFValue(::ot_unresolved, "unresolved", qpdf, og) { } std::shared_ptr -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 QPDF_Unresolved::shallowCopy() { - return create(); + throw std::logic_error( + "attempted to shallow copy unresolved QPDFObjectHandle"); + return create(qpdf, og); } std::string diff --git a/libqpdf/qpdf/QPDF_Unresolved.hh b/libqpdf/qpdf/QPDF_Unresolved.hh index c1231590..efcf4e3d 100644 --- a/libqpdf/qpdf/QPDF_Unresolved.hh +++ b/libqpdf/qpdf/QPDF_Unresolved.hh @@ -7,13 +7,13 @@ class QPDF_Unresolved: public QPDFValue { public: virtual ~QPDF_Unresolved() = default; - static std::shared_ptr create(); + 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); private: - QPDF_Unresolved(); + QPDF_Unresolved(QPDF* qpdf, QPDFObjGen const& og); }; #endif // QPDF_UNRESOLVED_HH -- cgit v1.2.3-54-g00ecf