File indexing completed on 2025-01-31 10:02:37
0001
0002
0003
0004
0005
0006
0007
0008 #if !defined(BOOST_SPIRIT_X3_EXTRACT_INT_APRIL_17_2006_0830AM)
0009 #define BOOST_SPIRIT_X3_EXTRACT_INT_APRIL_17_2006_0830AM
0010
0011 #include <boost/spirit/home/x3/support/traits/move_to.hpp>
0012 #include <boost/spirit/home/x3/support/numeric_utils/detail/extract_int.hpp>
0013 #include <boost/assert.hpp>
0014
0015 namespace boost { namespace spirit { namespace x3
0016 {
0017
0018
0019
0020 template <typename Iterator>
0021 inline bool
0022 extract_sign(Iterator& first, Iterator const& last)
0023 {
0024 (void)last;
0025 BOOST_ASSERT(first != last);
0026
0027
0028 bool neg = *first == '-';
0029 if (neg || (*first == '+'))
0030 {
0031 ++first;
0032 return neg;
0033 }
0034 return false;
0035 }
0036
0037
0038
0039
0040 template <typename T, unsigned Radix, unsigned MinDigits, int MaxDigits
0041 , bool Accumulate = false>
0042 struct extract_uint
0043 {
0044
0045 static_assert(
0046 (Radix >= 2 && Radix <= 36),
0047 "Error Unsupported Radix");
0048
0049 template <typename Iterator>
0050 inline static bool call(Iterator& first, Iterator const& last, T& attr)
0051 {
0052 if (first == last)
0053 return false;
0054
0055 typedef detail::extract_int<
0056 T
0057 , Radix
0058 , MinDigits
0059 , MaxDigits
0060 , detail::positive_accumulator<Radix>
0061 , Accumulate>
0062 extract_type;
0063
0064 Iterator save = first;
0065 if (!extract_type::parse(first, last, attr))
0066 {
0067 first = save;
0068 return false;
0069 }
0070 return true;
0071 }
0072
0073 template <typename Iterator, typename Attribute>
0074 inline static bool call(Iterator& first, Iterator const& last, Attribute& attr_)
0075 {
0076
0077 T attr;
0078 if (call(first, last, attr))
0079 {
0080 traits::move_to(attr, attr_);
0081 return true;
0082 }
0083 return false;
0084 }
0085 };
0086
0087
0088
0089
0090 template <typename T, unsigned Radix, unsigned MinDigits, int MaxDigits>
0091 struct extract_int
0092 {
0093
0094 static_assert(
0095 (Radix == 2 || Radix == 8 || Radix == 10 || Radix == 16),
0096 "Error Unsupported Radix");
0097
0098 template <typename Iterator>
0099 inline static bool call(Iterator& first, Iterator const& last, T& attr)
0100 {
0101 if (first == last)
0102 return false;
0103
0104 typedef detail::extract_int<
0105 T, Radix, MinDigits, MaxDigits>
0106 extract_pos_type;
0107
0108 typedef detail::extract_int<
0109 T, Radix, MinDigits, MaxDigits, detail::negative_accumulator<Radix> >
0110 extract_neg_type;
0111
0112 Iterator save = first;
0113 bool hit = extract_sign(first, last);
0114 if (hit)
0115 hit = extract_neg_type::parse(first, last, attr);
0116 else
0117 hit = extract_pos_type::parse(first, last, attr);
0118
0119 if (!hit)
0120 {
0121 first = save;
0122 return false;
0123 }
0124 return true;
0125 }
0126
0127 template <typename Iterator, typename Attribute>
0128 inline static bool call(Iterator& first, Iterator const& last, Attribute& attr_)
0129 {
0130
0131 T attr;
0132 if (call(first, last, attr))
0133 {
0134 traits::move_to(attr, attr_);
0135 return true;
0136 }
0137 return false;
0138 }
0139 };
0140 }}}
0141
0142 #endif