1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Define a Custom Attribute Mapping for a Generator</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="../auto.html" title="Create Components from Attributes (Qi and Karma)"> 9<link rel="prev" href="create_parser.html" title="Define a Custom Attribute Mapping for a Parser"> 10<link rel="next" href="../../../support.html" title="Supporting Libraries"> 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="create_parser.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../auto.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="../../../support.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.auto.create_generator"></a><a class="link" href="create_generator.html" title="Define a Custom Attribute Mapping for a Generator">Define 28 a Custom Attribute Mapping for a Generator</a> 29</h5></div></div></div> 30<h6> 31<a name="spirit.advanced.customize.auto.create_generator.h0"></a> 32 <span class="phrase"><a name="spirit.advanced.customize.auto.create_generator.create_generator"></a></span><a class="link" href="create_generator.html#spirit.advanced.customize.auto.create_generator.create_generator">create_generator</a> 33 </h6> 34<p> 35 The template <code class="computeroutput"><span class="identifier">create_generator</span></code> 36 is a type used as an customization point. It is invoked by the <span class="emphasis"><em>Karma</em></span> 37 <a class="link" href="../../../karma/reference/generate_api/create_generator.html" title="API for Automatic Generator Creation"><code class="computeroutput"><span class="identifier">create_generator</span></code></a> API function 38 in order to create a custom mapping of the given data type to a generator 39 expression. This generator expression will be returned from <a class="link" href="../../../karma/reference/generate_api/create_generator.html" title="API for Automatic Generator Creation"><code class="computeroutput"><span class="identifier">create_generator</span></code></a> whenever the 40 given data type is encountered. 41 </p> 42<h6> 43<a name="spirit.advanced.customize.auto.create_generator.h1"></a> 44 <span class="phrase"><a name="spirit.advanced.customize.auto.create_generator.module_headers"></a></span><a class="link" href="create_generator.html#spirit.advanced.customize.auto.create_generator.module_headers">Module 45 Headers</a> 46 </h6> 47<pre class="programlisting"><span class="comment">// forwards to <boost/spirit/home/karma/auto.hpp></span> 48<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">include</span><span class="special">/</span><span class="identifier">karma_auto</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<h6> 54<a name="spirit.advanced.customize.auto.create_generator.h2"></a> 55 <span class="phrase"><a name="spirit.advanced.customize.auto.create_generator.namespace"></a></span><a class="link" href="create_generator.html#spirit.advanced.customize.auto.create_generator.namespace">Namespace</a> 56 </h6> 57<div class="informaltable"><table class="table"> 58<colgroup><col></colgroup> 59<thead><tr><th> 60 <p> 61 Name 62 </p> 63 </th></tr></thead> 64<tbody><tr><td> 65 <p> 66 <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> 67 </p> 68 </td></tr></tbody> 69</table></div> 70<h6> 71<a name="spirit.advanced.customize.auto.create_generator.h3"></a> 72 <span class="phrase"><a name="spirit.advanced.customize.auto.create_generator.synopsis"></a></span><a class="link" href="create_generator.html#spirit.advanced.customize.auto.create_generator.synopsis">Synopsis</a> 73 </h6> 74<pre class="programlisting"><span class="keyword">template</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> 75<span class="keyword">struct</span> <span class="identifier">create_generator</span> 76<span class="special">{</span> 77 <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> 78 <span class="keyword">static</span> <span class="identifier">type</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">call</span><span class="special">();</span> 79<span class="special">};</span> 80</pre> 81<h6> 82<a name="spirit.advanced.customize.auto.create_generator.h4"></a> 83 <span class="phrase"><a name="spirit.advanced.customize.auto.create_generator.template_parameters"></a></span><a class="link" href="create_generator.html#spirit.advanced.customize.auto.create_generator.template_parameters">Template 84 parameters</a> 85 </h6> 86<div class="informaltable"><table class="table"> 87<colgroup> 88<col> 89<col> 90<col> 91</colgroup> 92<thead><tr> 93<th> 94 <p> 95 Parameter 96 </p> 97 </th> 98<th> 99 <p> 100 Description 101 </p> 102 </th> 103<th> 104 <p> 105 Default 106 </p> 107 </th> 108</tr></thead> 109<tbody> 110<tr> 111<td> 112 <p> 113 <code class="computeroutput"><span class="identifier">T</span></code> 114 </p> 115 </td> 116<td> 117 <p> 118 The type, <code class="computeroutput"><span class="identifier">T</span></code> 119 for which a custom mapping to a generator should be established. 120 </p> 121 </td> 122<td> 123 <p> 124 none 125 </p> 126 </td> 127</tr> 128<tr> 129<td> 130 <p> 131 <code class="computeroutput"><span class="identifier">Enable</span></code> 132 </p> 133 </td> 134<td> 135 <p> 136 Helper template parameter usable to selectively enable or disable 137 certain specializations of <code class="computeroutput"><span class="identifier">create_generator</span></code> 138 utilizing SFINAE (i.e. <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">enable_if</span></code> 139 or <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">disable_if</span></code>). 140 </p> 141 </td> 142<td> 143 <p> 144 <code class="computeroutput"><span class="keyword">void</span></code> 145 </p> 146 </td> 147</tr> 148</tbody> 149</table></div> 150<div class="variablelist"> 151<p class="title"><b>Notation</b></p> 152<dl class="variablelist"> 153<dt><span class="term"><code class="computeroutput"><span class="identifier">T</span></code></span></dt> 154<dd><p> 155 An arbitrary type. 156 </p></dd> 157</dl> 158</div> 159<h6> 160<a name="spirit.advanced.customize.auto.create_generator.h5"></a> 161 <span class="phrase"><a name="spirit.advanced.customize.auto.create_generator.expression_semantics"></a></span><a class="link" href="create_generator.html#spirit.advanced.customize.auto.create_generator.expression_semantics">Expression 162 Semantics</a> 163 </h6> 164<div class="informaltable"><table class="table"> 165<colgroup> 166<col> 167<col> 168</colgroup> 169<thead><tr> 170<th> 171 <p> 172 Expression 173 </p> 174 </th> 175<th> 176 <p> 177 Semantics 178 </p> 179 </th> 180</tr></thead> 181<tbody> 182<tr> 183<td> 184 <p> 185 <code class="computeroutput"><span class="identifier">create_generator</span><span class="special"><</span><span class="identifier">T</span><span class="special">>::</span><span class="identifier">type</span></code> 186 </p> 187 </td> 188<td> 189 <p> 190 Defines the type of the generator expression returned from 191 <code class="computeroutput"><span class="identifier">call</span></code>. 192 </p> 193 </td> 194</tr> 195<tr> 196<td> 197 <p> 198 <code class="computeroutput"><span class="identifier">create_generator</span><span class="special"><</span><span class="identifier">T</span><span class="special">>::</span><span class="identifier">call</span><span class="special">()</span></code> 199 </p> 200 </td> 201<td> 202 <p> 203 Returns a generator expression (usually this is a proto::expression) 204 to be used as the default generator for the given type, <code class="computeroutput"><span class="identifier">T</span></code>. 205 </p> 206 </td> 207</tr> 208</tbody> 209</table></div> 210<h6> 211<a name="spirit.advanced.customize.auto.create_generator.h6"></a> 212 <span class="phrase"><a name="spirit.advanced.customize.auto.create_generator.predefined_specializations"></a></span><a class="link" href="create_generator.html#spirit.advanced.customize.auto.create_generator.predefined_specializations">Predefined 213 Specializations</a> 214 </h6> 215<p> 216 <a href="http://boost-spirit.com" target="_top">Spirit</a> predefines specializations 217 of this customization point for several types. All predefined mappings 218 are listed here: <a class="link" href="../../../karma/reference/auto.html#spirit.karma.reference.auto.additional_requirements">Additional 219 Attribute Requirements for Generators</a>. 220 </p> 221<div class="note"><table border="0" summary="Note"> 222<tr> 223<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td> 224<th align="left">Note</th> 225</tr> 226<tr><td align="left" valign="top"><p> 227 It is possible to overload the predefined mappings for the listed types 228 by providing your own specialization of the <code class="computeroutput"><span class="identifier">create_generator</span></code> 229 customization point for the type to modify. 230 </p></td></tr> 231</table></div> 232<h6> 233<a name="spirit.advanced.customize.auto.create_generator.h7"></a> 234 <span class="phrase"><a name="spirit.advanced.customize.auto.create_generator.when_to_implement"></a></span><a class="link" href="create_generator.html#spirit.advanced.customize.auto.create_generator.when_to_implement">When 235 to implement</a> 236 </h6> 237<p> 238 The customization point <code class="computeroutput"><span class="identifier">create_generator</span></code> 239 needs to be implemented for a specific type whenever this type should 240 be usable with the API function <a class="link" href="../../../karma/reference/generate_api/create_generator.html" title="API for Automatic Generator Creation"><code class="computeroutput"><span class="identifier">create_generator</span></code></a> (which includes 241 using the <code class="computeroutput"><span class="identifier">karma</span><span class="special">::</span><span class="identifier">auto_</span></code> generator and the special API 242 functions based on the automatic creation of the matching generator type). 243 </p> 244<h6> 245<a name="spirit.advanced.customize.auto.create_generator.h8"></a> 246 <span class="phrase"><a name="spirit.advanced.customize.auto.create_generator.example"></a></span><a class="link" href="create_generator.html#spirit.advanced.customize.auto.create_generator.example">Example</a> 247 </h6> 248<p> 249 For an example of how to use the customization point <code class="computeroutput"><span class="identifier">create_generator</span></code> 250 please see here: <a class="link" href="../../../karma/reference/auto.html#spirit.karma.reference.auto.example">Example 251 for Using the <code class="computeroutput"><span class="identifier">karma</span><span class="special">::</span><span class="identifier">auto_</span></code> Generator</a>. 252 </p> 253</div> 254<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 255<td align="left"></td> 256<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p> 257 Distributed under the Boost Software License, Version 1.0. (See accompanying 258 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>) 259 </p> 260</div></td> 261</tr></table> 262<hr> 263<div class="spirit-nav"> 264<a accesskey="p" href="create_parser.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../auto.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="../../../support.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> 265</div> 266</body> 267</html> 268