• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>Re-Initialize an Attribute Value before Parsing (Qi)</title>
5<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css">
6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7<link rel="home" href="../../../index.html" title="Spirit 2.5.8">
8<link rel="up" href="../customize.html" title="Customization of Spirit's Attribute Handling">
9<link rel="prev" href="store_value/push_back.html" title="Store a Parsed Attribute Value into a Container (Qi)">
10<link rel="next" href="extract_from.html" title="Extract an Attribute Value to Generate Output (Karma)">
11</head>
12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13<table cellpadding="2" width="100%"><tr>
14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
15<td align="center"><a href="../../../../../../../index.html">Home</a></td>
16<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19<td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
20</tr></table>
21<hr>
22<div class="spirit-nav">
23<a accesskey="p" href="store_value/push_back.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../customize.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="extract_from.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
24</div>
25<div class="section">
26<div class="titlepage"><div><div><h4 class="title">
27<a name="spirit.advanced.customize.clear_value"></a><a class="link" href="clear_value.html" title="Re-Initialize an Attribute Value before Parsing (Qi)">Re-Initialize
28        an Attribute Value before Parsing (Qi)</a>
29</h4></div></div></div>
30<h6>
31<a name="spirit.advanced.customize.clear_value.h0"></a>
32          <span class="phrase"><a name="spirit.advanced.customize.clear_value.clear_value"></a></span><a class="link" href="clear_value.html#spirit.advanced.customize.clear_value.clear_value">clear_value</a>
33        </h6>
34<p>
35          The template <code class="computeroutput"><span class="identifier">clear_value</span></code>
36          is a type used as an attribute customization point. It is invoked by the
37          <span class="emphasis"><em>Qi</em></span> repetitive parsers (<a class="link" href="../../qi/reference/operator/kleene.html" title="Kleene Parser (*a)">Kleene</a>,
38          <a class="link" href="../../qi/reference/operator/plus.html" title="Plus Parser (+a)">Plus</a>, <a class="link" href="../../qi/reference/operator/list.html" title="List Parser (a % b)">List</a>,
39          and <a class="link" href="../../qi/reference/directive/repeat.html" title="Repetition Parser Directive (repeat[])">Repeat</a>)
40          in order to re-initialize the attribute instance passed to the embedded
41          parser after it has been stored in the provided container. This re-initialized
42          attribute instance is reused during the next iteration of the repetitive
43          parser.
44        </p>
45<h6>
46<a name="spirit.advanced.customize.clear_value.h1"></a>
47          <span class="phrase"><a name="spirit.advanced.customize.clear_value.module_headers"></a></span><a class="link" href="clear_value.html#spirit.advanced.customize.clear_value.module_headers">Module Headers</a>
48        </h6>
49<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">spirit</span><span class="special">/</span><span class="identifier">home</span><span class="special">/</span><span class="identifier">support</span><span class="special">/</span><span class="identifier">attributes</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
50</pre>
51<p>
52          Also, see <a class="link" href="../../structure/include.html" title="Include">Include Structure</a>.
53        </p>
54<div class="note"><table border="0" summary="Note">
55<tr>
56<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../images/note.png"></td>
57<th align="left">Note</th>
58</tr>
59<tr><td align="left" valign="top"><p>
60            This header file does not need to be included directly by any user program
61            as it is normally included by other Spirit header files relying on its
62            content.
63          </p></td></tr>
64</table></div>
65<h6>
66<a name="spirit.advanced.customize.clear_value.h2"></a>
67          <span class="phrase"><a name="spirit.advanced.customize.clear_value.namespace"></a></span><a class="link" href="clear_value.html#spirit.advanced.customize.clear_value.namespace">Namespace</a>
68        </h6>
69<div class="informaltable"><table class="table">
70<colgroup><col></colgroup>
71<thead><tr><th>
72                  <p>
73                    Name
74                  </p>
75                </th></tr></thead>
76<tbody><tr><td>
77                  <p>
78                    <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">traits</span></code>
79                  </p>
80                </td></tr></tbody>
81</table></div>
82<h6>
83<a name="spirit.advanced.customize.clear_value.h3"></a>
84          <span class="phrase"><a name="spirit.advanced.customize.clear_value.synopsis"></a></span><a class="link" href="clear_value.html#spirit.advanced.customize.clear_value.synopsis">Synopsis</a>
85        </h6>
86<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Attrib</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Enable</span><span class="special">&gt;</span>
87<span class="keyword">struct</span> <span class="identifier">clear_value</span>
88<span class="special">{</span>
89    <span class="keyword">static</span> <span class="keyword">void</span> <span class="identifier">call</span><span class="special">(</span><span class="identifier">Attrib</span><span class="special">&amp;</span> <span class="identifier">val</span><span class="special">);</span>
90<span class="special">};</span>
91</pre>
92<h6>
93<a name="spirit.advanced.customize.clear_value.h4"></a>
94          <span class="phrase"><a name="spirit.advanced.customize.clear_value.template_parameters"></a></span><a class="link" href="clear_value.html#spirit.advanced.customize.clear_value.template_parameters">Template
95          parameters</a>
96        </h6>
97<div class="informaltable"><table class="table">
98<colgroup>
99<col>
100<col>
101<col>
102</colgroup>
103<thead><tr>
104<th>
105                  <p>
106                    Parameter
107                  </p>
108                </th>
109<th>
110                  <p>
111                    Description
112                  </p>
113                </th>
114<th>
115                  <p>
116                    Default
117                  </p>
118                </th>
119</tr></thead>
120<tbody>
121<tr>
122<td>
123                  <p>
124                    <code class="computeroutput"><span class="identifier">Attrib</span></code>
125                  </p>
126                </td>
127<td>
128                  <p>
129                    The type, <code class="computeroutput"><span class="identifier">Attrib</span></code>
130                    of the attribute to be re-initialized.
131                  </p>
132                </td>
133<td>
134                  <p>
135                    none
136                  </p>
137                </td>
138</tr>
139<tr>
140<td>
141                  <p>
142                    <code class="computeroutput"><span class="identifier">Enable</span></code>
143                  </p>
144                </td>
145<td>
146                  <p>
147                    Helper template parameter usable to selectively enable or disable
148                    certain specializations of <code class="computeroutput"><span class="identifier">clear_value</span></code>
149                    utilizing SFINAE (i.e. <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">enable_if</span></code>
150                    or <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">disable_if</span></code>).
151                  </p>
152                </td>
153<td>
154                  <p>
155                    <code class="computeroutput"><span class="keyword">void</span></code>
156                  </p>
157                </td>
158</tr>
159</tbody>
160</table></div>
161<div class="variablelist">
162<p class="title"><b>Notation</b></p>
163<dl class="variablelist">
164<dt><span class="term"><code class="computeroutput"><span class="identifier">Attrib</span></code></span></dt>
165<dd><p>
166                A type to be used as a container to store attribute values in.
167              </p></dd>
168<dt><span class="term"><code class="computeroutput"><span class="identifier">attr</span></code></span></dt>
169<dd><p>
170                An attribute instance of type <code class="computeroutput"><span class="identifier">Attrib</span></code>.
171              </p></dd>
172<dt><span class="term"><code class="computeroutput"><span class="identifier">T1</span></code>, <code class="computeroutput"><span class="identifier">T2</span></code>, ...</span></dt>
173<dd><p>
174                Arbitrary types
175              </p></dd>
176</dl>
177</div>
178<h6>
179<a name="spirit.advanced.customize.clear_value.h5"></a>
180          <span class="phrase"><a name="spirit.advanced.customize.clear_value.expression_semantics"></a></span><a class="link" href="clear_value.html#spirit.advanced.customize.clear_value.expression_semantics">Expression
181          Semantics</a>
182        </h6>
183<div class="informaltable"><table class="table">
184<colgroup>
185<col>
186<col>
187</colgroup>
188<thead><tr>
189<th>
190                  <p>
191                    Expression
192                  </p>
193                </th>
194<th>
195                  <p>
196                    Semantics
197                  </p>
198                </th>
199</tr></thead>
200<tbody><tr>
201<td>
202                  <p>
203</p>
204<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">clear_value</span><span class="special">&lt;</span><span class="identifier">Attrib</span><span class="special">&gt;::</span><span class="identifier">call</span><span class="special">(</span><span class="identifier">Attrib</span><span class="special">&amp;</span> <span class="identifier">attr</span><span class="special">)</span></pre>
205<p>
206                  </p>
207                </td>
208<td>
209                  <p>
210                    Re-initialize the instance referred to by <code class="computeroutput"><span class="identifier">attr</span></code>
211                    in the most efficient way.
212                  </p>
213                </td>
214</tr></tbody>
215</table></div>
216<h6>
217<a name="spirit.advanced.customize.clear_value.h6"></a>
218          <span class="phrase"><a name="spirit.advanced.customize.clear_value.predefined_specializations"></a></span><a class="link" href="clear_value.html#spirit.advanced.customize.clear_value.predefined_specializations">Predefined
219          Specializations</a>
220        </h6>
221<p>
222          <a href="http://boost-spirit.com" target="_top">Spirit</a> predefines specializations
223          of this customization point for several types. The following table lists
224          those types together with the types exposed and the corresponding semantics:
225        </p>
226<div class="informaltable"><table class="table">
227<colgroup>
228<col>
229<col>
230</colgroup>
231<thead><tr>
232<th>
233                  <p>
234                    Template Parameters
235                  </p>
236                </th>
237<th>
238                  <p>
239                    Semantics
240                  </p>
241                </th>
242</tr></thead>
243<tbody>
244<tr>
245<td>
246                  <p>
247                    <code class="computeroutput"><span class="identifier">Attrib</span></code>
248                  </p>
249                </td>
250<td>
251                  <p>
252                    Re-initialize using assignment of default constructed value.
253                  </p>
254                </td>
255</tr>
256<tr>
257<td>
258                  <p>
259                    Any type <code class="computeroutput"><span class="identifier">T</span></code> for
260                    which <code class="computeroutput"><span class="identifier">is_container</span><span class="special">&lt;&gt;::</span><span class="identifier">type</span></code>
261                    is <code class="computeroutput"><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">true_</span></code>
262                  </p>
263                </td>
264<td>
265                  <p>
266                    Call the member function <code class="computeroutput"><span class="identifier">attr</span><span class="special">.</span><span class="identifier">clear</span><span class="special">()</span></code> for the passed attribute instance.
267                  </p>
268                </td>
269</tr>
270<tr>
271<td>
272                  <p>
273                    <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">Attrib</span><span class="special">&gt;</span></code>
274                  </p>
275                </td>
276<td>
277                  <p>
278                    Clear the <code class="computeroutput"><span class="identifier">optional</span></code>
279                    instance and leave it uninitialized.
280                  </p>
281                </td>
282</tr>
283<tr>
284<td>
285                  <p>
286                    <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">variant</span><span class="special">&lt;</span><span class="identifier">T1</span><span class="special">,</span>
287                    <span class="identifier">T2</span><span class="special">,</span>
288                    <span class="special">...&gt;</span></code>
289                  </p>
290                </td>
291<td>
292                  <p>
293                    Invoke the <code class="computeroutput"><span class="identifier">clear_value</span></code>
294                    customization point for the currently held value.
295                  </p>
296                </td>
297</tr>
298<tr>
299<td>
300                  <p>
301                    <code class="computeroutput"><span class="identifier">fusion</span><span class="special">::</span><span class="identifier">tuple</span><span class="special">&lt;</span><span class="identifier">T1</span><span class="special">,</span>
302                    <span class="identifier">T2</span><span class="special">,</span>
303                    <span class="special">...&gt;</span></code>
304                  </p>
305                </td>
306<td>
307                  <p>
308                    Invoke the <code class="computeroutput"><span class="identifier">clear_value</span></code>
309                    customization point for all elements of the tuple.
310                  </p>
311                </td>
312</tr>
313<tr>
314<td>
315                  <p>
316                    <code class="computeroutput"><span class="identifier">unused_type</span></code>
317                  </p>
318                </td>
319<td>
320                  <p>
321                    Do nothing.
322                  </p>
323                </td>
324</tr>
325</tbody>
326</table></div>
327<h6>
328<a name="spirit.advanced.customize.clear_value.h7"></a>
329          <span class="phrase"><a name="spirit.advanced.customize.clear_value.when_to_implement"></a></span><a class="link" href="clear_value.html#spirit.advanced.customize.clear_value.when_to_implement">When
330          to Implement</a>
331        </h6>
332<p>
333          The customization point <code class="computeroutput"><span class="identifier">clear_value</span></code>
334          needs to be implemented for a specific type whenever this type is to be
335          used as an attribute to be stored into a STL container and if the type
336          cannot be re-initialized using one of the specializations listed above.
337          Examples for this might be types not being default constructible or container
338          types not exposing a member function <code class="computeroutput"><span class="identifier">clear</span><span class="special">()</span></code>.
339        </p>
340</div>
341<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
342<td align="left"></td>
343<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p>
344        Distributed under the Boost Software License, Version 1.0. (See accompanying
345        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
346      </p>
347</div></td>
348</tr></table>
349<hr>
350<div class="spirit-nav">
351<a accesskey="p" href="store_value/push_back.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../customize.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="extract_from.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
352</div>
353</body>
354</html>
355