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.69.1"> |
---|
7 | <link rel="start" href="../index.html" title="The Boost C++ Libraries"> |
---|
8 | <link rel="up" href="../string_algo.html" title="Chapter 11. 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.png (6897 bytes)" 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><h3 class="title"> |
---|
27 | <a name="string_algo.concept"></a>Concepts</h3></div></div></div> |
---|
28 | <div class="toc"><dl> |
---|
29 | <dt><span class="section"><a href="concept.html#id2745880">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><h4 class="title"> |
---|
35 | <a name="id2745880"></a>Definitions</h4></div></div></div> |
---|
36 | <div class="table"> |
---|
37 | <a name="id2745884"></a><p class="title"><b>Table 11.12. 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><h4 class="title"> |
---|
79 | <a name="string_algo.finder_concept"></a>Finder Concept</h4></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="id2745984"></a><p class="title"><b>Table 11.13. 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<Iter></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><span class="bold"><strong>Examples</strong></span></p> |
---|
116 | <div class="itemizedlist"><ul type="disc"> |
---|
117 | <li> |
---|
118 | Finder implemented as a class. This Finder always returns the whole input as a match. <code class="computeroutput">operator()</code> |
---|
119 | is templated, so that the finder can be used on any iterator type. |
---|
120 | |
---|
121 | <pre class="programlisting"> |
---|
122 | struct simple_finder |
---|
123 | { |
---|
124 | template<typename ForwardIteratorT> |
---|
125 | boost::iterator_range<ForwardIterator> operator()( |
---|
126 | ForwardIteratorT Begin, |
---|
127 | ForwardIteratorT End ) |
---|
128 | { |
---|
129 | return boost::make_range( Begin, End ); |
---|
130 | } |
---|
131 | }; |
---|
132 | </pre> |
---|
133 | </li> |
---|
134 | <li> |
---|
135 | Function Finder. Finder can be any function object. That is, any ordinary function with the |
---|
136 | required signature can be used as well. However, such a function can be used only for |
---|
137 | a specific iterator type. |
---|
138 | |
---|
139 | <pre class="programlisting"> |
---|
140 | boost::iterator_range<std::string> simple_finder( |
---|
141 | std::string::const_iterator Begin, |
---|
142 | std::string::const_iterator End ) |
---|
143 | { |
---|
144 | return boost::make_range( Begin, End ); |
---|
145 | } |
---|
146 | </pre> |
---|
147 | </li> |
---|
148 | </ul></div> |
---|
149 | </div> |
---|
150 | <div class="section" lang="en"> |
---|
151 | <div class="titlepage"><div><div><h4 class="title"> |
---|
152 | <a name="string_algo.formatter_concept"></a>Formatter concept</h4></div></div></div> |
---|
153 | <p> |
---|
154 | Formatters are used by <a href="design.html#string_algo.replace" title="Replace Algorithms">replace algorithms</a>. |
---|
155 | They are used in close combination with finders. |
---|
156 | A formatter is a functor, which takes a result from a Finder operation and transforms it in a specific way. |
---|
157 | The operation of the formatter can use additional information provided by a specific finder, |
---|
158 | for example <code class="computeroutput"><a href="../id2586835.html" title="Function template regex_formatter">regex_formatter()</a></code> uses the match information from |
---|
159 | <code class="computeroutput"><a href="../id2559243.html" title="Function template regex_finder">regex_finder()</a></code> to format the result of formatter operation. |
---|
160 | </p> |
---|
161 | <div class="table"> |
---|
162 | <a name="id2746137"></a><p class="title"><b>Table 11.14. Valid Expressions</b></p> |
---|
163 | <table class="table" summary="Valid Expressions"> |
---|
164 | <colgroup> |
---|
165 | <col> |
---|
166 | <col> |
---|
167 | <col> |
---|
168 | </colgroup> |
---|
169 | <thead><tr> |
---|
170 | <th align="left">Expression</th> |
---|
171 | <th align="left">Return Type</th> |
---|
172 | <th align="left">Effects</th> |
---|
173 | </tr></thead> |
---|
174 | <tbody><tr> |
---|
175 | <td align="left"><code class="computeroutput">fmt(f(i,j))</code></td> |
---|
176 | <td align="left">A container type, accessible using container traits</td> |
---|
177 | <td align="left">Formats the result of the finder operation</td> |
---|
178 | </tr></tbody> |
---|
179 | </table> |
---|
180 | </div> |
---|
181 | <p> |
---|
182 | Similarly to finders, formatters generalize format operations. When a finder is used to |
---|
183 | select a part of the input, formatter takes this selection and performs some formating |
---|
184 | on it. Algorithms can abstract from formating using a formatter. |
---|
185 | </p> |
---|
186 | <p><span class="bold"><strong>Examples</strong></span></p> |
---|
187 | <div class="itemizedlist"><ul type="disc"> |
---|
188 | <li> |
---|
189 | Formatter implemented as a class. This Formatter does not perform any formating and |
---|
190 | returns the match, repackaged. <code class="computeroutput">operator()</code> |
---|
191 | is templated, so that the Formatter can be used on any Finder type. |
---|
192 | |
---|
193 | <pre class="programlisting"> |
---|
194 | struct simple_formatter |
---|
195 | { |
---|
196 | template<typename FindResultT> |
---|
197 | std::string operator()( const FindResultT& Match ) |
---|
198 | { |
---|
199 | std::string Temp( Match.begin(), Match.end() ); |
---|
200 | return Temp; |
---|
201 | } |
---|
202 | }; |
---|
203 | </pre> |
---|
204 | </li> |
---|
205 | <li> |
---|
206 | Function Formatter. Similarly to Finder, Formatter can be any function object. |
---|
207 | However, as a function, it can be used only with a specific Finder type. |
---|
208 | |
---|
209 | <pre class="programlisting"> |
---|
210 | std::string simple_formatter( boost::iterator_range<std::string::const_iterator>& Match ) |
---|
211 | { |
---|
212 | std::string Temp( Match.begin(), Match.end() ); |
---|
213 | return Temp; |
---|
214 | } |
---|
215 | </pre> |
---|
216 | </li> |
---|
217 | </ul></div> |
---|
218 | </div> |
---|
219 | </div> |
---|
220 | <table width="100%"><tr> |
---|
221 | <td align="left"><small><p>Last revised: July 16, 2004 at 09:06:39 GMT</p></small></td> |
---|
222 | <td align="right"><small>Copyright © 2002-2004 Pavol Droba</small></td> |
---|
223 | </tr></table> |
---|
224 | <hr> |
---|
225 | <div class="spirit-nav"> |
---|
226 | <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> |
---|
227 | </div> |
---|
228 | </body> |
---|
229 | </html> |
---|