From b0f054e600bd07f540ac0a081dd8b5a8cc561617 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Thu, 8 Sep 2022 16:38:36 -0400 Subject: Add ability to initialize Pl_Function with a C-style function --- include/qpdf/Pl_Function.hh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'include') diff --git a/include/qpdf/Pl_Function.hh b/include/qpdf/Pl_Function.hh index dd700e80..41c56a98 100644 --- a/include/qpdf/Pl_Function.hh +++ b/include/qpdf/Pl_Function.hh @@ -31,6 +31,9 @@ // // It is okay to not call finish() on this pipeline if it has no // "next". +// +// It is okay to keep calling write() after a previous write throws an +// exception as long as the delegated function allows it. #include @@ -41,8 +44,26 @@ class QPDF_DLL_CLASS Pl_Function: public Pipeline public: typedef std::function writer_t; + // The supplied function is called every time write is called. QPDF_DLL Pl_Function(char const* identifier, Pipeline* next, writer_t fn); + + // The supplied C-style function is called every time write is + // called. The udata option is passed into the function with each + // call. If the function returns a non-zero value, a runtime error + // is thrown. + typedef int (*writer_c_t)(unsigned char const*, size_t, void*); + QPDF_DLL + Pl_Function( + char const* identifier, Pipeline* next, writer_c_t fn, void* udata); + typedef int (*writer_c_char_t)(char const*, size_t, void*); + QPDF_DLL + Pl_Function( + char const* identifier, + Pipeline* next, + writer_c_char_t fn, + void* udata); + QPDF_DLL virtual ~Pl_Function(); -- cgit v1.2.3-54-g00ecf