Imported Upstream version 1.49.0
[platform/upstream/boost.git] / libs / spirit / doc / html / spirit / karma / reference / directive / maxwidth.html
1 <html>
2 <head>
3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>Generator Directives Controlling the Maximum Field Width (maxwidth[])</title>
5 <link rel="stylesheet" href="../../../../../../../../doc/src/boostbook.css" type="text/css">
6 <meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
7 <link rel="home" href="../../../../index.html" title="Spirit 2.5.2">
8 <link rel="up" href="../directive.html" title="Generator Directives">
9 <link rel="prev" href="upperlower.html" title="Generator Directives Controlling Case Sensitivity (upper[], lower[])">
10 <link rel="next" href="buffer.html" title="Generator Directive for Temporary Output Buffering (buffer[])">
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="upperlower.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="buffer.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.maxwidth"></a><a class="link" href="maxwidth.html" title="Generator Directives Controlling the Maximum Field Width (maxwidth[])">Generator
28           Directives Controlling the Maximum Field Width (<code class="computeroutput"><span class="identifier">maxwidth</span><span class="special">[]</span></code>)</a>
29 </h5></div></div></div>
30 <h6>
31 <a name="spirit.karma.reference.directive.maxwidth.h0"></a>
32             <span><a name="spirit.karma.reference.directive.maxwidth.description"></a></span><a class="link" href="maxwidth.html#spirit.karma.reference.directive.maxwidth.description">Description</a>
33           </h6>
34 <p>
35             The <code class="computeroutput"><span class="identifier">maxwidth</span><span class="special">[]</span></code>
36             directive allows to limit (truncate) the overall length of the output
37             generated by the embedded generator.
38           </p>
39 <h6>
40 <a name="spirit.karma.reference.directive.maxwidth.h1"></a>
41             <span><a name="spirit.karma.reference.directive.maxwidth.header"></a></span><a class="link" href="maxwidth.html#spirit.karma.reference.directive.maxwidth.header">Header</a>
42           </h6>
43 <pre class="programlisting"><span class="comment">// forwards to &lt;boost/spirit/home/karma/directive/maxwidth.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_maxwidth</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">maxwidth</span> <span class="comment">//
59                       alias: boost::spirit::karma::maxwidth</span></code>
60                     </p>
61                   </td></tr></tbody>
62 </table></div>
63 <h6>
64 <a name="spirit.karma.reference.directive.maxwidth.h2"></a>
65             <span><a name="spirit.karma.reference.directive.maxwidth.model_of"></a></span><a class="link" href="maxwidth.html#spirit.karma.reference.directive.maxwidth.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>
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">A</span></code></span></dt>
78 <dd><p>
79                   Attribute type of the generator <code class="computeroutput"><span class="identifier">a</span></code>
80                 </p></dd>
81 <dt><span class="term"><code class="computeroutput"><span class="identifier">num</span></code></span></dt>
82 <dd><p>
83                   Numeric literal, any unsigned integer value, or a <a class="link" href="../basics.html#spirit.karma.reference.basics.lazy_argument">Lazy
84                   Argument</a> that evaluates to an unsigned integer value
85                 </p></dd>
86 </dl>
87 </div>
88 <h6>
89 <a name="spirit.karma.reference.directive.maxwidth.h3"></a>
90             <span><a name="spirit.karma.reference.directive.maxwidth.expression_semantics"></a></span><a class="link" href="maxwidth.html#spirit.karma.reference.directive.maxwidth.expression_semantics">Expression
91             Semantics</a>
92           </h6>
93 <p>
94             Semantics of an expression is defined only where it differs from, or
95             is not defined in <a class="link" href="../generator_concepts/unarygenerator.html" title="UnaryGenerator"><code class="computeroutput"><span class="identifier">UnaryGenerator</span></code></a>.
96           </p>
97 <div class="informaltable"><table class="table">
98 <colgroup>
99 <col>
100 <col>
101 </colgroup>
102 <thead><tr>
103 <th>
104                     <p>
105                       Expression
106                     </p>
107                   </th>
108 <th>
109                     <p>
110                       Semantics
111                     </p>
112                   </th>
113 </tr></thead>
114 <tbody>
115 <tr>
116 <td>
117                     <p>
118                       <code class="computeroutput"><span class="identifier">maxwidth</span><span class="special">[</span><span class="identifier">a</span><span class="special">]</span></code>
119                     </p>
120                   </td>
121 <td>
122                     <p>
123                       Limit the overall length of the emitted output of the embedded
124                       generator (including characters generated by automatic delimiting)
125                       to the number of characters as defined by the preprocessor
126                       constant <code class="computeroutput"><span class="identifier">BOOST_KARMA_DEFAULT_FIELD_MAXWIDTH</span></code>.
127                       Any additional output is truncated. The directive succeeds
128                       as long as the embedded generator succeeded (unless the underlying
129                       output stream reports an error).
130                     </p>
131                   </td>
132 </tr>
133 <tr>
134 <td>
135                     <p>
136                       <code class="computeroutput"><span class="identifier">maxwidth</span><span class="special">(</span><span class="identifier">num</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]</span></code>
137                     </p>
138                   </td>
139 <td>
140                     <p>
141                       Limit the overall length of the emitted output of the embedded
142                       generator (including characters generated by automatic delimiting)
143                       to the number of characters as defined by <code class="computeroutput"><span class="identifier">num</span></code>.
144                       Any additional output is truncated. The directive succeeds
145                       as long as the embedded generator succeeded (unless the underlying
146                       output stream reports an error).
147                     </p>
148                   </td>
149 </tr>
150 </tbody>
151 </table></div>
152 <div class="note"><table border="0" summary="Note">
153 <tr>
154 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td>
155 <th align="left">Note</th>
156 </tr>
157 <tr><td align="left" valign="top">
158 <p>
159               The <code class="computeroutput"><span class="identifier">maxwidth</span><span class="special">[]</span></code>
160               generator directive does not pad the generated output to fill the specified
161               column width. If the emitted output is shorter than the specified (or
162               implied) column width, the generated output will be more narrow than
163               the column width.
164             </p>
165 <p>
166               If the output needs to always be equal to a specified column width,
167               use one of the alignment directives <code class="computeroutput"><span class="identifier">left</span><span class="special">-</span><span class="identifier">align</span><span class="special">[]</span></code>, <code class="computeroutput"><span class="identifier">center</span><span class="special">[]</span></code>, or <code class="computeroutput"><span class="identifier">right_align</span><span class="special">[]</span></code>, for instance:
168 </p>
169 <pre class="programlisting"><span class="identifier">maxwidth</span><span class="special">(</span><span class="number">8</span><span class="special">)[</span><span class="identifier">left_align</span><span class="special">(</span><span class="number">8</span><span class="special">)[</span><span class="string">"1234"</span><span class="special">]]</span>
170 </pre>
171 <p>
172               which will output: <code class="computeroutput"><span class="string">"1234 "</span></code>
173               (without the quotes).
174             </p>
175 </td></tr>
176 </table></div>
177 <h6>
178 <a name="spirit.karma.reference.directive.maxwidth.h4"></a>
179             <span><a name="spirit.karma.reference.directive.maxwidth.attributes"></a></span><a class="link" href="maxwidth.html#spirit.karma.reference.directive.maxwidth.attributes">Attributes</a>
180           </h6>
181 <p>
182             See <a class="link" href="../../quick_reference/compound_attribute_rules.html#spirit.karma.quick_reference.compound_attribute_rules.notation">Compound
183             Attribute Notation</a>.
184           </p>
185 <div class="informaltable"><table class="table">
186 <colgroup>
187 <col>
188 <col>
189 </colgroup>
190 <thead><tr>
191 <th>
192                     <p>
193                       Expression
194                     </p>
195                   </th>
196 <th>
197                     <p>
198                       Attribute
199                     </p>
200                   </th>
201 </tr></thead>
202 <tbody>
203 <tr>
204 <td>
205                     <p>
206                       <code class="computeroutput"><span class="identifier">maxwidth</span><span class="special">[</span><span class="identifier">a</span><span class="special">]</span></code>
207                     </p>
208                   </td>
209 <td>
210                     <p>
211 </p>
212 <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">maxwidth</span><span class="special">[</span><span class="identifier">a</span><span class="special">]:</span> <span class="identifier">A</span>
213 <span class="identifier">a</span><span class="special">:</span> <span class="identifier">Unused</span> <span class="special">--&gt;</span> <span class="identifier">maxwidth</span><span class="special">[</span><span class="identifier">a</span><span class="special">]:</span> <span class="identifier">Unused</span></pre>
214 <p>
215                     </p>
216                   </td>
217 </tr>
218 <tr>
219 <td>
220                     <p>
221                       <code class="computeroutput"><span class="identifier">maxwidth</span><span class="special">(</span><span class="identifier">num</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]</span></code>
222                     </p>
223                   </td>
224 <td>
225                     <p>
226 </p>
227 <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">maxwidth</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>
228 <span class="identifier">a</span><span class="special">:</span> <span class="identifier">Unused</span> <span class="special">--&gt;</span> <span class="identifier">maxwidth</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>
229 <p>
230                     </p>
231                   </td>
232 </tr>
233 </tbody>
234 </table></div>
235 <h6>
236 <a name="spirit.karma.reference.directive.maxwidth.h5"></a>
237             <span><a name="spirit.karma.reference.directive.maxwidth.complexity"></a></span><a class="link" href="maxwidth.html#spirit.karma.reference.directive.maxwidth.complexity">Complexity</a>
238           </h6>
239 <div class="blockquote"><blockquote class="blockquote"><p>
240               The overall complexity of the generator directive <code class="computeroutput"><span class="identifier">maxwidth</span><span class="special">[]</span></code> is defined by the complexity of its
241               embedded generator. The complexity of the directive itself is O(N),
242               where <code class="computeroutput"><span class="identifier">N</span></code> is the number
243               of characters generated by the maxwidth directive.
244             </p></blockquote></div>
245 <h6>
246 <a name="spirit.karma.reference.directive.maxwidth.h6"></a>
247             <span><a name="spirit.karma.reference.directive.maxwidth.example"></a></span><a class="link" href="maxwidth.html#spirit.karma.reference.directive.maxwidth.example">Example</a>
248           </h6>
249 <div class="note"><table border="0" summary="Note">
250 <tr>
251 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td>
252 <th align="left">Note</th>
253 </tr>
254 <tr><td align="left" valign="top"><p>
255               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>
256               section.
257             </p></td></tr>
258 </table></div>
259 <p>
260             Some includes:
261           </p>
262 <p>
263 </p>
264 <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>
265 <span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>
266 <span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">string</span><span class="special">&gt;</span>
267 </pre>
268 <p>
269           </p>
270 <p>
271             Some using declarations:
272           </p>
273 <p>
274 </p>
275 <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>
276 <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">maxwidth</span><span class="special">;</span>
277 <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">left_align</span><span class="special">;</span>
278 <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">right_align</span><span class="special">;</span>
279 </pre>
280 <p>
281           </p>
282 <p>
283             Basic usage of <code class="computeroutput"><span class="identifier">maxwidth</span></code>
284             generator directive:
285           </p>
286 <p>
287 </p>
288 <pre class="programlisting"><span class="identifier">test_generator</span><span class="special">(</span><span class="string">"01234"</span><span class="special">,</span> <span class="identifier">maxwidth</span><span class="special">(</span><span class="number">5</span><span class="special">)[</span><span class="string">"0123456789"</span><span class="special">]);</span>
289 <span class="identifier">test_generator</span><span class="special">(</span><span class="string">"  012"</span><span class="special">,</span> <span class="identifier">maxwidth</span><span class="special">(</span><span class="number">5</span><span class="special">)[</span><span class="identifier">right_align</span><span class="special">(</span><span class="number">12</span><span class="special">)[</span><span class="string">"0123456789"</span><span class="special">]]);</span>
290 <span class="identifier">test_generator</span><span class="special">(</span><span class="string">"0123    "</span><span class="special">,</span> <span class="identifier">maxwidth</span><span class="special">(</span><span class="number">8</span><span class="special">)[</span><span class="identifier">left_align</span><span class="special">(</span><span class="number">8</span><span class="special">)[</span><span class="string">"0123"</span><span class="special">]]);</span>
291 </pre>
292 <p>
293           </p>
294 </div>
295 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
296 <td align="left"></td>
297 <td align="right"><div class="copyright-footer">Copyright &#169; 2001-2011 Joel de Guzman, Hartmut Kaiser<p>
298         Distributed under the Boost Software License, Version 1.0. (See accompanying
299         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>)
300       </p>
301 </div></td>
302 </tr></table>
303 <hr>
304 <div class="spirit-nav">
305 <a accesskey="p" href="upperlower.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="buffer.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
306 </div>
307 </body>
308 </html>