Commit 7b3427502a6b469120f8eee0cf6dc5f9c3315c23

Authored by m-holger
1 parent 680b6874

Refactor `QPDFWriter` to replace `pl::Link` with direct use of `Pipeline` for im…

…proved clarity and reduced indirection in pipeline management.
libqpdf/QPDFWriter.cc
... ... @@ -141,7 +141,7 @@ namespace
141 141 }
142 142  
143 143 void
144   - activate(Popper& pp, std::unique_ptr<pl::Link> link)
  144 + activate(Popper& pp, std::unique_ptr<Pipeline> link)
145 145 {
146 146 count_buffer.clear();
147 147 activate(pp, false, &count_buffer, std::move(link));
... ... @@ -151,7 +151,7 @@ namespace
151 151 activate(
152 152 bool discard = false,
153 153 std::string* str = nullptr,
154   - std::unique_ptr<pl::Link> link = nullptr)
  154 + std::unique_ptr<Pipeline> link = nullptr)
155 155 {
156 156 Popper pp{*this};
157 157 activate(pp, discard, str, std::move(link));
... ... @@ -163,7 +163,7 @@ namespace
163 163 Popper& pp,
164 164 bool discard = false,
165 165 std::string* str = nullptr,
166   - std::unique_ptr<pl::Link> link = nullptr)
  166 + std::unique_ptr<Pipeline> link = nullptr)
167 167 {
168 168 std::unique_ptr<pl::Count> c;
169 169 if (link) {
... ... @@ -2735,9 +2735,7 @@ QPDFWriter::writeLinearized()
2735 2735 lin_pass1_file = QUtil::safe_fopen(m->lin_pass1_filename.c_str(), "wb");
2736 2736 m->pipeline_stack.activate(
2737 2737 pp_pass1,
2738   - std::make_unique<pl::Link>(
2739   - nullptr,
2740   - std::make_unique<Pl_StdioFile>("linearization pass1", lin_pass1_file)));
  2738 + std::make_unique<Pl_StdioFile>("linearization pass1", lin_pass1_file));
2741 2739 } else {
2742 2740 m->pipeline_stack.activate(pp_pass1, true);
2743 2741 }
... ...
libqpdf/qpdf/Pipeline_private.hh
... ... @@ -8,35 +8,6 @@
8 8  
9 9 namespace qpdf::pl
10 10 {
11   - struct Link
12   - {
13   - Link(std::unique_ptr<Link> next_link, std::unique_ptr<Pipeline> next_pl) :
14   - next_link(std::move(next_link)),
15   - next_pl(std::move(next_pl))
16   - {
17   - }
18   -
19   - std::unique_ptr<Link> next_link{nullptr};
20   - std::unique_ptr<Pipeline> next_pl{nullptr};
21   - };
22   -
23   - template <typename P, typename... Args>
24   - std::unique_ptr<Link>
25   - create(Args&&... args)
26   - {
27   - return std::make_unique<Link>(
28   - nullptr, std::make_unique<P>("", nullptr, std::forward<Args>(args)...));
29   - }
30   -
31   - template <typename P, typename... Args>
32   - std::unique_ptr<Link>
33   - create(std::unique_ptr<Link> link, Args&&... args)
34   - {
35   - auto* next = link->next_pl.get();
36   - return std::make_unique<Link>(
37   - std::move(link), std::make_unique<P>("", next, std::forward<Args>(args)...));
38   - }
39   -
40 11 class String final: public Pipeline
41 12 {
42 13 public:
... ... @@ -85,8 +56,8 @@ namespace qpdf::pl
85 56  
86 57 // Count the number of characters written. If 'next' is not set, the content written will be
87 58 // discarded.
88   - Count(unsigned long id, std::unique_ptr<Link> link) :
89   - Pipeline("", link ? link->next_pl.get() : nullptr),
  59 + Count(unsigned long id, std::unique_ptr<Pipeline> link) :
  60 + Pipeline("", link ? link.get() : nullptr),
90 61 link(std::move(link)),
91 62 id_(id),
92 63 pass_immediately_to_next(link)
... ... @@ -95,8 +66,8 @@ namespace qpdf::pl
95 66  
96 67 // Write to 'str'. If 'next' is set, 'str' will be written to 'next' when 'finish' is
97 68 // called.
98   - Count(unsigned long id, std::string& str, std::unique_ptr<Link> link = nullptr) :
99   - Pipeline("", link ? link->next_pl.get() : nullptr),
  69 + Count(unsigned long id, std::string& str, std::unique_ptr<Pipeline> link = nullptr) :
  70 + Pipeline("", link ? link.get() : nullptr),
100 71 str(&str),
101 72 link(std::move(link)),
102 73 id_(id)
... ... @@ -169,7 +140,7 @@ namespace qpdf::pl
169 140 private:
170 141 qpdf_offset_t count{0};
171 142 std::string* str{nullptr};
172   - std::unique_ptr<Link> link{nullptr};
  143 + std::unique_ptr<Pipeline> link{nullptr};
173 144 unsigned long id_{0};
174 145 bool pass_immediately_to_next{false};
175 146 };
... ...