diff options
Diffstat (limited to 'libqpdf')
-rw-r--r-- | libqpdf/Pl_Function.cc | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/libqpdf/Pl_Function.cc b/libqpdf/Pl_Function.cc index 32fcccf1..5f2dc042 100644 --- a/libqpdf/Pl_Function.cc +++ b/libqpdf/Pl_Function.cc @@ -15,6 +15,36 @@ Pl_Function::Pl_Function(char const* identifier, Pipeline* next, writer_t fn) : { } +Pl_Function::Pl_Function( + char const* identifier, Pipeline* next, writer_c_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(data, len, udata); + if (code != 0) { + throw std::runtime_error( + std::string(identifier) + " function returned code " + + QUtil::int_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 " + + QUtil::int_to_string(code)); + } + }; +} + Pl_Function::~Pl_Function() { // Must be explicit and not inline -- see QPDF_DLL_CLASS in |