1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Extract From a Container Attribute Value to Generate Output (Karma)</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="extract_from.html" title="Extract an Attribute Value to Generate Output (Karma)"> 10<link rel="next" href="iterate.html" title="Extract Attribute Values to Generate Output from a Container (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="extract_from.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="iterate.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.extract_from_container"></a><a class="link" href="extract_from_container.html" title="Extract From a Container Attribute Value to Generate Output (Karma)">Extract 28 From a Container Attribute Value to Generate Output (Karma)</a> 29</h4></div></div></div> 30<h6> 31<a name="spirit.advanced.customize.extract_from_container.h0"></a> 32 <span class="phrase"><a name="spirit.advanced.customize.extract_from_container.extract_from_container"></a></span><a class="link" href="extract_from_container.html#spirit.advanced.customize.extract_from_container.extract_from_container">extract_from_container</a> 33 </h6> 34<p> 35 Before generating output for a value this value needs to extracted from 36 the attribute instance provided by the user. The customization point <code class="computeroutput"><span class="identifier">extract_from_container</span></code> is utilized to 37 adapt this extraction for any data type possibly used to store the values 38 to output. 39 </p> 40<div class="note"><table border="0" summary="Note"> 41<tr> 42<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../images/note.png"></td> 43<th align="left">Note</th> 44</tr> 45<tr><td align="left" valign="top"><p> 46 The interface of this customization point has been changed with Boost 47 V1.44. We added the <code class="computeroutput"><span class="identifier">Exposed</span></code> 48 template parameter to allow for more fine grained specializations of 49 the required <span class="emphasis"><em>Spirit.Karma</em></span> attribute transformations. 50 </p></td></tr> 51</table></div> 52<h6> 53<a name="spirit.advanced.customize.extract_from_container.h1"></a> 54 <span class="phrase"><a name="spirit.advanced.customize.extract_from_container.module_headers"></a></span><a class="link" href="extract_from_container.html#spirit.advanced.customize.extract_from_container.module_headers">Module 55 Headers</a> 56 </h6> 57<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">karma</span><span class="special">/</span><span class="identifier">detail</span><span class="special">/</span><span class="identifier">extract_from</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 58</pre> 59<p> 60 Also, see <a class="link" href="../../structure/include.html" title="Include">Include Structure</a>. 61 </p> 62<div class="note"><table border="0" summary="Note"> 63<tr> 64<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../images/note.png"></td> 65<th align="left">Note</th> 66</tr> 67<tr><td align="left" valign="top"><p> 68 This header file does not need to be included directly by any user program 69 as it is normally included by other Spirit header files relying on its 70 content. 71 </p></td></tr> 72</table></div> 73<h6> 74<a name="spirit.advanced.customize.extract_from_container.h2"></a> 75 <span class="phrase"><a name="spirit.advanced.customize.extract_from_container.namespace"></a></span><a class="link" href="extract_from_container.html#spirit.advanced.customize.extract_from_container.namespace">Namespace</a> 76 </h6> 77<div class="informaltable"><table class="table"> 78<colgroup><col></colgroup> 79<thead><tr><th> 80 <p> 81 Name 82 </p> 83 </th></tr></thead> 84<tbody><tr><td> 85 <p> 86 <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> 87 </p> 88 </td></tr></tbody> 89</table></div> 90<h6> 91<a name="spirit.advanced.customize.extract_from_container.h3"></a> 92 <span class="phrase"><a name="spirit.advanced.customize.extract_from_container.synopsis"></a></span><a class="link" href="extract_from_container.html#spirit.advanced.customize.extract_from_container.synopsis">Synopsis</a> 93 </h6> 94<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Exposed</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">Enable</span><span class="special">></span> 95<span class="keyword">struct</span> <span class="identifier">extract_from_container</span> 96<span class="special">{</span> 97 <span class="keyword">typedef</span> <span class="special"><</span><span class="identifier">unspecified</span><span class="special">></span> <span class="identifier">type</span><span class="special">;</span> 98 99 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Context</span><span class="special">></span> 100 <span class="keyword">static</span> <span class="identifier">type</span> <span class="identifier">call</span><span class="special">(</span><span class="identifier">Attrib</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">attr</span><span class="special">,</span> <span class="identifier">Context</span><span class="special">&</span> <span class="identifier">context</span><span class="special">);</span> 101<span class="special">};</span> 102</pre> 103<h6> 104<a name="spirit.advanced.customize.extract_from_container.h4"></a> 105 <span class="phrase"><a name="spirit.advanced.customize.extract_from_container.template_parameters"></a></span><a class="link" href="extract_from_container.html#spirit.advanced.customize.extract_from_container.template_parameters">Template 106 parameters</a> 107 </h6> 108<div class="informaltable"><table class="table"> 109<colgroup> 110<col> 111<col> 112</colgroup> 113<thead><tr> 114<th> 115 <p> 116 Parameter 117 </p> 118 </th> 119<th> 120 <p> 121 Description 122 </p> 123 </th> 124<th> 125 <p> 126 Default 127 </p> 128 </th> 129</tr></thead> 130<tbody> 131<tr> 132<td> 133 <p> 134 <code class="computeroutput"><span class="identifier">Exposed</span></code> 135 </p> 136 </td> 137<td> 138 <p> 139 The type, <code class="computeroutput"><span class="identifier">Exposed</span></code> 140 of the attribute natively exposed by the component the <code class="computeroutput"><span class="identifier">extract_from_container</span></code> is invoked 141 from. 142 </p> 143 </td> 144<td> 145 <p> 146 none 147 </p> 148 </td> 149</tr> 150<tr> 151<td> 152 <p> 153 <code class="computeroutput"><span class="identifier">Attrib</span></code> 154 </p> 155 </td> 156<td> 157 <p> 158 The type, <code class="computeroutput"><span class="identifier">Attrib</span></code> 159 is the container attribute to be used to generate output from. 160 </p> 161 </td> 162<td> 163 <p> 164 none 165 </p> 166 </td> 167</tr> 168<tr> 169<td> 170 <p> 171 <code class="computeroutput"><span class="identifier">Enable</span></code> 172 </p> 173 </td> 174<td> 175 <p> 176 Helper template parameter usable to selectively enable or disable 177 certain specializations of <code class="computeroutput"><span class="identifier">clear_value</span></code> 178 utilizing SFINAE (i.e. <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">enable_if</span></code> 179 or <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">disable_if</span></code>). 180 </p> 181 </td> 182<td> 183 <p> 184 <code class="computeroutput"><span class="keyword">void</span></code> 185 </p> 186 </td> 187</tr> 188<tr> 189<td> 190 <p> 191 <code class="computeroutput"><span class="identifier">Context</span></code> 192 </p> 193 </td> 194<td> 195 <p> 196 This is the type of the current generator execution context. 197 </p> 198 </td> 199</tr> 200</tbody> 201</table></div> 202<h6> 203<a name="spirit.advanced.customize.extract_from_container.h5"></a> 204 <span class="phrase"><a name="spirit.advanced.customize.extract_from_container.notation"></a></span><a class="link" href="extract_from_container.html#spirit.advanced.customize.extract_from_container.notation">Notation</a> 205 </h6> 206<div class="variablelist"> 207<p class="title"><b>Notation</b></p> 208<dl class="variablelist"> 209<dt><span class="term"><code class="computeroutput"><span class="identifier">Exposed</span></code></span></dt> 210<dd><p> 211 A type exposed as the native attribute of a component. 212 </p></dd> 213<dt><span class="term"><code class="computeroutput"><span class="identifier">Attrib</span></code></span></dt> 214<dd><p> 215 A container type to be used to generate output from. 216 </p></dd> 217<dt><span class="term"><code class="computeroutput"><span class="identifier">attr</span></code></span></dt> 218<dd><p> 219 An attribute instance of type <code class="computeroutput"><span class="identifier">Attrib</span></code>. 220 </p></dd> 221<dt><span class="term"><code class="computeroutput"><span class="identifier">ctx</span></code></span></dt> 222<dd><p> 223 An instance of type <code class="computeroutput"><span class="identifier">Context</span></code>. 224 </p></dd> 225</dl> 226</div> 227<h6> 228<a name="spirit.advanced.customize.extract_from_container.h6"></a> 229 <span class="phrase"><a name="spirit.advanced.customize.extract_from_container.expression_semantics"></a></span><a class="link" href="extract_from_container.html#spirit.advanced.customize.extract_from_container.expression_semantics">Expression 230 Semantics</a> 231 </h6> 232<div class="informaltable"><table class="table"> 233<colgroup> 234<col> 235<col> 236</colgroup> 237<thead><tr> 238<th> 239 <p> 240 Expression 241 </p> 242 </th> 243<th> 244 <p> 245 Semantics 246 </p> 247 </th> 248</tr></thead> 249<tbody><tr> 250<td> 251 <p> 252</p> 253<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">extract_from_container</span><span class="special"><</span><span class="identifier">Exposed</span><span class="special">,</span> <span class="identifier">Attrib</span><span class="special">>::</span><span class="identifier">call</span><span class="special">(</span><span class="identifier">attr</span><span class="special">,</span> <span class="identifier">ctx</span><span class="special">)</span></pre> 254<p> 255 </p> 256 </td> 257<td> 258 <p> 259 Extract the value to generate output from the contaner given 260 by <code class="computeroutput"><span class="identifier">attr</span></code> and return 261 it to the caller. 262 </p> 263 </td> 264</tr></tbody> 265</table></div> 266<h6> 267<a name="spirit.advanced.customize.extract_from_container.h7"></a> 268 <span class="phrase"><a name="spirit.advanced.customize.extract_from_container.predefined_specializations"></a></span><a class="link" href="extract_from_container.html#spirit.advanced.customize.extract_from_container.predefined_specializations">Predefined 269 Specializations</a> 270 </h6> 271<p> 272 <a href="http://boost-spirit.com" target="_top">Spirit</a> predefines specializations 273 of this customization point for several types. The following table lists 274 those types together with the types exposed and the corresponding semantics: 275 </p> 276<div class="informaltable"><table class="table"> 277<colgroup> 278<col> 279<col> 280</colgroup> 281<thead><tr> 282<th> 283 <p> 284 Template Parameters 285 </p> 286 </th> 287<th> 288 <p> 289 Value 290 </p> 291 </th> 292</tr></thead> 293<tbody> 294<tr> 295<td> 296 <p> 297 <code class="computeroutput"><span class="identifier">Attrib</span></code> 298 </p> 299 </td> 300<td> 301 <p> 302 The exposed typedef <code class="computeroutput"><span class="identifier">type</span></code> 303 is defined to <code class="computeroutput"><span class="identifier">Attrib</span> 304 <span class="keyword">const</span><span class="special">&</span></code>. 305 The function <code class="computeroutput"><span class="identifier">call</span><span class="special">()</span></code> returns the argument by reference 306 without change. 307 </p> 308 </td> 309</tr> 310<tr> 311<td> 312 <p> 313 <code class="computeroutput"><span class="identifier">unused_type</span></code> 314 </p> 315 </td> 316<td> 317 <p> 318 The exposed typedef <code class="computeroutput"><span class="identifier">type</span></code> 319 is defined to <code class="computeroutput"><span class="identifier">unused_type</span></code>. 320 The function <code class="computeroutput"><span class="identifier">call</span><span class="special">()</span></code> returns an instance of <code class="computeroutput"><span class="identifier">unused_type</span></code>. 321 </p> 322 </td> 323</tr> 324</tbody> 325</table></div> 326<h6> 327<a name="spirit.advanced.customize.extract_from_container.h8"></a> 328 <span class="phrase"><a name="spirit.advanced.customize.extract_from_container.when_to_implement"></a></span><a class="link" href="extract_from_container.html#spirit.advanced.customize.extract_from_container.when_to_implement">When 329 to implement</a> 330 </h6> 331<p> 332 The customization point <code class="computeroutput"><span class="identifier">extract_from_container</span></code> 333 needs to be implemented for a specific container type whenever the default 334 implementation as shown above is not applicable. Examples for this could 335 be that the type to be extracted is different from <code class="computeroutput"><span class="identifier">Attrib</span></code> 336 and is not copy constructible. 337 </p> 338<h6> 339<a name="spirit.advanced.customize.extract_from_container.h9"></a> 340 <span class="phrase"><a name="spirit.advanced.customize.extract_from_container.example"></a></span><a class="link" href="extract_from_container.html#spirit.advanced.customize.extract_from_container.example">Example</a> 341 </h6> 342<p> 343 TBD 344 </p> 345</div> 346<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 347<td align="left"></td> 348<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p> 349 Distributed under the Boost Software License, Version 1.0. (See accompanying 350 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>) 351 </p> 352</div></td> 353</tr></table> 354<hr> 355<div class="spirit-nav"> 356<a accesskey="p" href="extract_from.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="iterate.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> 357</div> 358</body> 359</html> 360