aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/Pl_Function.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-06-19 14:56:36 +0200
committerJay Berkenbilt <ejb@ql.org>2022-06-19 15:12:29 +0200
commiteae75dbe448b0395aee7e49c2a9cca9f82680782 (patch)
treeea5a9edfbd52ca5c381e5f97f79e46693d4b2beb /libqpdf/Pl_Function.cc
parentbb0ea2f8e7d8fffa575b291004e4426138c7bb1a (diff)
downloadqpdf-eae75dbe448b0395aee7e49c2a9cca9f82680782.tar.zst
Add Pl_Function -- a generic function pipeline
Diffstat (limited to 'libqpdf/Pl_Function.cc')
-rw-r--r--libqpdf/Pl_Function.cc39
1 files changed, 39 insertions, 0 deletions
diff --git a/libqpdf/Pl_Function.cc b/libqpdf/Pl_Function.cc
new file mode 100644
index 00000000..32fcccf1
--- /dev/null
+++ b/libqpdf/Pl_Function.cc
@@ -0,0 +1,39 @@
+#include <qpdf/Pl_Function.hh>
+
+#include <qpdf/QUtil.hh>
+#include <errno.h>
+#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))
+{
+}
+
+Pl_Function::~Pl_Function()
+{
+ // Must be explicit and not inline -- see QPDF_DLL_CLASS in
+ // README-maintainer
+}
+
+void
+Pl_Function::write(unsigned char const* buf, size_t len)
+{
+ this->m->fn(buf, len);
+ if (getNext(true)) {
+ getNext()->write(buf, len);
+ }
+}
+
+void
+Pl_Function::finish()
+{
+ if (getNext(true)) {
+ getNext()->finish();
+ }
+}