]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*============================================================================= |
2 | Copyright (c) 2001-2014 Joel de Guzman | |
3 | ||
4 | Distributed under the Boost Software License, Version 1.0. (See accompanying | |
5 | file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
6 | ==============================================================================*/ | |
7 | #if !defined(BOOST_SPIRIT_X3_INT_APR_17_2006_0830AM) | |
8 | #define BOOST_SPIRIT_X3_INT_APR_17_2006_0830AM | |
9 | ||
10 | #include <boost/spirit/home/x3/core/parser.hpp> | |
11 | #include <boost/spirit/home/x3/core/skip_over.hpp> | |
12 | #include <boost/spirit/home/x3/support/numeric_utils/extract_int.hpp> | |
13 | #include <cstdint> | |
14 | ||
15 | namespace boost { namespace spirit { namespace x3 | |
16 | { | |
17 | /////////////////////////////////////////////////////////////////////////// | |
18 | template < | |
19 | typename T | |
20 | , unsigned Radix = 10 | |
21 | , unsigned MinDigits = 1 | |
22 | , int MaxDigits = -1> | |
23 | struct int_parser : parser<int_parser<T, Radix, MinDigits, MaxDigits>> | |
24 | { | |
25 | // check template parameter 'Radix' for validity | |
26 | static_assert( | |
27 | (Radix == 2 || Radix == 8 || Radix == 10 || Radix == 16), | |
28 | "Error Unsupported Radix"); | |
29 | ||
30 | typedef T attribute_type; | |
31 | static bool const has_attribute = true; | |
32 | ||
33 | template <typename Iterator, typename Context, typename Attribute> | |
34 | bool parse(Iterator& first, Iterator const& last | |
35 | , Context const& context, unused_type, Attribute& attr) const | |
36 | { | |
37 | typedef extract_int<T, Radix, MinDigits, MaxDigits> extract; | |
38 | x3::skip_over(first, last, context); | |
39 | return extract::call(first, last, attr); | |
40 | } | |
41 | }; | |
42 | ||
43 | #define BOOST_SPIRIT_X3_INT_PARSER(int_type, name) \ | |
44 | typedef int_parser<int_type> name##type; \ | |
45 | name##type const name = {}; \ | |
46 | /***/ | |
47 | ||
48 | BOOST_SPIRIT_X3_INT_PARSER(long, long_) | |
49 | BOOST_SPIRIT_X3_INT_PARSER(short, short_) | |
50 | BOOST_SPIRIT_X3_INT_PARSER(int, int_) | |
51 | BOOST_SPIRIT_X3_INT_PARSER(long long, long_long) | |
52 | ||
53 | BOOST_SPIRIT_X3_INT_PARSER(int8_t, int8) | |
54 | BOOST_SPIRIT_X3_INT_PARSER(int16_t, int16) | |
55 | BOOST_SPIRIT_X3_INT_PARSER(int32_t, int32) | |
56 | BOOST_SPIRIT_X3_INT_PARSER(int64_t, int64) | |
57 | ||
58 | #undef BOOST_SPIRIT_X3_INT_PARSER | |
59 | ||
60 | }}} | |
61 | ||
62 | #endif |