File: Pl_Function.cc

package info (click to toggle)
qpdf 12.3.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 72,644 kB
  • sloc: cpp: 59,031; perl: 12,172; ansic: 6,809; sh: 1,231; python: 1,041; xml: 43; makefile: 42
file content (70 lines) | stat: -rw-r--r-- 1,723 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <qpdf/Pl_Function.hh>

#include <stdexcept>

class Pl_Function::Members
{
  public:
    Members(writer_t fn) :
        fn(fn)
    {
    }
    Members(Members const&) = delete;
    ~Members() = default;

    writer_t fn;
};

Pl_Function::Pl_Function(char const* identifier, Pipeline* next, writer_t fn) :
    Pipeline(identifier, next),
    m(std::make_unique<Members>(fn))
{
}

Pl_Function::Pl_Function(char const* identifier, Pipeline* next, writer_c_t fn, void* udata) :
    Pipeline(identifier, next),
    m(std::make_unique<Members>(nullptr))
{
    m->fn = [identifier, fn, udata](unsigned char const* data, size_t len) {
        int code = fn(data, len, udata);
        if (code != 0) {
            throw std::runtime_error(
                std::string(identifier) + " function returned code " + std::to_string(code));
        }
    };
}

Pl_Function::Pl_Function(char const* identifier, Pipeline* next, writer_c_char_t fn, void* udata) :
    Pipeline(identifier, next),
    m(new Members(nullptr))
{
    m->fn = [identifier, fn, udata](unsigned char const* data, size_t len) {
        int code = fn(reinterpret_cast<char const*>(data), len, udata);
        if (code != 0) {
            throw std::runtime_error(
                std::string(identifier) + " function returned code " + std::to_string(code));
        }
    };
}

Pl_Function::~Pl_Function() // NOLINT (modernize-use-equals-default)
{
    // Must be explicit and not inline -- see QPDF_DLL_CLASS in README-maintainer
}

void
Pl_Function::write(unsigned char const* buf, size_t len)
{
    m->fn(buf, len);
    if (next()) {
        next()->write(buf, len);
    }
}

void
Pl_Function::finish()
{
    if (next()) {
        next()->finish();
    }
}