• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>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="../generator_concepts.html" title="Generator Concepts">
9<link rel="prev" href="../generator_concepts.html" title="Generator Concepts">
10<link rel="next" href="primitivegenerator.html" title="PrimitiveGenerator">
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="../generator_concepts.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../generator_concepts.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="primitivegenerator.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.generator_concepts.generator"></a><a class="link" href="generator.html" title="Generator">Generator</a>
28</h5></div></div></div>
29<h6>
30<a name="spirit.karma.reference.generator_concepts.generator.h0"></a>
31            <span class="phrase"><a name="spirit.karma.reference.generator_concepts.generator.description"></a></span><a class="link" href="generator.html#spirit.karma.reference.generator_concepts.generator.description">Description</a>
32          </h6>
33<p>
34            The <span class="emphasis"><em>Generator</em></span> is the most fundamental concept. A
35            Generator has a member function, <code class="computeroutput"><span class="identifier">generate</span></code>,
36            that accepts an <code class="computeroutput"><span class="identifier">OutputIterator</span></code>
37            and returns bool as its result. The iterator receives the data being
38            generated. The Generator's <code class="computeroutput"><span class="identifier">generate</span></code>
39            member function returns <code class="computeroutput"><span class="keyword">true</span></code>
40            if the generator succeeds. Each Generator can represent a specific pattern
41            or algorithm, or it can be a more complex generator formed as a composition
42            of other Generators.
43          </p>
44<div class="variablelist">
45<p class="title"><b>Notation</b></p>
46<dl class="variablelist">
47<dt><span class="term"><code class="computeroutput"><span class="identifier">g</span></code></span></dt>
48<dd><p>
49                  A <code class="computeroutput"><span class="identifier">Generator</span></code>.
50                </p></dd>
51<dt><span class="term"><code class="computeroutput"><span class="identifier">G</span></code></span></dt>
52<dd><p>
53                  A <code class="computeroutput"><span class="identifier">Generator</span></code> type.
54                </p></dd>
55<dt><span class="term"><code class="computeroutput"><span class="identifier">OutIter</span></code></span></dt>
56<dd><p>
57                  An <code class="computeroutput"><span class="identifier">OutputIterator</span></code>
58                  type.
59                </p></dd>
60<dt><span class="term"><code class="computeroutput"><span class="identifier">sink</span></code></span></dt>
61<dd><p>
62                  An <code class="computeroutput"><span class="identifier">OutputIterator</span></code>
63                  instance.
64                </p></dd>
65<dt><span class="term"><code class="computeroutput"><span class="identifier">Context</span></code></span></dt>
66<dd><p>
67                  The generator's Context type.
68                </p></dd>
69<dt><span class="term"><code class="computeroutput"><span class="identifier">context</span></code></span></dt>
70<dd><p>
71                  The generator's Context, or <code class="computeroutput"><span class="identifier">unused</span></code>.
72                </p></dd>
73<dt><span class="term"><code class="computeroutput"><span class="identifier">delimit</span></code></span></dt>
74<dd><p>
75                  A delimiter Generator, or <code class="computeroutput"><span class="identifier">unused</span></code>.
76                </p></dd>
77<dt><span class="term"><code class="computeroutput"><span class="identifier">attrib</span></code></span></dt>
78<dd><p>
79                  A Compatible Attributes, or <code class="computeroutput"><span class="identifier">unused</span></code>.
80                </p></dd>
81</dl>
82</div>
83<h6>
84<a name="spirit.karma.reference.generator_concepts.generator.h1"></a>
85            <span class="phrase"><a name="spirit.karma.reference.generator_concepts.generator.valid_expressions"></a></span><a class="link" href="generator.html#spirit.karma.reference.generator_concepts.generator.valid_expressions">Valid
86            Expressions</a>
87          </h6>
88<p>
89            In the expressions below, the behavior of the generator, <code class="computeroutput"><span class="identifier">g</span></code>, as well as how <code class="computeroutput"><span class="identifier">delimit</span></code>
90            and <code class="computeroutput"><span class="identifier">attrib</span></code> are handled
91            by <code class="computeroutput"><span class="identifier">g</span></code>, are left unspecified
92            in the base <code class="computeroutput"><span class="identifier">Generator</span></code>
93            concept. These are specified in subsequent, more refined concepts and
94            by the actual models thereof.
95          </p>
96<p>
97            For any Generator the following expressions must be valid:
98          </p>
99<div class="informaltable"><table class="table">
100<colgroup>
101<col>
102<col>
103<col>
104</colgroup>
105<thead><tr>
106<th>
107                    <p>
108                      Expression
109                    </p>
110                  </th>
111<th>
112                    <p>
113                      Semantics
114                    </p>
115                  </th>
116<th>
117                    <p>
118                      Return type
119                    </p>
120                  </th>
121</tr></thead>
122<tbody>
123<tr>
124<td>
125                    <p>
126</p>
127<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">g</span><span class="special">.</span><span class="identifier">generate</span><span class="special">(</span><span class="identifier">sink</span><span class="special">,</span> <span class="identifier">context</span><span class="special">,</span> <span class="identifier">delimit</span><span class="special">,</span> <span class="identifier">attrib</span><span class="special">)</span></pre>
128<p>
129                    </p>
130                  </td>
131<td>
132                    <p>
133                      Generate the output sequence by inserting the generated characters/tokens
134                      into <code class="computeroutput"><span class="identifier">sink</span></code>.
135                      Use the <code class="computeroutput"><span class="identifier">delimit</span></code>
136                      generator for delimiting. Return <code class="computeroutput"><span class="keyword">true</span></code>
137                      if successful, otherwise return <code class="computeroutput"><span class="keyword">false</span></code>.
138                    </p>
139                  </td>
140<td>
141                    <p>
142                      <code class="computeroutput"><span class="keyword">bool</span></code>
143                    </p>
144                  </td>
145</tr>
146<tr>
147<td>
148                    <p>
149                      <code class="computeroutput"><span class="identifier">g</span><span class="special">.</span><span class="identifier">what</span><span class="special">(</span><span class="identifier">context</span><span class="special">)</span></code>
150                    </p>
151                  </td>
152<td>
153                    <p>
154                      Get information about a Generator.
155                    </p>
156                  </td>
157<td>
158                    <p>
159                      <code class="computeroutput"><span class="identifier">info</span></code>
160                    </p>
161                  </td>
162</tr>
163</tbody>
164</table></div>
165<h6>
166<a name="spirit.karma.reference.generator_concepts.generator.h2"></a>
167            <span class="phrase"><a name="spirit.karma.reference.generator_concepts.generator.type_expressions"></a></span><a class="link" href="generator.html#spirit.karma.reference.generator_concepts.generator.type_expressions">Type
168            Expressions</a>
169          </h6>
170<div class="informaltable"><table class="table">
171<colgroup>
172<col>
173<col>
174</colgroup>
175<thead><tr>
176<th>
177                    <p>
178                      Expression
179                    </p>
180                  </th>
181<th>
182                    <p>
183                      Description
184                    </p>
185                  </th>
186</tr></thead>
187<tbody>
188<tr>
189<td>
190                    <p>
191                      <code class="computeroutput"><span class="identifier">G</span><span class="special">::</span><span class="keyword">template</span> <span class="identifier">attribute</span><span class="special">&lt;</span><span class="identifier">Context</span><span class="special">&gt;::</span><span class="identifier">type</span></code>
192                    </p>
193                  </td>
194<td>
195                    <p>
196                      The Generator's attribute.
197                    </p>
198                  </td>
199</tr>
200<tr>
201<td>
202                    <p>
203                      <code class="computeroutput"><span class="identifier">traits</span><span class="special">::</span><span class="identifier">is_generator</span><span class="special">&lt;</span><span class="identifier">G</span><span class="special">&gt;::</span><span class="identifier">type</span></code>
204                    </p>
205                  </td>
206<td>
207                    <p>
208                      Metafunction that evaluates to <code class="computeroutput"><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">true_</span></code>
209                      if a certain type, <code class="computeroutput"><span class="identifier">G</span></code>
210                      is a Generator, <code class="computeroutput"><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">false_</span></code>
211                      otherwise (See <a href="../../../../../../../../libs/mpl/doc/refmanual/integral-constant.html" target="_top">MPL
212                      Boolean Constant</a>).
213                    </p>
214                  </td>
215</tr>
216<tr>
217<td>
218                    <p>
219                      <code class="computeroutput"><span class="identifier">G</span><span class="special">::</span><span class="identifier">properties</span></code>
220                    </p>
221                  </td>
222<td>
223                    <p>
224                      An <code class="computeroutput"><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">int_</span></code> (See <a href="../../../../../../../../libs/mpl/doc/refmanual/integral-constant.html" target="_top">MPL
225                      Integral Constant</a>) holding a value from the <code class="computeroutput"><span class="identifier">karma</span><span class="special">::</span><span class="identifier">generator_properties</span></code> enumeration.
226                      The default value is <code class="computeroutput"><span class="identifier">generator_properties</span><span class="special">::</span><span class="identifier">no_properties</span></code>
227                    </p>
228                  </td>
229</tr>
230</tbody>
231</table></div>
232<h6>
233<a name="spirit.karma.reference.generator_concepts.generator.h3"></a>
234            <span class="phrase"><a name="spirit.karma.reference.generator_concepts.generator.postcondition"></a></span><a class="link" href="generator.html#spirit.karma.reference.generator_concepts.generator.postcondition">Postcondition</a>
235          </h6>
236<p>
237            Upon return from <code class="computeroutput"><span class="identifier">g</span><span class="special">.</span><span class="identifier">generate</span></code> the following post conditions
238            should hold:
239          </p>
240<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
241<li class="listitem">
242                On successful generation, <code class="computeroutput"><span class="identifier">sink</span></code>
243                receives the generated characters/tokens sequence.
244              </li>
245<li class="listitem">
246                No pre-delimits: <code class="computeroutput"><span class="identifier">delimit</span></code>
247                characters/tokens will not be emitted in front of any other output.
248              </li>
249<li class="listitem">
250                The attribute <code class="computeroutput"><span class="identifier">attrib</span></code>
251                has not been modified.
252              </li>
253</ul></div>
254<h6>
255<a name="spirit.karma.reference.generator_concepts.generator.h4"></a>
256            <span class="phrase"><a name="spirit.karma.reference.generator_concepts.generator.models"></a></span><a class="link" href="generator.html#spirit.karma.reference.generator_concepts.generator.models">Models</a>
257          </h6>
258<p>
259            All generators in <span class="emphasis"><em>Spirit.Karma</em></span> are models of the
260            <span class="emphasis"><em>Generator</em></span> concept.
261          </p>
262</div>
263<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
264<td align="left"></td>
265<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p>
266        Distributed under the Boost Software License, Version 1.0. (See accompanying
267        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>)
268      </p>
269</div></td>
270</tr></table>
271<hr>
272<div class="spirit-nav">
273<a accesskey="p" href="../generator_concepts.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../generator_concepts.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="primitivegenerator.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
274</div>
275</body>
276</html>
277