/src/qpdf/libqpdf/Pl_Count.cc
Line | Count | Source (jump to first uncovered line) |
1 | | #include <qpdf/Pl_Count.hh> |
2 | | |
3 | | #include <qpdf/QIntC.hh> |
4 | | |
5 | | class Pl_Count::Members |
6 | | { |
7 | | public: |
8 | 0 | Members() = default; |
9 | | Members(Members const&) = delete; |
10 | | ~Members() = default; |
11 | | |
12 | | // Must be qpdf_offset_t, not size_t, to handle writing more than size_t can handle. |
13 | | qpdf_offset_t count{0}; |
14 | | unsigned char last_char{'\0'}; |
15 | | }; |
16 | | |
17 | | Pl_Count::Pl_Count(char const* identifier, Pipeline* next) : |
18 | 0 | Pipeline(identifier, next), |
19 | 0 | m(std::make_unique<Members>()) |
20 | 0 | { |
21 | 0 | if (!next) { |
22 | 0 | throw std::logic_error("Attempt to create Pl_Count with nullptr as next"); |
23 | 0 | } |
24 | 0 | } |
25 | | |
26 | | Pl_Count::~Pl_Count() // NOLINT (modernize-use-equals-default) |
27 | 0 | { |
28 | | // Must be explicit and not inline -- see QPDF_DLL_CLASS in README-maintainer |
29 | 0 | } |
30 | | |
31 | | void |
32 | | Pl_Count::write(unsigned char const* buf, size_t len) |
33 | 0 | { |
34 | 0 | if (len) { |
35 | 0 | m->count += QIntC::to_offset(len); |
36 | 0 | m->last_char = buf[len - 1]; |
37 | 0 | next()->write(buf, len); |
38 | 0 | } |
39 | 0 | } |
40 | | |
41 | | void |
42 | | Pl_Count::finish() |
43 | 0 | { |
44 | 0 | next()->finish(); |
45 | 0 | } |
46 | | |
47 | | qpdf_offset_t |
48 | | Pl_Count::getCount() const |
49 | 0 | { |
50 | 0 | return m->count; |
51 | 0 | } |
52 | | |
53 | | unsigned char |
54 | | Pl_Count::getLastChar() const |
55 | 0 | { |
56 | 0 | return m->last_char; |
57 | 0 | } |