annotate DEPENDENCIES/generic/include/boost/spirit/home/x3/numeric/real_policies.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents f46d142149f5
children
rev   line source
Chris@102 1 /*=============================================================================
Chris@102 2 Copyright (c) 2001-2014 Joel de Guzman
Chris@102 3 Copyright (c) 2001-2011 Hartmut Kaiser
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(SPIRIT_REAL_POLICIES_APRIL_17_2006_1158PM)
Chris@102 9 #define SPIRIT_REAL_POLICIES_APRIL_17_2006_1158PM
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/string/detail/string_parse.hpp>
Chris@102 16 #include <boost/spirit/home/x3/support/numeric_utils/extract_int.hpp>
Chris@102 17
Chris@102 18 namespace boost { namespace spirit { namespace x3
Chris@102 19 {
Chris@102 20 ///////////////////////////////////////////////////////////////////////////
Chris@102 21 // Default (unsigned) real number policies
Chris@102 22 ///////////////////////////////////////////////////////////////////////////
Chris@102 23 template <typename T>
Chris@102 24 struct ureal_policies
Chris@102 25 {
Chris@102 26 // trailing dot policy suggested by Gustavo Guerra
Chris@102 27 static bool const allow_leading_dot = true;
Chris@102 28 static bool const allow_trailing_dot = true;
Chris@102 29 static bool const expect_dot = false;
Chris@102 30
Chris@102 31 template <typename Iterator>
Chris@102 32 static bool
Chris@102 33 parse_sign(Iterator& /*first*/, Iterator const& /*last*/)
Chris@102 34 {
Chris@102 35 return false;
Chris@102 36 }
Chris@102 37
Chris@102 38 template <typename Iterator, typename Attribute>
Chris@102 39 static bool
Chris@102 40 parse_n(Iterator& first, Iterator const& last, Attribute& attr_)
Chris@102 41 {
Chris@102 42 return extract_uint<T, 10, 1, -1>::call(first, last, attr_);
Chris@102 43 }
Chris@102 44
Chris@102 45 template <typename Iterator>
Chris@102 46 static bool
Chris@102 47 parse_dot(Iterator& first, Iterator const& last)
Chris@102 48 {
Chris@102 49 if (first == last || *first != '.')
Chris@102 50 return false;
Chris@102 51 ++first;
Chris@102 52 return true;
Chris@102 53 }
Chris@102 54
Chris@102 55 template <typename Iterator, typename Attribute>
Chris@102 56 static bool
Chris@102 57 parse_frac_n(Iterator& first, Iterator const& last, Attribute& attr_)
Chris@102 58 {
Chris@102 59 return extract_uint<T, 10, 1, -1, true>::call(first, last, attr_);
Chris@102 60 }
Chris@102 61
Chris@102 62 template <typename Iterator>
Chris@102 63 static bool
Chris@102 64 parse_exp(Iterator& first, Iterator const& last)
Chris@102 65 {
Chris@102 66 if (first == last || (*first != 'e' && *first != 'E'))
Chris@102 67 return false;
Chris@102 68 ++first;
Chris@102 69 return true;
Chris@102 70 }
Chris@102 71
Chris@102 72 template <typename Iterator>
Chris@102 73 static bool
Chris@102 74 parse_exp_n(Iterator& first, Iterator const& last, int& attr_)
Chris@102 75 {
Chris@102 76 return extract_int<int, 10, 1, -1>::call(first, last, attr_);
Chris@102 77 }
Chris@102 78
Chris@102 79 ///////////////////////////////////////////////////////////////////////
Chris@102 80 // The parse_nan() and parse_inf() functions get called whenever:
Chris@102 81 //
Chris@102 82 // - a number to parse does not start with a digit (after having
Chris@102 83 // successfully parsed an optional sign)
Chris@102 84 //
Chris@102 85 // or
Chris@102 86 //
Chris@102 87 // - after a floating point number of the value 1 (having no
Chris@102 88 // exponential part and a fractional part value of 0) has been
Chris@102 89 // parsed.
Chris@102 90 //
Chris@102 91 // The first call allows to recognize representations of NaN or Inf
Chris@102 92 // starting with a non-digit character (such as NaN, Inf, QNaN etc.).
Chris@102 93 //
Chris@102 94 // The second call allows to recognize representation formats starting
Chris@102 95 // with a 1.0 (such as 1.0#NAN or 1.0#INF etc.).
Chris@102 96 //
Chris@102 97 // The functions should return true if a Nan or Inf has been found. In
Chris@102 98 // this case the attr should be set to the matched value (NaN or
Chris@102 99 // Inf). The optional sign will be automatically applied afterwards.
Chris@102 100 //
Chris@102 101 // The default implementation below recognizes representations of NaN
Chris@102 102 // and Inf as mandated by the C99 Standard and as proposed for
Chris@102 103 // inclusion into the C++0x Standard: nan, nan(...), inf and infinity
Chris@102 104 // (the matching is performed case-insensitively).
Chris@102 105 ///////////////////////////////////////////////////////////////////////
Chris@102 106 template <typename Iterator, typename Attribute>
Chris@102 107 static bool
Chris@102 108 parse_nan(Iterator& first, Iterator const& last, Attribute& attr_)
Chris@102 109 {
Chris@102 110 if (first == last)
Chris@102 111 return false; // end of input reached
Chris@102 112
Chris@102 113 if (*first != 'n' && *first != 'N')
Chris@102 114 return false; // not "nan"
Chris@102 115
Chris@102 116 // nan[(...)] ?
Chris@102 117 if (detail::string_parse("nan", "NAN", first, last, unused))
Chris@102 118 {
Chris@102 119 if (*first == '(')
Chris@102 120 {
Chris@102 121 // skip trailing (...) part
Chris@102 122 Iterator i = first;
Chris@102 123
Chris@102 124 while (++i != last && *i != ')')
Chris@102 125 ;
Chris@102 126 if (i == last)
Chris@102 127 return false; // no trailing ')' found, give up
Chris@102 128
Chris@102 129 first = ++i;
Chris@102 130 }
Chris@102 131 attr_ = std::numeric_limits<T>::quiet_NaN();
Chris@102 132 return true;
Chris@102 133 }
Chris@102 134 return false;
Chris@102 135 }
Chris@102 136
Chris@102 137 template <typename Iterator, typename Attribute>
Chris@102 138 static bool
Chris@102 139 parse_inf(Iterator& first, Iterator const& last, Attribute& attr_)
Chris@102 140 {
Chris@102 141 if (first == last)
Chris@102 142 return false; // end of input reached
Chris@102 143
Chris@102 144 if (*first != 'i' && *first != 'I')
Chris@102 145 return false; // not "inf"
Chris@102 146
Chris@102 147 // inf or infinity ?
Chris@102 148 if (detail::string_parse("inf", "INF", first, last, unused))
Chris@102 149 {
Chris@102 150 // skip allowed 'inity' part of infinity
Chris@102 151 detail::string_parse("inity", "INITY", first, last, unused);
Chris@102 152 attr_ = std::numeric_limits<T>::infinity();
Chris@102 153 return true;
Chris@102 154 }
Chris@102 155 return false;
Chris@102 156 }
Chris@102 157 };
Chris@102 158
Chris@102 159 ///////////////////////////////////////////////////////////////////////////
Chris@102 160 // Default (signed) real number policies
Chris@102 161 ///////////////////////////////////////////////////////////////////////////
Chris@102 162 template <typename T>
Chris@102 163 struct real_policies : ureal_policies<T>
Chris@102 164 {
Chris@102 165 template <typename Iterator>
Chris@102 166 static bool
Chris@102 167 parse_sign(Iterator& first, Iterator const& last)
Chris@102 168 {
Chris@102 169 return extract_sign(first, last);
Chris@102 170 }
Chris@102 171 };
Chris@102 172
Chris@102 173 template <typename T>
Chris@102 174 struct strict_ureal_policies : ureal_policies<T>
Chris@102 175 {
Chris@102 176 static bool const expect_dot = true;
Chris@102 177 };
Chris@102 178
Chris@102 179 template <typename T>
Chris@102 180 struct strict_real_policies : real_policies<T>
Chris@102 181 {
Chris@102 182 static bool const expect_dot = true;
Chris@102 183 };
Chris@102 184 }}}
Chris@102 185
Chris@102 186 #endif