diff options
author | Jay Berkenbilt <ejb@ql.org> | 2022-09-08 22:38:36 +0200 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2022-09-08 23:35:27 +0200 |
commit | b0f054e600bd07f540ac0a081dd8b5a8cc561617 (patch) | |
tree | 5e539e77e5b2fc3f54e1380eb2b9877662bc43ef /libqpdf | |
parent | 5911a348a5ae9065610be5fe5f251cab399a52b8 (diff) | |
download | qpdf-b0f054e600bd07f540ac0a081dd8b5a8cc561617.tar.zst |
Add ability to initialize Pl_Function with a C-style function
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 |