2023-02-25 19:18:13 +00:00
|
|
|
// Copyright (c) 2005-2023 Jay Berkenbilt
|
2008-04-29 12:55:25 +00:00
|
|
|
//
|
2017-09-14 16:44:31 +00:00
|
|
|
// This file is part of qpdf.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
|
|
|
// in compliance with the License. You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
|
|
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
|
|
// or implied. See the License for the specific language governing permissions and limitations under
|
|
|
|
// the License.
|
|
|
|
//
|
|
|
|
// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic
|
|
|
|
// License. At your option, you may continue to consider qpdf to be licensed under those terms.
|
|
|
|
// Please see the manual for additional information.
|
2008-04-29 12:55:25 +00:00
|
|
|
|
|
|
|
// Generalized Pipeline interface. By convention, subclasses of Pipeline are called Pl_Something.
|
|
|
|
//
|
|
|
|
// When an instance of Pipeline is created with a pointer to a next pipeline, that pipeline writes
|
|
|
|
// its data to the next one when it finishes with it. In order to make possible a usage style in
|
|
|
|
// which a pipeline may be passed to a function which may stick other pipelines in front of it, the
|
|
|
|
// allocator of a pipeline is responsible for its destruction. In other words, one pipeline object
|
|
|
|
// does not attempt to manage the memory of its successor.
|
|
|
|
//
|
|
|
|
// The client is required to call finish() before destroying a Pipeline in order to avoid loss of
|
|
|
|
// data. A Pipeline class should not throw an exception in the destructor if this hasn't been done
|
2009-02-21 02:54:31 +00:00
|
|
|
// though since doing so causes too much trouble when deleting
|
2008-04-29 12:55:25 +00:00
|
|
|
// pipelines during error conditions.
|
|
|
|
//
|
2009-02-21 02:54:31 +00:00
|
|
|
// Some pipelines are reusable (i.e., you can call write() after calling finish() and can call
|
2008-04-29 12:55:25 +00:00
|
|
|
// finish() multiple times) while others are not. It is up to the caller to use a pipeline
|
|
|
|
// according to its own restrictions.
|
|
|
|
|
2018-08-12 18:07:22 +00:00
|
|
|
#ifndef PIPELINE_HH
|
|
|
|
#define PIPELINE_HH
|
2008-04-29 12:55:25 +00:00
|
|
|
|
2009-10-19 20:17:14 +00:00
|
|
|
#include <qpdf/DLL.h>
|
2022-09-23 19:15:39 +00:00
|
|
|
#include <qpdf/PointerHolder.hh> // unused -- remove in qpdf 12 (see #785)
|
2022-02-06 16:40:24 +00:00
|
|
|
|
|
|
|
#include <memory>
|
2009-09-26 18:36:04 +00:00
|
|
|
#include <string>
|
2008-04-29 12:55:25 +00:00
|
|
|
|
2022-04-10 13:29:11 +00:00
|
|
|
// Remember to use QPDF_DLL_CLASS on anything derived from Pipeline so it will work with
|
|
|
|
// dynamic_cast across the shared object boundary.
|
2019-06-22 00:27:31 +00:00
|
|
|
class QPDF_DLL_CLASS Pipeline
|
2008-04-29 12:55:25 +00:00
|
|
|
{
|
|
|
|
public:
|
2009-10-21 01:45:13 +00:00
|
|
|
QPDF_DLL
|
2008-04-29 12:55:25 +00:00
|
|
|
Pipeline(char const* identifier, Pipeline* next);
|
|
|
|
|
2009-10-21 01:45:13 +00:00
|
|
|
QPDF_DLL
|
2022-04-15 23:44:07 +00:00
|
|
|
virtual ~Pipeline() = default;
|
2008-04-29 12:55:25 +00:00
|
|
|
|
|
|
|
// Subclasses should implement write and finish to do their jobs and then, if they are not
|
2022-05-03 21:43:07 +00:00
|
|
|
// end-of-line pipelines, call getNext()->write or getNext()->finish.
|
2009-10-21 01:45:13 +00:00
|
|
|
QPDF_DLL
|
2022-05-03 21:43:07 +00:00
|
|
|
virtual void write(unsigned char const* data, size_t len) = 0;
|
2009-10-21 01:45:13 +00:00
|
|
|
QPDF_DLL
|
2008-04-29 12:55:25 +00:00
|
|
|
virtual void finish() = 0;
|
2019-08-28 02:10:11 +00:00
|
|
|
QPDF_DLL
|
|
|
|
std::string getIdentifier() const;
|
2008-04-29 12:55:25 +00:00
|
|
|
|
2022-05-03 21:58:58 +00:00
|
|
|
// These are convenience methods for making it easier to write certain other types of data to
|
|
|
|
// pipelines without having to cast. The methods that take char const* expect null-terminated C
|
|
|
|
// strings and do not write the null terminators.
|
|
|
|
QPDF_DLL
|
|
|
|
void writeCStr(char const* cstr);
|
|
|
|
QPDF_DLL
|
|
|
|
void writeString(std::string const&);
|
|
|
|
// This allows *p << "x" << "y" but is not intended to be a general purpose << compatible with
|
|
|
|
// ostream and does not have local awareness or the ability to be "imbued" with properties.
|
|
|
|
QPDF_DLL
|
|
|
|
Pipeline& operator<<(char const* cstr);
|
|
|
|
QPDF_DLL
|
|
|
|
Pipeline& operator<<(std::string const&);
|
2022-06-05 16:33:36 +00:00
|
|
|
QPDF_DLL
|
|
|
|
Pipeline& operator<<(short);
|
|
|
|
QPDF_DLL
|
|
|
|
Pipeline& operator<<(int);
|
|
|
|
QPDF_DLL
|
|
|
|
Pipeline& operator<<(long);
|
|
|
|
QPDF_DLL
|
|
|
|
Pipeline& operator<<(long long);
|
|
|
|
QPDF_DLL
|
|
|
|
Pipeline& operator<<(unsigned short);
|
|
|
|
QPDF_DLL
|
|
|
|
Pipeline& operator<<(unsigned int);
|
|
|
|
QPDF_DLL
|
|
|
|
Pipeline& operator<<(unsigned long);
|
|
|
|
QPDF_DLL
|
|
|
|
Pipeline& operator<<(unsigned long long);
|
2022-05-03 21:58:58 +00:00
|
|
|
|
|
|
|
// Overloaded write to reduce casting
|
|
|
|
QPDF_DLL
|
|
|
|
void write(char const* data, size_t len);
|
|
|
|
|
2008-04-29 12:55:25 +00:00
|
|
|
protected:
|
2020-12-28 18:02:58 +00:00
|
|
|
QPDF_DLL
|
2008-04-29 12:55:25 +00:00
|
|
|
Pipeline* getNext(bool allow_null = false);
|
|
|
|
std::string identifier;
|
|
|
|
|
|
|
|
private:
|
2020-04-03 15:59:29 +00:00
|
|
|
Pipeline(Pipeline const&) = delete;
|
|
|
|
Pipeline& operator=(Pipeline const&) = delete;
|
2008-04-29 12:55:25 +00:00
|
|
|
|
2020-04-03 15:59:29 +00:00
|
|
|
Pipeline* next;
|
2008-04-29 12:55:25 +00:00
|
|
|
};
|
|
|
|
|
2018-08-12 18:07:22 +00:00
|
|
|
#endif // PIPELINE_HH
|