Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/doc/html/string_algo/concept.html @ 47

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

updated boost from 1_33_1 to 1_34_1

File size: 9.7 KB
Line 
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
4<title>Concepts</title>
5<link rel="stylesheet" href="../boostbook.css" type="text/css">
6<meta name="generator" content="DocBook XSL Stylesheets V1.68.1">
7<link rel="start" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
8<link rel="up" href="../string_algo.html" title="Chapter 14. Boost String Algorithms Library">
9<link rel="prev" href="design.html" title="Design Topics">
10<link rel="next" href="reference.html" title="Reference">
11</head>
12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13<table cellpadding="2" width="100%">
14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
15<td align="center"><a href="../../../index.htm">Home</a></td>
16<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
17<td align="center"><a href="../../../people/people.htm">People</a></td>
18<td align="center"><a href="../../../more/faq.htm">FAQ</a></td>
19<td align="center"><a href="../../../more/index.htm">More</a></td>
20</table>
21<hr>
22<div class="spirit-nav">
23<a accesskey="p" href="design.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../string_algo.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="reference.html"><img src="../images/next.png" alt="Next"></a>
24</div>
25<div class="section" lang="en">
26<div class="titlepage"><div><div><h2 class="title" style="clear: both">
27<a name="string_algo.concept"></a>Concepts</h2></div></div></div>
28<div class="toc"><dl>
29<dt><span class="section"><a href="concept.html#id1642149">Definitions</a></span></dt>
30<dt><span class="section"><a href="concept.html#string_algo.finder_concept">Finder Concept</a></span></dt>
31<dt><span class="section"><a href="concept.html#string_algo.formatter_concept">Formatter concept</a></span></dt>
32</dl></div>
33<div class="section" lang="en">
34<div class="titlepage"><div><div><h3 class="title">
35<a name="id1642149"></a>Definitions</h3></div></div></div>
36<div class="table">
37<a name="id1642154"></a><p class="title"><b>Table 14.13. Notation</b></p>
38<table class="table" summary="Notation">
39<colgroup>
40<col>
41<col>
42</colgroup>
43<tbody>
44<tr>
45<td align="left"><code class="computeroutput">F</code></td>
46<td align="left">A type that is a model of Finder</td>
47</tr>
48<tr>
49<td align="left"><code class="computeroutput">Fmt</code></td>
50<td align="left">A type that is a model of Formatter</td>
51</tr>
52<tr>
53<td align="left"><code class="computeroutput">Iter</code></td>
54<td align="left">
55                            Iterator Type
56                        </td>
57</tr>
58<tr>
59<td align="left"><code class="computeroutput">f</code></td>
60<td align="left">Object of type <code class="computeroutput">F</code>
61</td>
62</tr>
63<tr>
64<td align="left"><code class="computeroutput">fmt</code></td>
65<td align="left">Object of type <code class="computeroutput">Fmt</code>
66</td>
67</tr>
68<tr>
69<td align="left"><code class="computeroutput">i,j</code></td>
70<td align="left">Objects of type <code class="computeroutput">Iter</code>
71</td>
72</tr>
73</tbody>
74</table>
75</div>
76</div>
77<div class="section" lang="en">
78<div class="titlepage"><div><div><h3 class="title">
79<a name="string_algo.finder_concept"></a>Finder Concept</h3></div></div></div>
80<p>
81            Finder is a functor which searches for an arbitrary part of a container.
82            The result of the search is given as an <code class="computeroutput">iterator_range</code> 
83            delimiting the selected part.
84        </p>
85<div class="table">
86<a name="id1642290"></a><p class="title"><b>Table 14.14. Valid Expressions</b></p>
87<table class="table" summary="Valid Expressions">
88<colgroup>
89<col>
90<col>
91<col>
92</colgroup>
93<thead><tr>
94<th align="left">Expression</th>
95<th align="left">Return Type</th>
96<th align="left">Effects</th>
97</tr></thead>
98<tbody><tr>
99<td align="left"><code class="computeroutput">f(i,j)</code></td>
100<td align="left">Convertible to <code class="computeroutput">iterator_range&lt;Iter&gt;</code>
101</td>
102<td align="left">Perform the search on the interval [i,j) and returns the result of the search</td>
103</tr></tbody>
104</table>
105</div>
106<p>
107            Various algorithms need to perform a search in a container and a Finder is a generalization of such
108            search operations that allows algorithms to abstract from searching. For instance, generic replace
109            algorithms can replace any part of the input, and the Finder is used to select the desired one.
110        </p>
111<p>
112            Note, that it is only required that the finder works with a particular iterator type. However,
113            a Finder operation can be defined as a template, allowing the Finder to work with any iterator.
114        </p>
115<p>
116            <span class="bold"><strong>Examples</strong></span>
117        </p>
118<p> 
119            </p>
120<div class="itemizedlist"><ul type="disc">
121<li>
122                    Finder implemented as a class. This Finder always returns the whole input as a match. <code class="computeroutput">operator()</code>
123                    is templated, so that the finder can be used on any iterator type.
124                   
125                    <pre class="programlisting">
126struct simple_finder
127{
128    template&lt;typename ForwardIteratorT&gt;
129    boost::iterator_range&lt;ForwardIterator&gt; operator()(
130        ForwardIteratorT Begin,
131        ForwardIteratorT End )
132    {
133        return boost::make_range( Begin, End );
134    }
135};
136        </pre>
137</li>
138<li>
139                    Function Finder. Finder can be any function object. That is, any ordinary function with the
140                    required signature can be used as well. However, such a function can be used only for
141                    a specific iterator type.
142                   
143                    <pre class="programlisting">
144boost::iterator_range&lt;std::string&gt; simple_finder(
145    std::string::const_iterator Begin,
146    std::string::const_iterator End )
147{
148    return boost::make_range( Begin, End );
149}
150        </pre>
151</li>
152</ul></div>
153<p>
154        </p>
155</div>
156<div class="section" lang="en">
157<div class="titlepage"><div><div><h3 class="title">
158<a name="string_algo.formatter_concept"></a>Formatter concept</h3></div></div></div>
159<p>
160            Formatters are used by <a href="design.html#string_algo.replace" title="Replace Algorithms">replace algorithms</a>.
161            They are used in close combination with finders.
162            A formatter is a functor, which takes a result from a Finder operation and transforms it in a specific way.
163            The operation of the formatter can use additional information provided by a specific finder,
164            for example <code class="computeroutput"><a href="../boost/algorithm/regex_formatter.html" title="Function template regex_formatter">regex_formatter()</a></code> uses the match information from
165            <code class="computeroutput"><a href="../boost/algorithm/regex_finder.html" title="Function template regex_finder">regex_finder()</a></code> to format the result of formatter operation.
166        </p>
167<div class="table">
168<a name="id1642464"></a><p class="title"><b>Table 14.15. Valid Expressions</b></p>
169<table class="table" summary="Valid Expressions">
170<colgroup>
171<col>
172<col>
173<col>
174</colgroup>
175<thead><tr>
176<th align="left">Expression</th>
177<th align="left">Return Type</th>
178<th align="left">Effects</th>
179</tr></thead>
180<tbody><tr>
181<td align="left"><code class="computeroutput">fmt(f(i,j))</code></td>
182<td align="left">A container type, accessible using container traits</td>
183<td align="left">Formats the result of the finder operation</td>
184</tr></tbody>
185</table>
186</div>
187<p>
188            Similarly to finders, formatters generalize format operations. When a finder is used to
189            select a part of the input, formatter takes this selection and performs some formating
190            on it. Algorithms can abstract from formating using a formatter.
191        </p>
192<p>
193            <span class="bold"><strong>Examples</strong></span>
194        </p>
195<p> 
196            </p>
197<div class="itemizedlist"><ul type="disc">
198<li>
199                    Formatter implemented as a class. This Formatter does not perform any formating and
200                    returns the match, repackaged. <code class="computeroutput">operator()</code>
201                    is templated, so that the Formatter can be used on any Finder type.
202                   
203                    <pre class="programlisting">
204struct simple_formatter
205{
206    template&lt;typename FindResultT&gt;
207    std::string operator()( const FindResultT&amp; Match )
208    {
209        std::string Temp( Match.begin(), Match.end() );
210        return Temp;
211    }
212};
213                </pre>
214</li>
215<li>
216                    Function Formatter. Similarly to Finder, Formatter can be any function object.
217                    However, as a function, it can be used only with a specific Finder type.
218                 
219                    <pre class="programlisting">
220std::string simple_formatter( boost::iterator_range&lt;std::string::const_iterator&gt;&amp; Match )
221{
222    std::string Temp( Match.begin(), Match.end() );
223    return Temp;
224}
225                    </pre>
226</li>
227</ul></div>
228<p>
229        </p>
230</div>
231</div>
232<table width="100%"><tr>
233<td align="left"><small><p>Last revised: August 16, 2006 at 07:10:47 GMT</p></small></td>
234<td align="right"><small>Copyright © 2002-2004 Pavol Droba</small></td>
235</tr></table>
236<hr>
237<div class="spirit-nav">
238<a accesskey="p" href="design.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../string_algo.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="reference.html"><img src="../images/next.png" alt="Next"></a>
239</div>
240</body>
241</html>
Note: See TracBrowser for help on using the repository browser.