2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-06-06 04:10:52 +00:00

Add method QPDFObject::getQPDF and remove QPDFObjectHandle::qpdf

This commit is contained in:
m-holger 2022-08-14 11:19:00 +01:00
parent 4a8515912c
commit 5033e3b215
3 changed files with 16 additions and 13 deletions

View File

@ -97,6 +97,12 @@ class QPDFObject
{
return value->type_name;
}
// Returns nullptr for direct objects
QPDF*
getQPDF() const
{
return value->qpdf;
}
void
setDescription(QPDF* qpdf, std::string const& description)
{

View File

@ -973,8 +973,8 @@ class QPDFObjectHandle
// null for a direct object if allow_nullptr is set to true or
// throws a runtime error otherwise.
QPDF_DLL
inline QPDF*
getOwningQPDF(bool allow_nullptr = true, std::string const& error_msg = "");
inline QPDF* getOwningQPDF(
bool allow_nullptr = true, std::string const& error_msg = "") const;
// Create a shallow copy of an object as a direct object, but do not
// traverse across indirect object boundaries. That means that,
@ -1584,7 +1584,6 @@ class QPDFObjectHandle
QPDF* qpdf,
QPDFObjGen const& og,
std::shared_ptr<QPDFObject> const& obj) :
qpdf(qpdf),
og(og),
obj(obj)
{
@ -1641,7 +1640,6 @@ class QPDFObjectHandle
// Moving members of QPDFObjectHandle into a smart pointer incurs
// a substantial performance penalty since QPDFObjectHandle
// objects are copied around so frequently.
QPDF* qpdf;
QPDFObjGen og;
std::shared_ptr<QPDFObject> obj;
};
@ -1896,14 +1894,15 @@ QPDFObjectHandle::isInitialized() const
// Indirect object accessors
inline QPDF*
QPDFObjectHandle::getOwningQPDF(
bool allow_nullptr, std::string const& error_msg)
bool allow_nullptr, std::string const& error_msg) const
{
// Will be null for direct objects
if (!allow_nullptr && (this->qpdf == nullptr)) {
auto result = isInitialized() ? this->obj->getQPDF() : nullptr;
if (!allow_nullptr && (result == nullptr)) {
throw std::runtime_error(
error_msg == "" ? "attempt to use a null qpdf object" : error_msg);
}
return this->qpdf;
return result;
}
inline void

View File

@ -235,13 +235,11 @@ LastChar::getLastChar()
return this->last_char;
}
QPDFObjectHandle::QPDFObjectHandle() :
qpdf(nullptr)
QPDFObjectHandle::QPDFObjectHandle()
{
}
QPDFObjectHandle::QPDFObjectHandle(std::shared_ptr<QPDFObject> const& data) :
qpdf(nullptr),
obj(data)
{
}
@ -2284,7 +2282,6 @@ QPDFObjectHandle::copyObject(
" reserved object handle direct");
}
qpdf = nullptr;
og = QPDFObjGen();
std::shared_ptr<QPDFObject> new_obj;
@ -2572,8 +2569,9 @@ QPDFObjectHandle::isImage(bool exclude_imagemask)
void
QPDFObjectHandle::checkOwnership(QPDFObjectHandle const& item) const
{
if ((this->qpdf != nullptr) && (item.qpdf != nullptr) &&
(this->qpdf != item.qpdf)) {
auto qpdf = getOwningQPDF();
auto item_qpdf = item.getOwningQPDF();
if ((qpdf != nullptr) && (item_qpdf != nullptr) && (qpdf != item_qpdf)) {
QTC::TC("qpdf", "QPDFObjectHandle check ownership");
throw std::logic_error(
"Attempting to add an object from a different QPDF."