Commit c5b728f87bceddf98f5de5fa3a1a81ab2fe823ff
1 parent
afb09d2e
Introduce `QPDF::Doc` to encapsulate document-level operations
Add `QPDF::Doc` as an inner class to manage document-level functionality. Update memory management in `QPDF::Members` to include `Doc` and ensure proper initialization. Add `QPDF::doc()` method for internal access. Refactor constructors accordingly.
Showing
3 changed files
with
38 additions
and
3 deletions
include/qpdf/QPDF.hh
| ... | ... | @@ -794,6 +794,7 @@ class QPDF |
| 794 | 794 | |
| 795 | 795 | // End of the public API. The following classes and methods are for qpdf internal use only. |
| 796 | 796 | |
| 797 | + class Doc; | |
| 797 | 798 | class Writer; |
| 798 | 799 | class Resolver; |
| 799 | 800 | class StreamCopier; |
| ... | ... | @@ -807,6 +808,7 @@ class QPDF |
| 807 | 808 | inline QPDFOutlineDocumentHelper& outlines(); |
| 808 | 809 | inline QPDFPageDocumentHelper& pages(); |
| 809 | 810 | inline QPDFPageLabelDocumentHelper& page_labels(); |
| 811 | + inline Doc& doc(); | |
| 810 | 812 | |
| 811 | 813 | // For testing only -- do not add to DLL |
| 812 | 814 | static bool test_json_validators(); | ... | ... |
libqpdf/QPDF.cc
| ... | ... | @@ -178,7 +178,8 @@ QPDF::QPDFVersion() |
| 178 | 178 | return QPDF::qpdf_version; |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | -QPDF::Members::Members() : | |
| 181 | +QPDF::Members::Members(QPDF& qpdf) : | |
| 182 | + doc(qpdf, *this), | |
| 182 | 183 | log(QPDFLogger::defaultLogger()), |
| 183 | 184 | file(new InvalidInputSource()), |
| 184 | 185 | encp(new EncryptionParameters) |
| ... | ... | @@ -186,7 +187,7 @@ QPDF::Members::Members() : |
| 186 | 187 | } |
| 187 | 188 | |
| 188 | 189 | QPDF::QPDF() : |
| 189 | - m(std::make_unique<Members>()) | |
| 190 | + m(std::make_unique<Members>(*this)) | |
| 190 | 191 | { |
| 191 | 192 | m->tokenizer.allowEOF(); |
| 192 | 193 | // Generate a unique ID. It just has to be unique among all QPDF objects allocated throughout | ... | ... |
libqpdf/qpdf/QPDF_private.hh
| ... | ... | @@ -405,17 +405,43 @@ class QPDF::PatternFinder final: public InputSource::Finder |
| 405 | 405 | bool (QPDF::*checker)(); |
| 406 | 406 | }; |
| 407 | 407 | |
| 408 | +// This class is used to represent a PDF document. | |
| 409 | +// | |
| 410 | +// The main function of the QPDF class is to represent a PDF document. Doc is the implementation | |
| 411 | +// class for this aspect of QPDF. | |
| 412 | +class QPDF::Doc | |
| 413 | +{ | |
| 414 | + public: | |
| 415 | + Doc() = delete; | |
| 416 | + Doc(Doc const&) = delete; | |
| 417 | + Doc(Doc&&) = delete; | |
| 418 | + Doc& operator=(Doc const&) = delete; | |
| 419 | + Doc& operator=(Doc&&) = delete; | |
| 420 | + ~Doc() = default; | |
| 421 | + | |
| 422 | + Doc(QPDF& qpdf, QPDF::Members& m) : | |
| 423 | + qpdf(qpdf), | |
| 424 | + m(m) | |
| 425 | + { | |
| 426 | + } | |
| 427 | + | |
| 428 | + private: | |
| 429 | + QPDF& qpdf; | |
| 430 | + QPDF::Members& m; | |
| 431 | +}; | |
| 432 | + | |
| 408 | 433 | class QPDF::Members |
| 409 | 434 | { |
| 410 | 435 | friend class QPDF; |
| 411 | 436 | friend class ResolveRecorder; |
| 412 | 437 | |
| 413 | 438 | public: |
| 414 | - Members(); | |
| 439 | + Members(QPDF& qpdf); | |
| 415 | 440 | Members(Members const&) = delete; |
| 416 | 441 | ~Members() = default; |
| 417 | 442 | |
| 418 | 443 | private: |
| 444 | + Doc doc; | |
| 419 | 445 | std::shared_ptr<QPDFLogger> log; |
| 420 | 446 | unsigned long long unique_id{0}; |
| 421 | 447 | qpdf::Tokenizer tokenizer; |
| ... | ... | @@ -562,6 +588,12 @@ QPDF::page_labels() |
| 562 | 588 | return *m->page_labels; |
| 563 | 589 | } |
| 564 | 590 | |
| 591 | +inline QPDF::Doc& | |
| 592 | +QPDF::doc() | |
| 593 | +{ | |
| 594 | + return m->doc; | |
| 595 | +} | |
| 596 | + | |
| 565 | 597 | // Throw a generic exception for unusual error conditions that do not be covered during CI testing. |
| 566 | 598 | inline void |
| 567 | 599 | QPDF::no_ci_stop_if(bool condition, std::string const& message, std::string const& context) | ... | ... |