line_filter.html 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <HTML>
  3. <HEAD>
  4. <TITLE>Class Template basic_line_filter</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">Class Template <CODE>basic_line_filter</CODE></H1>
  11. <HR CLASS="banner">
  12. <!-- End Banner -->
  13. <DL class="page-index">
  14. <DT><A href="#description">Description</A></DT>
  15. <DT><A href="#headers">Headers</A></DT>
  16. <DT><A href="#reference">Reference</A></DT>
  17. <DT><A href="#example">Example</A></DT>
  18. </DL>
  19. <HR>
  20. <A NAME="description"></A>
  21. <H2>Description</H2>
  22. <P>
  23. The class template <CODE>basic_line_filter</CODE> is a <A HREF='../concepts/dual_use_filter.html'>DualUseFilter</A> for use as a base class by Filters which filter a character sequence one line at a time. Derived classes override the <CODE>private</CODE> <CODE>virtual</CODE> function <CODE>do_filter</CODE>, which takes a line of unfiltered text as argument returns the result of filtering the line.
  24. </P>
  25. <A NAME="headers"></A>
  26. <H2>Headers</H2>
  27. <DL class="page-index">
  28. <DT><A CLASS="header" HREF="../../../../boost/iostreams/filter/line.hpp"><CODE>&lt;boost/iostreams/filter/line.hpp&gt;</CODE></A></DT>
  29. </DL>
  30. <A NAME="reference"></A>
  31. <H2>Reference</H2>
  32. <H4>Synopsis</H4>
  33. <PRE CLASS="broken_ie"><SPAN CLASS="keyword">namespace</SPAN> boost { <SPAN CLASS="keyword">namespace</SPAN> iostreams {
  34. <SPAN CLASS='keyword'>template</SPAN>&lt;<SPAN CLASS='keyword'>typename</SPAN> <A CLASS='documented' HREF='#template_params'>Ch</A>, <SPAN CLASS='keyword'>typename</SPAN> <A CLASS='documented' HREF='#template_params'>Alloc</A> = std::allocator&lt;Ch&gt; &gt;
  35. <SPAN CLASS='keyword'>class</SPAN> <A CLASS='documented' HREF='#template_params'>basic_line_filter</A> {
  36. <SPAN CLASS='keyword'>public:</SPAN>
  37. <SPAN CLASS='keyword'>typedef</SPAN> Ch char_type;
  38. <SPAN CLASS='keyword'>typedef</SPAN> std::basic_string&lt;
  39. Ch,
  40. std::char_traits&lt;char_type&gt;,
  41. Alloc
  42. &gt; string_type;
  43. <SPAN CLASS='keyword'>typedef</SPAN> <SPAN CLASS='omitted'>[implementation-defined]</SPAN> category;
  44. <SPAN CLASS='keyword'>protected:</SPAN>
  45. basic_line_filter();
  46. <SPAN CLASS='keyword'>public:</SPAN>
  47. <SPAN CLASS='keyword'>virtual</SPAN> ~basic_line_filter();
  48. <SPAN CLASS='keyword'>private:</SPAN>
  49. <SPAN CLASS='keyword'>virtual</SPAN> string_type <A CLASS='documented' HREF='#do_filter'>do_filter</A>(<SPAN CLASS='keyword'>const</SPAN> string_type&amp; line) <SPAN CLASS='numeric_literal'>= 0</SPAN>;
  50. };
  51. <SPAN CLASS='keyword'>typedef</SPAN> basic_line_filter&lt;<SPAN CLASS='keyword'>char</SPAN>&gt; <SPAN CLASS='defined'>line_filter</SPAN>;
  52. <SPAN CLASS='keyword'>typedef</SPAN> basic_line_filter&lt;<SPAN CLASS='keyword'>wchar_t</SPAN>&gt; <SPAN CLASS='defined'>wline_filter</SPAN>;
  53. } } <SPAN CLASS="comment">// End namespace boost::io</SPAN></PRE>
  54. <A NAME="template_params"></A>
  55. <H4>Template parameters</H4>
  56. <TABLE STYLE="margin-left:2em" BORDER=0 CELLPADDING=2>
  57. <TR>
  58. <TR>
  59. <TD VALIGN="top"><I>Ch</I></TD><TD WIDTH="2em" VALIGN="top">-</TD>
  60. <TD>The <A HREF='../guide/traits.html#char_type'>character type</A></TD>
  61. </TR>
  62. <TR>
  63. <TD VALIGN="top"><I>Alloc</I></TD><TD WIDTH="2em" VALIGN="top">-</TD>
  64. <TD>A standard library allocator type (<A CLASS="bib_ref" HREF="../bibliography.html#iso">[ISO]</A>, 20.1.5), used to allocate a character buffer</TD>
  65. </TR>
  66. </TABLE>
  67. <A NAME="do_filter"></A>
  68. <H4><CODE>line_filter::do_filter</CODE></H4>
  69. <PRE CLASS="broken_ie"> <SPAN CLASS='keyword'>virtual</SPAN> string_type do_filter(<SPAN CLASS='keyword'>const</SPAN> string_type&amp; line) <SPAN CLASS='numeric_literal'>= 0</SPAN>;</PRE>
  70. <P>The argument <CODE>line</CODE> represents a single line of unfiltered text, not including any terminal newline character. Returns the result of filtering <CODE>line</CODE>.</P>
  71. <A NAME="example"></A>
  72. <H2>Example</H2>
  73. <P>The following example shows a <CODE>line_filter</CODE> which counts the number of lines which exceed a given length.</P>
  74. <PRE CLASS="broken_ie"><SPAN CLASS='preprocessor'>#include</SPAN> <A CLASS='header' HREF='../../../../boost/iostreams/filter/line.hpp'><SPAN CLASS='literal'>&lt;boost/iostreams/filter/line.hpp&gt;</SPAN></A>
  75. <SPAN CLASS='keyword'>namespace</SPAN> io = boost::iostreams;
  76. <SPAN CLASS='keyword'>class</SPAN> long_line_counter : <SPAN CLASS='keyword'>public</SPAN> io::line_filter {
  77. <SPAN CLASS='keyword'>public</SPAN>
  78. <SPAN CLASS="keyword">explicit</SPAN> long_line_counter(<SPAN CLASS='keyword'>int</SPAN> max_length = <SPAN CLASS='numeric_literal'>80</SPAN>)
  79. : max_(max_length), count_(<SPAN CLASS='numeric_literal'>0</SPAN>)
  80. { }
  81. <SPAN CLASS='keyword'>int</SPAN> count() <SPAN CLASS='keyword'>const</SPAN> { <SPAN CLASS='keyword'>return</SPAN> count_; }
  82. <SPAN CLASS='keyword'>private:</SPAN>
  83. std::string do_filter(<SPAN CLASS='keyword'>const</SPAN> std::string&amp; line)
  84. {
  85. <SPAN CLASS='keyword'>if</SPAN> (line.size() &gt; max_)
  86. ++count_;
  87. }
  88. <SPAN CLASS='keyword'>int</SPAN> max_;
  89. <SPAN CLASS='keyword'>int</SPAN> count_;
  90. };</PRE>
  91. <!-- Begin Footer -->
  92. <HR>
  93. <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>
  94. <P CLASS="copyright">
  95. 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>)
  96. </P>
  97. <!-- End Footer -->
  98. </BODY>