From c5b728f87bceddf98f5de5fa3a1a81ab2fe823ff Mon Sep 17 00:00:00 2001 From: m-holger Date: Sun, 5 Oct 2025 10:51:42 +0100 Subject: [PATCH] Introduce `QPDF::Doc` to encapsulate document-level operations --- include/qpdf/QPDF.hh | 2 ++ libqpdf/QPDF.cc | 5 +++-- libqpdf/qpdf/QPDF_private.hh | 34 +++++++++++++++++++++++++++++++++- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/include/qpdf/QPDF.hh b/include/qpdf/QPDF.hh index e82be88..2ada9d1 100644 --- a/include/qpdf/QPDF.hh +++ b/include/qpdf/QPDF.hh @@ -794,6 +794,7 @@ class QPDF // End of the public API. The following classes and methods are for qpdf internal use only. + class Doc; class Writer; class Resolver; class StreamCopier; @@ -807,6 +808,7 @@ class QPDF inline QPDFOutlineDocumentHelper& outlines(); inline QPDFPageDocumentHelper& pages(); inline QPDFPageLabelDocumentHelper& page_labels(); + inline Doc& doc(); // For testing only -- do not add to DLL static bool test_json_validators(); diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index 1854427..93d12be 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -178,7 +178,8 @@ QPDF::QPDFVersion() return QPDF::qpdf_version; } -QPDF::Members::Members() : +QPDF::Members::Members(QPDF& qpdf) : + doc(qpdf, *this), log(QPDFLogger::defaultLogger()), file(new InvalidInputSource()), encp(new EncryptionParameters) @@ -186,7 +187,7 @@ QPDF::Members::Members() : } QPDF::QPDF() : - m(std::make_unique()) + m(std::make_unique(*this)) { m->tokenizer.allowEOF(); // Generate a unique ID. It just has to be unique among all QPDF objects allocated throughout diff --git a/libqpdf/qpdf/QPDF_private.hh b/libqpdf/qpdf/QPDF_private.hh index 55c340a..193a5fb 100644 --- a/libqpdf/qpdf/QPDF_private.hh +++ b/libqpdf/qpdf/QPDF_private.hh @@ -405,17 +405,43 @@ class QPDF::PatternFinder final: public InputSource::Finder bool (QPDF::*checker)(); }; +// This class is used to represent a PDF document. +// +// The main function of the QPDF class is to represent a PDF document. Doc is the implementation +// class for this aspect of QPDF. +class QPDF::Doc +{ + public: + Doc() = delete; + Doc(Doc const&) = delete; + Doc(Doc&&) = delete; + Doc& operator=(Doc const&) = delete; + Doc& operator=(Doc&&) = delete; + ~Doc() = default; + + Doc(QPDF& qpdf, QPDF::Members& m) : + qpdf(qpdf), + m(m) + { + } + + private: + QPDF& qpdf; + QPDF::Members& m; +}; + class QPDF::Members { friend class QPDF; friend class ResolveRecorder; public: - Members(); + Members(QPDF& qpdf); Members(Members const&) = delete; ~Members() = default; private: + Doc doc; std::shared_ptr log; unsigned long long unique_id{0}; qpdf::Tokenizer tokenizer; @@ -562,6 +588,12 @@ QPDF::page_labels() return *m->page_labels; } +inline QPDF::Doc& +QPDF::doc() +{ + return m->doc; +} + // Throw a generic exception for unusual error conditions that do not be covered during CI testing. inline void QPDF::no_ci_stop_if(bool condition, std::string const& message, std::string const& context) -- libgit2 0.21.4