<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML> <HEAD> <TITLE>Pipelines</TITLE> <LINK REL="stylesheet" HREF="../../../../boost.css"> <LINK REL="stylesheet" HREF="../theme/iostreams.css"> </HEAD> <BODY> <!-- Begin Banner --> <H1 CLASS="title">User's Guide</H1> <HR CLASS="banner"> <!-- End Banner --> <!-- Begin Nav --> <DIV CLASS='nav'> <A HREF='lifetimes.html'><IMG BORDER=0 WIDTH=19 HEIGHT=19 SRC='../../../../doc/src/images/prev.png'></A> <A HREF='guide.html'><IMG BORDER=0 WIDTH=19 HEIGHT=19 SRC='../../../../doc/src/images/up.png'></A> <A HREF='views.html'><IMG BORDER=0 WIDTH=19 HEIGHT=19 SRC='../../../../doc/src/images/next.png'></A> </DIV> <!-- End Nav --> <H2>3.8 Pipelines</H2> <DL class="page-index"> <DT><A href="#overview">Overview</A></DT> <DT><A href="#examples">Examples</A></DT> <DT><A href="#headers">Headers</A></DT> <DT><A href="#reference">Reference</A></DT> </DL> <HR STYLE="margin-top:1em"> <A NAME="overview"></A> <H2>Overview</H2> <P> A pipeline is an expression of the form </P> <PRE CLASS="broken_ie">filter<SUB>1</SUB> | ... | filter<SUB>n</SUB> | filter-or-device</PRE> <P> consiting of one or more filters and an optional device, joined using <CODE>operator|</CODE>. Pipelines are a convenient way to pass chains of Filters and Devices to the constructor or <CODE>push</CODE> function of a <A HREF="../classes/filtering_stream.html"><CODE>filtering_stream</CODE></A> or <A HREF="../classes/filtering_streambuf.html"><CODE>filtering_streambuf</CODE></A>. </P> <P> In order for instances of a model of Filter to appear in a pipeline, it must be declared <A HREF="../concepts/pipable.html">Pipable</A> using the macro <A HREF="#boost_iostreams_pipable"><CODE>BOOST_IOSTREAMS_PIPABLE</CODE></A>. </P> <P> Pipelines for C++ filtering were introduced by Jan Christiaan van Winkel and John van Krieken. <I>See</I> <A CLASS="bib_ref" HREF="../bibliography.html#van_winkel">[van Winkel].</A> </P> <A NAME="examples"></A> <H2>Examples</H2> <P>The following example defines a <A HREF="../concepts/pipable.html">Pipable</A> InputFilter.</P> <PRE CLASS="broken_ie"><SPAN CLASS='preprocessor'>#include</SPAN> <A CLASS='header' HREF='../../../../boost/iostreams/concepts.hpp'><SPAN CLASS='literal'><boost/iostreams/concepts.hpp></SPAN></A> <SPAN CLASS='preprocessor'>#include</SPAN> <A CLASS='header' HREF='../../../../boost/iostreams/pipeline.hpp'><SPAN CLASS='literal'><boost/iostreams/pipeline.hpp></SPAN></A> <SPAN CLASS="keyword">namespace</SPAN> io = boost::iostreams; <SPAN CLASS="keyword">class</SPAN> my_filter : <SPAN CLASS="keyword">public</SPAN> io::input_filter { <SPAN CLASS="keyword">public:</SPAN> <SPAN CLASS='omitted'>...</SPAN> <SPAN CLASS="keyword">template</SPAN><<SPAN CLASS="keyword">typename</SPAN> Source> <SPAN CLASS="keyword">int</SPAN> get(Source& src) { <SPAN CLASS='omitted'> ...</SPAN> } }; BOOST_IOSTREAMS_PIPABLE(my_filter, 0) </PRE> <P>No semicolon is required (or allowed) following the macro invocation. The following example shows a <A HREF="../classes/filtering_stream.html"><CODE>filtering_stream</CODE></A> constructed from a pipeline</CODE>.</P> <PRE CLASS="broken_ie"><SPAN CLASS='preprocessor'>#include</SPAN> <A CLASS='header' HREF='../../../../boost/iostreams/filtering_stream.hpp'><SPAN CLASS='literal'><boost/iostreams/filtering_stream.hpp></SPAN></A> <SPAN CLASS='preprocessor'>#include</SPAN> <A CLASS='header' HREF='../../../../boost/iostreams/device/file.hpp'><SPAN CLASS='literal'><boost/iostreams/device/file.hpp></SPAN></A> <SPAN CLASS='preprocessor'>#include</SPAN> <A CLASS='header' HREF='../../../../boost/iostreams/filter/counter.hpp'><SPAN CLASS='literal'><boost/iostreams/filter/counter.hpp></SPAN></A> <SPAN CLASS="keyword">namespace</SPAN> io = boost::iostreams; <SPAN CLASS="keyword">int</SPAN> main() { <SPAN CLASS='comment'>// Write to the file "hello," counting</SPAN> <SPAN CLASS='comment'>// the number of lines and characters</SPAN> io::filtering_ostream out(io::counter() | io::file("hello")); <SPAN CLASS='omitted'>...</SPAN> }</PRE> <A NAME="headers"></A> <H2>Headers</H2> <DL class="page-index"> <DT><A CLASS="header" HREF="../../../../boost/iostreams/pipeline.hpp"><CODE><boost/iostreams/pipeline.hpp></CODE></A></DT> </DL> <A NAME="boost_iostreams_pipable"></A> <A NAME="reference"></A> <H2>Reference</H2> <PRE CLASS="broken_ie"> <SPAN CLASS='preprocessor'>#define</SPAN> BOOST_IOSTREAMS_PIPABLE(filter, arity) <SPAN CLASS='omitted'>...</SPAN> </PRE> <H4>Description</H4> <P>Defines the overloads of <CODE>operator|</CODE> necessary for a <A HREF="../concepts/filter.html">Filter</A> to appear in pipelines.</P> <A NAME="macro_params"></A> <H4>Macro parameters</H4> <TABLE STYLE="margin-left:2em" BORDER=0 CELLPADDING=2> <TR> <TR> <TD VALIGN="top"><I>filter</I></TD><TD WIDTH="2em" VALIGN="top">-</TD> <TD>The name of the <A HREF="../concepts/filter.html">Filter</A> to be declared <A HREF="../concepts/pipable.html">Pipable</A></TD> </TR> <TR> <TD VALIGN="top"><I>arity</I></TD><TD WIDTH="2em" VALIGN="top">-</TD> <TD>The <A HREF="../concepts/filter.html">Filter</A>'s template arity, <I>i.e.</I>, the number or its template parameters; a value of <CODE>0</CODE> indicates that it is not a class template</TD> </TR> </TABLE> <!-- Begin Footer --> <HR STYLE="margin-top:1em"> <P CLASS="copyright">Revised 02 Feb 2008</P> <P CLASS="copyright">© Copyright 2008 <a href="http://www.coderage.com/" target="_top">CodeRage, LLC</a><br/>© Copyright 2004-2007 <a href="http://www.coderage.com/turkanis/" target="_top">Jonathan Turkanis</a></P> <P CLASS="copyright"> Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at <A HREF="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</A>) </P> <!-- End Footer --> </BODY>