2
1
mirror of https://github.com/qpdf/qpdf.git synced 2025-01-31 02:48:31 +00:00

Add private method QPDF::nextObjGen

This commit is contained in:
m-holger 2022-09-26 18:43:28 +01:00 committed by Jay Berkenbilt
parent b3d71e1f58
commit 0a3c533186
2 changed files with 10 additions and 3 deletions

View File

@ -1185,6 +1185,7 @@ class QPDF
void stopOnError(std::string const& message);
QPDFObjectHandle reserveObjectIfNotExists(QPDFObjGen const& og);
QPDFObjectHandle reserveStream(QPDFObjGen const& og);
QPDFObjGen nextObjGen();
QPDFObjectHandle
newIndirect(QPDFObjGen const&, std::shared_ptr<QPDFObject> const&);
QPDFObjectHandle makeIndirectObject(std::shared_ptr<QPDFObject> const& obj);

View File

@ -1976,15 +1976,21 @@ QPDF::isUnresolved(QPDFObjGen const& og)
return !isCached(og) || m->obj_cache[og].object->isUnresolved();
}
QPDFObjectHandle
QPDF::makeIndirectObject(std::shared_ptr<QPDFObject> const& obj)
QPDFObjGen
QPDF::nextObjGen()
{
int max_objid = toI(getObjectCount());
if (max_objid == std::numeric_limits<int>::max()) {
throw std::range_error(
"max object id is too high to create new objects");
}
QPDFObjGen next(max_objid + 1, 0);
return QPDFObjGen(max_objid + 1, 0);
}
QPDFObjectHandle
QPDF::makeIndirectObject(std::shared_ptr<QPDFObject> const& obj)
{
QPDFObjGen next{nextObjGen()};
m->obj_cache[next] = ObjCache(obj, -1, -1);
return newIndirect(next, m->obj_cache[next].object);
}