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