Commit 8486b9deabdab182bdf2646bd4ee5ca391c0a565
1 parent
79af9774
Refactor `Doc::Objects`: extend `Common` inheritance, streamline constructors, a…
…nd improve encapsulation.
Showing
2 changed files
with
19 additions
and
27 deletions
libqpdf/QPDF_Stream.cc
| @@ -30,7 +30,7 @@ using Streams = QPDF::Doc::Objects::Streams; | @@ -30,7 +30,7 @@ using Streams = QPDF::Doc::Objects::Streams; | ||
| 30 | bool | 30 | bool |
| 31 | Streams::immediate_copy_from() const | 31 | Streams::immediate_copy_from() const |
| 32 | { | 32 | { |
| 33 | - return qpdf_.m->immediate_copy_from; | 33 | + return qpdf.m->immediate_copy_from; |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | class Streams::Copier final: public QPDFObjectHandle::StreamDataProvider | 36 | class Streams::Copier final: public QPDFObjectHandle::StreamDataProvider |
| @@ -83,10 +83,10 @@ class Streams::Copier final: public QPDFObjectHandle::StreamDataProvider | @@ -83,10 +83,10 @@ class Streams::Copier final: public QPDFObjectHandle::StreamDataProvider | ||
| 83 | if (data != copied_data.end()) { | 83 | if (data != copied_data.end()) { |
| 84 | auto& fd = data->second; | 84 | auto& fd = data->second; |
| 85 | QTC::TC("qpdf", "QPDF pipe foreign encrypted stream", fd.encp->encrypted ? 0 : 1); | 85 | QTC::TC("qpdf", "QPDF pipe foreign encrypted stream", fd.encp->encrypted ? 0 : 1); |
| 86 | - if (streams.qpdf().pipeStreamData( | 86 | + if (streams.qpdf.pipeStreamData( |
| 87 | fd.encp, | 87 | fd.encp, |
| 88 | fd.file, | 88 | fd.file, |
| 89 | - streams.qpdf(), | 89 | + streams.qpdf, |
| 90 | fd.source_og, | 90 | fd.source_og, |
| 91 | fd.offset, | 91 | fd.offset, |
| 92 | fd.length, | 92 | fd.length, |
| @@ -128,8 +128,8 @@ class Streams::Copier final: public QPDFObjectHandle::StreamDataProvider | @@ -128,8 +128,8 @@ class Streams::Copier final: public QPDFObjectHandle::StreamDataProvider | ||
| 128 | std::map<QPDFObjGen, Data> copied_data; | 128 | std::map<QPDFObjGen, Data> copied_data; |
| 129 | }; | 129 | }; |
| 130 | 130 | ||
| 131 | -Streams::Streams(QPDF& qpdf) : | ||
| 132 | - qpdf_(qpdf), | 131 | +Streams::Streams(Common& common) : |
| 132 | + Common(common), | ||
| 133 | copier_(std::make_shared<Copier>(*this)) | 133 | copier_(std::make_shared<Copier>(*this)) |
| 134 | { | 134 | { |
| 135 | } | 135 | } |
libqpdf/qpdf/QPDF_private.hh
| @@ -624,15 +624,12 @@ class QPDF::Doc::Linearization: Common | @@ -624,15 +624,12 @@ class QPDF::Doc::Linearization: Common | ||
| 624 | class QPDF::Doc::Objects: Common | 624 | class QPDF::Doc::Objects: Common |
| 625 | { | 625 | { |
| 626 | public: | 626 | public: |
| 627 | - class Foreign | 627 | + class Foreign: Common |
| 628 | { | 628 | { |
| 629 | - class Copier | 629 | + class Copier: Common |
| 630 | { | 630 | { |
| 631 | public: | 631 | public: |
| 632 | - Copier(QPDF& qpdf) : | ||
| 633 | - qpdf(qpdf) | ||
| 634 | - { | ||
| 635 | - } | 632 | + inline Copier(QPDF& qpdf); |
| 636 | 633 | ||
| 637 | QPDFObjectHandle copied(QPDFObjectHandle const& foreign); | 634 | QPDFObjectHandle copied(QPDFObjectHandle const& foreign); |
| 638 | 635 | ||
| @@ -641,15 +638,14 @@ class QPDF::Doc::Objects: Common | @@ -641,15 +638,14 @@ class QPDF::Doc::Objects: Common | ||
| 641 | replace_indirect_object(QPDFObjectHandle const& foreign, bool top = false); | 638 | replace_indirect_object(QPDFObjectHandle const& foreign, bool top = false); |
| 642 | void reserve_objects(QPDFObjectHandle const& foreign, bool top = false); | 639 | void reserve_objects(QPDFObjectHandle const& foreign, bool top = false); |
| 643 | 640 | ||
| 644 | - QPDF& qpdf; | ||
| 645 | std::map<QPDFObjGen, QPDFObjectHandle> object_map; | 641 | std::map<QPDFObjGen, QPDFObjectHandle> object_map; |
| 646 | std::vector<QPDFObjectHandle> to_copy; | 642 | std::vector<QPDFObjectHandle> to_copy; |
| 647 | QPDFObjGen::set visiting; | 643 | QPDFObjGen::set visiting; |
| 648 | }; | 644 | }; |
| 649 | 645 | ||
| 650 | public: | 646 | public: |
| 651 | - Foreign(QPDF& qpdf) : | ||
| 652 | - qpdf(qpdf) | 647 | + Foreign(Common& common) : |
| 648 | + Common(common) | ||
| 653 | { | 649 | { |
| 654 | } | 650 | } |
| 655 | 651 | ||
| @@ -670,18 +666,17 @@ class QPDF::Doc::Objects: Common | @@ -670,18 +666,17 @@ class QPDF::Doc::Objects: Common | ||
| 670 | private: | 666 | private: |
| 671 | Copier& copier(QPDFObjectHandle const& foreign); | 667 | Copier& copier(QPDFObjectHandle const& foreign); |
| 672 | 668 | ||
| 673 | - QPDF& qpdf; | ||
| 674 | std::map<unsigned long long, Copier> copiers; | 669 | std::map<unsigned long long, Copier> copiers; |
| 675 | }; // class QPDF::Doc::Objects::Foreign | 670 | }; // class QPDF::Doc::Objects::Foreign |
| 676 | 671 | ||
| 677 | - class Streams | 672 | + class Streams: Common |
| 678 | { | 673 | { |
| 679 | // Copier manages the copying of streams into this PDF. It is used both for copying | 674 | // Copier manages the copying of streams into this PDF. It is used both for copying |
| 680 | // local and foreign streams. | 675 | // local and foreign streams. |
| 681 | class Copier; | 676 | class Copier; |
| 682 | 677 | ||
| 683 | public: | 678 | public: |
| 684 | - Streams(QPDF& qpdf); | 679 | + Streams(Common& common); |
| 685 | 680 | ||
| 686 | Streams() = delete; | 681 | Streams() = delete; |
| 687 | Streams(Streams const&) = delete; | 682 | Streams(Streams const&) = delete; |
| @@ -714,12 +709,6 @@ class QPDF::Doc::Objects: Common | @@ -714,12 +709,6 @@ class QPDF::Doc::Objects: Common | ||
| 714 | will_retry); | 709 | will_retry); |
| 715 | } | 710 | } |
| 716 | 711 | ||
| 717 | - QPDF& | ||
| 718 | - qpdf() const | ||
| 719 | - { | ||
| 720 | - return qpdf_; | ||
| 721 | - } | ||
| 722 | - | ||
| 723 | std::shared_ptr<Copier>& | 712 | std::shared_ptr<Copier>& |
| 724 | copier() | 713 | copier() |
| 725 | { | 714 | { |
| @@ -729,8 +718,6 @@ class QPDF::Doc::Objects: Common | @@ -729,8 +718,6 @@ class QPDF::Doc::Objects: Common | ||
| 729 | bool immediate_copy_from() const; | 718 | bool immediate_copy_from() const; |
| 730 | 719 | ||
| 731 | private: | 720 | private: |
| 732 | - QPDF& qpdf_; | ||
| 733 | - | ||
| 734 | std::shared_ptr<Copier> copier_; | 721 | std::shared_ptr<Copier> copier_; |
| 735 | }; // class QPDF::Doc::Objects::Streams | 722 | }; // class QPDF::Doc::Objects::Streams |
| 736 | 723 | ||
| @@ -744,8 +731,8 @@ class QPDF::Doc::Objects: Common | @@ -744,8 +731,8 @@ class QPDF::Doc::Objects: Common | ||
| 744 | 731 | ||
| 745 | Objects(Doc& doc) : | 732 | Objects(Doc& doc) : |
| 746 | Common(doc.qpdf, doc.m), | 733 | Common(doc.qpdf, doc.m), |
| 747 | - foreign_(doc.qpdf), | ||
| 748 | - streams_(doc.qpdf) | 734 | + foreign_(*this), |
| 735 | + streams_(*this) | ||
| 749 | { | 736 | { |
| 750 | } | 737 | } |
| 751 | 738 | ||
| @@ -997,6 +984,11 @@ QPDF::doc() | @@ -997,6 +984,11 @@ QPDF::doc() | ||
| 997 | return *m; | 984 | return *m; |
| 998 | } | 985 | } |
| 999 | 986 | ||
| 987 | +inline QPDF::Doc::Objects::Foreign::Copier::Copier(QPDF& qpdf) : | ||
| 988 | + Common(qpdf, qpdf.doc().m) | ||
| 989 | +{ | ||
| 990 | +} | ||
| 991 | + | ||
| 1000 | // Throw a generic exception for unusual error conditions that do not be covered during CI testing. | 992 | // Throw a generic exception for unusual error conditions that do not be covered during CI testing. |
| 1001 | inline void | 993 | inline void |
| 1002 | QPDF::no_ci_stop_if(bool condition, std::string const& message, std::string const& context) | 994 | QPDF::no_ci_stop_if(bool condition, std::string const& message, std::string const& context) |