summaryrefslogtreecommitdiffstats
path: root/libqpdf/QPDF_Destroyed.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-09-08 14:03:57 +0200
committerJay Berkenbilt <ejb@ql.org>2022-09-08 16:36:39 +0200
commitdba61da1bfb7e4d74c723f369d1c017df9707a14 (patch)
tree04c51f86dc066c710c23423fe178e051b20b49d9 /libqpdf/QPDF_Destroyed.cc
parent264e25f391f83bcbeb60590f18ff96719b086454 (diff)
downloadqpdf-dba61da1bfb7e4d74c723f369d1c017df9707a14.tar.zst
Create a special "destroyed" type rather than using null
When a QPDF is destroyed, changing indirect objects to direct nulls makes them effectively disappear silently when they sneak into other places. Instead, we should treat this as an error. Adding a destroyed object type makes this possible.
Diffstat (limited to 'libqpdf/QPDF_Destroyed.cc')
-rw-r--r--libqpdf/QPDF_Destroyed.cc39
1 files changed, 39 insertions, 0 deletions
diff --git a/libqpdf/QPDF_Destroyed.cc b/libqpdf/QPDF_Destroyed.cc
new file mode 100644
index 00000000..55308c9a
--- /dev/null
+++ b/libqpdf/QPDF_Destroyed.cc
@@ -0,0 +1,39 @@
+#include <qpdf/QPDF_Destroyed.hh>
+
+#include <stdexcept>
+
+QPDF_Destroyed::QPDF_Destroyed() :
+ QPDFValue(::ot_destroyed, "destroyed")
+{
+}
+
+std::shared_ptr<QPDFValue>
+QPDF_Destroyed::getInstance()
+{
+ static std::shared_ptr<QPDFValue> instance(new QPDF_Destroyed());
+ return instance;
+}
+
+std::shared_ptr<QPDFValueProxy>
+QPDF_Destroyed::shallowCopy()
+{
+ throw std::logic_error(
+ "attempted to shallow copy QPDFObjectHandle from destroyed QPDF");
+ return nullptr;
+}
+
+std::string
+QPDF_Destroyed::unparse()
+{
+ throw std::logic_error(
+ "attempted to unparse a QPDFObjectHandle from a destroyed QPDF");
+ return "";
+}
+
+JSON
+QPDF_Destroyed::getJSON(int json_version)
+{
+ throw std::logic_error(
+ "attempted to get JSON from a QPDFObjectHandle from a destroyed QPDF");
+ return JSON::makeNull();
+}