Commit 9e03dc54cc50c173f75375e76b31607a03c3f4a4

Authored by m-holger
1 parent 83fc18af

Add new method Objects::swap

include/qpdf/QPDF.hh
... ... @@ -391,7 +391,7 @@ class QPDF
391 391 void replaceObject(int objid, int generation, QPDFObjectHandle);
392 392  
393 393 // Swap two objects given by ID. Prior to qpdf 10.2.1, existing QPDFObjectHandle instances that
394   - // reference them objects not notice the swap, but this was fixed in 10.2.1.
  394 + // reference the objects did not notice the swap, but this was fixed in 10.2.1.
395 395 QPDF_DLL
396 396 void swapObjects(QPDFObjGen const& og1, QPDFObjGen const& og2);
397 397 QPDF_DLL
... ...
libqpdf/QPDF.cc
... ... @@ -882,7 +882,13 @@ QPDF::copyStreamData(QPDFObjectHandle result, QPDFObjectHandle foreign)
882 882 void
883 883 QPDF::swapObjects(int objid1, int generation1, int objid2, int generation2)
884 884 {
885   - swapObjects(QPDFObjGen(objid1, generation1), QPDFObjGen(objid2, generation2));
  885 + m->objects.swap(QPDFObjGen(objid1, generation1), QPDFObjGen(objid2, generation2));
  886 +}
  887 +
  888 +void
  889 +QPDF::swapObjects(QPDFObjGen const& og1, QPDFObjGen const& og2)
  890 +{
  891 + m->objects.swap(og1, og2);
886 892 }
887 893  
888 894 unsigned long long
... ...
libqpdf/QPDF_objects.cc
... ... @@ -1779,12 +1779,12 @@ Objects::erase(QPDFObjGen og)
1779 1779 }
1780 1780  
1781 1781 void
1782   -QPDF::swapObjects(QPDFObjGen const& og1, QPDFObjGen const& og2)
  1782 +Objects::swap(QPDFObjGen og1, QPDFObjGen og2)
1783 1783 {
1784 1784 // Force objects to be read from the input source if needed, then swap them in the cache.
1785   - m->objects.resolve(og1);
1786   - m->objects.resolve(og2);
1787   - m->objects.obj_cache[og1].object->swapWith(m->objects.obj_cache[og2].object);
  1785 + resolve(og1);
  1786 + resolve(og2);
  1787 + obj_cache[og1].object->swapWith(obj_cache[og2].object);
1788 1788 }
1789 1789  
1790 1790 size_t
... ...
libqpdf/qpdf/QPDF_objects.hh
... ... @@ -445,6 +445,8 @@ class QPDF::Objects
445 445  
446 446 void replace(QPDFObjGen og, QPDFObjectHandle oh);
447 447  
  448 + void swap(QPDFObjGen og1, QPDFObjGen og2);
  449 +
448 450 std::map<QPDFObjGen, Entry> obj_cache;
449 451  
450 452 QPDFObjectHandle readObjectInStream(std::shared_ptr<InputSource>& input, int obj);
... ...