1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 2<HTML> 3<HEAD> 4 <TITLE>Pipelines</TITLE> 5 <LINK REL="stylesheet" HREF="../../../../boost.css"> 6 <LINK REL="stylesheet" HREF="../theme/iostreams.css"> 7</HEAD> 8<BODY> 9 10<!-- Begin Banner --> 11 12 <H1 CLASS="title">User's Guide</H1> 13 <HR CLASS="banner"> 14 15<!-- End Banner --> 16 17<!-- Begin Nav --> 18 19<DIV CLASS='nav'> 20 <A HREF='lifetimes.html'><IMG BORDER=0 WIDTH=19 HEIGHT=19 SRC='../../../../doc/src/images/prev.png'></A> 21 <A HREF='guide.html'><IMG BORDER=0 WIDTH=19 HEIGHT=19 SRC='../../../../doc/src/images/up.png'></A> 22 <A HREF='views.html'><IMG BORDER=0 WIDTH=19 HEIGHT=19 SRC='../../../../doc/src/images/next.png'></A> 23</DIV> 24 25<!-- End Nav --> 26 27<H2>3.8 Pipelines</H2> 28 29<DL class="page-index"> 30 <DT><A href="#overview">Overview</A></DT> 31 <DT><A href="#examples">Examples</A></DT> 32 <DT><A href="#headers">Headers</A></DT> 33 <DT><A href="#reference">Reference</A></DT> 34</DL> 35 36<HR STYLE="margin-top:1em"> 37 38<A NAME="overview"></A> 39<H2>Overview</H2> 40 41<P> 42 A pipeline is an expression of the form 43</P> 44<PRE CLASS="broken_ie">filter<SUB>1</SUB> | ... | filter<SUB>n</SUB> | filter-or-device</PRE> 45<P> 46consiting 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>. 47</P> 48 49<P> 50 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>. 51</P> 52 53<P> 54 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> 55</P> 56 57<A NAME="examples"></A> 58<H2>Examples</H2> 59 60<P>The following example defines a <A HREF="../concepts/pipable.html">Pipable</A> InputFilter.</P> 61 62<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> 63<SPAN CLASS='preprocessor'>#include</SPAN> <A CLASS='header' HREF='../../../../boost/iostreams/pipeline.hpp'><SPAN CLASS='literal'><boost/iostreams/pipeline.hpp></SPAN></A> 64 65<SPAN CLASS="keyword">namespace</SPAN> io = boost::iostreams; 66 67<SPAN CLASS="keyword">class</SPAN> my_filter : <SPAN CLASS="keyword">public</SPAN> io::input_filter { 68<SPAN CLASS="keyword">public:</SPAN> 69 <SPAN CLASS='omitted'>...</SPAN> 70 <SPAN CLASS="keyword">template</SPAN><<SPAN CLASS="keyword">typename</SPAN> Source> 71 <SPAN CLASS="keyword">int</SPAN> get(Source& src) 72 { 73 <SPAN CLASS='omitted'> ...</SPAN> 74 } 75}; 76BOOST_IOSTREAMS_PIPABLE(my_filter, 0) 77</PRE> 78 79<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> 80 81<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> 82<SPAN CLASS='preprocessor'>#include</SPAN> <A CLASS='header' HREF='../../../../boost/iostreams/device/file.hpp'><SPAN CLASS='literal'><boost/iostreams/device/file.hpp></SPAN></A> 83<SPAN CLASS='preprocessor'>#include</SPAN> <A CLASS='header' HREF='../../../../boost/iostreams/filter/counter.hpp'><SPAN CLASS='literal'><boost/iostreams/filter/counter.hpp></SPAN></A> 84 85<SPAN CLASS="keyword">namespace</SPAN> io = boost::iostreams; 86 87<SPAN CLASS="keyword">int</SPAN> main() 88{ 89 <SPAN CLASS='comment'>// Write to the file "hello," counting</SPAN> 90 <SPAN CLASS='comment'>// the number of lines and characters</SPAN> 91 io::filtering_ostream out(io::counter() | io::file("hello")); 92 <SPAN CLASS='omitted'>...</SPAN> 93}</PRE> 94 95<A NAME="headers"></A> 96<H2>Headers</H2> 97 98<DL class="page-index"> 99 <DT><A CLASS="header" HREF="../../../../boost/iostreams/pipeline.hpp"><CODE><boost/iostreams/pipeline.hpp></CODE></A></DT> 100</DL> 101 102<A NAME="boost_iostreams_pipable"></A> 103<A NAME="reference"></A> 104<H2>Reference</H2> 105 106<PRE CLASS="broken_ie"> 107 108<SPAN CLASS='preprocessor'>#define</SPAN> BOOST_IOSTREAMS_PIPABLE(filter, arity) <SPAN CLASS='omitted'>...</SPAN> 109 110</PRE> 111 112<H4>Description</H4> 113 114<P>Defines the overloads of <CODE>operator|</CODE> necessary for a <A HREF="../concepts/filter.html">Filter</A> to appear in pipelines.</P> 115 116<A NAME="macro_params"></A> 117<H4>Macro parameters</H4> 118 119<TABLE STYLE="margin-left:2em" BORDER=0 CELLPADDING=2> 120<TR> 121 <TR> 122 <TD VALIGN="top"><I>filter</I></TD><TD WIDTH="2em" VALIGN="top">-</TD> 123 <TD>The name of the <A HREF="../concepts/filter.html">Filter</A> to be declared <A HREF="../concepts/pipable.html">Pipable</A></TD> 124 </TR> 125 <TR> 126 <TD VALIGN="top"><I>arity</I></TD><TD WIDTH="2em" VALIGN="top">-</TD> 127 <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> 128 </TR> 129</TABLE> 130 131<!-- Begin Footer --> 132 133<HR STYLE="margin-top:1em"> 134 135<P CLASS="copyright">© Copyright 2008 <a href="http://www.coderage.com/" target="_top">CodeRage, LLC</a><br/>© Copyright 2004-2007 <a href="https://www.boost.org/users/people/jonathan_turkanis.html" target="_top">Jonathan Turkanis</a></P> 136<P CLASS="copyright"> 137 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>) 138</P> 139 140<!-- End Footer --> 141 142</BODY>