Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/iostreams/doc/classes/line_filter.html @ 29

Last change on this file since 29 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 5.8 KB
Line 
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
10<!-- Begin Banner -->
11
12    <H1 CLASS="title">Class Template <CODE>basic_line_filter</CODE></H1>
13    <HR CLASS="banner">
14
15<!-- End Banner -->
16
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>
22</DL>
23
24<HR>
25
26<A NAME="description"></A>
27<H2>Description</H2>
28
29<P>
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.
31</P>
32
33<A NAME="headers"></A>
34<H2>Headers</H2>
35
36<DL class="page-index">
37  <DT><A CLASS="header" HREF="../../../../boost/iostreams/filter/line.hpp"><CODE>&lt;boost/iostreams/filter/line.hpp&gt;</CODE></A></DT>
38</DL>
39
40<A NAME="reference"></A>
41<H2>Reference</H2>
42
43<H4>Synopsis</H4>
44
45<PRE CLASS="broken_ie"><SPAN CLASS="keyword">namespace</SPAN> boost { <SPAN CLASS="keyword">namespace</SPAN> iostreams {
46
47<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;
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&lt;
52                Ch,
53                std::char_traits&lt;char_type&gt;,   
54                Alloc
55            &gt;                                 string_type;
56    <SPAN CLASS='keyword'>typedef</SPAN> <SPAN CLASS='omitted'>[implementation-defined]</SPAN>          category;
57<SPAN CLASS='keyword'>protected:</SPAN>
58    basic_line_filter();
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>;
63};
64
65<SPAN CLASS='keyword'>typedef</SPAN> basic_line_filter&lt;<SPAN CLASS='keyword'>char</SPAN>&gt;     <SPAN CLASS='defined'>line_filter</SPAN>;
66<SPAN CLASS='keyword'>typedef</SPAN> basic_line_filter&lt;<SPAN CLASS='keyword'>wchar_t</SPAN>&gt;  <SPAN CLASS='defined'>wline_filter</SPAN>;
67
68} } <SPAN CLASS="comment">// End namespace boost::io</SPAN></PRE>
69
70<A NAME="template_params"></A>
71<H4>Template parameters</H4>
72
73<TABLE STYLE="margin-left:2em" BORDER=0 CELLPADDING=2>
74<TR>
75    <TR>
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>
78    </TR>
79    <TR>
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>
82    </TR>
83</TABLE>
84
85<A NAME="do_filter"></A>
86<H4><CODE>line_filter::do_filter</CODE></H4>
87
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>
89
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>
91
92<A NAME="example"></A>
93<H2>Example</H2>
94
95<P>The following example shows a <CODE>line_filter</CODE> which counts the number of lines which exceed a given length.</P>
96
97<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>
98
99<SPAN CLASS='keyword'>namespace</SPAN> io = boost::iostreams;
100
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>)
105        { }
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)
109    {
110        <SPAN CLASS='keyword'>if</SPAN> (line.size() &gt; max_)
111            ++count_;
112    }
113    <SPAN CLASS='keyword'>int</SPAN> max_;
114    <SPAN CLASS='keyword'>int</SPAN> count_;
115};</PRE>
116
117<!-- Begin Footer -->
118
119<HR>
120<P CLASS="copyright">Revised
121<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
12220 May, 2004
123<!--webbot bot="Timestamp" endspan i-checksum="38504" -->
124</P>
125
126<P CLASS="copyright">&copy; Copyright <A HREF="http://www.kangaroologic.com" TARGET="_top">Jonathan Turkanis</A>, 2004</P>
127<P CLASS="copyright"> 
128    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>)
129</P>
130
131<!-- End Footer -->
132
133</BODY>
Note: See TracBrowser for help on using the repository browser.