2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 10:58:58 +00:00

Add new method Objects::replace

This commit is contained in:
m-holger 2024-10-07 17:18:00 +01:00
parent 6c9903062f
commit 83fc18af09
3 changed files with 15 additions and 6 deletions

View File

@ -597,9 +597,15 @@ QPDF::getObjectByID(int id, int gen)
}
void
QPDF::replaceObject(int objid, int generation, QPDFObjectHandle oh)
QPDF::replaceObject(int id, int gen, QPDFObjectHandle replacement)
{
replaceObject(QPDFObjGen(objid, generation), oh);
m->objects.replace(QPDFObjGen(id, gen), replacement);
}
void
QPDF::replaceObject(QPDFObjGen const& og, QPDFObjectHandle replacement)
{
m->objects.replace(og, replacement);
}
void
@ -610,7 +616,7 @@ QPDF::replaceReserved(QPDFObjectHandle reserved, QPDFObjectHandle replacement)
if (!(tc == ::ot_reserved || tc == ::ot_null)) {
throw std::logic_error("replaceReserved called with non-reserved object");
}
replaceObject(reserved.getObjGen(), replacement);
m->objects.replace(reserved.getObjGen(), replacement);
}
QPDFObjectHandle

View File

@ -1758,13 +1758,13 @@ Objects::get_for_json(int id, int gen)
}
void
QPDF::replaceObject(QPDFObjGen const& og, QPDFObjectHandle oh)
Objects::replace(QPDFObjGen og, QPDFObjectHandle oh)
{
if (!oh || (oh.isIndirect() && !(oh.isStream() && oh.getObjGen() == og))) {
QTC::TC("qpdf", "QPDF replaceObject called with indirect object");
throw std::logic_error("QPDF::replaceObject called with indirect object handle");
}
objects().update_table(og, oh.getObj());
update_table(og, oh.getObj());
}
void

View File

@ -441,6 +441,10 @@ class QPDF::Objects
return get(QPDFObjGen(id, gen));
}
void erase(QPDFObjGen og);
void replace(QPDFObjGen og, QPDFObjectHandle oh);
std::map<QPDFObjGen, Entry> obj_cache;
QPDFObjectHandle readObjectInStream(std::shared_ptr<InputSource>& input, int obj);
@ -469,7 +473,6 @@ class QPDF::Objects
size_t table_size();
private:
void erase(QPDFObjGen og);
bool cached(QPDFObjGen og);
bool unresolved(QPDFObjGen og);