• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>API for Automatic Generator Creation</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="../generate_api.html" title="Generator API">
9<link rel="prev" href="stream_api.html" title="Stream Based Generator API">
10<link rel="next" href="../action.html" title="Semantic Actions with Generators">
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="stream_api.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../generate_api.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="../action.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.karma.reference.generate_api.create_generator"></a><a class="link" href="create_generator.html" title="API for Automatic Generator Creation">API
28          for Automatic Generator Creation</a>
29</h5></div></div></div>
30<h6>
31<a name="spirit.karma.reference.generate_api.create_generator.h0"></a>
32            <span class="phrase"><a name="spirit.karma.reference.generate_api.create_generator.description"></a></span><a class="link" href="create_generator.html#spirit.karma.reference.generate_api.create_generator.description">Description</a>
33          </h6>
34<p>
35            The library implements a special API returning a generator instance for
36            a supplied attribute type. This function finds the best matching generator
37            type for the attribute based on a set of simple matching rules (as outlined
38            in the table below) applied recursively to the attribute type. The returned
39            generator can be utilized to emit output for the provided attribute.
40          </p>
41<h6>
42<a name="spirit.karma.reference.generate_api.create_generator.h1"></a>
43            <span class="phrase"><a name="spirit.karma.reference.generate_api.create_generator.header"></a></span><a class="link" href="create_generator.html#spirit.karma.reference.generate_api.create_generator.header">Header</a>
44          </h6>
45<pre class="programlisting"><span class="comment">// forwards to &lt;boost/spirit/home/karma/auto.hpp&gt;</span>
46<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">include</span><span class="special">/</span><span class="identifier">karma_auto</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
47</pre>
48<p>
49            Also, see <a class="link" href="../../../structure/include.html" title="Include">Include Structure</a>.
50          </p>
51<h6>
52<a name="spirit.karma.reference.generate_api.create_generator.h2"></a>
53            <span class="phrase"><a name="spirit.karma.reference.generate_api.create_generator.namespace"></a></span><a class="link" href="create_generator.html#spirit.karma.reference.generate_api.create_generator.namespace">Namespace</a>
54          </h6>
55<div class="informaltable"><table class="table">
56<colgroup><col></colgroup>
57<thead><tr><th>
58                    <p>
59                      Name
60                    </p>
61                  </th></tr></thead>
62<tbody>
63<tr><td>
64                    <p>
65                      <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">karma</span><span class="special">::</span><span class="identifier">create_generator</span></code>
66                    </p>
67                  </td></tr>
68<tr><td>
69                    <p>
70                      <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><span class="special">::</span><span class="identifier">create_generator_exists</span></code>
71                    </p>
72                  </td></tr>
73</tbody>
74</table></div>
75<h6>
76<a name="spirit.karma.reference.generate_api.create_generator.h3"></a>
77            <span class="phrase"><a name="spirit.karma.reference.generate_api.create_generator.synopsis"></a></span><a class="link" href="create_generator.html#spirit.karma.reference.generate_api.create_generator.synopsis">Synopsis</a>
78          </h6>
79<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">spirit</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">karma</span>
80<span class="special">{</span>
81    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Attr</span><span class="special">&gt;</span>
82    <span class="keyword">inline</span> <span class="special">&lt;</span><span class="identifier">unspecified</span><span class="special">&gt;</span>
83    <span class="identifier">create_generator</span><span class="special">();</span>
84<span class="special">}}}</span>
85</pre>
86<p>
87            The returned instance can be directly passed as the generator (or the
88            delimiting generator) to any of the <span class="emphasis"><em>Spirit.Karma</em></span>
89            API functions. Additionally it can be assigned to a rule as the rules
90            right hand side expression. This function will return a valid generator
91            type only if the meta function <code class="computeroutput"><span class="identifier">traits</span><span class="special">::</span><span class="identifier">create_generator_exists</span></code>
92            returns <code class="computeroutput"><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">true_</span></code>. Otherwise it will fail compiling.
93          </p>
94<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">spirit</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">traits</span>
95<span class="special">{</span>
96    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Attr</span><span class="special">&gt;</span>
97    <span class="keyword">struct</span> <span class="identifier">create_generator_exists</span><span class="special">;</span>
98<span class="special">}}}</span>
99</pre>
100<p>
101            The meta function evaluates to <code class="computeroutput"><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">true_</span></code>
102            if <code class="computeroutput"><span class="identifier">create_generator</span></code> would
103            return a valid generator for the given type <code class="computeroutput"><span class="identifier">Attr</span></code>.
104          </p>
105<p>
106            The following table outlines the mapping rules from the attribute type
107            to the generator type. These rules are applied recursively to create
108            the generator type which can be used to generate output from the given
109            attribute type.
110          </p>
111<div class="informaltable"><table class="table">
112<colgroup>
113<col>
114<col>
115</colgroup>
116<thead><tr>
117<th>
118                    <p>
119                      Attribute type
120                    </p>
121                  </th>
122<th>
123                    <p>
124                      Generator type
125                    </p>
126                  </th>
127</tr></thead>
128<tbody>
129<tr>
130<td>
131                    <p>
132                      <code class="computeroutput"><span class="keyword">char</span></code>, <code class="computeroutput"><span class="keyword">wchar_t</span></code>
133                    </p>
134                  </td>
135<td>
136                    <p>
137                      <code class="computeroutput"><span class="identifier">standard</span><span class="special">::</span><span class="identifier">char_</span></code>, <code class="computeroutput"><span class="identifier">standard_wide</span><span class="special">::</span><span class="identifier">char_</span></code>
138                    </p>
139                  </td>
140</tr>
141<tr>
142<td>
143                    <p>
144                      <code class="computeroutput"><span class="keyword">short</span></code>, <code class="computeroutput"><span class="keyword">int</span></code>, <code class="computeroutput"><span class="keyword">long</span></code>
145                    </p>
146                  </td>
147<td>
148                    <p>
149                      <code class="computeroutput"><span class="identifier">short_</span></code>, <code class="computeroutput"><span class="identifier">int_</span></code>, <code class="computeroutput"><span class="identifier">long_</span></code>
150                    </p>
151                  </td>
152</tr>
153<tr>
154<td>
155                    <p>
156                      <code class="computeroutput"><span class="keyword">unsigned</span> <span class="keyword">short</span></code>,
157                      <code class="computeroutput"><span class="keyword">unsigned</span> <span class="keyword">int</span></code>,
158                      <code class="computeroutput"><span class="keyword">unsigned</span> <span class="keyword">long</span></code>
159                    </p>
160                  </td>
161<td>
162                    <p>
163                      <code class="computeroutput"><span class="identifier">ushort_</span></code>, <code class="computeroutput"><span class="identifier">uint_</span></code>, <code class="computeroutput"><span class="identifier">ulong_</span></code>
164                    </p>
165                  </td>
166</tr>
167<tr>
168<td>
169                    <p>
170                      <code class="computeroutput"><span class="keyword">float</span></code>, <code class="computeroutput"><span class="keyword">double</span></code>, <code class="computeroutput"><span class="keyword">long</span>
171                      <span class="keyword">double</span></code>
172                    </p>
173                  </td>
174<td>
175                    <p>
176                      <code class="computeroutput"><span class="identifier">float_</span></code>, <code class="computeroutput"><span class="identifier">double_</span></code>, <code class="computeroutput"><span class="identifier">long_double</span></code>
177                    </p>
178                  </td>
179</tr>
180<tr>
181<td>
182                    <p>
183                      <code class="computeroutput"><span class="keyword">short</span></code>, <code class="computeroutput"><span class="keyword">int</span></code>, <code class="computeroutput"><span class="keyword">long</span></code>
184                    </p>
185                  </td>
186<td>
187                    <p>
188                      <code class="computeroutput"><span class="identifier">short_</span></code>, <code class="computeroutput"><span class="identifier">int_</span></code>, <code class="computeroutput"><span class="identifier">long_</span></code>
189                    </p>
190                  </td>
191</tr>
192<tr>
193<td>
194                    <p>
195                      <code class="computeroutput"><span class="keyword">long</span> <span class="keyword">long</span></code>,
196                      <code class="computeroutput"><span class="keyword">unsigned</span> <span class="keyword">long</span>
197                      <span class="keyword">long</span></code>
198                    </p>
199                  </td>
200<td>
201                    <p>
202                      <code class="computeroutput"><span class="identifier">long_long</span></code>,
203                      <code class="computeroutput"><span class="identifier">ulong_long</span></code>
204                    </p>
205                  </td>
206</tr>
207<tr>
208<td>
209                    <p>
210                      <code class="computeroutput"><span class="keyword">bool</span></code>
211                    </p>
212                  </td>
213<td>
214                    <p>
215                      <code class="computeroutput"><span class="identifier">bool_</span></code>
216                    </p>
217                  </td>
218</tr>
219<tr>
220<td>
221                    <p>
222                      Any string (<code class="computeroutput"><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span></code>,
223                      <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span></code>, etc.)
224                    </p>
225                  </td>
226<td>
227                    <p>
228                      <code class="computeroutput"><span class="identifier">string</span></code>
229                    </p>
230                  </td>
231</tr>
232<tr>
233<td>
234                    <p>
235                      Any (STL) container
236                    </p>
237                  </td>
238<td>
239                    <p>
240                      Kleene Star (unary <code class="computeroutput"><span class="char">'*'</span></code>)
241                    </p>
242                  </td>
243</tr>
244<tr>
245<td>
246                    <p>
247                      Any Fusion sequence
248                    </p>
249                  </td>
250<td>
251                    <p>
252                      Sequence operator (<code class="computeroutput"><span class="char">'&lt;&lt;'</span></code>)
253                    </p>
254                  </td>
255</tr>
256<tr>
257<td>
258                    <p>
259                      <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">optional</span><span class="special">&lt;&gt;</span></code>
260                    </p>
261                  </td>
262<td>
263                    <p>
264                      Optional operator (unary <code class="computeroutput"><span class="char">'-'</span></code>)
265                    </p>
266                  </td>
267</tr>
268<tr>
269<td>
270                    <p>
271                      <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">variant</span><span class="special">&lt;&gt;</span></code>
272                    </p>
273                  </td>
274<td>
275                    <p>
276                      Alternative operator (<code class="computeroutput"><span class="char">'|'</span></code>)
277                    </p>
278                  </td>
279</tr>
280</tbody>
281</table></div>
282<div class="important"><table border="0" summary="Important">
283<tr>
284<td rowspan="2" align="center" valign="top" width="25"><img alt="[Important]" src="../../../../images/important.png"></td>
285<th align="left">Important</th>
286</tr>
287<tr><td align="left" valign="top"><p>
288              The mapping for the generators <code class="computeroutput"><span class="identifier">long_long</span></code>
289              and <code class="computeroutput"><span class="identifier">ulong_long</span></code> are
290              only available on platforms where the preprocessor constant <code class="computeroutput"><span class="identifier">BOOST_HAS_LONG_LONG</span></code> is defined (i.e.
291              on platforms having native support for <code class="computeroutput"><span class="keyword">long</span>
292              <span class="keyword">long</span></code> and <code class="computeroutput"><span class="keyword">unsigned</span>
293              <span class="keyword">long</span> <span class="keyword">long</span></code>
294              (64 bit) signed and unsigned integer types).
295            </p></td></tr>
296</table></div>
297<h6>
298<a name="spirit.karma.reference.generate_api.create_generator.h4"></a>
299            <span class="phrase"><a name="spirit.karma.reference.generate_api.create_generator.template_parameters"></a></span><a class="link" href="create_generator.html#spirit.karma.reference.generate_api.create_generator.template_parameters">Template
300            parameters</a>
301          </h6>
302<div class="informaltable"><table class="table">
303<colgroup>
304<col>
305<col>
306</colgroup>
307<thead><tr>
308<th>
309                    <p>
310                      Parameter
311                    </p>
312                  </th>
313<th>
314                    <p>
315                      Description
316                    </p>
317                  </th>
318</tr></thead>
319<tbody><tr>
320<td>
321                    <p>
322                      <code class="computeroutput"><span class="identifier">Attr</span></code>
323                    </p>
324                  </td>
325<td>
326                    <p>
327                      An attribute type utilized to create the corresponding generator
328                      type from.
329                    </p>
330                  </td>
331</tr></tbody>
332</table></div>
333</div>
334<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
335<td align="left"></td>
336<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p>
337        Distributed under the Boost Software License, Version 1.0. (See accompanying
338        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>)
339      </p>
340</div></td>
341</tr></table>
342<hr>
343<div class="spirit-nav">
344<a accesskey="p" href="stream_api.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../generate_api.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="../action.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
345</div>
346</body>
347</html>
348