1 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN">
4 <TITLE>Class Template basic_grep_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_grep_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=
"#installation">Installation
</A></DT>
21 <DT><A href=
"#reference">Reference
</A></DT>
26 <A NAME=
"description"></A>
30 The class template
<CODE>basic_grep_filter
</CODE> filters a character sequence line by line using a regular expression provided at construction, in a manner similar to the command-line utility
<i>grep
</i> (
<A CLASS=
"bib_ref" HREF=
"../bibliography.html#grep">[IEEE]
</A>). The filter uses regular expressions from the
<A HREF=
"http://www.boost.org/libs/regex" TARGET=
"_top">Boost Regular Expression Library
</A> (
<A CLASS=
"bib_ref" HREF=
"../bibliography.html#maddock">[Maddock]
</A>).
33 By default, the filtered character sequence consists of those lines of the unfiltered sequence that contain a subsequence matching the regular expression. By specifying appropriate options at construction,
<CODE>basic_grep_filter
</CODE> can be made to pass through only those lines which exactly match the regular expression (as if the option
<i>-x
</i> had been passed to the command-line utility) or only those lines that
<i>do not
</i> contain a match (as if the option
<i>-v
</i> had been passed to the command-line utility).
36 A running count of the lines in the filtered character sequence is available via the member function
<code><a href=
"#count">count
</a></code>.
39 <A NAME=
"headers"></A>
42 <DL class=
"page-index">
43 <DT><A CLASS=
"header" HREF=
"../../../../boost/iostreams/filter/grep.hpp"><CODE><boost/iostreams/filter/grep.hpp
></CODE></A></DT>
46 <A NAME=
"installation"></A>
50 The template
<CODE>basic_grep_filter
</CODE> uses the
<A HREF=
"http://www.boost.org/libs/regex" TARGET=
"_top">Boost Regular Expression Library
</A>, which must be built separately. See
<A HREF=
"http://www.boost.org/libs/regex/doc/html/boost_regex/install.html" TARGET=
"_top">here
</A> for details.
53 <A NAME=
"reference"></A>
58 <PRE CLASS=
"broken_ie"><SPAN CLASS=
"keyword">namespace
</SPAN> boost {
<SPAN CLASS=
"keyword">namespace
</SPAN> iostreams {
60 <SPAN CLASS=
"preprocessor">#include
</SPAN> <A CLASS=
"header" HREF=
"../../../../boost/function.hpp" TARGET=
"_top"><SPAN CLASS=
"literal"><boost/function.hpp
></SPAN></A>
61 <SPAN CLASS=
"preprocessor">#include
</SPAN> <A CLASS=
"header" HREF=
"../../../../boost/regex.hpp" TARGET=
"_top"><SPAN CLASS=
"literal"><boost/regex.hpp
></SPAN></A>
63 <SPAN CLASS=
"keyword">namespace
</SPAN> grep {
65 <SPAN CLASS=
"keyword">const
</SPAN> <SPAN CLASS=
"keyword">int
</SPAN> invert;
66 <SPAN CLASS=
"keyword">const
</SPAN> <SPAN CLASS=
"keyword">int
</SPAN> whole_line;
70 <SPAN CLASS=
"keyword">template
</SPAN>< <SPAN CLASS=
"keyword">typename
</SPAN> <A HREF=
"#template_params" CLASS=
"documented">Ch
</A>,
71 <SPAN CLASS=
"keyword">typename
</SPAN> <A HREF=
"#template_params" CLASS=
"documented">Tr
</A> = regex_traits
<Ch
>,
72 <SPAN CLASS=
"keyword">typename
</SPAN> <A HREF=
"#template_params" CLASS=
"documented">Alloc
</A> = std::allocator
<Ch
> >
73 <SPAN CLASS=
"keyword">class
</SPAN> <A HREF=
"#template_params" CLASS=
"documented">basic_grep_filter
</A> {
74 <SPAN CLASS=
"keyword">public:
</SPAN>
75 <A CLASS=
"documented" HREF=
"#constructor">basic_grep_filter
</A>(
<SPAN CLASS=
"keyword">const
</SPAN> basic_regex
<Ch, Tr, Alloc
>& pattern,
76 regex_constants::match_flag_type flags =
77 regex_constants::match_default,
78 <SPAN CLASS=
"keyword">int
</SPAN> options =
<SPAN CLASS=
"numeric_literal">0</SPAN> );
79 <SPAN CLASS=
"keyword">int
</SPAN> <A CLASS=
"documented" HREF=
"#count">count
</A>()
<SPAN CLASS=
"keyword">const
</SPAN>;
82 <SPAN CLASS=
"keyword">typedef
</SPAN> basic_grep_filter
<<SPAN CLASS=
"keyword">char
</SPAN>> <SPAN CLASS=
"defined">grep_filter
</SPAN>;
83 <SPAN CLASS=
"keyword">typedef
</SPAN> basic_grep_filter
<<SPAN CLASS=
"keyword">wchar_t
</SPAN>> <SPAN CLASS=
"defined">wgrep_filter
</SPAN>;
85 } } // End namespace boost::io
</PRE>
87 <A NAME=
"template_params"></A>
88 <H4>Template parameters
</H4>
90 <TABLE STYLE=
"margin-left:2em" BORDER=
0 CELLPADDING=
2>
93 <TD VALIGN=
"top"><I>Ch
</I></TD><TD WIDTH=
"2em" VALIGN=
"top">-
</TD>
94 <TD>The character type
</TD>
97 <TD VALIGN=
"top"><I>Tr
</I></TD><TD WIDTH=
"2em" VALIGN=
"top">-
</TD>
98 <TD>The
<A HREF=
"http://www.boost.org/libs/regex/doc/html/boost_regex/ref/regex_traits.html" TARGET=
"_top">regular expression traits
</A> type
</TD>
101 <TD VALIGN=
"top"><I>Alloc
</I></TD><TD WIDTH=
"2em" VALIGN=
"top">-
</TD>
102 <TD>A standard library allocator type (
<A CLASS=
"bib_ref" HREF=
"../bibliography.html#iso">[ISO]
</A>,
20.1.5), used to allocate character buffers
</TD>
106 <A NAME=
"constructor"></A>
107 <H4><CODE>basic_grep_filter::basic_grep_filter
</CODE></H4>
109 <PRE CLASS=
"broken_ie"> <B>basic_grep_filter
</B>(
<SPAN CLASS=
"keyword">const
</SPAN> basic_regex
<Ch, Tr, Alloc
>& pattern,
110 regex_constants::match_flag_type flags =
111 regex_constants::match_default,
112 <SPAN CLASS=
"keyword">int
</SPAN> options =
<SPAN CLASS=
"numeric_literal">0</SPAN> );
</PRE>
114 <P>Constructs a
<CODE>basic_grep_filter
</CODE> from the given regular expression, match flags, and grep options. The parameters have the following interpretations:
</P>
116 <TABLE STYLE=
"margin-left:2em" BORDER=
0 CELLPADDING=
2>
119 <TD VALIGN=
"top"><I>pattern
</I></TD><TD WIDTH=
"2em" VALIGN=
"top">-
</TD>
120 <TD>The regular expression to be matched against the stream of unfiltered data
</TD>
123 <TD VALIGN=
"top"><I>flags
</I></TD><TD WIDTH=
"2em" VALIGN=
"top">-
</TD>
124 <TD>The flags passed to
<A HREF=
"http://www.boost.org/libs/regex/doc/html/boost_regex/ref/regex_search.html" TARGET=
"_top">regex_search
</A> or
<A HREF=
"http://www.boost.org/libs/regex/doc/html/boost_regex/ref/regex_match.html" TARGET=
"_top">regex_match
</A> to specify regular expression matching behavior
</TD>
127 <TD VALIGN=
"top"><I>options
</I></TD><TD WIDTH=
"2em" VALIGN=
"top">-
</TD>
128 <TD>A bitwise OR of zero or more constants from the namespace
<CODE>boost::iostreams::grep
</CODE>. Currently two constants are recongnized:
<CODE>grep::whole_line
</CODE> causes the filter to pass through only those lines which exactly match the regular expression, and
<CODE>grep::invert
</CODE> causes the filter to pass through only those lines that
<i>do not
</i> contain a match.
</TD>
135 <H4><CODE>basic_grep_filter::count
</CODE></H4>
137 <A NAME=
"second_constructor"></A>
139 <PRE CLASS=
"broken_ie"> <SPAN CLASS=
"keyword">int
</SPAN> count()
<SPAN CLASS=
"keyword">const
</SPAN>;
</PRE>
141 <P>Returns a running count of the lines passed through from the unfiltered character sequence to the filtered character sequence. The count is reset to zero automatically when the filter begins processing a new character sequence.
</P>
143 <!-- Begin Footer -->
147 <P CLASS=
"copyright">© Copyright
2008 <a href=
"http://www.coderage.com/" target=
"_top">CodeRage, LLC
</a></P>
148 <P CLASS=
"copyright">
149 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>)