Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/spirit/doc/predefined_actors.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: 27.2 KB
Line 
1<html>
2<head>
3<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
4<title>predefined_actors</title>
5<link rel="stylesheet" href="theme/style.css" type="text/css">
6</head>
7<body>
8<table width="100%" height="48" border="0" background="theme/bkd2.gif" cellspacing="2">
9  <tr>
10    <td width="10">
11    </td>
12    <td width="85%"> <font size="6" face="Verdana, Arial, Helvetica, sans-serif"><b>Predefined
13      Actors</b></font></td>
14    <td width="112"><a href="http://spirit.sf.net"><img src="theme/spirit.gif" align="right" border="0"></a></td>
15  </tr>
16</table>
17<br>
18<table border="0">
19  <tr>
20    <td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
21    <td width="30"><a href="indepth_the_parser_context.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
22    <td width="20"><a href="parametric_parsers.html"><img src="theme/r_arr.gif" width="20" height="19" border="0"></a></td>
23  </tr>
24</table>
25<h2>Actors</h2><p>
26The framework has a number of predefined semantic action functors.
27Experience shows that these functors are so often used that they were included
28as part of the core framework to spare the user from having to reinvent the
29same functionality over and over again.</p>
30<h2>Quick example: <tt>assign_a</tt> actor</h2>
31<code>
32<pre>    <span class=keyword>int </span><span class=identifier>i</span><span class=special>,</span><span class=identifier> j</span><span class=special>;
33    </span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string </span><span class=identifier>s</span><span class=special>;
34    </span><span class=identifier>r </span><span class=special>= </span><span class=identifier>int_p</span><span class=special>[</span><span class=identifier>assign_a</span><span class=special>(</span><span class=identifier>i</span><span class=special>)] &gt;&gt; (+</span><span class=identifier>alpha_p</span><span class=special>)[</span><span class=identifier>assign_a</span><span class=special>(</span><span class=identifier>s</span><span class=special>)] &gt;&gt; </span><span class=identifier>int_p</span><span class=special>[</span><span class=identifier>assign_a</span><span class=special>(</span><span class=identifier>j</span><span class=special>,</span><span class=identifier>i</span><span class=special>)];</span></pre>
35</code>
36<p>
37Given an input <tt>123456 Hello 789</tt>, </p>
38<ol><li><tt>assign_a(i)</tt> will extract the number <tt>123456</tt> and assign it to <tt>i</tt>, </li><li><tt>assign_a(s)</tt> will extract the string <tt>&quot;Hello&quot;</tt> and assign it to <tt>s</tt>,</li><li><tt>assign_a(j,i)</tt> will assign i to j, j=i, without using the parse result.</li></ol>
39<p> Technically, the expression <tt>assign_a(v)</tt> is a template function that
40  generates a semantic action. In fact, actor instances are not created directly
41  since they usually involve a number of template parameters. Instead generator
42  functions (&quot;helper functions&quot;) are provided to generate actors from
43  their arguments. All helper functions have the &quot;_a&quot; suffix. For example,
44  <tt>append_actor</tt> is created using the <tt>append_a</tt> function. </p>
45<p>
46The semantic action generated is polymorphic and should work with any
47type as long as it is compatible with the arguments received from the parser.
48It might not be obvious, but a string can accept the iterator first and last
49arguments that are passed into a generic semantic action (see above). In fact,
50any STL container that has an <tt>assign(first, last)</tt> member function can be
51used.</p>
52<h2>Actors summary</h2><p>
53Below are tables summarizing the &quot;built-in&quot; actors with the
54conventions given below.</p>
55<ul>
56  <li><tt>ref</tt> is a <b>reference</b> to an object stored in a policy holder
57    actor</li>
58  <li><tt>value_ref</tt> and <tt>key_ref</tt> are <b>const reference</b>s stored
59    in a policy holder actor</li>
60  <li><tt>value</tt> is the <b>parse result</b>. This could be the result for
61    the single argument () operator or the two argument () operator</li>
62  <li><tt>vt</tt> stands for the <tt>value_type</tt> type: <tt>type&amp; ref;
63    // vt is type::value_type</tt>.</li>
64</ul>
65<p> Note that examples are provided after the tables.</p>
66<table width="90%" border="0" align="center">
67  <tr> 
68    <td class="table_title" colspan="8"> Unary operator actors</td>
69  </tr>
70    <td width="30%" class="table_cells">++ref</td>  <td width="70%" class="table_cells"><b>increment_a</b>(ref)</td>
71  </tr>
72    <td class="table_cells">--ref</td>  <td class="table_cells"><b>decrement_a</b>(ref)</td>
73  </tr>
74</table>
75<table width="90%" border="0" align="center">
76  <tr> 
77    <td class="table_title" colspan="26"> Assign actors</td>
78  </tr>
79  <tr>
80    <td class="table_cells">ref = value</td>
81    <td class="table_cells"><b>assign_a</b>(ref)</td>
82  </tr>
83    <td width="30%" class="table_cells">ref = value_ref</td>
84    <td width="70%" class="table_cells"><b>assign_a</b>(ref, value_ref)</td>
85  </tr>
86</table>
87<table width="90%" border="0" align="center">
88  <tr> 
89    <td class="table_title" colspan="30"> Container actors </td>
90  </tr>
91  <tr> 
92    <td width="30%" class="table_cells">ref.push_back(value)</td>
93    <td width="70%" class="table_cells"><b>push_back_a</b>(ref)</td>
94  </tr>
95  <td class="table_cells">ref.push_back(value_ref)</td>
96  <td class="table_cells"><b>push_back_a</b>(ref, value_ref)</td>
97  </tr>
98  <td class="table_cells">ref.push_front(value)</td>
99  <td class="table_cells"><b>push_front_a</b>(ref)</td>
100  </tr>
101  <td class="table_cells">ref.push_front(value_ref)</td>
102  <td class="table_cells"><b>push_front_a</b>(ref, value_ref)</td>
103  </tr>
104  <td class="table_cells">ref.clear()</td>
105  <td class="table_cells"><b>clear_a</b>(ref)</td>
106  </tr>
107</table>
108<table width="90%" border="0" align="center">
109  <tr> 
110    <td class="table_title" colspan="14"> Associative container actors </td>
111  </tr>
112    <td width="30%" class="table_cells">ref.insert(vt(value, value_ref))</td>  <td width="70%" class="table_cells"><b>insert_key_a</b>(ref, value_ref)</td>
113  </tr>  <tr>
114      <td class="table_cells"> ref.insert(vt(key_ref,value_ref)) </td>
115      <td class="table_cells"> <strong>insert_at_a</strong>(ref, key_ref_, value_ref)</td>
116    </tr>
117    <tr>
118      <td class="table_cells"> ref.insert(vt(key_ref,value)) </td>
119      <td class="table_cells"> <strong>insert_at_a</strong>(ref, key_ref) </td>
120    </tr>
121    <td class="table_cells">ref[value] = value_ref</td>
122    <td class="table_cells"><b>assign_key_a</b>(ref, value_ref)</td>
123  </tr>
124  <td class="table_cells">ref.erase(ref,value)</td>
125  <td class="table_cells"><b>erase_a</b>(ref)</td>
126  </tr>
127  <td class="table_cells">ref.erase(ref,key_ref)</td>
128    <td class="table_cells"><b>erase_a</b>(ref, key_ref)</td>
129  </tr>
130</table>
131<table width="90%" border="0" align="center">
132  <tr> 
133    <td class="table_title" colspan="8"> Miscellanous actors </td>
134  </tr>
135  <tr> 
136    <td width="30%" class="table_cells">swaps aref and bref</td>
137    <td width="70%" class="table_cells"><strong>swap_a</strong>(aref, bref)</td>
138  </tr>
139</table>
140<h3>Include Files</h3>
141<p>The header files for the predefined actors are located in <tt>boost/spirit/actor</tt>.
142  The file <tt>actors.hpp</tt> contains all the includes for all the actors. You
143  may include just the specific header files that you need. The list below enumerates
144  the header files.</p>
145<pre>    <span class="preprocessor">#include</span> <span class="special">&lt;</span>boost<span class="special">/</span>spirit<span class="special">/</span>actor<span class="special">/</span><span class="identifier">assign_actor</span><span class="special">.</span>hpp<span class="special">&gt;<br></span>    <span class="preprocessor">#include</span> <span class="special">&lt;</span>boost<span class="special">/</span>spirit<span class="special">/</span>actor<span class="special">/</span><span class="identifier">assign_key</span><span class="special">.</span>hpp<span class="special">&gt;</span><span class="special"></span><span class="special"></span>
146    <span class="preprocessor">#include</span> <span class="special">&lt;</span>boost<span class="special">/</span>spirit<span class="special">/</span>actor<span class="special">/</span><span class="identifier">clear_actor</span><span class="special">.</span>hpp<span class="special">&gt;</span><span class="special"></span><span class="special"></span>
147    <span class="preprocessor">#include</span> <span class="special">&lt;</span>boost<span class="special">/</span>spirit<span class="special">/</span>actor<span class="special">/</span><span class="identifier">decrement_actor</span><span class="special">.</span>hpp<span class="special">&gt;</span><span class="special"></span><span class="special"></span>
148    <span class="preprocessor">#include</span> <span class="special">&lt;</span>boost<span class="special">/</span>spirit<span class="special">/</span>actor<span class="special">/</span><span class="identifier">erase_actor</span><span class="special">.</span>hpp<span class="special">&gt;</span><span class="special"></span> <br>    <span class="preprocessor">#include</span> <span class="special">&lt;</span>boost<span class="special">/</span>spirit<span class="special">/</span>actor<span class="special">/</span><span class="identifier">increment_actor</span><span class="special">.</span>hpp<span class="special">&gt;<br></span>    <span class="preprocessor">#include</span> <span class="special">&lt;</span>boost<span class="special">/</span>spirit<span class="special">/</span>actor<span class="special">/</span><span class="identifier">insert_key_actor</span><span class="special">.</span>hpp<span class="special">&gt;</span><span class="special"></span><span class="special"></span>
149    <span class="preprocessor">#include</span> <span class="special">&lt;</span>boost<span class="special">/</span>spirit<span class="special">/</span>actor<span class="special">/</span>insert_at_actor.hpp<span class="special">&gt;</span>
150    <span class="preprocessor">#include</span> <span class="special">&lt;</span>boost<span class="special">/</span>spirit<span class="special">/</span>actor<span class="special">/</span><span class="identifier">push_back_actor</span><span class="special">.</span>hpp<span class="special">&gt;</span><span class="special"></span><span class="special"></span>
151    <span class="preprocessor">#include</span> <span class="special">&lt;</span>boost<span class="special">/</span>spirit<span class="special">/</span>actor<span class="special">/</span><span class="identifier">push_front_actor</span><span class="special">.</span>hpp<span class="special">&gt;</span><span class="special"></span><span class="special"></span>
152    <span class="preprocessor">#include</span> <span class="special">&lt;</span>boost<span class="special">/</span>spirit<span class="special">/</span>actor<span class="special">/</span><span class="identifier">swap_actor</span><span class="special">.</span>hpp<span class="special">&gt;</span><span class="special"></span><span class="special"></span></pre>
153<h3>Examples</h3>
154<h4>Increment a value</h4>
155<p>
156Suppose that your input string is </p>
157<code>
158<pre>    1,2,-3,4,...
159</pre>
160</code><p>
161and we want to count the number of ints. The actor <tt>increment_a</tt> applies <tt>++</tt> to its reference:</p>
162<code>
163<pre>    <span class=keyword>int </span><span class=identifier>count </span><span class=special>= </span><span class=number>0</span><span class=special>;   
164    </span><span class=identifier>rule</span><span class=special>&lt;&gt; </span><span class=identifier>r </span><span class=special>= </span><span class=identifier>list_p</span><span class=special>.</span><span class=identifier>direct</span><span class=special>(</span><span class=identifier>int_p</span><span class=special>[</span><span class=identifier>increment_a</span><span class=special>(</span><span class=identifier>count</span><span class=special>)], </span><span class=identifier>ch_p</span><span class=special>(</span><span class=literal>','</span><span class=special>));</span></pre>
165</code> 
166<h4>Append values to a vector (or other container)</h4>
167<p> Here, you want to fill a <tt>vector&lt;int&gt;</tt> with the numbers. The
168  actor <tt>push_back_a</tt> can be used to insert the integers at the back of
169  the vector:</p>
170<code>
171<pre>    <span class=identifier>vector</span><span class=special>&lt;</span><span class=keyword>int</span><span class=special>&gt; </span><span class=identifier>v</span><span class=special>;
172    </span><span class=identifier>rule</span><span class=special>&lt;&gt; </span><span class=identifier>r </span><span class=special>= </span><span class=identifier>list_p</span><span class=special>.</span><span class=identifier>direct</span><span class=special>(</span><span class=identifier>int_p</span><span class=special>[</span><span class=identifier>push_back_a</span><span class=special>(</span><span class=identifier>v</span><span class=special>)], </span><span class=identifier>ch_p</span><span class=special>(</span><span class=literal>','</span><span class=special>));</span></pre>
173</code>
174<h4>insert key-value pairs into a map</h4><p>
175Suppose that your input string is </p>
176<code> 
177<pre>    (1,2) (3,4) ...
178</pre>
179</code>
180<p> and you want to parse the pair into a <tt>map&lt;int,int&gt;</tt>. <tt>assign_a</tt> 
181  can be used to store key and values in a temporary key variable, while <tt>insert_a</tt> 
182  is used to insert it into the map:</p>
183<pre>    <code><span class=identifier>map</span><span class=special>&lt;</span><span class=keyword>int</span><span class=special>, </span><span class=keyword>int</span><span class="special">&gt;::</span>value_type<span class=keyword> </span>k<span class=special>;
184    </span><span class=identifier>map</span><span class=special>&lt;</span><span class=keyword>int</span><span class=special>, </span><span class=keyword>int</span><span class=special>&gt; </span><span class=identifier>m</span><span class=special>;
185   
186    </span><span class=identifier>rule</span><span class=special>&lt;&gt; </span><span class=identifier>pair </span><span class=special>= </span><span class=identifier>
187        confix_p</span><span class=special>(
188            </span><span class=literal>'('</span><span class=special>
189          , </span><span class=identifier>int_p</span><span class=special>[</span><span class=identifier>assign_a</span><span class=special>(</span>k.first<span class=special>)] &gt;&gt; </span><span class=literal>','</span><span class=special> &gt;&gt; </span><span class=identifier>int_p</span><span class=special>[</span><span class=identifier>assign_a</span><span class=special>(</span>k.second<span class=special>)]
190          ,</span><span class=literal> ')'
191        </span><span class=special>)<br>        [</span><span class=identifier>insert_at_a</span><span class=special>(</span><span class=identifier>m</span><span class=special>, </span><span class=identifier>k</span><span class=identifier></span><span class=special>)]
192        ;</span></code></pre> 
193<h2>Policy holder actors and policy actions</h2>
194<p> The action takes place through a call to the <tt>()</tt> operator: single
195  argument <tt>()</tt> operator call for character parsers and two argument (first,
196  last) call for phrase parsers. Actors should implement at least one of the two
197  <tt>()</tt> operator.</p>
198<p>
199A lot of actors need to store reference to one or more objects. For
200example, actions on container need to store a reference to the container.</p>
201<p> Therefore, this kind of actor have been broken down into <strong>a)</strong> 
202  an action policy that does the action (act member function), <strong>b)</strong> 
203  policy holder actor that stores the references and feeds the act member function.</p>
204<h3>Policy holder actors</h3>
205<p> The available policy holders are enumerated below.</p>
206<table width="90%" border="0" align="center">
207  <tr> 
208    <td class="table_title" colspan="24"> Policy holders </td>
209  </tr>
210  <tr>
211    <td class="table_cells">Name</td>
212    <td class="table_cells">Stored variables</td>
213    <td class="table_cells">Act signature</td>
214  </tr>
215  <td class="table_cells">ref_actor</td>
216  <td class="table_cells">1 reference</td>
217  <td class="table_cells"><tt>act(ref)</tt></td>
218  </tr>
219  <td class="table_cells">ref_value_actor</td>
220  <td class="table_cells">1 ref</td>
221    <td class="table_cells"> <tt>act(ref, value)</tt> or <tt>act(ref, first, last)</tt></td>
222  </tr>
223    <td class="table_cells">ref_const_ref_actor</td>
224  <td class="table_cells">1 ref and 1 const ref</td>
225  <td class="table_cells"><tt>act(ref, const_ref)</tt></td>
226  </tr>
227    <td class="table_cells">ref_const_ref_value_actor</td>
228  <td class="table_cells">1 ref</td>
229    <td class="table_cells"><tt>act(ref, value)</tt> or <tt>act(ref, first, last)</tt></td>
230  </tr>
231    <td class="table_cells">ref_const_ref_const_ref_actor</td>
232  <td class="table_cells">1 ref, 2 const ref</td>
233  <td class="table_cells"><tt>act(ref, const_ref1, const_ref2)</tt></td>
234  </tr>
235</table>
236<h3>Include Files</h3>
237<p>The predefined policy header files are located in <tt>boost/spirit/actor</tt>:</p>
238<pre>    <span class="preprocessor">#include</span> <span class="special">&lt;</span>boost<span class="special">/</span>spirit<span class="special">/</span>actor<span class="special">/</span>ref_actor<span class="special">.</span>hpp<span class="special">&gt;<br></span>    <span class="preprocessor">#include</span> <span class="special">&lt;</span>boost<span class="special">/</span>spirit<span class="special">/</span>actor<span class="special">/</span>ref_value_actor<span class="special">.</span>hpp<span class="special">&gt;</span><span class="special"></span><span class="special"></span>
239    <span class="preprocessor">#include</span> <span class="special">&lt;</span>boost<span class="special">/</span>spirit<span class="special">/</span>actor<span class="special">/</span>ref_const_ref<span class="special">.</span>hpp<span class="special">&gt;</span><span class="special"></span>
240    <span class="preprocessor">#include</span> <span class="special">&lt;</span>boost<span class="special">/</span>spirit<span class="special">/</span>actor<span class="special">/</span>ref_const_ref_value<span class="special">.</span>hpp<span class="special">&gt;</span><span class="special"></span>
241    <span class="preprocessor">#include</span> <span class="special">&lt;</span>boost<span class="special">/</span>spirit<span class="special">/</span>actor<span class="special">/</span>ref_const_ref_value<span class="special">.</span>hpp<span class="special">&gt;</span><span class="special"></span>
242    <span class="preprocessor">#include</span> <span class="special">&lt;</span>boost<span class="special">/</span>spirit<span class="special">/</span>actor<span class="special">/</span>ref_const_ref_const_ref<span class="special">.</span>hpp<span class="special">&gt;</span><span class="special"></span></pre>
243<h3>Holder naming convention</h3>
244<p> Policy holder have the following naming convention:</p>
245<pre>    <code>&lt;member&gt;_ &gt;&gt; *&lt;member&gt; &gt;&gt; !value &gt;&gt; actor</code></pre>
246<p> where <tt>member</tt> is the action policy member which can be of type:</p>
247<ul>
248  <li>ref, a reference</li>
249  <li>const_ref, a const reference</li>
250  <li>value, by value</li>
251  <li>empty, no stored members</li>
252</ul>
253<p> and <tt>value</tt> states if the policy uses the parse result or not.</p>
254<h3>Holder example: <tt>ref_actor</tt> class</h3>
255<pre><code>    <span class=comment>// this is the building block for action that 
256    // take a reference and the parse result
257
258    </span><span class=keyword>template</span><span class=special>&lt;
259        </span><span class=keyword>typename </span><span class=identifier>T</span><span class=special>,</span><span class="comment"> // reference type</span><span class=identifier>
260        </span><span class=keyword>typename </span><span class=identifier>ActionT </span><span class=comment>// action policy
261    </span><span class=special>&gt;
262    </span><span class=keyword>class </span><span class=identifier>ref_value_actor </span><span class=special>: </span><span class=keyword>public </span><span class=identifier>ActionT
263    </span><span class=special>{
264</span>    <span class=keyword>public</span><span class=special>:
265
266        </span><span class=keyword>explicit </span><span class=identifier>ref_value_actor</span><span class=special>(</span><span class=identifier>T</span><span class=special>&amp; </span><span class=identifier>ref_</span><span class=special>)
267        : </span><span class=identifier>ref</span><span class=special>(</span><span class=identifier>ref_</span><span class=special>){}
268
269        </span><span class=keyword>template</span><span class=special>&lt;</span><span class=keyword>typename </span><span class=identifier>T2</span><span class=special>&gt;
270        </span><span class=keyword>void operator</span><span class=special>()(</span><span class=identifier>T2 </span><span class=keyword>const</span><span class=special>&amp; </span><span class=identifier>val</span><span class=special>) </span><span class=keyword>const
271        </span><span class=special>{
272            </span><span class=identifier>act</span><span class=special>(</span><span class=identifier>ref</span><span class=special>, </span><span class=identifier>val</span><span class=special>);</span><span class="comment"> // defined in ActionT</span><span class=identifier>
273        </span><span class=special>}
274
275        </span><span class=keyword>template</span><span class=special>&lt;</span><span class=keyword>typename </span><span class=identifier>IteratorT</span><span class=special>&gt;
276        </span><span class=keyword>void operator</span><span class=special>()(
277            </span><span class=identifier>IteratorT </span><span class=keyword>const</span><span class=special>&amp; </span><span class=identifier>first</span><span class=special>,
278            </span><span class=identifier>IteratorT </span><span class=keyword>const</span><span class=special>&amp; </span><span class=identifier>last</span><span class=special>) </span><span class=keyword>const
279        </span><span class=special>{
280            </span><span class=identifier>act</span><span class=special>(</span><span class=identifier>ref</span><span class=special>,</span><span class=identifier>first</span><span class=special>,</span><span class=identifier>last</span><span class=special>);</span><span class="comment"> // defined in ActionT</span><span class=identifier>
281        </span><span class=special>}
282
283    </span><span class=keyword>private</span><span class=special>:
284
285</span><span class=identifier>       T</span><span class=special>&amp; </span><span class=identifier>ref</span><span class=special>;
286    };</span></code></pre> 
287<h3>Actor example: <tt>assign_actor</tt></h3>
288<code>
289<pre>    <span class=comment>// assign_action assigns the parse result to the reference
290
291    </span><span class=keyword>struct </span><span class=identifier>assign_action
292    </span><span class=special>{
293        </span><span class=keyword>template</span><span class=special>&lt;
294            </span><span class=keyword>typename </span><span class=identifier>T</span><span class=special>,
295            </span><span class=keyword>typename </span><span class=identifier>ValueT
296        </span><span class=special>&gt;
297        </span><span class=keyword>void </span><span class=identifier>act</span><span class=special>(</span><span class=identifier>T</span><span class=special>&amp; </span><span class=identifier>ref</span><span class=special>, </span><span class=identifier>ValueT </span><span class=keyword>const</span><span class=special>&amp; </span><span class=identifier>value</span><span class=special>) </span><span class=keyword>const
298        </span><span class=special>{
299            </span><span class=identifier>ref</span><span class=special> = </span><span class=special></span><span class=identifier>value</span><span class=special>;
300        }
301       
302        </span><span class=keyword>template</span><span class=special>&lt;
303            </span><span class=keyword>typename </span><span class=identifier>T</span><span class=special>,
304            </span><span class=keyword>typename </span><span class=identifier>IteratorT
305        </span><span class=special>&gt;
306        </span><span class=keyword>void </span><span class=identifier>act</span><span class=special>(
307            </span><span class=identifier>T</span><span class=special>&amp; </span><span class=identifier>ref</span><span class=special>,
308            </span><span class=identifier>IteratorT </span><span class=keyword>const</span><span class=special>&amp; </span><span class=identifier>first</span><span class=special>,
309            </span><span class=identifier>IteratorT </span><span class=keyword>const</span><span class=special>&amp; </span><span class=identifier>last</span><span class=special>) </span><span class=keyword>const
310        </span><span class=special>{
311            </span><span class=keyword>typedef </span><span class=keyword>typename </span><span class=identifier>T</span><span class=special>::</span><span class=identifier>value_type </span><span class=identifier>value_type</span><span class=special>;
312            </span><span class=identifier>value_type </span><span class=identifier>vt</span><span class=special>(</span><span class=identifier>first</span><span class=special>,</span><span class=identifier> last</span><span class=special>);
313            </span><span class=identifier>ref</span><span class=special> = </span><span class=special></span><span class=identifier>vt</span><span class=special>;
314        }
315    };</span></pre>
316</code> 
317<h3>Helper function example: <tt>assign_a</tt> function</h3>
318<code> 
319<pre>
320    <span class=comment>// assign_a is a polymorphic helper function that generators an
321    // assign_actor based on ref_value_actor, assign_action and the
322    // type of its argument.
323
324    </span><span class=keyword>template</span><span class=special>&lt;</span><span class=keyword>typename </span><span class=identifier>T</span><span class=special>&gt;
325    </span><span class=keyword>inline </span><span class=identifier>ref_value_actor</span><span class=special>&lt;</span><span class=identifier>T</span><span class=special>, </span>assign<span class=identifier>_action</span><span class=special>&gt;</span><span class=identifier>
326    assign_a</span><span class=special>(</span><span class=identifier>T</span><span class=special>&amp; </span><span class=identifier>ref</span><span class=special>)
327    {
328        </span><span class=keyword>return </span><span class=identifier>ref_value_actor</span><span class=special>&lt;</span><span class=identifier>T</span><span class=special>,</span><span class=identifier> assign_action</span><span class=special>&gt;(</span><span class=identifier>ref</span><span class=special>);
329    }</span></pre>
330</code>
331<table border="0">
332  <tr>
333    <td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
334    <td width="30"><a href="indepth_the_parser_context.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
335    <td width="20"><a href="parametric_parsers.html"><img src="theme/r_arr.gif" width="20" height="19" border="0"></a></td>
336  </tr>
337</table>
338<br>
339<hr size="1">
340<p class="copyright">Copyright &copy; 2003 <font color="#666666">Jonathan de Halleux</font><font size="2"><font size="2"><font color="#666666"> 
341  </font></font> </font><br>
342  Copyright &copy; 2003 Joel de Guzman<br>
343  <br>
344  <font size="2">Use, modification and distribution is subject to the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) </font>  </p>
345</body>
346</html>
Note: See TracBrowser for help on using the repository browser.