pipelines.html 5.9 KB

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