From 7dc197ef88a3f19a830f38d19aba649175d53c5e Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Wed, 10 Aug 2011 12:42:48 -0400 Subject: implement replace and swap --- libqpdf/QPDF.cc | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'libqpdf/QPDF.cc') diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index c9eee703..9bdbbdb6 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -1887,6 +1887,39 @@ QPDF::getObjectByID(int objid, int generation) return QPDFObjectHandle::Factory::newIndirect(this, objid, generation); } +void +QPDF::replaceObject(int objid, int generation, QPDFObjectHandle oh) +{ + if (oh.isIndirect()) + { + QTC::TC("qpdf", "QPDF replaceObject called with indirect object"); + throw std::logic_error( + "QPDF::replaceObject called with indirect object handle"); + } + + // Force new object to appear in the cache + resolve(objid, generation); + + // Replace the object in the object cache + ObjGen og(objid, generation); + this->obj_cache[og] = + ObjCache(QPDFObjectHandle::ObjAccessor::getObject(oh), -1, -1); +} + +void +QPDF::swapObjects(int objid1, int generation1, int objid2, int generation2) +{ + // Force objects to be loaded into cache; then swap them in the + // cache. + resolve(objid1, generation1); + resolve(objid2, generation2); + ObjGen og1(objid1, generation1); + ObjGen og2(objid2, generation2); + ObjCache t = this->obj_cache[og1]; + this->obj_cache[og1] = this->obj_cache[og2]; + this->obj_cache[og2] = t; +} + void QPDF::trimTrailerForWrite() { -- cgit v1.2.3-54-g00ecf