Commit 64059014c9288e740214be8242cac4a29e29284c
Committed by
Jay Berkenbilt
1 parent
b1eb1a95
Refactor QPDFObjectHandle::shallowCopy
Showing
2 changed files
with
4 additions
and
63 deletions
include/qpdf/QPDFObjectHandle.hh
| ... | ... | @@ -1628,8 +1628,6 @@ class QPDFObjectHandle |
| 1628 | 1628 | void objectWarning(std::string const& warning); |
| 1629 | 1629 | void assertType(char const* type_name, bool istype); |
| 1630 | 1630 | bool dereference(); |
| 1631 | - void copyObject1(std::set<QPDFObjGen>& visited); | |
| 1632 | - void shallowCopyInternal1(QPDFObjectHandle& oh); | |
| 1633 | 1631 | void copyObject( |
| 1634 | 1632 | std::set<QPDFObjGen>& visited, |
| 1635 | 1633 | bool cross_indirect, | ... | ... |
libqpdf/QPDFObjectHandle.cc
| ... | ... | @@ -2200,68 +2200,11 @@ QPDFObjectHandle::hasObjectDescription() |
| 2200 | 2200 | QPDFObjectHandle |
| 2201 | 2201 | QPDFObjectHandle::shallowCopy() |
| 2202 | 2202 | { |
| 2203 | - QPDFObjectHandle result; | |
| 2204 | - shallowCopyInternal1(result); | |
| 2205 | - return result; | |
| 2206 | -} | |
| 2207 | - | |
| 2208 | -void | |
| 2209 | -QPDFObjectHandle::shallowCopyInternal1(QPDFObjectHandle& new_obj) | |
| 2210 | -{ | |
| 2211 | - assertInitialized(); | |
| 2212 | - | |
| 2213 | - if (isStream()) { | |
| 2214 | - // Handled bt QPDF_Stream::copy() | |
| 2215 | - } | |
| 2216 | - new_obj = QPDFObjectHandle(obj->copy(true)); | |
| 2217 | - | |
| 2218 | - std::set<QPDFObjGen> visited; | |
| 2219 | - new_obj.copyObject1(visited); | |
| 2220 | -} | |
| 2221 | - | |
| 2222 | -void | |
| 2223 | -QPDFObjectHandle::copyObject1(std::set<QPDFObjGen>& visited) | |
| 2224 | -{ | |
| 2225 | - assertInitialized(); | |
| 2226 | - | |
| 2227 | - std::shared_ptr<QPDFObject> new_obj; | |
| 2228 | - | |
| 2229 | - if (isStream()) { | |
| 2230 | - new_obj = obj->copy(); | |
| 2231 | - } | |
| 2232 | - | |
| 2233 | - auto cur_og = getObjGen(); | |
| 2234 | - if (cur_og.getObj() != 0) { | |
| 2235 | - if (visited.count(cur_og)) { | |
| 2236 | - throw std::runtime_error( | |
| 2237 | - "loop detected while converting object from " | |
| 2238 | - "indirect to direct"); | |
| 2239 | - } | |
| 2240 | - visited.insert(cur_og); | |
| 2241 | - } | |
| 2242 | - | |
| 2243 | - if (isReserved()) { | |
| 2244 | - new_obj = obj->copy(); | |
| 2245 | - } | |
| 2246 | - | |
| 2247 | - if (isBool() || isInteger() || isName() || isNull() || isReal() || | |
| 2248 | - isString()) { | |
| 2249 | - // copy(true) and copy(false) are the same | |
| 2250 | - new_obj = obj->copy(); | |
| 2251 | - } else if (isArray()) { | |
| 2252 | - new_obj = obj->copy(); | |
| 2253 | - } else if (isDictionary()) { | |
| 2254 | - new_obj = obj->copy(); | |
| 2255 | - } else { | |
| 2256 | - throw std::logic_error("QPDFObjectHandle::makeDirectInternal: " | |
| 2257 | - "unknown object type"); | |
| 2258 | - } | |
| 2259 | - | |
| 2260 | - this->obj = new_obj; | |
| 2261 | - | |
| 2262 | - if (cur_og.getObj()) { | |
| 2263 | - visited.erase(cur_og); | |
| 2203 | + if (!dereference()) { | |
| 2204 | + throw std::logic_error("operation attempted on uninitialized " | |
| 2205 | + "QPDFObjectHandle"); | |
| 2264 | 2206 | } |
| 2207 | + return QPDFObjectHandle(obj->copy()); | |
| 2265 | 2208 | } |
| 2266 | 2209 | |
| 2267 | 2210 | QPDFObjectHandle | ... | ... |