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 | 30 | bool |
| 31 | 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 | 36 | class Streams::Copier final: public QPDFObjectHandle::StreamDataProvider |
| ... | ... | @@ -83,10 +83,10 @@ class Streams::Copier final: public QPDFObjectHandle::StreamDataProvider |
| 83 | 83 | if (data != copied_data.end()) { |
| 84 | 84 | auto& fd = data->second; |
| 85 | 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 | 87 | fd.encp, |
| 88 | 88 | fd.file, |
| 89 | - streams.qpdf(), | |
| 89 | + streams.qpdf, | |
| 90 | 90 | fd.source_og, |
| 91 | 91 | fd.offset, |
| 92 | 92 | fd.length, |
| ... | ... | @@ -128,8 +128,8 @@ class Streams::Copier final: public QPDFObjectHandle::StreamDataProvider |
| 128 | 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 | 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 | 624 | class QPDF::Doc::Objects: Common |
| 625 | 625 | { |
| 626 | 626 | public: |
| 627 | - class Foreign | |
| 627 | + class Foreign: Common | |
| 628 | 628 | { |
| 629 | - class Copier | |
| 629 | + class Copier: Common | |
| 630 | 630 | { |
| 631 | 631 | public: |
| 632 | - Copier(QPDF& qpdf) : | |
| 633 | - qpdf(qpdf) | |
| 634 | - { | |
| 635 | - } | |
| 632 | + inline Copier(QPDF& qpdf); | |
| 636 | 633 | |
| 637 | 634 | QPDFObjectHandle copied(QPDFObjectHandle const& foreign); |
| 638 | 635 | |
| ... | ... | @@ -641,15 +638,14 @@ class QPDF::Doc::Objects: Common |
| 641 | 638 | replace_indirect_object(QPDFObjectHandle const& foreign, bool top = false); |
| 642 | 639 | void reserve_objects(QPDFObjectHandle const& foreign, bool top = false); |
| 643 | 640 | |
| 644 | - QPDF& qpdf; | |
| 645 | 641 | std::map<QPDFObjGen, QPDFObjectHandle> object_map; |
| 646 | 642 | std::vector<QPDFObjectHandle> to_copy; |
| 647 | 643 | QPDFObjGen::set visiting; |
| 648 | 644 | }; |
| 649 | 645 | |
| 650 | 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 | 666 | private: |
| 671 | 667 | Copier& copier(QPDFObjectHandle const& foreign); |
| 672 | 668 | |
| 673 | - QPDF& qpdf; | |
| 674 | 669 | std::map<unsigned long long, Copier> copiers; |
| 675 | 670 | }; // class QPDF::Doc::Objects::Foreign |
| 676 | 671 | |
| 677 | - class Streams | |
| 672 | + class Streams: Common | |
| 678 | 673 | { |
| 679 | 674 | // Copier manages the copying of streams into this PDF. It is used both for copying |
| 680 | 675 | // local and foreign streams. |
| 681 | 676 | class Copier; |
| 682 | 677 | |
| 683 | 678 | public: |
| 684 | - Streams(QPDF& qpdf); | |
| 679 | + Streams(Common& common); | |
| 685 | 680 | |
| 686 | 681 | Streams() = delete; |
| 687 | 682 | Streams(Streams const&) = delete; |
| ... | ... | @@ -714,12 +709,6 @@ class QPDF::Doc::Objects: Common |
| 714 | 709 | will_retry); |
| 715 | 710 | } |
| 716 | 711 | |
| 717 | - QPDF& | |
| 718 | - qpdf() const | |
| 719 | - { | |
| 720 | - return qpdf_; | |
| 721 | - } | |
| 722 | - | |
| 723 | 712 | std::shared_ptr<Copier>& |
| 724 | 713 | copier() |
| 725 | 714 | { |
| ... | ... | @@ -729,8 +718,6 @@ class QPDF::Doc::Objects: Common |
| 729 | 718 | bool immediate_copy_from() const; |
| 730 | 719 | |
| 731 | 720 | private: |
| 732 | - QPDF& qpdf_; | |
| 733 | - | |
| 734 | 721 | std::shared_ptr<Copier> copier_; |
| 735 | 722 | }; // class QPDF::Doc::Objects::Streams |
| 736 | 723 | |
| ... | ... | @@ -744,8 +731,8 @@ class QPDF::Doc::Objects: Common |
| 744 | 731 | |
| 745 | 732 | Objects(Doc& doc) : |
| 746 | 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 | 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 | 992 | // Throw a generic exception for unusual error conditions that do not be covered during CI testing. |
| 1001 | 993 | inline void |
| 1002 | 994 | QPDF::no_ci_stop_if(bool condition, std::string const& message, std::string const& context) | ... | ... |