aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorm-holger <m-holger@kubitscheck.org>2022-08-02 22:35:04 +0200
committerm-holger <m-holger@kubitscheck.org>2022-09-01 15:19:34 +0200
commit431bd666c0504af0c8a016a96a73b7efbf9737c9 (patch)
tree26fcbcb8e62fcb87aa1a694fad5172f92c6eab7c /include
parent43983109f25ba12db3fded12d0ea9a991b8a1d5c (diff)
downloadqpdf-431bd666c0504af0c8a016a96a73b7efbf9737c9.tar.zst
Split QPDFObject into QPDFObject and QPDFValue
Diffstat (limited to 'include')
-rw-r--r--include/qpdf/QPDFObject.hh97
-rw-r--r--include/qpdf/QPDFValue.hh93
2 files changed, 171 insertions, 19 deletions
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 <qpdf/Constants.h>
#include <qpdf/DLL.h>
#include <qpdf/JSON.hh>
+#include <qpdf/QPDFValue.hh>
#include <qpdf/Types.h>
#include <string>
@@ -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<QPDFObject> shallowCopy() = 0;
- virtual std::string unparse() = 0;
- virtual JSON getJSON(int json_version) = 0;
+
+ std::shared_ptr<QPDFObject>
+ 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<QPDFObject> o)
+ {
+ value = o->value;
+ }
+ void
+ swapWith(std::shared_ptr<QPDFObject> o)
+ {
+ auto v = value;
+ value = o->value;
+ o->value = v;
+ }
+
+ template <typename T>
+ T*
+ as()
+ {
+ return dynamic_cast<T*>(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<QPDFObject> 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<QPDFValue> 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 <qpdf/Constants.h>
+#include <qpdf/DLL.h>
+#include <qpdf/JSON.hh>
+#include <qpdf/Types.h>
+
+#include <string>
+
+class QPDF;
+class QPDFObjectHandle;
+class QPDFObject;
+
+class QPDFValue
+{
+ friend class QPDFObject;
+
+ public:
+ virtual ~QPDFValue() = default;
+
+ virtual std::shared_ptr<QPDFObject> 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<QPDFObject> 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