• 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 Directive Separating Output Into Columns (columns[])</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="../directive.html" title="Generator Directives">
9<link rel="prev" href="duplicate.html" title="Generator Directive Duplicating Attributes (duplicate[])">
10<link rel="next" href="as.html" title="Generator Directives Forcing Atomic Extraction (as&lt;T&gt;, as_string[], as_wstring[])">
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="duplicate.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../directive.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="as.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.directive.columns"></a><a class="link" href="columns.html" title="Generator Directive Separating Output Into Columns (columns[])">Generator
28          Directive Separating Output Into Columns (<code class="computeroutput"><span class="identifier">columns</span><span class="special">[]</span></code>)</a>
29</h5></div></div></div>
30<h6>
31<a name="spirit.karma.reference.directive.columns.h0"></a>
32            <span class="phrase"><a name="spirit.karma.reference.directive.columns.description"></a></span><a class="link" href="columns.html#spirit.karma.reference.directive.columns.description">Description</a>
33          </h6>
34<p>
35            The <code class="computeroutput"><span class="identifier">columns</span><span class="special">[]</span></code>
36            directive separates the output emitted by the embedded generator by inserting
37            special column separators.
38          </p>
39<h6>
40<a name="spirit.karma.reference.directive.columns.h1"></a>
41            <span class="phrase"><a name="spirit.karma.reference.directive.columns.header"></a></span><a class="link" href="columns.html#spirit.karma.reference.directive.columns.header">Header</a>
42          </h6>
43<pre class="programlisting"><span class="comment">// forwards to &lt;boost/spirit/home/karma/directive/columns.hpp&gt;</span>
44<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_columns</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
45</pre>
46<p>
47            Also, see <a class="link" href="../../../structure/include.html" title="Include">Include Structure</a>.
48          </p>
49<div class="informaltable"><table class="table">
50<colgroup><col></colgroup>
51<thead><tr><th>
52                    <p>
53                      Name
54                    </p>
55                  </th></tr></thead>
56<tbody><tr><td>
57                    <p>
58                      <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">columns</span> <span class="comment">//
59                      alias: boost::spirit::karma::columns</span></code>
60                    </p>
61                  </td></tr></tbody>
62</table></div>
63<h6>
64<a name="spirit.karma.reference.directive.columns.h2"></a>
65            <span class="phrase"><a name="spirit.karma.reference.directive.columns.model_of"></a></span><a class="link" href="columns.html#spirit.karma.reference.directive.columns.model_of">Model of</a>
66          </h6>
67<div class="blockquote"><blockquote class="blockquote"><p>
68              <a class="link" href="../generator_concepts/unarygenerator.html" title="UnaryGenerator"><code class="computeroutput"><span class="identifier">UnaryGenerator</span></code></a>
69            </p></blockquote></div>
70<div class="variablelist">
71<p class="title"><b>Notation</b></p>
72<dl class="variablelist">
73<dt><span class="term"><code class="computeroutput"><span class="identifier">a</span></code></span></dt>
74<dd><p>
75                  A generator object
76                </p></dd>
77<dt><span class="term"><code class="computeroutput"><span class="identifier">g</span></code></span></dt>
78<dd><p>
79                  A generator object, or a <a class="link" href="../basics.html#spirit.karma.reference.basics.lazy_argument">Lazy
80                  Argument</a> that evaluates to a generator object, will be used
81                  to emit column separators
82                </p></dd>
83<dt><span class="term"><code class="computeroutput"><span class="identifier">A</span></code></span></dt>
84<dd>
85<p>
86                  Attribute type of generator <code class="computeroutput"><span class="identifier">a</span></code>
87                </p>
88<p>
89                  [<code class="computeroutput"><span class="identifier">num</span></code>
90                </p>
91<p>
92                  Numeric literal, any unsigned integer value, or a <a class="link" href="../basics.html#spirit.karma.reference.basics.lazy_argument">Lazy
93                  Argument</a> that evaluates to an unsigned integer value defining
94                  the number of items to emit in between the column separators
95                </p>
96</dd>
97</dl>
98</div>
99<h6>
100<a name="spirit.karma.reference.directive.columns.h3"></a>
101            <span class="phrase"><a name="spirit.karma.reference.directive.columns.expression_semantics"></a></span><a class="link" href="columns.html#spirit.karma.reference.directive.columns.expression_semantics">Expression
102            Semantics</a>
103          </h6>
104<p>
105            Semantics of an expression is defined only where it differs from, or
106            is not defined in <a class="link" href="../generator_concepts/unarygenerator.html" title="UnaryGenerator"><code class="computeroutput"><span class="identifier">UnaryGenerator</span></code></a>.
107          </p>
108<div class="informaltable"><table class="table">
109<colgroup>
110<col>
111<col>
112</colgroup>
113<thead><tr>
114<th>
115                    <p>
116                      Expression
117                    </p>
118                  </th>
119<th>
120                    <p>
121                      Semantics
122                    </p>
123                  </th>
124</tr></thead>
125<tbody>
126<tr>
127<td>
128                    <p>
129                      <code class="computeroutput"><span class="identifier">columns</span><span class="special">[</span><span class="identifier">a</span><span class="special">]</span></code>
130                    </p>
131                  </td>
132<td>
133                    <p>
134                      The <code class="computeroutput"><span class="identifier">columns</span></code>
135                      directive invokes a generator after each N-th element of the
136                      embedded generator has been emitted. The number of columns
137                      is defined by the preprocessor constant <code class="computeroutput"><span class="identifier">BOOST_KARMA_DEFAULT_COLUMNS</span></code>.
138                      The column separator used will be <code class="computeroutput"><span class="identifier">karma</span><span class="special">::</span><span class="identifier">eol</span></code>.
139                    </p>
140                  </td>
141</tr>
142<tr>
143<td>
144                    <p>
145                      <code class="computeroutput"><span class="identifier">columns</span><span class="special">(</span><span class="identifier">num</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]</span></code>
146                    </p>
147                  </td>
148<td>
149                    <p>
150                      The <code class="computeroutput"><span class="identifier">columns</span></code>
151                      directive invokes a generator after each N-th element of the
152                      embedded generator has been emitted. The number of columns
153                      is defined by the argument to the directive <code class="computeroutput"><span class="identifier">num</span></code>.
154                      The column separator used will be <code class="computeroutput"><span class="identifier">karma</span><span class="special">::</span><span class="identifier">eol</span></code>.
155                    </p>
156                  </td>
157</tr>
158<tr>
159<td>
160                    <p>
161                      <code class="computeroutput"><span class="identifier">columns</span><span class="special">(</span><span class="identifier">g</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]</span></code>
162                    </p>
163                  </td>
164<td>
165                    <p>
166                      The <code class="computeroutput"><span class="identifier">columns</span></code>
167                      directive invokes a generator after each N-th element of the
168                      embedded generator has been emitted. The number of columns
169                      is defined by the preprocessor constant <code class="computeroutput"><span class="identifier">BOOST_KARMA_DEFAULT_COLUMNS</span></code>.
170                      The column separator used will be <code class="computeroutput"><span class="identifier">g</span></code>.
171                    </p>
172                  </td>
173</tr>
174<tr>
175<td>
176                    <p>
177                      <code class="computeroutput"><span class="identifier">columns</span><span class="special">(</span><span class="identifier">num</span><span class="special">,</span>
178                      <span class="identifier">g</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]</span></code>
179                    </p>
180                  </td>
181<td>
182                    <p>
183                      The <code class="computeroutput"><span class="identifier">columns</span></code>
184                      directive invokes a generator after each N-th element of the
185                      embedded generator has been emitted. The number of columns
186                      is defined by the argument to the directive <code class="computeroutput"><span class="identifier">num</span></code>.
187                      The column separator used will be <code class="computeroutput"><span class="identifier">g</span></code>.
188                    </p>
189                  </td>
190</tr>
191</tbody>
192</table></div>
193<h6>
194<a name="spirit.karma.reference.directive.columns.h4"></a>
195            <span class="phrase"><a name="spirit.karma.reference.directive.columns.attributes"></a></span><a class="link" href="columns.html#spirit.karma.reference.directive.columns.attributes">Attributes</a>
196          </h6>
197<p>
198            See <a class="link" href="../../quick_reference/compound_attribute_rules.html#spirit.karma.quick_reference.compound_attribute_rules.notation">Compound
199            Attribute Notation</a>.
200          </p>
201<div class="informaltable"><table class="table">
202<colgroup>
203<col>
204<col>
205</colgroup>
206<thead><tr>
207<th>
208                    <p>
209                      Expression
210                    </p>
211                  </th>
212<th>
213                    <p>
214                      Attribute
215                    </p>
216                  </th>
217</tr></thead>
218<tbody>
219<tr>
220<td>
221                    <p>
222                      <code class="computeroutput"><span class="identifier">columns</span><span class="special">[</span><span class="identifier">a</span><span class="special">]</span></code>
223                    </p>
224                  </td>
225<td>
226                    <p>
227</p>
228<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">a</span><span class="special">:</span> <span class="identifier">A</span> <span class="special">--&gt;</span> <span class="identifier">columns</span><span class="special">[</span><span class="identifier">a</span><span class="special">]:</span> <span class="identifier">A</span>
229<span class="identifier">a</span><span class="special">:</span> <span class="identifier">Unused</span> <span class="special">--&gt;</span> <span class="identifier">columns</span><span class="special">[</span><span class="identifier">a</span><span class="special">]:</span> <span class="identifier">Unused</span></pre>
230<p>
231                    </p>
232                  </td>
233</tr>
234<tr>
235<td>
236                    <p>
237                      <code class="computeroutput"><span class="identifier">columns</span><span class="special">(</span><span class="identifier">num</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]</span></code>
238                    </p>
239                  </td>
240<td>
241                    <p>
242</p>
243<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">a</span><span class="special">:</span> <span class="identifier">A</span> <span class="special">--&gt;</span> <span class="identifier">columns</span><span class="special">(</span><span class="identifier">num</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]:</span> <span class="identifier">A</span>
244<span class="identifier">a</span><span class="special">:</span> <span class="identifier">Unused</span> <span class="special">--&gt;</span> <span class="identifier">columns</span><span class="special">(</span><span class="identifier">num</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]:</span> <span class="identifier">Unused</span></pre>
245<p>
246                    </p>
247                  </td>
248</tr>
249<tr>
250<td>
251                    <p>
252                      <code class="computeroutput"><span class="identifier">columns</span><span class="special">(</span><span class="identifier">g</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]</span></code>
253                    </p>
254                  </td>
255<td>
256                    <p>
257</p>
258<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">a</span><span class="special">:</span> <span class="identifier">A</span> <span class="special">--&gt;</span> <span class="identifier">columns</span><span class="special">(</span><span class="identifier">g</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]:</span> <span class="identifier">A</span>
259<span class="identifier">a</span><span class="special">:</span> <span class="identifier">Unused</span> <span class="special">--&gt;</span> <span class="identifier">columns</span><span class="special">(</span><span class="identifier">g</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]:</span> <span class="identifier">Unused</span></pre>
260<p>
261                    </p>
262                  </td>
263</tr>
264<tr>
265<td>
266                    <p>
267                      <code class="computeroutput"><span class="identifier">columns</span><span class="special">(</span><span class="identifier">num</span><span class="special">,</span>
268                      <span class="identifier">g</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]</span></code>
269                    </p>
270                  </td>
271<td>
272                    <p>
273</p>
274<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">a</span><span class="special">:</span> <span class="identifier">A</span> <span class="special">--&gt;</span> <span class="identifier">columns</span><span class="special">(</span><span class="identifier">num</span><span class="special">,</span> <span class="identifier">g</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]:</span> <span class="identifier">A</span>
275<span class="identifier">a</span><span class="special">:</span> <span class="identifier">Unused</span> <span class="special">--&gt;</span> <span class="identifier">columns</span><span class="special">(</span><span class="identifier">num</span><span class="special">,</span> <span class="identifier">g</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]:</span> <span class="identifier">Unused</span></pre>
276<p>
277                    </p>
278                  </td>
279</tr>
280</tbody>
281</table></div>
282<h6>
283<a name="spirit.karma.reference.directive.columns.h5"></a>
284            <span class="phrase"><a name="spirit.karma.reference.directive.columns.complexity"></a></span><a class="link" href="columns.html#spirit.karma.reference.directive.columns.complexity">Complexity</a>
285          </h6>
286<div class="blockquote"><blockquote class="blockquote"><p>
287              The overall complexity of the <code class="computeroutput"><span class="identifier">columns</span></code>
288              generator directive depends on the complexity of the embedded generator.
289              The complexity of the <code class="computeroutput"><span class="identifier">columns</span></code>
290              generator directive itself is O(N), where <code class="computeroutput"><span class="identifier">N</span></code>
291              is the number of inserted column separators.
292            </p></blockquote></div>
293<h6>
294<a name="spirit.karma.reference.directive.columns.h6"></a>
295            <span class="phrase"><a name="spirit.karma.reference.directive.columns.example"></a></span><a class="link" href="columns.html#spirit.karma.reference.directive.columns.example">Example</a>
296          </h6>
297<div class="note"><table border="0" summary="Note">
298<tr>
299<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td>
300<th align="left">Note</th>
301</tr>
302<tr><td align="left" valign="top"><p>
303              The test harness for the example(s) below is presented in the <a class="link" href="../basics.html#spirit.karma.reference.basics.examples">Basics Examples</a>
304              section.
305            </p></td></tr>
306</table></div>
307<p>
308            Some includes:
309          </p>
310<p>
311</p>
312<pre class="programlisting"><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</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
313<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">support_utree</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
314<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">phoenix_core</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
315<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">phoenix_operator</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
316<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">fusion</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">std_pair</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
317<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>
318<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">string</span><span class="special">&gt;</span>
319</pre>
320<p>
321          </p>
322<p>
323            Some using declarations:
324          </p>
325<p>
326</p>
327<pre class="programlisting"><span class="keyword">using</span> <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">double_</span><span class="special">;</span>
328<span class="keyword">using</span> <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">columns</span><span class="special">;</span>
329<span class="keyword">using</span> <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">space</span><span class="special">;</span>
330</pre>
331<p>
332          </p>
333<p>
334            Basic usage of the <code class="computeroutput"><span class="identifier">columns</span></code>
335            generators:
336          </p>
337<p>
338</p>
339<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span> <span class="identifier">v</span><span class="special">;</span>
340<span class="identifier">v</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="number">1.0</span><span class="special">);</span>
341<span class="identifier">v</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="number">2.0</span><span class="special">);</span>
342<span class="identifier">v</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="number">3.0</span><span class="special">);</span>
343<span class="identifier">test_generator_attr</span><span class="special">(</span><span class="string">"1.0\n2.0\n3.0\n"</span><span class="special">,</span> <span class="identifier">columns</span><span class="special">(</span><span class="number">1</span><span class="special">)[*</span><span class="identifier">double_</span><span class="special">],</span> <span class="identifier">v</span><span class="special">);</span>
344<span class="identifier">test_generator_attr_delim</span><span class="special">(</span><span class="string">"1.0 2.0 \n3.0 \n"</span><span class="special">,</span> <span class="identifier">columns</span><span class="special">(</span><span class="number">2</span><span class="special">)[*</span><span class="identifier">double_</span><span class="special">],</span> <span class="identifier">space</span><span class="special">,</span> <span class="identifier">v</span><span class="special">);</span>
345</pre>
346<p>
347          </p>
348</div>
349<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
350<td align="left"></td>
351<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p>
352        Distributed under the Boost Software License, Version 1.0. (See accompanying
353        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>)
354      </p>
355</div></td>
356</tr></table>
357<hr>
358<div class="spirit-nav">
359<a accesskey="p" href="duplicate.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../directive.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="as.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
360</div>
361</body>
362</html>
363