Commit 79af97744222a58c115d588cf2a8144f8e736847
1 parent
0c591c10
Refactor `Doc` components: introduce `Common` base class, streamline constructor…
…s, and improve encapsulation.
Showing
2 changed files
with
40 additions
and
29 deletions
libqpdf/QPDF.cc
| @@ -127,9 +127,10 @@ QPDF::QPDFVersion() | @@ -127,9 +127,10 @@ QPDF::QPDFVersion() | ||
| 127 | 127 | ||
| 128 | QPDF::Members::Members(QPDF& qpdf) : | 128 | QPDF::Members::Members(QPDF& qpdf) : |
| 129 | Doc(qpdf, this), | 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 | log(QPDFLogger::defaultLogger()), | 134 | log(QPDFLogger::defaultLogger()), |
| 134 | file(std::make_shared<InvalidInputSource>()), | 135 | file(std::make_shared<InvalidInputSource>()), |
| 135 | encp(std::make_shared<EncryptionParameters>()) | 136 | encp(std::make_shared<EncryptionParameters>()) |
libqpdf/qpdf/QPDF_private.hh
| @@ -304,6 +304,29 @@ class QPDF::Doc | @@ -304,6 +304,29 @@ class QPDF::Doc | ||
| 304 | class Resolver; | 304 | class Resolver; |
| 305 | class Writer; | 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 | Doc() = delete; | 330 | Doc() = delete; |
| 308 | Doc(Doc const&) = delete; | 331 | Doc(Doc const&) = delete; |
| 309 | Doc(Doc&&) = delete; | 332 | Doc(Doc&&) = delete; |
| @@ -498,7 +521,7 @@ class QPDF::Doc::Encryption | @@ -498,7 +521,7 @@ class QPDF::Doc::Encryption | ||
| 498 | bool encrypt_metadata; | 521 | bool encrypt_metadata; |
| 499 | }; // class QPDF::Doc::Encryption | 522 | }; // class QPDF::Doc::Encryption |
| 500 | 523 | ||
| 501 | -class QPDF::Doc::Linearization | 524 | +class QPDF::Doc::Linearization: Common |
| 502 | { | 525 | { |
| 503 | public: | 526 | public: |
| 504 | Linearization() = delete; | 527 | Linearization() = delete; |
| @@ -508,9 +531,8 @@ class QPDF::Doc::Linearization | @@ -508,9 +531,8 @@ class QPDF::Doc::Linearization | ||
| 508 | Linearization& operator=(Linearization&&) = delete; | 531 | Linearization& operator=(Linearization&&) = delete; |
| 509 | ~Linearization() = default; | 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,13 +619,9 @@ class QPDF::Doc::Linearization | ||
| 597 | std::function<int(QPDFObjectHandle&)> skip_stream_parameters); | 619 | std::function<int(QPDFObjectHandle&)> skip_stream_parameters); |
| 598 | void filterCompressedObjects(std::map<int, int> const& object_stream_data); | 620 | void filterCompressedObjects(std::map<int, int> const& object_stream_data); |
| 599 | void filterCompressedObjects(QPDFWriter::ObjTable const& object_stream_data); | 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 | public: | 626 | public: |
| 609 | class Foreign | 627 | class Foreign |
| @@ -724,11 +742,10 @@ class QPDF::Doc::Objects | @@ -724,11 +742,10 @@ class QPDF::Doc::Objects | ||
| 724 | Objects& operator=(Objects&&) = delete; | 742 | Objects& operator=(Objects&&) = delete; |
| 725 | ~Objects() = default; | 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,15 +830,12 @@ class QPDF::Doc::Objects | ||
| 813 | bool isUnresolved(QPDFObjGen og); | 830 | bool isUnresolved(QPDFObjGen og); |
| 814 | void setLastObjectDescription(std::string const& description, QPDFObjGen og); | 831 | void setLastObjectDescription(std::string const& description, QPDFObjGen og); |
| 815 | 832 | ||
| 816 | - QPDF& qpdf; | ||
| 817 | - QPDF::Members* m; | ||
| 818 | - | ||
| 819 | Foreign foreign_; | 833 | Foreign foreign_; |
| 820 | Streams streams_; | 834 | Streams streams_; |
| 821 | }; // class QPDF::Doc::Objects | 835 | }; // class QPDF::Doc::Objects |
| 822 | 836 | ||
| 823 | // This class is used to represent a PDF Pages tree. | 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 | public: | 840 | public: |
| 827 | Pages() = delete; | 841 | Pages() = delete; |
| @@ -831,9 +845,8 @@ class QPDF::Doc::Pages | @@ -831,9 +845,8 @@ class QPDF::Doc::Pages | ||
| 831 | Pages& operator=(Pages&&) = delete; | 845 | Pages& operator=(Pages&&) = delete; |
| 832 | ~Pages() = default; | 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,13 +865,9 @@ class QPDF::Doc::Pages | ||
| 852 | std::map<std::string, std::vector<QPDFObjectHandle>>&, | 865 | std::map<std::string, std::vector<QPDFObjectHandle>>&, |
| 853 | bool allow_changes, | 866 | bool allow_changes, |
| 854 | bool warn_skipped_keys); | 867 | bool warn_skipped_keys); |
| 855 | - | ||
| 856 | - private: | ||
| 857 | - QPDF& qpdf; | ||
| 858 | - QPDF::Members* m; | ||
| 859 | }; // class QPDF::Doc::Pages | 868 | }; // class QPDF::Doc::Pages |
| 860 | 869 | ||
| 861 | -class QPDF::Members: QPDF::Doc | 870 | +class QPDF::Members: Doc |
| 862 | { | 871 | { |
| 863 | friend class QPDF; | 872 | friend class QPDF; |
| 864 | friend class ResolveRecorder; | 873 | friend class ResolveRecorder; |
| @@ -869,6 +878,7 @@ class QPDF::Members: QPDF::Doc | @@ -869,6 +878,7 @@ class QPDF::Members: QPDF::Doc | ||
| 869 | ~Members() = default; | 878 | ~Members() = default; |
| 870 | 879 | ||
| 871 | private: | 880 | private: |
| 881 | + Doc::Common c; | ||
| 872 | Doc::Linearization lin; | 882 | Doc::Linearization lin; |
| 873 | Doc::Objects objects; | 883 | Doc::Objects objects; |
| 874 | Doc::Pages pages; | 884 | Doc::Pages pages; |