1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
4
<TITLE>Class Template basic_line_filter</TITLE>
5
<LINK REL="stylesheet" HREF="../../../../boost.css">
6
<LINK REL="stylesheet" HREF="../theme/iostreams.css">
12
<H1 CLASS="title">Class Template <CODE>basic_line_filter</CODE></H1>
17
<DL class="page-index">
18
<DT><A href="#description">Description</A></DT>
19
<DT><A href="#headers">Headers</A></DT>
20
<DT><A href="#reference">Reference</A></DT>
21
<DT><A href="#example">Example</A></DT>
26
<A NAME="description"></A>
30
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.
33
<A NAME="headers"></A>
36
<DL class="page-index">
37
<DT><A CLASS="header" HREF="../../../../boost/iostreams/filter/line.hpp"><CODE><boost/iostreams/filter/line.hpp></CODE></A></DT>
40
<A NAME="reference"></A>
45
<PRE CLASS="broken_ie"><SPAN CLASS="keyword">namespace</SPAN> boost { <SPAN CLASS="keyword">namespace</SPAN> iostreams {
47
<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> >
48
<SPAN CLASS='keyword'>class</SPAN> <A CLASS='documented' HREF='#template_params'>basic_line_filter</A> {
49
<SPAN CLASS='keyword'>public:</SPAN>
50
<SPAN CLASS='keyword'>typedef</SPAN> Ch char_type;
51
<SPAN CLASS='keyword'>typedef</SPAN> std::basic_string<
53
std::char_traits<char_type>,
56
<SPAN CLASS='keyword'>typedef</SPAN> <SPAN CLASS='omitted'>[implementation-defined]</SPAN> category;
57
<SPAN CLASS='keyword'>protected:</SPAN>
59
<SPAN CLASS='keyword'>public:</SPAN>
60
<SPAN CLASS='keyword'>virtual</SPAN> ~basic_line_filter();
61
<SPAN CLASS='keyword'>private:</SPAN>
62
<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>;
65
<SPAN CLASS='keyword'>typedef</SPAN> basic_line_filter<<SPAN CLASS='keyword'>char</SPAN>> <SPAN CLASS='defined'>line_filter</SPAN>;
66
<SPAN CLASS='keyword'>typedef</SPAN> basic_line_filter<<SPAN CLASS='keyword'>wchar_t</SPAN>> <SPAN CLASS='defined'>wline_filter</SPAN>;
68
} } <SPAN CLASS="comment">// End namespace boost::io</SPAN></PRE>
70
<A NAME="template_params"></A>
71
<H4>Template parameters</H4>
73
<TABLE STYLE="margin-left:2em" BORDER=0 CELLPADDING=2>
76
<TD VALIGN="top"><I>Ch</I></TD><TD WIDTH="2em" VALIGN="top">-</TD>
77
<TD>The <A HREF='../guide/traits.html#char_type'>character type</A></TD>
80
<TD VALIGN="top"><I>Alloc</I></TD><TD WIDTH="2em" VALIGN="top">-</TD>
81
<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>
85
<A NAME="do_filter"></A>
86
<H4><CODE>line_filter::do_filter</CODE></H4>
88
<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>
90
<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>
92
<A NAME="example"></A>
95
<P>The following example shows a <CODE>line_filter</CODE> which counts the number of lines which exceed a given length.</P>
97
<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>
99
<SPAN CLASS='keyword'>namespace</SPAN> io = boost::iostreams;
101
<SPAN CLASS='keyword'>class</SPAN> long_line_counter : <SPAN CLASS='keyword'>public</SPAN> io::line_filter {
102
<SPAN CLASS='keyword'>public</SPAN>
103
<SPAN CLASS="keyword">explicit</SPAN> long_line_counter(<SPAN CLASS='keyword'>int</SPAN> max_length = <SPAN CLASS='numeric_literal'>80</SPAN>)
104
: max_(max_length), count_(<SPAN CLASS='numeric_literal'>0</SPAN>)
106
<SPAN CLASS='keyword'>int</SPAN> count() <SPAN CLASS='keyword'>const</SPAN> { <SPAN CLASS='keyword'>return</SPAN> count_; }
107
<SPAN CLASS='keyword'>private:</SPAN>
108
std::string do_filter(<SPAN CLASS='keyword'>const</SPAN> std::string& line)
110
<SPAN CLASS='keyword'>if</SPAN> (line.size() > max_)
113
<SPAN CLASS='keyword'>int</SPAN> max_;
114
<SPAN CLASS='keyword'>int</SPAN> count_;
117
<!-- Begin Footer -->
121
<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>
122
<P CLASS="copyright">
123
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>)