| <html> |
| <head> |
| <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> |
| <title>Signed Integers (int_, etc.)</title> |
| <link rel="stylesheet" href="../../../../../../../../doc/src/boostbook.css" type="text/css"> |
| <meta name="generator" content="DocBook XSL Stylesheets V1.75.0"> |
| <link rel="home" href="../../../../index.html" title="Spirit 2.4.1"> |
| <link rel="up" href="../numeric.html" title="Numeric"> |
| <link rel="prev" href="uint.html" title="Unsigned Integers (uint_, etc.)"> |
| <link rel="next" href="real.html" title="Real Numbers (float_, double_, etc.)"> |
| </head> |
| <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> |
| <table cellpadding="2" width="100%"><tr> |
| <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../../boost.png"></td> |
| <td align="center"><a href="../../../../../../../../index.html">Home</a></td> |
| <td align="center"><a href="../../../../../../../../libs/libraries.htm">Libraries</a></td> |
| <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> |
| <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> |
| <td align="center"><a href="../../../../../../../../more/index.htm">More</a></td> |
| </tr></table> |
| <hr> |
| <div class="spirit-nav"> |
| <a accesskey="p" href="uint.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../numeric.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="real.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> |
| </div> |
| <div class="section"> |
| <div class="titlepage"><div><div><h5 class="title"> |
| <a name="spirit.qi.reference.numeric.int"></a><a class="link" href="int.html" title="Signed Integers (int_, etc.)">Signed Integers |
| (<code class="computeroutput"><span class="identifier">int_</span></code>, etc.)</a> |
| </h5></div></div></div> |
| <a name="spirit.qi.reference.numeric.int.description"></a><h6> |
| <a name="id906889"></a> |
| <a class="link" href="int.html#spirit.qi.reference.numeric.int.description">Description</a> |
| </h6> |
| <p> |
| The <code class="computeroutput"><span class="identifier">int_parser</span></code> can parse |
| signed integers of arbitrary length and size. This is almost the same |
| as the <code class="computeroutput"><span class="identifier">uint_parser</span></code>. The |
| only difference is the additional task of parsing the <code class="computeroutput"><span class="char">'+'</span></code> |
| or <code class="computeroutput"><span class="char">'-'</span></code> sign preceding the number. |
| The class interface is the same as that of the <code class="computeroutput"><span class="identifier">uint_parser</span></code>. |
| </p> |
| <p> |
| The <code class="computeroutput"><span class="identifier">int_parser</span></code> parser |
| can be used to parse ordinary primitive C/C++ integers or even user defined |
| scalars such as bigints (unlimited precision integers) as long as the |
| type follows certain expression requirements (documented below). |
| </p> |
| <a name="spirit.qi.reference.numeric.int.header"></a><h6> |
| <a name="id908051"></a> |
| <a class="link" href="int.html#spirit.qi.reference.numeric.int.header">Header</a> |
| </h6> |
| <pre class="programlisting"><span class="comment">// forwards to <boost/spirit/home/qi/numeric/int.hpp> |
| </span><span class="preprocessor">#include</span> <span class="special"><</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">qi_int</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> |
| </pre> |
| <p> |
| Also, see <a class="link" href="../../../structure/include.html" title="Include">Include Structure</a>. |
| </p> |
| <a name="spirit.qi.reference.numeric.int.namespace"></a><h6> |
| <a name="id908125"></a> |
| <a class="link" href="int.html#spirit.qi.reference.numeric.int.namespace">Namespace</a> |
| </h6> |
| <div class="informaltable"><table class="table"> |
| <colgroup><col></colgroup> |
| <thead><tr><th> |
| <p> |
| Name |
| </p> |
| </th></tr></thead> |
| <tbody> |
| <tr><td> |
| <p> |
| <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">short_</span> <span class="comment">// |
| alias: boost::spirit::qi::short_</span></code> |
| </p> |
| </td></tr> |
| <tr><td> |
| <p> |
| <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">int_</span> <span class="comment">// alias: |
| boost::spirit::qi::int_</span></code> |
| </p> |
| </td></tr> |
| <tr><td> |
| <p> |
| <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">long_</span> <span class="comment">// |
| alias: boost::spirit::qi::long_</span></code> |
| </p> |
| </td></tr> |
| <tr><td> |
| <p> |
| <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">long_long</span> <span class="comment">// |
| alias: boost::spirit::qi::long_long</span></code> |
| </p> |
| </td></tr> |
| </tbody> |
| </table></div> |
| <div class="note"><table border="0" summary="Note"> |
| <tr> |
| <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td> |
| <th align="left">Note</th> |
| </tr> |
| <tr><td align="left" valign="top"><p> |
| <code class="computeroutput"><span class="identifier">long_long</span></code> is only available |
| on platforms where the preprocessor constant <code class="computeroutput"><span class="identifier">BOOST_HAS_LONG_LONG</span></code> |
| is defined (i.e. on platforms having native support for <code class="computeroutput"><span class="keyword">signed</span> <span class="keyword">long</span> |
| <span class="keyword">long</span></code> (64 bit) unsigned integer |
| types). |
| </p></td></tr> |
| </table></div> |
| <a name="spirit.qi.reference.numeric.int.synopsis"></a><h6> |
| <a name="id908358"></a> |
| <a class="link" href="int.html#spirit.qi.reference.numeric.int.synopsis">Synopsis</a> |
| </h6> |
| <pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span> |
| <span class="keyword">typename</span> <span class="identifier">T</span> |
| <span class="special">,</span> <span class="keyword">unsigned</span> <span class="identifier">Radix</span> |
| <span class="special">,</span> <span class="keyword">unsigned</span> <span class="identifier">MinDigits</span> |
| <span class="special">,</span> <span class="keyword">int</span> <span class="identifier">MaxDigits</span><span class="special">></span> |
| <span class="keyword">struct</span> <span class="identifier">int_parser</span><span class="special">;</span> |
| </pre> |
| <a name="spirit.qi.reference.numeric.int.template_parameters"></a><h6> |
| <a name="id908454"></a> |
| <a class="link" href="int.html#spirit.qi.reference.numeric.int.template_parameters">Template |
| parameters</a> |
| </h6> |
| <div class="informaltable"><table class="table"> |
| <colgroup> |
| <col> |
| <col> |
| <col> |
| </colgroup> |
| <thead><tr> |
| <th> |
| <p> |
| Parameter |
| </p> |
| </th> |
| <th> |
| <p> |
| Description |
| </p> |
| </th> |
| <th> |
| <p> |
| Default |
| </p> |
| </th> |
| </tr></thead> |
| <tbody> |
| <tr> |
| <td> |
| <p> |
| <code class="computeroutput"><span class="identifier">T</span></code> |
| </p> |
| </td> |
| <td> |
| <p> |
| The numeric base type of the numeric parser. |
| </p> |
| </td> |
| <td> |
| <p> |
| none |
| </p> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <p> |
| <code class="computeroutput"><span class="identifier">Radix</span></code> |
| </p> |
| </td> |
| <td> |
| <p> |
| The radix base. This can be either 2: binary, 8: octal, 10: |
| decimal and 16: hexadecimal. |
| </p> |
| </td> |
| <td> |
| <p> |
| 10 |
| </p> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <p> |
| <code class="computeroutput"><span class="identifier">MinDigits</span></code> |
| </p> |
| </td> |
| <td> |
| <p> |
| The minimum number of digits allowable. |
| </p> |
| </td> |
| <td> |
| <p> |
| 1 |
| </p> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <p> |
| <code class="computeroutput"><span class="identifier">MaxDigits</span></code> |
| </p> |
| </td> |
| <td> |
| <p> |
| The maximum number of digits allowable. If this is -1, then |
| the maximum limit becomes unbounded. |
| </p> |
| </td> |
| <td> |
| <p> |
| -1 |
| </p> |
| </td> |
| </tr> |
| </tbody> |
| </table></div> |
| <a name="spirit.qi.reference.numeric.int.model_of"></a><h6> |
| <a name="id908639"></a> |
| <a class="link" href="int.html#spirit.qi.reference.numeric.int.model_of">Model of</a> |
| </h6> |
| <div class="blockquote"><blockquote class="blockquote"><p> |
| <a class="link" href="../parser_concepts/primitiveparser.html" title="PrimitiveParser"><code class="computeroutput"><span class="identifier">PrimitiveParser</span></code></a> |
| </p></blockquote></div> |
| <div class="variablelist"> |
| <p class="title"><b>Notation</b></p> |
| <dl> |
| <dt><span class="term"><code class="computeroutput"><span class="identifier">NP</span></code></span></dt> |
| <dd><p> |
| An instance of <code class="computeroutput"><span class="identifier">int_parser</span></code> |
| (type). |
| </p></dd> |
| <dt><span class="term"><code class="computeroutput"><span class="identifier">n</span></code></span></dt> |
| <dd><p> |
| An object of <code class="computeroutput"><span class="identifier">T</span></code>, |
| the numeric base type. |
| </p></dd> |
| </dl> |
| </div> |
| <a name="spirit.qi.reference.numeric.int.expression_semantics"></a><h6> |
| <a name="id908730"></a> |
| <a class="link" href="int.html#spirit.qi.reference.numeric.int.expression_semantics">Expression |
| Semantics</a> |
| </h6> |
| <p> |
| Semantics of an expression is defined only where it differs from, or |
| is not defined in <a class="link" href="../parser_concepts/primitiveparser.html" title="PrimitiveParser"><code class="computeroutput"><span class="identifier">PrimitiveParser</span></code></a>. |
| </p> |
| <div class="informaltable"><table class="table"> |
| <colgroup> |
| <col> |
| <col> |
| </colgroup> |
| <thead><tr> |
| <th> |
| <p> |
| Expression |
| </p> |
| </th> |
| <th> |
| <p> |
| Semantics |
| </p> |
| </th> |
| </tr></thead> |
| <tbody> |
| <tr> |
| <td> |
| <p> |
| <code class="computeroutput"><span class="identifier">NP</span><span class="special">()</span></code> |
| </p> |
| </td> |
| <td> |
| <p> |
| Instantiate and (default) construct an <code class="computeroutput"><span class="identifier">int_parser</span></code> |
| </p> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <p> |
| <code class="computeroutput"><span class="identifier">short_</span></code> |
| </p> |
| </td> |
| <td> |
| <p> |
| Create an <code class="computeroutput"><span class="identifier">int_parser</span><span class="special"><</span><span class="keyword">short</span><span class="special">,</span> <span class="number">10</span><span class="special">,</span> <span class="number">1</span><span class="special">,</span> <span class="special">-</span><span class="number">1</span><span class="special">></span></code> |
| </p> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <p> |
| <code class="computeroutput"><span class="identifier">long_</span></code> |
| </p> |
| </td> |
| <td> |
| <p> |
| Create an <code class="computeroutput"><span class="identifier">int_parser</span><span class="special"><</span><span class="keyword">long</span><span class="special">,</span> <span class="number">10</span><span class="special">,</span> <span class="number">1</span><span class="special">,</span> <span class="special">-</span><span class="number">1</span><span class="special">></span></code> |
| </p> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <p> |
| <code class="computeroutput"><span class="identifier">int_</span></code> |
| </p> |
| </td> |
| <td> |
| <p> |
| Create an <code class="computeroutput"><span class="identifier">int_parser</span><span class="special"><</span><span class="keyword">int</span><span class="special">,</span> <span class="number">10</span><span class="special">,</span> <span class="number">1</span><span class="special">,</span> <span class="special">-</span><span class="number">1</span><span class="special">></span></code> |
| </p> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <p> |
| <code class="computeroutput"><span class="identifier">long_long</span></code> |
| </p> |
| </td> |
| <td> |
| <p> |
| Create an <code class="computeroutput"><span class="identifier">int_parser</span><span class="special"><</span><span class="keyword">long</span> |
| <span class="keyword">long</span><span class="special">,</span> |
| <span class="number">10</span><span class="special">,</span> |
| <span class="number">1</span><span class="special">,</span> |
| <span class="special">-</span><span class="number">1</span><span class="special">></span></code> |
| </p> |
| </td> |
| </tr> |
| </tbody> |
| </table></div> |
| <div class="important"><table border="0" summary="Important"> |
| <tr> |
| <td rowspan="2" align="center" valign="top" width="25"><img alt="[Important]" src="../../../../images/important.png"></td> |
| <th align="left">Important</th> |
| </tr> |
| <tr><td align="left" valign="top"><p> |
| All numeric parsers check for overflow conditions based on the type |
| <code class="computeroutput"><span class="identifier">T</span></code> the corresponding |
| <code class="computeroutput"><span class="identifier">int_parser</span><span class="special"><></span></code> |
| has been instantiated with. If the parsed number overflows this type |
| the parsing fails. Please be aware that the overflow check is not based |
| on the type of the supplied attribute but solely depends on the template |
| parameter <code class="computeroutput"><span class="identifier">T</span></code>. |
| </p></td></tr> |
| </table></div> |
| <a name="spirit.qi.reference.numeric.int.attributes"></a><h6> |
| <a name="id909154"></a> |
| <a class="link" href="int.html#spirit.qi.reference.numeric.int.attributes">Attributes</a> |
| </h6> |
| <div class="blockquote"><blockquote class="blockquote"><p> |
| <code class="computeroutput"><span class="identifier">T</span></code>, The numeric base |
| type of the numeric parser. |
| </p></blockquote></div> |
| <a name="spirit.qi.reference.numeric.int.complexity"></a><h6> |
| <a name="id909181"></a> |
| <a class="link" href="int.html#spirit.qi.reference.numeric.int.complexity">Complexity</a> |
| </h6> |
| <div class="blockquote"><blockquote class="blockquote"><p> |
| O(N), where N is the number of digits being parsed plus the sign. |
| </p></blockquote></div> |
| <a name="spirit.qi.reference.numeric.int.minimum_expression_requirements_for__code__phrase_role__identifier__t__phrase___code_"></a><h6> |
| <a name="id909202"></a> |
| <a class="link" href="int.html#spirit.qi.reference.numeric.int.minimum_expression_requirements_for__code__phrase_role__identifier__t__phrase___code_">Minimum |
| Expression Requirements for <code class="computeroutput"><span class="identifier">T</span></code></a> |
| </h6> |
| <p> |
| For the numeric base type, <code class="computeroutput"><span class="identifier">T</span></code>, |
| the expression requirements below must be valid: |
| </p> |
| <div class="informaltable"><table class="table"> |
| <colgroup> |
| <col> |
| <col> |
| </colgroup> |
| <thead><tr> |
| <th> |
| <p> |
| Expression |
| </p> |
| </th> |
| <th> |
| <p> |
| Semantics |
| </p> |
| </th> |
| </tr></thead> |
| <tbody> |
| <tr> |
| <td> |
| <p> |
| <code class="computeroutput"><span class="identifier">T</span><span class="special">()</span></code> |
| </p> |
| </td> |
| <td> |
| <p> |
| Default construct. |
| </p> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <p> |
| <code class="computeroutput"><span class="identifier">T</span><span class="special">(</span><span class="number">0</span><span class="special">)</span></code> |
| </p> |
| </td> |
| <td> |
| <p> |
| Construct from an <code class="computeroutput"><span class="keyword">int</span></code>. |
| </p> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <p> |
| <code class="computeroutput"><span class="identifier">n</span> <span class="special">+</span> |
| <span class="identifier">n</span></code> |
| </p> |
| </td> |
| <td> |
| <p> |
| Addition. |
| </p> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <p> |
| <code class="computeroutput"><span class="identifier">n</span> <span class="special">-</span> |
| <span class="identifier">n</span></code> |
| </p> |
| </td> |
| <td> |
| <p> |
| Subtraction. |
| </p> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <p> |
| <code class="computeroutput"><span class="identifier">n</span> <span class="special">*</span> |
| <span class="identifier">n</span></code> |
| </p> |
| </td> |
| <td> |
| <p> |
| Multiplication. |
| </p> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <p> |
| <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">T</span><span class="special">>::</span><span class="identifier">is_bounded</span></code> |
| </p> |
| </td> |
| <td> |
| <p> |
| <code class="computeroutput"><span class="keyword">true</span></code> or <code class="computeroutput"><span class="keyword">false</span></code> if <code class="computeroutput"><span class="identifier">T</span></code> |
| bounded. |
| </p> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <p> |
| <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">T</span><span class="special">>::</span><span class="identifier">digits</span></code> |
| </p> |
| </td> |
| <td> |
| <p> |
| Maximum Digits for <code class="computeroutput"><span class="identifier">T</span></code>, |
| radix digits. Required only if <code class="computeroutput"><span class="identifier">T</span></code> |
| is bounded. |
| </p> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <p> |
| <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">T</span><span class="special">>::</span><span class="identifier">digits10</span></code> |
| </p> |
| </td> |
| <td> |
| <p> |
| Maximum Digits for <code class="computeroutput"><span class="identifier">T</span></code>, |
| base 10. Required only if <code class="computeroutput"><span class="identifier">T</span></code> |
| is bounded. |
| </p> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <p> |
| <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">T</span><span class="special">>::</span><span class="identifier">max</span><span class="special">()</span></code> |
| </p> |
| </td> |
| <td> |
| <p> |
| Maximum value for <code class="computeroutput"><span class="identifier">T</span></code>. |
| Required only if <code class="computeroutput"><span class="identifier">T</span></code> |
| is bounded. |
| </p> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <p> |
| <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">T</span><span class="special">>::</span><span class="identifier">min</span><span class="special">()</span></code> |
| </p> |
| </td> |
| <td> |
| <p> |
| Minimum value for <code class="computeroutput"><span class="identifier">T</span></code>. |
| Required only if <code class="computeroutput"><span class="identifier">T</span></code> |
| is bounded. |
| </p> |
| </td> |
| </tr> |
| </tbody> |
| </table></div> |
| <a name="spirit.qi.reference.numeric.int.example"></a><h6> |
| <a name="id909767"></a> |
| <a class="link" href="int.html#spirit.qi.reference.numeric.int.example">Example</a> |
| </h6> |
| <div class="note"><table border="0" summary="Note"> |
| <tr> |
| <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td> |
| <th align="left">Note</th> |
| </tr> |
| <tr><td align="left" valign="top"><p> |
| The test harness for the example(s) below is presented in the <a class="link" href="../basics.html#spirit.qi.reference.basics.examples">Basics Examples</a> |
| section. |
| </p></td></tr> |
| </table></div> |
| <p> |
| Some using declarations: |
| </p> |
| <p> |
| |
| </p> |
| <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">qi</span><span class="special">::</span><span class="identifier">int_</span><span class="special">;</span> |
| </pre> |
| <p> |
| </p> |
| <p> |
| Basic signed integers: |
| </p> |
| <p> |
| |
| </p> |
| <pre class="programlisting"><span class="identifier">test_parser</span><span class="special">(</span><span class="string">"+12345"</span><span class="special">,</span> <span class="identifier">int_</span><span class="special">);</span> |
| <span class="identifier">test_parser</span><span class="special">(</span><span class="string">"-12345"</span><span class="special">,</span> <span class="identifier">int_</span><span class="special">);</span> |
| </pre> |
| <p> |
| </p> |
| </div> |
| <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> |
| <td align="left"></td> |
| <td align="right"><div class="copyright-footer">Copyright © 2001-2010 Joel de Guzman, Hartmut Kaiser<p> |
| Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 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>) |
| </p> |
| </div></td> |
| </tr></table> |
| <hr> |
| <div class="spirit-nav"> |
| <a accesskey="p" href="uint.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../numeric.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="real.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> |
| </div> |
| </body> |
| </html> |