1 /*=============================================================================
2 Copyright (c) 2001-2014 Joel de Guzman
3 Copyright (c) 2011 Jan Frederick Eick
5 Distributed under the Boost Software License, Version 1.0. (See accompanying
6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 ==============================================================================*/
8 #if !defined(BOOST_SPIRIT_X3_EXTRACT_INT_APRIL_17_2006_0830AM)
9 #define BOOST_SPIRIT_X3_EXTRACT_INT_APRIL_17_2006_0830AM
11 #include <boost/spirit/home/x3/support/traits/move_to.hpp>
12 #include <boost/spirit/home/x3/support/numeric_utils/detail/extract_int.hpp>
13 #include <boost/assert.hpp>
15 namespace boost { namespace spirit { namespace x3
17 ///////////////////////////////////////////////////////////////////////////
18 // Extract the prefix sign (- or +), return true if a '-' was found
19 ///////////////////////////////////////////////////////////////////////////
20 template <typename Iterator>
22 extract_sign(Iterator& first, Iterator const& last)
24 (void)last; // silence unused warnings
25 BOOST_ASSERT(first != last); // precondition
28 bool neg = *first == '-';
29 if (neg || (*first == '+'))
37 ///////////////////////////////////////////////////////////////////////////
38 // Low level unsigned integer parser
39 ///////////////////////////////////////////////////////////////////////////
40 template <typename T, unsigned Radix, unsigned MinDigits, int MaxDigits
41 , bool Accumulate = false>
44 // check template parameter 'Radix' for validity
46 (Radix >= 2 && Radix <= 36),
47 "Error Unsupported Radix");
49 template <typename Iterator>
50 inline static bool call(Iterator& first, Iterator const& last, T& attr)
55 typedef detail::extract_int<
60 , detail::positive_accumulator<Radix>
64 Iterator save = first;
65 if (!extract_type::parse(first, last,
66 detail::cast_unsigned<T>::call(attr)))
74 template <typename Iterator, typename Attribute>
75 inline static bool call(Iterator& first, Iterator const& last, Attribute& attr_)
77 // this case is called when Attribute is not T
79 if (call(first, last, attr))
81 traits::move_to(attr, attr_);
88 ///////////////////////////////////////////////////////////////////////////
89 // Low level signed integer parser
90 ///////////////////////////////////////////////////////////////////////////
91 template <typename T, unsigned Radix, unsigned MinDigits, int MaxDigits>
94 // check template parameter 'Radix' for validity
96 (Radix == 2 || Radix == 8 || Radix == 10 || Radix == 16),
97 "Error Unsupported Radix");
99 template <typename Iterator>
100 inline static bool call(Iterator& first, Iterator const& last, T& attr)
105 typedef detail::extract_int<
106 T, Radix, MinDigits, MaxDigits>
109 typedef detail::extract_int<
110 T, Radix, MinDigits, MaxDigits, detail::negative_accumulator<Radix> >
113 Iterator save = first;
114 bool hit = extract_sign(first, last);
116 hit = extract_neg_type::parse(first, last, attr);
118 hit = extract_pos_type::parse(first, last, attr);
128 template <typename Iterator, typename Attribute>
129 inline static bool call(Iterator& first, Iterator const& last, Attribute& attr_)
131 // this case is called when Attribute is not T
133 if (call(first, last, attr))
135 traits::move_to(attr, attr_);