From d1ebe30ff63a2f79da041e2d0c4718523db1beda Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Thu, 21 Jun 2012 16:14:34 -0400 Subject: Add QPDFObjectHandle::shallowCopy() --- libqpdf/QPDFObjectHandle.cc | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'libqpdf') diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index 53d9414c..4e28c405 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -663,6 +663,38 @@ QPDFObjectHandle::newStream(QPDF* qpdf, PointerHolder data) return result; } +QPDFObjectHandle +QPDFObjectHandle::shallowCopy() +{ + assertInitialized(); + + if (isStream()) + { + QTC::TC("qpdf", "QPDFObjectHandle ERR shallow copy stream"); + throw std::runtime_error( + "attempt to make a shallow copy of a stream"); + } + + QPDFObjectHandle new_obj; + if (isArray()) + { + QTC::TC("qpdf", "QPDFObjectHandle shallow copy array"); + new_obj = newArray(getArrayAsVector()); + } + else if (isDictionary()) + { + QTC::TC("qpdf", "QPDFObjectHandle shallow copy dictionary"); + new_obj = newDictionary(getDictAsMap()); + } + else + { + QTC::TC("qpdf", "QPDFObjectHandle shallow copy scalar"); + new_obj = *this; + } + + return new_obj; +} + void QPDFObjectHandle::makeDirectInternal(std::set& visited) { -- cgit v1.2.3-54-g00ecf