Refactor QPDFObjectHandle::shallowCopy

This commit is contained in:
m-holger 2022-11-14 22:06:04 +00:00 committed by Jay Berkenbilt
parent b1eb1a9584
commit 64059014c9
2 changed files with 4 additions and 63 deletions

View File

@ -1628,8 +1628,6 @@ class QPDFObjectHandle
void objectWarning(std::string const& warning);
void assertType(char const* type_name, bool istype);
bool dereference();
void copyObject1(std::set<QPDFObjGen>& visited);
void shallowCopyInternal1(QPDFObjectHandle& oh);
void copyObject(
std::set<QPDFObjGen>& visited,
bool cross_indirect,

View File

@ -2200,68 +2200,11 @@ QPDFObjectHandle::hasObjectDescription()
QPDFObjectHandle
QPDFObjectHandle::shallowCopy()
{
QPDFObjectHandle result;
shallowCopyInternal1(result);
return result;
}
void
QPDFObjectHandle::shallowCopyInternal1(QPDFObjectHandle& new_obj)
{
assertInitialized();
if (isStream()) {
// Handled bt QPDF_Stream::copy()
}
new_obj = QPDFObjectHandle(obj->copy(true));
std::set<QPDFObjGen> visited;
new_obj.copyObject1(visited);
}
void
QPDFObjectHandle::copyObject1(std::set<QPDFObjGen>& visited)
{
assertInitialized();
std::shared_ptr<QPDFObject> new_obj;
if (isStream()) {
new_obj = obj->copy();
}
auto cur_og = getObjGen();
if (cur_og.getObj() != 0) {
if (visited.count(cur_og)) {
throw std::runtime_error(
"loop detected while converting object from "
"indirect to direct");
}
visited.insert(cur_og);
}
if (isReserved()) {
new_obj = obj->copy();
}
if (isBool() || isInteger() || isName() || isNull() || isReal() ||
isString()) {
// copy(true) and copy(false) are the same
new_obj = obj->copy();
} else if (isArray()) {
new_obj = obj->copy();
} else if (isDictionary()) {
new_obj = obj->copy();
} else {
throw std::logic_error("QPDFObjectHandle::makeDirectInternal: "
"unknown object type");
}
this->obj = new_obj;
if (cur_og.getObj()) {
visited.erase(cur_og);
if (!dereference()) {
throw std::logic_error("operation attempted on uninitialized "
"QPDFObjectHandle");
}
return QPDFObjectHandle(obj->copy());
}
QPDFObjectHandle