A pipeline is an expression of the form
filter1 | ... | filtern | filter-or-device
consiting of one or more filters and an optional device, joined using operator|
. Pipelines are a convenient way to pass chains of Filters and Devices to the constructor or push
function of a filtering_stream
or filtering_streambuf
.
In order for instances of a model of Filter to appear in a pipeline, it must be declared Pipable using the macro BOOST_IOSTREAMS_PIPABLE
.
Pipelines for C++ filtering were introduced by Jan Christiaan van Winkel and John van Krieken. See [van Winkel].
The following example defines a Pipable InputFilter.
#include <boost/iostreams/concepts.hpp> #include <boost/iostreams/pipeline.hpp> namespace io = boost::iostreams; class my_filter : public io::input_filter { public: ... template<typename Source> int get(Source& src) { ... } }; BOOST_IOSTREAMS_PIPABLE(my_filter, 0)
No semicolon is required (or allowed) following the macro invocation. The following example shows a filtering_stream
constructed from a pipeline.
#include <boost/iostreams/filtering_stream.hpp> #include <boost/iostreams/device/file.hpp> #include <boost/iostreams/filter/counter.hpp> namespace io = boost::iostreams; int main() { // Write to the file "hello," counting // the number of lines and characters io::filtering_ostream out(io::counter() | io::file("hello")); ... }
<boost/iostreams/pipeline.hpp>
#define BOOST_IOSTREAMS_PIPABLE(filter, arity) ...
Defines the overloads of operator|
necessary for a Filter to appear in pipelines.
filter | - | The name of the Filter to be declared Pipable |
arity | - | The Filter's template arity, i.e., the number or its template parameters; a value of 0 indicates that it is not a class template |
© Copyright 2008 CodeRage, LLC
© Copyright 2004-2007 Jonathan Turkanis
Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)