Commit 79af97744222a58c115d588cf2a8144f8e736847

Authored by m-holger
1 parent 0c591c10

Refactor `Doc` components: introduce `Common` base class, streamline constructor…

…s, and improve encapsulation.
libqpdf/QPDF.cc
... ... @@ -127,9 +127,10 @@ QPDF::QPDFVersion()
127 127  
128 128 QPDF::Members::Members(QPDF& qpdf) :
129 129 Doc(qpdf, this),
130   - lin(qpdf, this),
131   - objects(qpdf, this),
132   - pages(qpdf, this),
  130 + c(qpdf, this),
  131 + lin(*this),
  132 + objects(*this),
  133 + pages(*this),
133 134 log(QPDFLogger::defaultLogger()),
134 135 file(std::make_shared<InvalidInputSource>()),
135 136 encp(std::make_shared<EncryptionParameters>())
... ...
libqpdf/qpdf/QPDF_private.hh
... ... @@ -304,6 +304,29 @@ class QPDF::Doc
304 304 class Resolver;
305 305 class Writer;
306 306  
  307 + // This is the common base-class for all document components. It is used by the other document
  308 + // components to access common functionality. It is not meant to be used directly by the user.
  309 + class Common
  310 + {
  311 + public:
  312 + Common() = delete;
  313 + Common(Common const&) = default;
  314 + Common(Common&&) = delete;
  315 + Common& operator=(Common const&) = delete;
  316 + Common& operator=(Common&&) = delete;
  317 + ~Common() = default;
  318 +
  319 + Common(QPDF& qpdf, QPDF::Members* m) :
  320 + qpdf(qpdf),
  321 + m(m)
  322 + {
  323 + }
  324 +
  325 + protected:
  326 + QPDF& qpdf;
  327 + QPDF::Members* m;
  328 + };
  329 +
307 330 Doc() = delete;
308 331 Doc(Doc const&) = delete;
309 332 Doc(Doc&&) = delete;
... ... @@ -498,7 +521,7 @@ class QPDF::Doc::Encryption
498 521 bool encrypt_metadata;
499 522 }; // class QPDF::Doc::Encryption
500 523  
501   -class QPDF::Doc::Linearization
  524 +class QPDF::Doc::Linearization: Common
502 525 {
503 526 public:
504 527 Linearization() = delete;
... ... @@ -508,9 +531,8 @@ class QPDF::Doc::Linearization
508 531 Linearization& operator=(Linearization&&) = delete;
509 532 ~Linearization() = default;
510 533  
511   - Linearization(QPDF& qpdf, QPDF::Members* m) :
512   - qpdf(qpdf),
513   - m(m)
  534 + Linearization(Doc& doc) :
  535 + Common(doc.qpdf, doc.m)
514 536 {
515 537 }
516 538  
... ... @@ -597,13 +619,9 @@ class QPDF::Doc::Linearization
597 619 std::function<int(QPDFObjectHandle&)> skip_stream_parameters);
598 620 void filterCompressedObjects(std::map<int, int> const& object_stream_data);
599 621 void filterCompressedObjects(QPDFWriter::ObjTable const& object_stream_data);
600   -
601   - private:
602   - QPDF& qpdf;
603   - QPDF::Members* m;
604 622 };
605 623  
606   -class QPDF::Doc::Objects
  624 +class QPDF::Doc::Objects: Common
607 625 {
608 626 public:
609 627 class Foreign
... ... @@ -724,11 +742,10 @@ class QPDF::Doc::Objects
724 742 Objects& operator=(Objects&&) = delete;
725 743 ~Objects() = default;
726 744  
727   - Objects(QPDF& qpdf, QPDF::Members* m) :
728   - qpdf(qpdf),
729   - m(m),
730   - foreign_(qpdf),
731   - streams_(qpdf)
  745 + Objects(Doc& doc) :
  746 + Common(doc.qpdf, doc.m),
  747 + foreign_(doc.qpdf),
  748 + streams_(doc.qpdf)
732 749 {
733 750 }
734 751  
... ... @@ -813,15 +830,12 @@ class QPDF::Doc::Objects
813 830 bool isUnresolved(QPDFObjGen og);
814 831 void setLastObjectDescription(std::string const& description, QPDFObjGen og);
815 832  
816   - QPDF& qpdf;
817   - QPDF::Members* m;
818   -
819 833 Foreign foreign_;
820 834 Streams streams_;
821 835 }; // class QPDF::Doc::Objects
822 836  
823 837 // This class is used to represent a PDF Pages tree.
824   -class QPDF::Doc::Pages
  838 +class QPDF::Doc::Pages: Common
825 839 {
826 840 public:
827 841 Pages() = delete;
... ... @@ -831,9 +845,8 @@ class QPDF::Doc::Pages
831 845 Pages& operator=(Pages&&) = delete;
832 846 ~Pages() = default;
833 847  
834   - Pages(QPDF& qpdf, QPDF::Members* m) :
835   - qpdf(qpdf),
836   - m(m)
  848 + Pages(Doc& doc) :
  849 + Common(doc.qpdf, doc.m)
837 850 {
838 851 }
839 852  
... ... @@ -852,13 +865,9 @@ class QPDF::Doc::Pages
852 865 std::map<std::string, std::vector<QPDFObjectHandle>>&,
853 866 bool allow_changes,
854 867 bool warn_skipped_keys);
855   -
856   - private:
857   - QPDF& qpdf;
858   - QPDF::Members* m;
859 868 }; // class QPDF::Doc::Pages
860 869  
861   -class QPDF::Members: QPDF::Doc
  870 +class QPDF::Members: Doc
862 871 {
863 872 friend class QPDF;
864 873 friend class ResolveRecorder;
... ... @@ -869,6 +878,7 @@ class QPDF::Members: QPDF::Doc
869 878 ~Members() = default;
870 879  
871 880 private:
  881 + Doc::Common c;
872 882 Doc::Linearization lin;
873 883 Doc::Objects objects;
874 884 Doc::Pages pages;
... ...