• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>Stream Based Generator API</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="iterator_api.html" title="Iterator Based Generator API">
10<link rel="next" href="create_generator.html" title="API for Automatic Generator Creation">
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="iterator_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="create_generator.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.stream_api"></a><a class="link" href="stream_api.html" title="Stream Based Generator API">Stream
28          Based Generator API</a>
29</h5></div></div></div>
30<h6>
31<a name="spirit.karma.reference.generate_api.stream_api.h0"></a>
32            <span class="phrase"><a name="spirit.karma.reference.generate_api.stream_api.description"></a></span><a class="link" href="stream_api.html#spirit.karma.reference.generate_api.stream_api.description">Description</a>
33          </h6>
34<p>
35            The library provides a couple of Standard IO <a href="http://www.cppreference.com/wiki/io/io_flags#manipulators" target="_top">Manipulators</a>
36            allowing to integrate <span class="emphasis"><em>Spirit.Karma</em></span> output generation
37            facilities with Standard output streams. These generator manipulators
38            have two forms. The first form, <code class="computeroutput"><span class="identifier">format</span></code>,
39            concatenates the output generated by the involved components without
40            inserting any output in between. The second, <code class="computeroutput"><span class="identifier">format_delimited</span></code>,
41            intersperses the output generated by the involved components using the
42            given delimiter generator. Both versions can take in attributes by (constant)
43            reference that hold the attribute values to output.
44          </p>
45<h6>
46<a name="spirit.karma.reference.generate_api.stream_api.h1"></a>
47            <span class="phrase"><a name="spirit.karma.reference.generate_api.stream_api.header"></a></span><a class="link" href="stream_api.html#spirit.karma.reference.generate_api.stream_api.header">Header</a>
48          </h6>
49<pre class="programlisting"><span class="comment">// forwards to &lt;boost/spirit/home/karma/stream/format_manip.hpp&gt;</span>
50<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_format</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
51</pre>
52<p>
53            For variadic attributes:
54          </p>
55<pre class="programlisting"><span class="comment">// forwards to &lt;boost/spirit/home/karma/stream/format_manip_attr.hpp&gt;</span>
56<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_format_attr</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
57</pre>
58<p>
59            The variadic attributes version of the API allows one or more attributes
60            to be passed into the <code class="computeroutput"><span class="identifier">format</span></code>
61            manipulators. The manipulators taking two or more attributes are usable
62            when the generator expression is a <a class="link" href="../operator/sequence.html" title="Sequence Generator (a &lt;&lt; b)">Sequence
63            (<code class="computeroutput"><span class="special">&lt;&lt;</span></code>)</a> only.
64            In this case each of the attributes passed have to match the corresponding
65            part of the sequence.
66          </p>
67<p>
68            For the API functions deducing the correct (matching) generator type
69            from the supplied attribute type:
70          </p>
71<pre class="programlisting"><span class="comment">// forwards to &lt;boost/spirit/home/karma/format_auto.hpp&gt;</span>
72<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_format_auto</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
73</pre>
74<p>
75            Also, see <a class="link" href="../../../structure/include.html" title="Include">Include Structure</a>.
76          </p>
77<h6>
78<a name="spirit.karma.reference.generate_api.stream_api.h2"></a>
79            <span class="phrase"><a name="spirit.karma.reference.generate_api.stream_api.namespace"></a></span><a class="link" href="stream_api.html#spirit.karma.reference.generate_api.stream_api.namespace">Namespace</a>
80          </h6>
81<div class="informaltable"><table class="table">
82<colgroup><col></colgroup>
83<thead><tr><th>
84                    <p>
85                      Name
86                    </p>
87                  </th></tr></thead>
88<tbody>
89<tr><td>
90                    <p>
91                      <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">format</span></code>
92                    </p>
93                  </td></tr>
94<tr><td>
95                    <p>
96                      <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">format_delimited</span></code>
97                    </p>
98                  </td></tr>
99<tr><td>
100                    <p>
101                      <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">delimit_flag</span><span class="special">::</span><span class="identifier">predelimit</span></code>
102                    </p>
103                  </td></tr>
104<tr><td>
105                    <p>
106                      <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">delimit_flag</span><span class="special">::</span><span class="identifier">dont_predelimit</span></code>
107                    </p>
108                  </td></tr>
109</tbody>
110</table></div>
111<h6>
112<a name="spirit.karma.reference.generate_api.stream_api.h3"></a>
113            <span class="phrase"><a name="spirit.karma.reference.generate_api.stream_api.synopsis"></a></span><a class="link" href="stream_api.html#spirit.karma.reference.generate_api.stream_api.synopsis">Synopsis</a>
114          </h6>
115<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>
116<span class="special">{</span>
117    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Expr</span><span class="special">&gt;</span>
118    <span class="keyword">inline</span> <span class="special">&lt;</span><span class="identifier">unspecified</span><span class="special">&gt;</span>
119    <span class="identifier">format</span><span class="special">(</span>
120        <span class="identifier">Expr</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">xpr</span><span class="special">);</span>
121
122    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Expr</span>
123      <span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attr1</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attr2</span><span class="special">,</span> <span class="special">...,</span> <span class="keyword">typename</span> <span class="identifier">AttrN</span><span class="special">&gt;</span>
124    <span class="keyword">inline</span> <span class="special">&lt;</span><span class="identifier">unspecified</span><span class="special">&gt;</span>
125    <span class="identifier">format</span><span class="special">(</span>
126        <span class="identifier">Expr</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">xpr</span>
127      <span class="special">,</span> <span class="identifier">Attr1</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">attr1</span><span class="special">,</span> <span class="identifier">Attr2</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">attr2</span><span class="special">,</span> <span class="special">...,</span> <span class="identifier">AttrN</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">attrN</span><span class="special">);</span>
128
129    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Expr</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Delimiter</span><span class="special">&gt;</span>
130    <span class="keyword">inline</span> <span class="special">&lt;</span><span class="identifier">unspecified</span><span class="special">&gt;</span>
131    <span class="identifier">format_delimited</span><span class="special">(</span>
132        <span class="identifier">Expr</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">expr</span>
133      <span class="special">,</span> <span class="identifier">Delimiter</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">d</span>
134      <span class="special">,</span> <span class="identifier">BOOST_SCOPED_ENUM</span><span class="special">(</span><span class="identifier">delimit_flag</span><span class="special">)</span> <span class="identifier">pre_delimit</span> <span class="special">=</span> <span class="identifier">delimit_flag</span><span class="special">::</span><span class="identifier">dont_predelimit</span><span class="special">);</span>
135
136    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Expr</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Delimiter</span>
137      <span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attr1</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attr2</span><span class="special">,</span> <span class="special">...,</span> <span class="keyword">typename</span> <span class="identifier">AttrN</span><span class="special">&gt;</span>
138    <span class="keyword">inline</span> <span class="special">&lt;</span><span class="identifier">unspecified</span><span class="special">&gt;</span>
139    <span class="identifier">format_delimited</span><span class="special">(</span>
140        <span class="identifier">Expr</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">expr</span>
141      <span class="special">,</span> <span class="identifier">Delimiter</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">d</span>
142      <span class="special">,</span> <span class="identifier">Attr1</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">attr1</span><span class="special">,</span> <span class="identifier">Attr2</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">attr2</span><span class="special">,</span> <span class="special">...,</span> <span class="identifier">AttrN</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">attrN</span><span class="special">);</span>
143
144    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Expr</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Delimiter</span>
145      <span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attr1</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attr2</span><span class="special">,</span> <span class="special">...,</span> <span class="keyword">typename</span> <span class="identifier">AttrN</span><span class="special">&gt;</span>
146    <span class="keyword">inline</span> <span class="special">&lt;</span><span class="identifier">unspecified</span><span class="special">&gt;</span>
147    <span class="identifier">format_delimited</span><span class="special">(</span>
148        <span class="identifier">Expr</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">expr</span>
149      <span class="special">,</span> <span class="identifier">Delimiter</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">d</span>
150      <span class="special">,</span> <span class="identifier">BOOST_SCOPED_ENUM</span><span class="special">(</span><span class="identifier">delimit_flag</span><span class="special">)</span> <span class="identifier">pre_delimit</span>
151      <span class="special">,</span> <span class="identifier">Attr1</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">attr1</span><span class="special">,</span> <span class="identifier">Attr2</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">attr2</span><span class="special">,</span> <span class="special">...,</span> <span class="identifier">AttrN</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">attrN</span><span class="special">);</span>
152<span class="special">}}}</span>
153</pre>
154<p>
155            <span class="emphasis"><em>Spirit.Karma</em></span> generator API functions based on the
156            automatic creation of the matching generator type:
157          </p>
158<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>
159<span class="special">{</span>
160    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Attr</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Delimiter</span><span class="special">&gt;</span>
161    <span class="keyword">inline</span> <span class="special">&lt;</span><span class="identifier">unspecified</span><span class="special">&gt;</span>
162    <span class="identifier">format_delimited</span><span class="special">(</span>
163        <span class="identifier">Attr</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">attr</span>
164      <span class="special">,</span> <span class="identifier">Delimiter</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">d</span>
165      <span class="special">,</span> <span class="identifier">BOOST_SCOPED_ENUM</span><span class="special">(</span><span class="identifier">delimit_flag</span><span class="special">)</span> <span class="identifier">pre_delimit</span> <span class="special">=</span> <span class="identifier">delimit_flag</span><span class="special">::</span><span class="identifier">dont_predelimit</span><span class="special">);</span>
166
167    <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>
168    <span class="keyword">inline</span> <span class="special">&lt;</span><span class="identifier">unspecified</span><span class="special">&gt;</span>
169    <span class="identifier">format</span><span class="special">(</span>
170        <span class="identifier">Attr</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">xpr</span><span class="special">);</span>
171<span class="special">}}}</span>
172</pre>
173<p>
174            All functions above return a standard IO stream manipulator instance
175            (see <a href="http://www.cppreference.com/wiki/io/io_flags#manipulators" target="_top">Manipulators</a>),
176            which when streamed to an output stream will result in generating the
177            output as emitted by the embedded <span class="emphasis"><em>Spirit.Karma</em></span> generator
178            expression. Any error occurring during the invocation of the <span class="emphasis"><em>Spirit.Karma</em></span>
179            generators will be reflected in the streams status flag (<code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">ios_base</span><span class="special">::</span><span class="identifier">failbit</span></code> will be set).
180          </p>
181<p>
182            The maximum number of supported arguments is limited by the preprocessor
183            constant <code class="computeroutput"><span class="identifier">SPIRIT_ARGUMENTS_LIMIT</span></code>.
184            This constant defaults to the value defined by the preprocessor constant
185            <code class="computeroutput"><span class="identifier">PHOENIX_LIMIT</span></code> (which
186            in turn defaults to <code class="computeroutput"><span class="number">10</span></code>).
187          </p>
188<div class="note"><table border="0" summary="Note">
189<tr>
190<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td>
191<th align="left">Note</th>
192</tr>
193<tr><td align="left" valign="top"><p>
194              The variadic manipulators with two or more attributes internally combine
195              (constant) references to all passed attributes into a <code class="computeroutput"><span class="identifier">fusion</span><span class="special">::</span><span class="identifier">vector</span></code> and forward this as a combined
196              attribute to the corresponding manipulator taking one attribute.
197            </p></td></tr>
198</table></div>
199<p>
200            The <code class="computeroutput"><span class="identifier">format_delimited</span></code>
201            manipulators not taking an explicit <code class="computeroutput"><span class="identifier">delimit_flag</span></code>
202            as one of their arguments don't invoke the passed delimiter before starting
203            to generate output from the generator expression. This can be enabled
204            by using the other version of that manipulator while passing <code class="computeroutput"><span class="identifier">delimit_flag</span><span class="special">::</span><span class="identifier">predelimit</span></code> to the corresponding argument.
205          </p>
206<h6>
207<a name="spirit.karma.reference.generate_api.stream_api.h4"></a>
208            <span class="phrase"><a name="spirit.karma.reference.generate_api.stream_api.template_parameters"></a></span><a class="link" href="stream_api.html#spirit.karma.reference.generate_api.stream_api.template_parameters">Template
209            parameters</a>
210          </h6>
211<div class="informaltable"><table class="table">
212<colgroup>
213<col>
214<col>
215</colgroup>
216<thead><tr>
217<th>
218                    <p>
219                      Parameter
220                    </p>
221                  </th>
222<th>
223                    <p>
224                      Description
225                    </p>
226                  </th>
227</tr></thead>
228<tbody>
229<tr>
230<td>
231                    <p>
232                      <code class="computeroutput"><span class="identifier">Expr</span></code>
233                    </p>
234                  </td>
235<td>
236                    <p>
237                      An expression that can be converted to a Karma generator.
238                    </p>
239                  </td>
240</tr>
241<tr>
242<td>
243                    <p>
244                      <code class="computeroutput"><span class="identifier">Delimiter</span></code>
245                    </p>
246                  </td>
247<td>
248                    <p>
249                      Generator used to delimit the output of the expression components.
250                    </p>
251                  </td>
252</tr>
253<tr>
254<td>
255                    <p>
256                      <code class="computeroutput"><span class="identifier">Attr</span></code>
257                    </p>
258                  </td>
259<td>
260                    <p>
261                      An attribute type utilized to create the corresponding generator
262                      type from.
263                    </p>
264                  </td>
265</tr>
266<tr>
267<td>
268                    <p>
269                      <code class="computeroutput"><span class="identifier">Attr1</span></code>, <code class="computeroutput"><span class="identifier">Attr2</span></code>, ..., <code class="computeroutput"><span class="identifier">AttrN</span></code>
270                    </p>
271                  </td>
272<td>
273                    <p>
274                      One or more attributes.
275                    </p>
276                  </td>
277</tr>
278</tbody>
279</table></div>
280</div>
281<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
282<td align="left"></td>
283<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p>
284        Distributed under the Boost Software License, Version 1.0. (See accompanying
285        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>)
286      </p>
287</div></td>
288</tr></table>
289<hr>
290<div class="spirit-nav">
291<a accesskey="p" href="iterator_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="create_generator.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
292</div>
293</body>
294</html>
295