2022-09-08 15:12:10 +00:00
|
|
|
#ifndef QPDFOBJECT_HH
|
|
|
|
#define QPDFOBJECT_HH
|
|
|
|
|
|
|
|
// NOTE: This file is called QPDFObject_private.hh instead of QPDFObject.hh because of
|
|
|
|
// include/qpdf/QPDFObject.hh. See comments there for an explanation.
|
2008-04-29 12:55:25 +00:00
|
|
|
|
2021-12-17 17:34:48 +00:00
|
|
|
#include <qpdf/Constants.h>
|
2009-10-19 20:17:14 +00:00
|
|
|
#include <qpdf/DLL.h>
|
2018-12-17 22:40:29 +00:00
|
|
|
#include <qpdf/JSON.hh>
|
2022-08-02 20:35:04 +00:00
|
|
|
#include <qpdf/QPDFValue.hh>
|
2021-12-17 17:34:48 +00:00
|
|
|
#include <qpdf/Types.h>
|
2009-08-06 19:00:25 +00:00
|
|
|
|
2008-04-29 12:55:25 +00:00
|
|
|
#include <string>
|
2023-02-17 13:58:21 +00:00
|
|
|
#include <string_view>
|
2008-04-29 12:55:25 +00:00
|
|
|
|
2010-06-06 13:32:08 +00:00
|
|
|
class QPDF;
|
|
|
|
class QPDFObjectHandle;
|
|
|
|
|
2022-09-08 15:29:23 +00:00
|
|
|
class QPDFObject
|
2008-04-29 12:55:25 +00:00
|
|
|
{
|
2022-08-02 20:35:04 +00:00
|
|
|
friend class QPDFValue;
|
2013-01-22 14:57:07 +00:00
|
|
|
|
2022-08-02 20:35:04 +00:00
|
|
|
public:
|
2022-09-08 15:29:23 +00:00
|
|
|
QPDFObject() = default;
|
2022-08-02 20:35:04 +00:00
|
|
|
|
2022-09-08 15:29:23 +00:00
|
|
|
std::shared_ptr<QPDFObject>
|
2022-11-14 17:54:12 +00:00
|
|
|
copy(bool shallow = false)
|
2022-08-02 20:35:04 +00:00
|
|
|
{
|
2022-11-14 17:54:12 +00:00
|
|
|
return value->copy(shallow);
|
2022-08-02 20:35:04 +00:00
|
|
|
}
|
|
|
|
std::string
|
|
|
|
unparse()
|
|
|
|
{
|
|
|
|
return value->unparse();
|
|
|
|
}
|
|
|
|
JSON
|
|
|
|
getJSON(int json_version)
|
|
|
|
{
|
|
|
|
return value->getJSON(json_version);
|
|
|
|
}
|
2022-12-21 13:14:05 +00:00
|
|
|
std::string
|
|
|
|
getStringValue() const
|
|
|
|
{
|
|
|
|
return value->getStringValue();
|
|
|
|
}
|
2013-01-22 14:57:07 +00:00
|
|
|
// Return a unique type code for the object
|
2022-09-01 21:39:52 +00:00
|
|
|
qpdf_object_type_e
|
2022-08-02 20:35:04 +00:00
|
|
|
getTypeCode() const
|
|
|
|
{
|
2022-08-02 21:57:33 +00:00
|
|
|
return value->type_code;
|
2022-08-02 20:35:04 +00:00
|
|
|
}
|
2013-01-22 14:57:07 +00:00
|
|
|
|
|
|
|
// Return a string literal that describes the type, useful for debugging and testing
|
2022-08-02 20:35:04 +00:00
|
|
|
char const*
|
|
|
|
getTypeName() const
|
|
|
|
{
|
2022-08-02 21:57:33 +00:00
|
|
|
return value->type_name;
|
2022-08-02 20:35:04 +00:00
|
|
|
}
|
2022-09-07 18:11:24 +00:00
|
|
|
|
2022-08-14 10:19:00 +00:00
|
|
|
QPDF*
|
|
|
|
getQPDF() const
|
|
|
|
{
|
|
|
|
return value->qpdf;
|
|
|
|
}
|
2022-08-14 10:32:20 +00:00
|
|
|
QPDFObjGen
|
|
|
|
getObjGen() const
|
|
|
|
{
|
|
|
|
return value->og;
|
|
|
|
}
|
2022-08-02 20:35:04 +00:00
|
|
|
void
|
2022-12-15 09:56:46 +00:00
|
|
|
setDescription(
|
2023-02-15 10:11:38 +00:00
|
|
|
QPDF* qpdf, std::shared_ptr<QPDFValue::Description>& description, qpdf_offset_t offset = -1)
|
2022-08-02 20:35:04 +00:00
|
|
|
{
|
2022-12-15 09:56:46 +00:00
|
|
|
return value->setDescription(qpdf, description, offset);
|
2022-08-02 20:35:04 +00:00
|
|
|
}
|
2023-02-17 13:58:21 +00:00
|
|
|
void
|
|
|
|
setChildDescription(
|
|
|
|
std::shared_ptr<QPDFObject> parent,
|
|
|
|
std::string_view const& static_descr,
|
|
|
|
std::string var_descr)
|
|
|
|
{
|
|
|
|
auto qpdf = parent ? parent->value->qpdf : nullptr;
|
|
|
|
value->setChildDescription(qpdf, parent->value, static_descr, var_descr);
|
|
|
|
}
|
|
|
|
void
|
|
|
|
setChildDescription(
|
|
|
|
std::shared_ptr<QPDFValue> parent,
|
|
|
|
std::string_view const& static_descr,
|
|
|
|
std::string var_descr)
|
|
|
|
{
|
|
|
|
auto qpdf = parent ? parent->qpdf : nullptr;
|
|
|
|
value->setChildDescription(qpdf, parent, static_descr, var_descr);
|
|
|
|
}
|
2022-08-02 20:35:04 +00:00
|
|
|
bool
|
|
|
|
getDescription(QPDF*& qpdf, std::string& description)
|
|
|
|
{
|
2022-12-31 12:13:32 +00:00
|
|
|
qpdf = value->qpdf;
|
|
|
|
description = value->getDescription();
|
|
|
|
return qpdf != nullptr;
|
2022-08-02 20:35:04 +00:00
|
|
|
}
|
|
|
|
bool
|
|
|
|
hasDescription()
|
|
|
|
{
|
|
|
|
return value->hasDescription();
|
|
|
|
}
|
|
|
|
void
|
|
|
|
setParsedOffset(qpdf_offset_t offset)
|
|
|
|
{
|
|
|
|
value->setParsedOffset(offset);
|
|
|
|
}
|
|
|
|
qpdf_offset_t
|
|
|
|
getParsedOffset()
|
|
|
|
{
|
|
|
|
return value->getParsedOffset();
|
|
|
|
}
|
|
|
|
void
|
2022-09-08 15:29:23 +00:00
|
|
|
assign(std::shared_ptr<QPDFObject> o)
|
2022-08-02 20:35:04 +00:00
|
|
|
{
|
|
|
|
value = o->value;
|
|
|
|
}
|
|
|
|
void
|
2022-09-08 15:29:23 +00:00
|
|
|
swapWith(std::shared_ptr<QPDFObject> o)
|
2022-08-02 20:35:04 +00:00
|
|
|
{
|
|
|
|
auto v = value;
|
|
|
|
value = o->value;
|
|
|
|
o->value = v;
|
2022-08-14 00:05:32 +00:00
|
|
|
auto og = value->og;
|
|
|
|
value->og = o->value->og;
|
|
|
|
o->value->og = og;
|
2022-08-02 20:35:04 +00:00
|
|
|
}
|
2022-08-14 00:05:32 +00:00
|
|
|
|
|
|
|
void
|
2022-12-16 16:19:15 +00:00
|
|
|
setDefaultDescription(QPDF* qpdf, QPDFObjGen const& og)
|
2022-08-14 00:05:32 +00:00
|
|
|
{
|
2022-09-08 15:06:15 +00:00
|
|
|
// Intended for use by the QPDF class
|
2022-12-16 16:19:15 +00:00
|
|
|
value->setDefaultDescription(qpdf, og);
|
|
|
|
}
|
|
|
|
void
|
|
|
|
setObjGen(QPDF* qpdf, QPDFObjGen const& og)
|
|
|
|
{
|
2022-08-14 00:05:32 +00:00
|
|
|
value->qpdf = qpdf;
|
|
|
|
value->og = og;
|
|
|
|
}
|
|
|
|
void
|
2022-09-08 15:06:15 +00:00
|
|
|
disconnect()
|
|
|
|
{
|
|
|
|
// Disconnect an object from its owning QPDF. This is called by QPDF's destructor.
|
|
|
|
value->disconnect();
|
2022-08-14 00:05:32 +00:00
|
|
|
value->qpdf = nullptr;
|
|
|
|
value->og = QPDFObjGen();
|
|
|
|
}
|
2022-09-08 15:06:15 +00:00
|
|
|
// Mark an object as destroyed. Used by QPDF's destructor for its indirect objects.
|
2022-09-08 12:03:57 +00:00
|
|
|
void destroy();
|
|
|
|
|
2022-08-10 12:16:06 +00:00
|
|
|
bool
|
2022-08-14 09:50:30 +00:00
|
|
|
isUnresolved() const
|
2022-08-10 12:16:06 +00:00
|
|
|
{
|
|
|
|
return value->type_code == ::ot_unresolved;
|
|
|
|
}
|
2022-08-14 09:50:30 +00:00
|
|
|
void
|
|
|
|
resolve()
|
|
|
|
{
|
|
|
|
if (isUnresolved()) {
|
|
|
|
doResolve();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void doResolve();
|
|
|
|
|
2022-08-02 20:35:04 +00:00
|
|
|
template <typename T>
|
|
|
|
T*
|
|
|
|
as()
|
|
|
|
{
|
|
|
|
return dynamic_cast<T*>(value.get());
|
|
|
|
}
|
2013-01-22 14:57:07 +00:00
|
|
|
|
2018-02-16 22:25:27 +00:00
|
|
|
private:
|
2022-09-08 15:29:23 +00:00
|
|
|
QPDFObject(QPDFObject const&) = delete;
|
|
|
|
QPDFObject& operator=(QPDFObject const&) = delete;
|
2022-08-02 20:35:04 +00:00
|
|
|
std::shared_ptr<QPDFValue> value;
|
2008-04-29 12:55:25 +00:00
|
|
|
};
|
|
|
|
|
2022-09-08 15:12:10 +00:00
|
|
|
#endif // QPDFOBJECT_HH
|