2022-06-19 12:56:36 +00:00
|
|
|
#include <qpdf/Pl_Function.hh>
|
|
|
|
|
|
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
Pl_Function::Members::Members(writer_t fn) :
|
|
|
|
fn(fn)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Pl_Function::Pl_Function(char const* identifier, Pipeline* next, writer_t fn) :
|
|
|
|
Pipeline(identifier, next),
|
|
|
|
m(new Members(fn))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-05-21 17:35:09 +00:00
|
|
|
Pl_Function::Pl_Function(char const* identifier, Pipeline* next, writer_c_t fn, void* udata) :
|
2022-09-08 20:38:36 +00:00
|
|
|
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(
|
2023-05-21 17:35:09 +00:00
|
|
|
std::string(identifier) + " function returned code " + std::to_string(code));
|
2022-09-08 20:38:36 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-05-21 17:35:09 +00:00
|
|
|
Pl_Function::Pl_Function(char const* identifier, Pipeline* next, writer_c_char_t fn, void* udata) :
|
2022-09-08 20:38:36 +00:00
|
|
|
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(
|
2023-05-21 17:35:09 +00:00
|
|
|
std::string(identifier) + " function returned code " + std::to_string(code));
|
2022-09-08 20:38:36 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-06-19 12:56:36 +00:00
|
|
|
Pl_Function::~Pl_Function()
|
|
|
|
{
|
2023-05-27 17:19:52 +00:00
|
|
|
// Must be explicit and not inline -- see QPDF_DLL_CLASS in README-maintainer
|
2022-06-19 12:56:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Pl_Function::write(unsigned char const* buf, size_t len)
|
|
|
|
{
|
2023-05-21 13:42:34 +00:00
|
|
|
m->fn(buf, len);
|
2022-06-19 12:56:36 +00:00
|
|
|
if (getNext(true)) {
|
|
|
|
getNext()->write(buf, len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Pl_Function::finish()
|
|
|
|
{
|
|
|
|
if (getNext(true)) {
|
|
|
|
getNext()->finish();
|
|
|
|
}
|
|
|
|
}
|