1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Store an Attribute Value after a Parser Produced a Value (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="../assign_to.html" title="Store a Parsed Attribute Value (Qi)"> 9<link rel="prev" href="assign_to_attribute_from_iterators.html" title="Store an Attribute after a Parser Produced a Pair of Iterators (Qi)"> 10<link rel="next" href="assign_to_container_from_value.html" title="Store an Attribute Value into a Container after a Parser Produced a Value (Qi)"> 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="assign_to_attribute_from_iterators.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../assign_to.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="assign_to_container_from_value.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h5 class="title"> 27<a name="spirit.advanced.customize.assign_to.assign_to_attribute_from_value"></a><a class="link" href="assign_to_attribute_from_value.html" title="Store an Attribute Value after a Parser Produced a Value (Qi)">Store 28 an Attribute Value after a Parser Produced a Value (Qi)</a> 29</h5></div></div></div> 30<h6> 31<a name="spirit.advanced.customize.assign_to.assign_to_attribute_from_value.h0"></a> 32 <span class="phrase"><a name="spirit.advanced.customize.assign_to.assign_to_attribute_from_value.assign_to_attribute_from_value"></a></span><a class="link" href="assign_to_attribute_from_value.html#spirit.advanced.customize.assign_to.assign_to_attribute_from_value.assign_to_attribute_from_value">assign_to_attribute_from_value</a> 33 </h6> 34<p> 35 The template <code class="computeroutput"><span class="identifier">assign_to_attribute_from_value</span></code> 36 is a type used as an attribute customization point. It is invoked by 37 all primitive <span class="emphasis"><em>Qi</em></span> parsers in order to store a parsed 38 attribute value into the attribute instance provided by the user, if 39 this attribute is not a container type (<code class="computeroutput"><span class="identifier">is_container</span><span class="special"><</span><span class="identifier">T</span><span class="special">>::</span><span class="identifier">type</span></code> 40 evaluates to <code class="computeroutput"><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">false_</span></code>, where <code class="computeroutput"><span class="identifier">T</span></code> 41 is the attribute type). 42 </p> 43<h6> 44<a name="spirit.advanced.customize.assign_to.assign_to_attribute_from_value.h1"></a> 45 <span class="phrase"><a name="spirit.advanced.customize.assign_to.assign_to_attribute_from_value.module_headers"></a></span><a class="link" href="assign_to_attribute_from_value.html#spirit.advanced.customize.assign_to.assign_to_attribute_from_value.module_headers">Module 46 Headers</a> 47 </h6> 48<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</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">qi</span><span class="special">/</span><span class="identifier">detail</span><span class="special">/</span><span class="identifier">assign_to</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 49</pre> 50<p> 51 Also, see <a class="link" href="../../../structure/include.html" title="Include">Include Structure</a>. 52 </p> 53<div class="note"><table border="0" summary="Note"> 54<tr> 55<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td> 56<th align="left">Note</th> 57</tr> 58<tr><td align="left" valign="top"><p> 59 This header file does not need to be included directly by any user 60 program as it is normally included by other Spirit header files relying 61 on its content. 62 </p></td></tr> 63</table></div> 64<h6> 65<a name="spirit.advanced.customize.assign_to.assign_to_attribute_from_value.h2"></a> 66 <span class="phrase"><a name="spirit.advanced.customize.assign_to.assign_to_attribute_from_value.namespace"></a></span><a class="link" href="assign_to_attribute_from_value.html#spirit.advanced.customize.assign_to.assign_to_attribute_from_value.namespace">Namespace</a> 67 </h6> 68<div class="informaltable"><table class="table"> 69<colgroup><col></colgroup> 70<thead><tr><th> 71 <p> 72 Name 73 </p> 74 </th></tr></thead> 75<tbody><tr><td> 76 <p> 77 <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> 78 </p> 79 </td></tr></tbody> 80</table></div> 81<h6> 82<a name="spirit.advanced.customize.assign_to.assign_to_attribute_from_value.h3"></a> 83 <span class="phrase"><a name="spirit.advanced.customize.assign_to.assign_to_attribute_from_value.synopsis"></a></span><a class="link" href="assign_to_attribute_from_value.html#spirit.advanced.customize.assign_to.assign_to_attribute_from_value.synopsis">Synopsis</a> 84 </h6> 85<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Attrib</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Enable</span><span class="special">></span> 86<span class="keyword">struct</span> <span class="identifier">assign_to_attribute_from_value</span> 87<span class="special">{</span> 88 <span class="keyword">static</span> <span class="keyword">void</span> <span class="identifier">call</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">val</span><span class="special">,</span> <span class="identifier">Attrib</span><span class="special">&</span> <span class="identifier">attr</span><span class="special">);</span> 89<span class="special">};</span> 90</pre> 91<h6> 92<a name="spirit.advanced.customize.assign_to.assign_to_attribute_from_value.h4"></a> 93 <span class="phrase"><a name="spirit.advanced.customize.assign_to.assign_to_attribute_from_value.template_parameters"></a></span><a class="link" href="assign_to_attribute_from_value.html#spirit.advanced.customize.assign_to.assign_to_attribute_from_value.template_parameters">Template 94 parameters</a> 95 </h6> 96<div class="informaltable"><table class="table"> 97<colgroup> 98<col> 99<col> 100<col> 101</colgroup> 102<thead><tr> 103<th> 104 <p> 105 Parameter 106 </p> 107 </th> 108<th> 109 <p> 110 Description 111 </p> 112 </th> 113<th> 114 <p> 115 Default 116 </p> 117 </th> 118</tr></thead> 119<tbody> 120<tr> 121<td> 122 <p> 123 <code class="computeroutput"><span class="identifier">Attrib</span></code> 124 </p> 125 </td> 126<td> 127 <p> 128 The type, <code class="computeroutput"><span class="identifier">Attrib</span></code> 129 is the type of the attribute as passed in by the user. This 130 type is not a container type (<code class="computeroutput"><span class="identifier">is_container</span><span class="special"><</span><span class="identifier">Attrib</span><span class="special">>::</span><span class="identifier">type</span></code> 131 evaluates to <code class="computeroutput"><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">false_</span></code>). 132 </p> 133 </td> 134<td> 135 <p> 136 none 137 </p> 138 </td> 139</tr> 140<tr> 141<td> 142 <p> 143 <code class="computeroutput"><span class="identifier">T</span></code> 144 </p> 145 </td> 146<td> 147 <p> 148 The type, <code class="computeroutput"><span class="identifier">T</span></code> 149 is the type of the attribute instance as produced by the parser. 150 </p> 151 </td> 152<td> 153 <p> 154 none 155 </p> 156 </td> 157</tr> 158<tr> 159<td> 160 <p> 161 <code class="computeroutput"><span class="identifier">Enable</span></code> 162 </p> 163 </td> 164<td> 165 <p> 166 Helper template parameter usable to selectively enable or disable 167 certain specializations of <code class="computeroutput"><span class="identifier">assign_to_attribute_from_value</span></code> 168 utilizing SFINAE (i.e. <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">enable_if</span></code> 169 or <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">disable_if</span></code>). 170 </p> 171 </td> 172<td> 173 <p> 174 <code class="computeroutput"><span class="keyword">void</span></code> 175 </p> 176 </td> 177</tr> 178</tbody> 179</table></div> 180<div class="variablelist"> 181<p class="title"><b>Notation</b></p> 182<dl class="variablelist"> 183<dt><span class="term"><code class="computeroutput"><span class="identifier">Attrib</span></code></span></dt> 184<dd><p> 185 A type to be used as the target to store the attribute value in. 186 This type is guaranteed not to be a container type (<code class="computeroutput"><span class="identifier">is_container</span><span class="special"><</span><span class="identifier">Attrib</span><span class="special">>::</span><span class="identifier">type</span></code> evaluates to <code class="computeroutput"><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">false_</span></code>). 187 </p></dd> 188<dt><span class="term"><code class="computeroutput"><span class="identifier">attr</span></code></span></dt> 189<dd><p> 190 An attribute instance of type <code class="computeroutput"><span class="identifier">Attrib</span></code>. 191 </p></dd> 192<dt><span class="term"><code class="computeroutput"><span class="identifier">T</span></code></span></dt> 193<dd><p> 194 A type as produced by the parser. The parser temporarily stores 195 its parsed values using this type. 196 </p></dd> 197<dt><span class="term"><code class="computeroutput"><span class="identifier">t</span></code></span></dt> 198<dd><p> 199 An attribute instance of type <code class="computeroutput"><span class="identifier">T</span></code>. 200 </p></dd> 201</dl> 202</div> 203<h6> 204<a name="spirit.advanced.customize.assign_to.assign_to_attribute_from_value.h5"></a> 205 <span class="phrase"><a name="spirit.advanced.customize.assign_to.assign_to_attribute_from_value.expression_semantics"></a></span><a class="link" href="assign_to_attribute_from_value.html#spirit.advanced.customize.assign_to.assign_to_attribute_from_value.expression_semantics">Expression 206 Semantics</a> 207 </h6> 208<div class="informaltable"><table class="table"> 209<colgroup> 210<col> 211<col> 212</colgroup> 213<thead><tr> 214<th> 215 <p> 216 Expression 217 </p> 218 </th> 219<th> 220 <p> 221 Semantics 222 </p> 223 </th> 224</tr></thead> 225<tbody><tr> 226<td> 227 <p> 228</p> 229<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">assign_to_attribute_from_value</span><span class="special"><</span><span class="identifier">Attrib</span><span class="special">,</span> <span class="identifier">T</span><span class="special">>::</span><span class="identifier">call</span><span class="special">(</span><span class="identifier">t</span><span class="special">,</span> <span class="identifier">attr</span><span class="special">)</span></pre> 230<p> 231 </p> 232 </td> 233<td> 234 <p> 235 Copy (assign) the value <code class="computeroutput"><span class="identifier">t</span></code> 236 to the attribute <code class="computeroutput"><span class="identifier">attr</span></code>. 237 </p> 238 </td> 239</tr></tbody> 240</table></div> 241<h6> 242<a name="spirit.advanced.customize.assign_to.assign_to_attribute_from_value.h6"></a> 243 <span class="phrase"><a name="spirit.advanced.customize.assign_to.assign_to_attribute_from_value.predefined_specializations"></a></span><a class="link" href="assign_to_attribute_from_value.html#spirit.advanced.customize.assign_to.assign_to_attribute_from_value.predefined_specializations">Predefined 244 Specializations</a> 245 </h6> 246<div class="informaltable"><table class="table"> 247<colgroup> 248<col> 249<col> 250</colgroup> 251<thead><tr> 252<th> 253 <p> 254 Template Parameters 255 </p> 256 </th> 257<th> 258 <p> 259 Semantics 260 </p> 261 </th> 262</tr></thead> 263<tbody> 264<tr> 265<td> 266 <p> 267 <code class="computeroutput"><span class="identifier">Attrib</span></code>, <code class="computeroutput"><span class="identifier">T</span></code> 268 </p> 269 </td> 270<td> 271 <p> 272 Assign the argument <code class="computeroutput"><span class="identifier">t</span></code> 273 to <code class="computeroutput"><span class="identifier">attr</span></code>. 274 </p> 275 </td> 276</tr> 277<tr> 278<td> 279 <p> 280 <code class="computeroutput"><span class="identifier">unused_type</span></code>, 281 <code class="computeroutput"><span class="identifier">T</span></code> 282 </p> 283 </td> 284<td> 285 <p> 286 Do nothing. 287 </p> 288 </td> 289</tr> 290</tbody> 291</table></div> 292<h6> 293<a name="spirit.advanced.customize.assign_to.assign_to_attribute_from_value.h7"></a> 294 <span class="phrase"><a name="spirit.advanced.customize.assign_to.assign_to_attribute_from_value.when_to_implement"></a></span><a class="link" href="assign_to_attribute_from_value.html#spirit.advanced.customize.assign_to.assign_to_attribute_from_value.when_to_implement">When 295 to implement</a> 296 </h6> 297<p> 298 The customization point <code class="computeroutput"><span class="identifier">assign_to_attribute_from_value</span></code> 299 needs to be implemented for a specific type whenever the default implementation 300 as shown above is not applicable. Examples for this could be that the 301 type <code class="computeroutput"><span class="identifier">Attrib</span></code> is not copy 302 constructible. 303 </p> 304</div> 305<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 306<td align="left"></td> 307<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p> 308 Distributed under the Boost Software License, Version 1.0. (See accompanying 309 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>) 310 </p> 311</div></td> 312</tr></table> 313<hr> 314<div class="spirit-nav"> 315<a accesskey="p" href="assign_to_attribute_from_iterators.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../assign_to.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="assign_to_container_from_value.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> 316</div> 317</body> 318</html> 319