aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2018-02-16 02:45:19 +0100
committerJay Berkenbilt <ejb@ql.org>2018-02-19 03:05:47 +0100
commite410b0fe0d8c1da3e0b0e075b54f247b952389ef (patch)
tree49020a0201961e9e6e0da9b4ab7fa2a498529759 /include
parent1fdd86a04924e4ab9543133b74df3322cffbd358 (diff)
downloadqpdf-e410b0fe0d8c1da3e0b0e075b54f247b952389ef.tar.zst
Simplify TokenFilter interface
Expose Pl_QPDFTokenizer, and have it do more of the work of managing the token filter's pipeline.
Diffstat (limited to 'include')
-rw-r--r--include/qpdf/Pl_QPDFTokenizer.hh6
-rw-r--r--include/qpdf/QPDFObjectHandle.hh36
2 files changed, 22 insertions, 20 deletions
diff --git a/include/qpdf/Pl_QPDFTokenizer.hh b/include/qpdf/Pl_QPDFTokenizer.hh
index be34b32e..65dc7919 100644
--- a/include/qpdf/Pl_QPDFTokenizer.hh
+++ b/include/qpdf/Pl_QPDFTokenizer.hh
@@ -41,8 +41,12 @@
class Pl_QPDFTokenizer: public Pipeline
{
public:
+ // Whatever pipeline is provided as "next" will be set as the
+ // pipeline that the token filter writes to. If next is not
+ // provided, any output written by the filter will be discarded.
Pl_QPDFTokenizer(char const* identifier,
- QPDFObjectHandle::TokenFilter* filter);
+ QPDFObjectHandle::TokenFilter* filter,
+ Pipeline* next = 0);
virtual ~Pl_QPDFTokenizer();
virtual void write(unsigned char* buf, size_t len);
virtual void finish();
diff --git a/include/qpdf/QPDFObjectHandle.hh b/include/qpdf/QPDFObjectHandle.hh
index 1f0d550a..81195a95 100644
--- a/include/qpdf/QPDFObjectHandle.hh
+++ b/include/qpdf/QPDFObjectHandle.hh
@@ -45,6 +45,7 @@ class QPDF_Dictionary;
class QPDF_Array;
class QPDFTokenizer;
class QPDFExc;
+class Pl_QPDFTokenizer;
class QPDFObjectHandle
{
@@ -81,18 +82,13 @@ class QPDFObjectHandle
// in a lexically aware fashion. TokenFilters can be attached to
// streams using the addTokenFilter or addContentTokenFilter
// methods or can be applied on the spot by filterPageContents.
+ // You may also use Pl_QPDFTokenizer directly if you need full
+ // control.
+ //
// The handleToken method is called for each token, including the
// eof token, and then handleEOF is called at the very end.
// Handlers may call write (or writeToken) to pass data
- // downstream. The finish() method must be called exactly one time
- // to ensure that any written data is flushed out. The default
- // handleEOF calls finish. If you override handleEOF, you must
- // ensure that finish() is called either there or in response to
- // whatever event causes you to terminate creation of output.
- // Failure to call finish() may result in some of the data you
- // have written being lost. You should not rely on a destructor
- // for calling finish() since the destructor call may occur later
- // than you expect. Please see examples/pdf-filter-tokens.cc and
+ // downstream. Please see examples/pdf-filter-tokens.cc and
// examples/pdf-count-strings.cc for examples of using
// TokenFilters.
//
@@ -115,15 +111,17 @@ class QPDFObjectHandle
{
}
virtual void handleToken(QPDFTokenizer::Token const&) = 0;
- virtual void handleEOF()
- {
- // If you override handleEOF, you must be sure to call
- // finish().
- finish();
- }
+ virtual void handleEOF();
- // This is called internally by the qpdf library.
- void setPipeline(Pipeline*);
+ class PipelineAccessor
+ {
+ friend class Pl_QPDFTokenizer;
+ private:
+ static void setPipeline(TokenFilter* f, Pipeline* p)
+ {
+ f->setPipeline(p);
+ }
+ };
protected:
QPDF_DLL
@@ -132,10 +130,10 @@ class QPDFObjectHandle
void write(std::string const& str);
QPDF_DLL
void writeToken(QPDFTokenizer::Token const&);
- QPDF_DLL
- void finish();
private:
+ void setPipeline(Pipeline*);
+
Pipeline* pipeline;
};