2022-08-02 20:35:04 +00:00
|
|
|
#ifndef QPDFVALUE_HH
|
|
|
|
#define QPDFVALUE_HH
|
|
|
|
|
|
|
|
#include <qpdf/Constants.h>
|
|
|
|
#include <qpdf/DLL.h>
|
|
|
|
#include <qpdf/JSON.hh>
|
2022-08-12 14:14:11 +00:00
|
|
|
#include <qpdf/QPDFObjGen.hh>
|
2022-08-02 20:35:04 +00:00
|
|
|
#include <qpdf/Types.h>
|
|
|
|
|
|
|
|
#include <string>
|
2023-02-17 13:58:21 +00:00
|
|
|
#include <string_view>
|
2023-02-15 10:11:38 +00:00
|
|
|
#include <variant>
|
2022-08-02 20:35:04 +00:00
|
|
|
|
|
|
|
class QPDF;
|
|
|
|
class QPDFObjectHandle;
|
2022-09-08 15:29:23 +00:00
|
|
|
class QPDFObject;
|
2022-08-02 20:35:04 +00:00
|
|
|
|
2023-02-17 13:58:21 +00:00
|
|
|
class QPDFValue: public std::enable_shared_from_this<QPDFValue>
|
2022-08-02 20:35:04 +00:00
|
|
|
{
|
2022-09-08 15:29:23 +00:00
|
|
|
friend class QPDFObject;
|
2022-08-02 20:35:04 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~QPDFValue() = default;
|
|
|
|
|
2022-11-14 17:54:12 +00:00
|
|
|
virtual std::shared_ptr<QPDFObject> copy(bool shallow = false) = 0;
|
2022-08-02 20:35:04 +00:00
|
|
|
virtual std::string unparse() = 0;
|
2024-02-09 13:09:08 +00:00
|
|
|
virtual void writeJSON(int json_version, JSON::Writer& p) = 0;
|
2023-02-15 10:11:38 +00:00
|
|
|
|
2023-02-09 12:43:56 +00:00
|
|
|
struct JSON_Descr
|
|
|
|
{
|
|
|
|
JSON_Descr(std::shared_ptr<std::string> input, std::string const& object) :
|
|
|
|
input(input),
|
|
|
|
object(object)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<std::string> input;
|
|
|
|
std::string object;
|
|
|
|
};
|
|
|
|
|
2023-02-17 13:58:21 +00:00
|
|
|
struct ChildDescr
|
|
|
|
{
|
|
|
|
ChildDescr(
|
|
|
|
std::shared_ptr<QPDFValue> parent,
|
|
|
|
std::string_view const& static_descr,
|
|
|
|
std::string var_descr) :
|
|
|
|
parent(parent),
|
|
|
|
static_descr(static_descr),
|
|
|
|
var_descr(var_descr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::weak_ptr<QPDFValue> parent;
|
|
|
|
std::string_view const& static_descr;
|
|
|
|
std::string var_descr;
|
|
|
|
};
|
|
|
|
|
|
|
|
using Description = std::variant<std::string, JSON_Descr, ChildDescr>;
|
2023-02-15 10:11:38 +00:00
|
|
|
|
2022-08-02 20:35:04 +00:00
|
|
|
virtual void
|
2023-02-15 10:11:38 +00:00
|
|
|
setDescription(QPDF* qpdf_p, std::shared_ptr<Description>& description, qpdf_offset_t offset)
|
2022-08-02 20:35:04 +00:00
|
|
|
{
|
2022-09-07 18:11:24 +00:00
|
|
|
qpdf = qpdf_p;
|
2022-08-02 20:35:04 +00:00
|
|
|
object_description = description;
|
2022-12-15 09:56:46 +00:00
|
|
|
setParsedOffset(offset);
|
2022-08-02 20:35:04 +00:00
|
|
|
}
|
2022-12-16 16:19:15 +00:00
|
|
|
void
|
|
|
|
setDefaultDescription(QPDF* a_qpdf, QPDFObjGen const& a_og)
|
|
|
|
{
|
|
|
|
qpdf = a_qpdf;
|
|
|
|
og = a_og;
|
|
|
|
}
|
2023-02-17 13:58:21 +00:00
|
|
|
void
|
|
|
|
setChildDescription(
|
|
|
|
QPDF* a_qpdf,
|
|
|
|
std::shared_ptr<QPDFValue> parent,
|
|
|
|
std::string_view const& static_descr,
|
|
|
|
std::string var_descr)
|
|
|
|
{
|
|
|
|
object_description =
|
|
|
|
std::make_shared<Description>(ChildDescr(parent, static_descr, var_descr));
|
|
|
|
qpdf = a_qpdf;
|
|
|
|
}
|
2023-02-15 10:35:10 +00:00
|
|
|
std::string getDescription();
|
2022-08-02 20:35:04 +00:00
|
|
|
bool
|
|
|
|
hasDescription()
|
|
|
|
{
|
2023-02-15 11:30:33 +00:00
|
|
|
return object_description || og.isIndirect();
|
2022-08-02 20:35:04 +00:00
|
|
|
}
|
|
|
|
void
|
|
|
|
setParsedOffset(qpdf_offset_t offset)
|
|
|
|
{
|
2022-08-10 12:16:06 +00:00
|
|
|
if (parsed_offset < 0) {
|
|
|
|
parsed_offset = offset;
|
|
|
|
}
|
2022-08-02 20:35:04 +00:00
|
|
|
}
|
|
|
|
qpdf_offset_t
|
|
|
|
getParsedOffset()
|
|
|
|
{
|
|
|
|
return parsed_offset;
|
|
|
|
}
|
2022-08-12 14:14:11 +00:00
|
|
|
QPDF*
|
|
|
|
getQPDF()
|
|
|
|
{
|
|
|
|
return qpdf;
|
|
|
|
}
|
|
|
|
QPDFObjGen
|
|
|
|
getObjGen()
|
|
|
|
{
|
|
|
|
return og;
|
|
|
|
}
|
2022-09-07 20:49:31 +00:00
|
|
|
virtual void
|
2022-09-08 15:06:15 +00:00
|
|
|
disconnect()
|
2022-09-07 20:49:31 +00:00
|
|
|
{
|
|
|
|
}
|
2022-12-21 13:14:05 +00:00
|
|
|
virtual std::string
|
|
|
|
getStringValue() const
|
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
2022-08-02 20:35:04 +00:00
|
|
|
|
|
|
|
protected:
|
2022-09-27 11:40:39 +00:00
|
|
|
QPDFValue() = default;
|
|
|
|
|
2022-08-02 21:57:33 +00:00
|
|
|
QPDFValue(qpdf_object_type_e type_code, char const* type_name) :
|
|
|
|
type_code(type_code),
|
|
|
|
type_name(type_name)
|
|
|
|
{
|
|
|
|
}
|
2022-08-12 14:14:11 +00:00
|
|
|
QPDFValue(
|
|
|
|
qpdf_object_type_e type_code, char const* type_name, QPDF* qpdf, QPDFObjGen const& og) :
|
|
|
|
type_code(type_code),
|
|
|
|
type_name(type_name),
|
|
|
|
qpdf(qpdf),
|
|
|
|
og(og)
|
|
|
|
{
|
|
|
|
}
|
2022-09-03 23:58:53 +00:00
|
|
|
|
2022-09-08 15:29:23 +00:00
|
|
|
static std::shared_ptr<QPDFObject> do_create(QPDFValue*);
|
2022-08-02 20:35:04 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
QPDFValue(QPDFValue const&) = delete;
|
|
|
|
QPDFValue& operator=(QPDFValue const&) = delete;
|
2023-02-15 10:11:38 +00:00
|
|
|
std::shared_ptr<Description> object_description;
|
2022-09-27 11:40:39 +00:00
|
|
|
|
|
|
|
const qpdf_object_type_e type_code{::ot_uninitialized};
|
|
|
|
char const* type_name{"uninitialized"};
|
2022-08-12 14:14:11 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
QPDF* qpdf{nullptr};
|
2022-09-27 11:40:39 +00:00
|
|
|
QPDFObjGen og{};
|
|
|
|
qpdf_offset_t parsed_offset{-1};
|
2022-08-02 20:35:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // QPDFVALUE_HH
|