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/html/images/prev.png'></A> |
---|
21 | <A HREF='guide.html'><IMG BORDER=0 WIDTH=19 HEIGHT=19 SRC='../../../../doc/html/images/up.png'></A> |
---|
22 | <A HREF='views.html'><IMG BORDER=0 WIDTH=19 HEIGHT=19 SRC='../../../../doc/html/images/next.png'></A> |
---|
23 | </DIV> |
---|
24 | |
---|
25 | <!-- End Nav --> |
---|
26 | |
---|
27 | <A NAME="overview"></A> |
---|
28 | <H2>3.8 Pipelines</H2> |
---|
29 | |
---|
30 | <DL class="page-index"> |
---|
31 | <DT><A href="#overview">Overview</A></DT> |
---|
32 | <DT><A href="#examples">Examples</A></DT> |
---|
33 | <DT><A href="#headers">Headers</A></DT> |
---|
34 | <DT><A href="#reference">Reference</A></DT> |
---|
35 | </DL> |
---|
36 | |
---|
37 | <HR STYLE="margin-top:1em"> |
---|
38 | |
---|
39 | <A NAME="overview"></A> |
---|
40 | <H2>Overview</H2> |
---|
41 | |
---|
42 | <P> |
---|
43 | A pipeline is an expression of the form |
---|
44 | </P> |
---|
45 | <PRE CLASS="broken_ie">filter<SUB>1</SUB> | ... | filter<SUB>n</SUB> | filter-or-device</PRE> |
---|
46 | <P> |
---|
47 | 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>. |
---|
48 | </P> |
---|
49 | |
---|
50 | <P> |
---|
51 | 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>. |
---|
52 | </P> |
---|
53 | |
---|
54 | <P> |
---|
55 | 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> |
---|
56 | </P> |
---|
57 | |
---|
58 | <A NAME="examples"></A> |
---|
59 | <H2>Examples</H2> |
---|
60 | |
---|
61 | <P>The following example defines a <A HREF="../concepts/pipable.html">Pipable</A> InputFilter.</P> |
---|
62 | |
---|
63 | <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> |
---|
64 | <SPAN CLASS='preprocessor'>#include</SPAN> <A CLASS='header' HREF='../../../../boost/iostreams/pipeline.hpp'><SPAN CLASS='literal'><boost/iostreams/pipeline.hpp></SPAN></A> |
---|
65 | |
---|
66 | <SPAN CLASS="keyword">namespace</SPAN> io = boost::iostreams; |
---|
67 | |
---|
68 | <SPAN CLASS="keyword">class</SPAN> my_filter : <SPAN CLASS="keyword">public</SPAN> io::input_filter { |
---|
69 | <SPAN CLASS="keyword">public:</SPAN> |
---|
70 | <SPAN CLASS='omitted'>...</SPAN> |
---|
71 | <SPAN CLASS="keyword">template</SPAN><<SPAN CLASS="keyword">typename</SPAN> Source> |
---|
72 | <SPAN CLASS="keyword">int</SPAN> get(Source& src) |
---|
73 | { |
---|
74 | <SPAN CLASS='omitted'> ...</SPAN> |
---|
75 | } |
---|
76 | }; |
---|
77 | BOOST_IOSTREAMS_PIPABLE(my_filter, 0) |
---|
78 | </PRE> |
---|
79 | |
---|
80 | <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> |
---|
81 | |
---|
82 | <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> |
---|
83 | <SPAN CLASS='preprocessor'>#include</SPAN> <A CLASS='header' HREF='../../../../boost/iostreams/device/file.hpp'><SPAN CLASS='literal'><boost/iostreams/device/file.hpp></SPAN></A> |
---|
84 | <SPAN CLASS='preprocessor'>#include</SPAN> <A CLASS='header' HREF='../../../../boost/iostreams/filter/counter.hpp'><SPAN CLASS='literal'><boost/iostreams/filter/counter.hpp></SPAN></A> |
---|
85 | |
---|
86 | <SPAN CLASS="keyword">namespace</SPAN> io = boost::iostreams; |
---|
87 | |
---|
88 | <SPAN CLASS="keyword">int</SPAN> main() |
---|
89 | { |
---|
90 | <SPAN CLASS='comment'>// Write to the file "hello," counting</SPAN> |
---|
91 | <SPAN CLASS='comment'>// the number of lines and characters</SPAN> |
---|
92 | io::filtering_ostream out(io::counter() | io::file("hello")); |
---|
93 | <SPAN CLASS='omitted'>...</SPAN> |
---|
94 | }</PRE> |
---|
95 | |
---|
96 | <A NAME="headers"></A> |
---|
97 | <H2>Headers</H2> |
---|
98 | |
---|
99 | <DL class="page-index"> |
---|
100 | <DT><A CLASS="header" HREF="../../../../boost/iostreams/pipeline.hpp"><CODE><boost/iostreams/pipeline.hpp></CODE></A></DT> |
---|
101 | </DL> |
---|
102 | |
---|
103 | <A NAME="boost_iostreams_pipable"></A> |
---|
104 | <A NAME="reference"></A> |
---|
105 | <H2>Reference</H2> |
---|
106 | |
---|
107 | <PRE CLASS="broken_ie"> |
---|
108 | |
---|
109 | <SPAN CLASS='preprocessor'>#define</SPAN> BOOST_IOSTREAMS_PIPABLE(filter, arity) <SPAN CLASS='omitted'>...</SPAN> |
---|
110 | |
---|
111 | </PRE> |
---|
112 | |
---|
113 | <H4>Description</H4> |
---|
114 | |
---|
115 | <P>Defines the overloads of <CODE>operator|</CODE> necessary for a <A HREF="../concepts/filter.html">Filter</A> to appear in pipelines.</P> |
---|
116 | |
---|
117 | <A NAME="macro_params"></A> |
---|
118 | <H4>Macro parameters</H4> |
---|
119 | |
---|
120 | <TABLE STYLE="margin-left:2em" BORDER=0 CELLPADDING=2> |
---|
121 | <TR> |
---|
122 | <TR> |
---|
123 | <TD VALIGN="top"><I>filter</I></TD><TD WIDTH="2em" VALIGN="top">-</TD> |
---|
124 | <TD>The name of the <A HREF="../concepts/filter.html">Filter</A> to be declared <A HREF="../concepts/pipable.html">Pipable</A></TD> |
---|
125 | </TR> |
---|
126 | <TR> |
---|
127 | <TD VALIGN="top"><I>arity</I></TD><TD WIDTH="2em" VALIGN="top">-</TD> |
---|
128 | <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> |
---|
129 | </TR> |
---|
130 | </TABLE> |
---|
131 | |
---|
132 | <!-- Begin Footer --> |
---|
133 | |
---|
134 | <HR STYLE="margin-top:1em"> |
---|
135 | <P CLASS="copyright">Revised |
---|
136 | <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan --> |
---|
137 | 20 May, 2004 |
---|
138 | <!--webbot bot="Timestamp" endspan i-checksum="38504" --> |
---|
139 | </P> |
---|
140 | |
---|
141 | <P CLASS="copyright">© Copyright <A HREF="http://www.kangaroologic.com" TARGET="_top">Jonathan Turkanis</A>, 2004</P> |
---|
142 | <P CLASS="copyright"> |
---|
143 | 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>) |
---|
144 | </P> |
---|
145 | |
---|
146 | <!-- End Footer --> |
---|
147 | |
---|
148 | </BODY> |
---|