| 1 | /*============================================================================= |
| 2 | Copyright (c) 2001-2014 Joel de Guzman |
| 3 | |
| 4 | Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 5 | file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 6 | ==============================================================================*/ |
| 7 | #if !defined(BOOST_SPIRIT_X3_REAL_APRIL_18_2006_0850AM) |
| 8 | #define BOOST_SPIRIT_X3_REAL_APRIL_18_2006_0850AM |
| 9 | |
| 10 | #include <boost/spirit/home/x3/core/parser.hpp> |
| 11 | #include <boost/spirit/home/x3/core/skip_over.hpp> |
| 12 | #include <boost/spirit/home/x3/numeric/real_policies.hpp> |
| 13 | #include <boost/spirit/home/x3/support/numeric_utils/extract_real.hpp> |
| 14 | |
| 15 | namespace boost { namespace spirit { namespace x3 |
| 16 | { |
| 17 | template <typename T, typename RealPolicies = real_policies<T> > |
| 18 | struct real_parser : parser<real_parser<T, RealPolicies> > |
| 19 | { |
| 20 | typedef T attribute_type; |
| 21 | static bool const has_attribute = true; |
| 22 | |
| 23 | constexpr real_parser() |
| 24 | : policies() {} |
| 25 | |
| 26 | constexpr real_parser(RealPolicies const& policies) |
| 27 | : policies(policies) {} |
| 28 | |
| 29 | template <typename Iterator, typename Context> |
| 30 | bool parse(Iterator& first, Iterator const& last |
| 31 | , Context const& context, unused_type, T& attr_) const |
| 32 | { |
| 33 | x3::skip_over(first, last, context); |
| 34 | return extract_real<T, RealPolicies>::parse(first, last, attr_, policies); |
| 35 | } |
| 36 | |
| 37 | template <typename Iterator, typename Context, typename Attribute> |
| 38 | bool parse(Iterator& first, Iterator const& last |
| 39 | , Context const& context, unused_type, Attribute& attr_param) const |
| 40 | { |
| 41 | // this case is called when Attribute is not T |
| 42 | T attr_; |
| 43 | if (parse(first, last, context, unused, attr_)) |
| 44 | { |
| 45 | traits::move_to(attr_, attr_param); |
| 46 | return true; |
| 47 | } |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | RealPolicies policies; |
| 52 | }; |
| 53 | |
| 54 | typedef real_parser<float> float_type; |
| 55 | constexpr float_type float_ = {}; |
| 56 | |
| 57 | typedef real_parser<double> double_type; |
| 58 | constexpr double_type double_ = {}; |
| 59 | |
| 60 | typedef real_parser<long double> long_double_type; |
| 61 | constexpr long_double_type long_double = {}; |
| 62 | |
| 63 | }}} |
| 64 | |
| 65 | #endif |
| 66 | |