grep_filter.html 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <HTML>
  3. <HEAD>
  4. <TITLE>Class Template basic_grep_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_grep_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="#installation">Installation</A></DT>
  17. <DT><A href="#reference">Reference</A></DT>
  18. </DL>
  19. <HR>
  20. <A NAME="description"></A>
  21. <H2>Description</H2>
  22. <P>
  23. 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>).
  24. </P>
  25. <P>
  26. 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).
  27. </P>
  28. <P>
  29. A running count of the lines in the filtered character sequence is available via the member function <code><a href="#count">count</a></code>.
  30. </P>
  31. <A NAME="headers"></A>
  32. <H2>Headers</H2>
  33. <DL class="page-index">
  34. <DT><A CLASS="header" HREF="../../../../boost/iostreams/filter/grep.hpp"><CODE>&lt;boost/iostreams/filter/grep.hpp&gt;</CODE></A></DT>
  35. </DL>
  36. <A NAME="installation"></A>
  37. <H2>Installation</H2>
  38. <P>
  39. 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.
  40. </P>
  41. <A NAME="reference"></A>
  42. <H2>Reference</H2>
  43. <H4>Synopsis</H4>
  44. <PRE CLASS="broken_ie"><SPAN CLASS="keyword">namespace</SPAN> boost { <SPAN CLASS="keyword">namespace</SPAN> iostreams {
  45. <SPAN CLASS="preprocessor">#include</SPAN> <A CLASS="header" HREF="../../../../boost/function.hpp" TARGET="_top"><SPAN CLASS="literal">&lt;boost/function.hpp&gt;</SPAN></A>
  46. <SPAN CLASS="preprocessor">#include</SPAN> <A CLASS="header" HREF="../../../../boost/regex.hpp" TARGET="_top"><SPAN CLASS="literal">&lt;boost/regex.hpp&gt;</SPAN></A>
  47. <SPAN CLASS="keyword">namespace</SPAN> grep {
  48. <SPAN CLASS="keyword">const</SPAN> <SPAN CLASS="keyword">int</SPAN> invert;
  49. <SPAN CLASS="keyword">const</SPAN> <SPAN CLASS="keyword">int</SPAN> whole_line;
  50. }
  51. <SPAN CLASS="keyword">template</SPAN>&lt; <SPAN CLASS="keyword">typename</SPAN> <A HREF="#template_params" CLASS="documented">Ch</A>,
  52. <SPAN CLASS="keyword">typename</SPAN> <A HREF="#template_params" CLASS="documented">Tr</A> = regex_traits&lt;Ch&gt;,
  53. <SPAN CLASS="keyword">typename</SPAN> <A HREF="#template_params" CLASS="documented">Alloc</A> = std::allocator&lt;Ch&gt; &gt;
  54. <SPAN CLASS="keyword">class</SPAN> <A HREF="#template_params" CLASS="documented">basic_grep_filter</A> {
  55. <SPAN CLASS="keyword">public:</SPAN>
  56. <A CLASS="documented" HREF="#constructor">basic_grep_filter</A>( <SPAN CLASS="keyword">const</SPAN> basic_regex&lt;Ch, Tr, Alloc&gt;&amp; pattern,
  57. regex_constants::match_flag_type flags =
  58. regex_constants::match_default,
  59. <SPAN CLASS="keyword">int</SPAN> options = <SPAN CLASS="numeric_literal">0</SPAN> );
  60. <SPAN CLASS="keyword">int</SPAN> <A CLASS="documented" HREF="#count">count</A>() <SPAN CLASS="keyword">const</SPAN>;
  61. };
  62. <SPAN CLASS="keyword">typedef</SPAN> basic_grep_filter&lt;<SPAN CLASS="keyword">char</SPAN>&gt; <SPAN CLASS="defined">grep_filter</SPAN>;
  63. <SPAN CLASS="keyword">typedef</SPAN> basic_grep_filter&lt;<SPAN CLASS="keyword">wchar_t</SPAN>&gt; <SPAN CLASS="defined">wgrep_filter</SPAN>;
  64. } } // End namespace boost::io</PRE>
  65. <A NAME="template_params"></A>
  66. <H4>Template parameters</H4>
  67. <TABLE STYLE="margin-left:2em" BORDER=0 CELLPADDING=2>
  68. <TR>
  69. <TR>
  70. <TD VALIGN="top"><I>Ch</I></TD><TD WIDTH="2em" VALIGN="top">-</TD>
  71. <TD>The character type</TD>
  72. </TR>
  73. <TR>
  74. <TD VALIGN="top"><I>Tr</I></TD><TD WIDTH="2em" VALIGN="top">-</TD>
  75. <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>
  76. </TR>
  77. <TR>
  78. <TD VALIGN="top"><I>Alloc</I></TD><TD WIDTH="2em" VALIGN="top">-</TD>
  79. <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>
  80. </TR>
  81. </TABLE>
  82. <A NAME="constructor"></A>
  83. <H4><CODE>basic_grep_filter::basic_grep_filter</CODE></H4>
  84. <PRE CLASS="broken_ie"> <B>basic_grep_filter</B>( <SPAN CLASS="keyword">const</SPAN> basic_regex&lt;Ch, Tr, Alloc&gt;&amp; pattern,
  85. regex_constants::match_flag_type flags =
  86. regex_constants::match_default,
  87. <SPAN CLASS="keyword">int</SPAN> options = <SPAN CLASS="numeric_literal">0</SPAN> );</PRE>
  88. <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>
  89. <TABLE STYLE="margin-left:2em" BORDER=0 CELLPADDING=2>
  90. <TR>
  91. <TR>
  92. <TD VALIGN="top"><I>pattern</I></TD><TD WIDTH="2em" VALIGN="top">-</TD>
  93. <TD>The regular expression to be matched against the stream of unfiltered data</TD>
  94. </TR>
  95. <TR>
  96. <TD VALIGN="top"><I>flags</I></TD><TD WIDTH="2em" VALIGN="top">-</TD>
  97. <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>
  98. </TR>
  99. <TR>
  100. <TD VALIGN="top"><I>options</I></TD><TD WIDTH="2em" VALIGN="top">-</TD>
  101. <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>
  102. </TR>
  103. </TABLE>
  104. </P>
  105. <A NAME="count"></A>
  106. <H4><CODE>basic_grep_filter::count</CODE></H4>
  107. <A NAME="second_constructor"></A>
  108. <PRE CLASS="broken_ie"> <SPAN CLASS="keyword">int</SPAN> count() <SPAN CLASS="keyword">const</SPAN>;</PRE>
  109. <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>
  110. <!-- Begin Footer -->
  111. <HR>
  112. <P CLASS="copyright">&copy; Copyright 2008 <a href="http://www.coderage.com/" target="_top">CodeRage, LLC</a></P>
  113. <P CLASS="copyright">
  114. 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>)
  115. </P>
  116. <!-- End Footer -->
  117. </BODY>