Chris@102
|
1 /*=============================================================================
|
Chris@102
|
2 Copyright (c) 2001-2014 Joel de Guzman
|
Chris@102
|
3 Copyright (c) 2011 Jan Frederick Eick
|
Chris@102
|
4
|
Chris@102
|
5 Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@102
|
6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@102
|
7 ==============================================================================*/
|
Chris@102
|
8 #if !defined(BOOST_SPIRIT_X3_UINT_APR_17_2006_0901AM)
|
Chris@102
|
9 #define BOOST_SPIRIT_X3_UINT_APR_17_2006_0901AM
|
Chris@102
|
10
|
Chris@102
|
11 #if defined(_MSC_VER)
|
Chris@102
|
12 #pragma once
|
Chris@102
|
13 #endif
|
Chris@102
|
14
|
Chris@102
|
15 #include <boost/spirit/home/x3/core/parser.hpp>
|
Chris@102
|
16 #include <boost/spirit/home/x3/core/skip_over.hpp>
|
Chris@102
|
17 #include <boost/spirit/home/x3/support/numeric_utils/extract_int.hpp>
|
Chris@102
|
18 #include <cstdint>
|
Chris@102
|
19
|
Chris@102
|
20 namespace boost { namespace spirit { namespace x3
|
Chris@102
|
21 {
|
Chris@102
|
22 ///////////////////////////////////////////////////////////////////////////
|
Chris@102
|
23 template <
|
Chris@102
|
24 typename T
|
Chris@102
|
25 , unsigned Radix = 10
|
Chris@102
|
26 , unsigned MinDigits = 1
|
Chris@102
|
27 , int MaxDigits = -1>
|
Chris@102
|
28 struct uint_parser : parser<uint_parser<T, Radix, MinDigits, MaxDigits>>
|
Chris@102
|
29 {
|
Chris@102
|
30 // check template parameter 'Radix' for validity
|
Chris@102
|
31 static_assert(
|
Chris@102
|
32 (Radix >= 2 && Radix <= 36),
|
Chris@102
|
33 "Error Unsupported Radix");
|
Chris@102
|
34
|
Chris@102
|
35 typedef T attribute_type;
|
Chris@102
|
36 static bool const has_attribute = true;
|
Chris@102
|
37
|
Chris@102
|
38 template <typename Iterator, typename Context, typename Attribute>
|
Chris@102
|
39 bool parse(Iterator& first, Iterator const& last
|
Chris@102
|
40 , Context const& context, unused_type, Attribute& attr) const
|
Chris@102
|
41 {
|
Chris@102
|
42 typedef extract_uint<T, Radix, MinDigits, MaxDigits> extract;
|
Chris@102
|
43 x3::skip_over(first, last, context);
|
Chris@102
|
44 return extract::call(first, last, attr);
|
Chris@102
|
45 }
|
Chris@102
|
46 };
|
Chris@102
|
47
|
Chris@102
|
48 #define BOOST_SPIRIT_X3_UINT_PARSER(uint_type, name) \
|
Chris@102
|
49 typedef uint_parser<uint_type> name##type; \
|
Chris@102
|
50 name##type const name = {}; \
|
Chris@102
|
51 /***/
|
Chris@102
|
52
|
Chris@102
|
53 BOOST_SPIRIT_X3_UINT_PARSER(unsigned long, ulong_)
|
Chris@102
|
54 BOOST_SPIRIT_X3_UINT_PARSER(unsigned short, ushort_)
|
Chris@102
|
55 BOOST_SPIRIT_X3_UINT_PARSER(unsigned int, uint_)
|
Chris@102
|
56 BOOST_SPIRIT_X3_UINT_PARSER(unsigned long long, ulong_long)
|
Chris@102
|
57
|
Chris@102
|
58 BOOST_SPIRIT_X3_UINT_PARSER(uint8_t, uint8)
|
Chris@102
|
59 BOOST_SPIRIT_X3_UINT_PARSER(uint16_t, uint16)
|
Chris@102
|
60 BOOST_SPIRIT_X3_UINT_PARSER(uint32_t, uint32)
|
Chris@102
|
61 BOOST_SPIRIT_X3_UINT_PARSER(uint64_t, uint64)
|
Chris@102
|
62
|
Chris@102
|
63 #undef BOOST_SPIRIT_X3_UINT_PARSER
|
Chris@102
|
64
|
Chris@102
|
65 #define BOOST_SPIRIT_X3_UINT_PARSER(uint_type, radix, name) \
|
Chris@102
|
66 typedef uint_parser<uint_type, radix> name##type; \
|
Chris@102
|
67 name##type const name = name##type(); \
|
Chris@102
|
68 /***/
|
Chris@102
|
69
|
Chris@102
|
70 BOOST_SPIRIT_X3_UINT_PARSER(unsigned, 2, bin)
|
Chris@102
|
71 BOOST_SPIRIT_X3_UINT_PARSER(unsigned, 8, oct)
|
Chris@102
|
72 BOOST_SPIRIT_X3_UINT_PARSER(unsigned, 16, hex)
|
Chris@102
|
73
|
Chris@102
|
74 #undef BOOST_SPIRIT_X3_UINT_PARSER
|
Chris@102
|
75
|
Chris@102
|
76
|
Chris@102
|
77 }}}
|
Chris@102
|
78
|
Chris@102
|
79 #endif
|