| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| <HTML> |
| <HEAD> |
| <TITLE>Class Template basic_line_filter</TITLE> |
| <LINK REL="stylesheet" HREF="../../../../boost.css"> |
| <LINK REL="stylesheet" HREF="../theme/iostreams.css"> |
| </HEAD> |
| <BODY> |
| |
| <!-- Begin Banner --> |
| |
| <H1 CLASS="title">Class Template <CODE>basic_line_filter</CODE></H1> |
| <HR CLASS="banner"> |
| |
| <!-- End Banner --> |
| |
| <DL class="page-index"> |
| <DT><A href="#description">Description</A></DT> |
| <DT><A href="#headers">Headers</A></DT> |
| <DT><A href="#reference">Reference</A></DT> |
| <DT><A href="#example">Example</A></DT> |
| </DL> |
| |
| <HR> |
| |
| <A NAME="description"></A> |
| <H2>Description</H2> |
| |
| <P> |
| 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. |
| </P> |
| |
| <A NAME="headers"></A> |
| <H2>Headers</H2> |
| |
| <DL class="page-index"> |
| <DT><A CLASS="header" HREF="../../../../boost/iostreams/filter/line.hpp"><CODE><boost/iostreams/filter/line.hpp></CODE></A></DT> |
| </DL> |
| |
| <A NAME="reference"></A> |
| <H2>Reference</H2> |
| |
| <H4>Synopsis</H4> |
| |
| <PRE CLASS="broken_ie"><SPAN CLASS="keyword">namespace</SPAN> boost { <SPAN CLASS="keyword">namespace</SPAN> iostreams { |
| |
| <SPAN CLASS='keyword'>template</SPAN><<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<Ch> > |
| <SPAN CLASS='keyword'>class</SPAN> <A CLASS='documented' HREF='#template_params'>basic_line_filter</A> { |
| <SPAN CLASS='keyword'>public:</SPAN> |
| <SPAN CLASS='keyword'>typedef</SPAN> Ch char_type; |
| <SPAN CLASS='keyword'>typedef</SPAN> std::basic_string< |
| Ch, |
| std::char_traits<char_type>, |
| Alloc |
| > string_type; |
| <SPAN CLASS='keyword'>typedef</SPAN> <SPAN CLASS='omitted'>[implementation-defined]</SPAN> category; |
| <SPAN CLASS='keyword'>protected:</SPAN> |
| basic_line_filter(); |
| <SPAN CLASS='keyword'>public:</SPAN> |
| <SPAN CLASS='keyword'>virtual</SPAN> ~basic_line_filter(); |
| <SPAN CLASS='keyword'>private:</SPAN> |
| <SPAN CLASS='keyword'>virtual</SPAN> string_type <A CLASS='documented' HREF='#do_filter'>do_filter</A>(<SPAN CLASS='keyword'>const</SPAN> string_type& line) <SPAN CLASS='numeric_literal'>= 0</SPAN>; |
| }; |
| |
| <SPAN CLASS='keyword'>typedef</SPAN> basic_line_filter<<SPAN CLASS='keyword'>char</SPAN>> <SPAN CLASS='defined'>line_filter</SPAN>; |
| <SPAN CLASS='keyword'>typedef</SPAN> basic_line_filter<<SPAN CLASS='keyword'>wchar_t</SPAN>> <SPAN CLASS='defined'>wline_filter</SPAN>; |
| |
| } } <SPAN CLASS="comment">// End namespace boost::io</SPAN></PRE> |
| |
| <A NAME="template_params"></A> |
| <H4>Template parameters</H4> |
| |
| <TABLE STYLE="margin-left:2em" BORDER=0 CELLPADDING=2> |
| <TR> |
| <TR> |
| <TD VALIGN="top"><I>Ch</I></TD><TD WIDTH="2em" VALIGN="top">-</TD> |
| <TD>The <A HREF='../guide/traits.html#char_type'>character type</A></TD> |
| </TR> |
| <TR> |
| <TD VALIGN="top"><I>Alloc</I></TD><TD WIDTH="2em" VALIGN="top">-</TD> |
| <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> |
| </TR> |
| </TABLE> |
| |
| <A NAME="do_filter"></A> |
| <H4><CODE>line_filter::do_filter</CODE></H4> |
| |
| <PRE CLASS="broken_ie"> <SPAN CLASS='keyword'>virtual</SPAN> string_type do_filter(<SPAN CLASS='keyword'>const</SPAN> string_type& line) <SPAN CLASS='numeric_literal'>= 0</SPAN>;</PRE> |
| |
| <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> |
| |
| <A NAME="example"></A> |
| <H2>Example</H2> |
| |
| <P>The following example shows a <CODE>line_filter</CODE> which counts the number of lines which exceed a given length.</P> |
| |
| <PRE CLASS="broken_ie"><SPAN CLASS='preprocessor'>#include</SPAN> <A CLASS='header' HREF='../../../../boost/iostreams/filter/line.hpp'><SPAN CLASS='literal'><boost/iostreams/filter/line.hpp></SPAN></A> |
| |
| <SPAN CLASS='keyword'>namespace</SPAN> io = boost::iostreams; |
| |
| <SPAN CLASS='keyword'>class</SPAN> long_line_counter : <SPAN CLASS='keyword'>public</SPAN> io::line_filter { |
| <SPAN CLASS='keyword'>public</SPAN> |
| <SPAN CLASS="keyword">explicit</SPAN> long_line_counter(<SPAN CLASS='keyword'>int</SPAN> max_length = <SPAN CLASS='numeric_literal'>80</SPAN>) |
| : max_(max_length), count_(<SPAN CLASS='numeric_literal'>0</SPAN>) |
| { } |
| <SPAN CLASS='keyword'>int</SPAN> count() <SPAN CLASS='keyword'>const</SPAN> { <SPAN CLASS='keyword'>return</SPAN> count_; } |
| <SPAN CLASS='keyword'>private:</SPAN> |
| std::string do_filter(<SPAN CLASS='keyword'>const</SPAN> std::string& line) |
| { |
| <SPAN CLASS='keyword'>if</SPAN> (line.size() > max_) |
| ++count_; |
| } |
| <SPAN CLASS='keyword'>int</SPAN> max_; |
| <SPAN CLASS='keyword'>int</SPAN> count_; |
| };</PRE> |
| |
| <!-- Begin Footer --> |
| |
| <HR> |
| <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> |