PageRenderTime 39ms CodeModel.GetById 12ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 0ms

/src/contrib/boost/spirit/home/qi/numeric/real.hpp

http://pythonocc.googlecode.com/
C++ Header | 133 lines | 98 code | 16 blank | 19 comment | 1 complexity | 6067ce781f7aa1a11de3448833be0fb3 MD5 | raw file
  1/*=============================================================================
  2    Copyright (c) 2001-2010 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_REAL_APRIL_18_2006_0850AM)
  8#define BOOST_SPIRIT_REAL_APRIL_18_2006_0850AM
  9
 10#if defined(_MSC_VER)
 11#pragma once
 12#endif
 13
 14#include <boost/spirit/home/qi/skip_over.hpp>
 15#include <boost/spirit/home/qi/numeric/real_policies.hpp>
 16#include <boost/spirit/home/qi/numeric/numeric_utils.hpp>
 17#include <boost/spirit/home/qi/numeric/detail/real_impl.hpp>
 18#include <boost/spirit/home/qi/meta_compiler.hpp>
 19#include <boost/spirit/home/qi/parser.hpp>
 20#include <boost/spirit/home/support/common_terminals.hpp>
 21
 22namespace boost { namespace spirit
 23{
 24    ///////////////////////////////////////////////////////////////////////////
 25    // Enablers
 26    ///////////////////////////////////////////////////////////////////////////
 27    template <>
 28    struct use_terminal<qi::domain, tag::float_> // enables float_
 29      : mpl::true_ {};
 30
 31    template <>
 32    struct use_terminal<qi::domain, tag::double_> // enables double_
 33      : mpl::true_ {};
 34
 35    template <>
 36    struct use_terminal<qi::domain, tag::long_double> // enables long_double
 37      : mpl::true_ {};
 38}}
 39
 40namespace boost { namespace spirit { namespace qi
 41{
 42    using spirit::float_;
 43    using spirit::float__type;
 44    using spirit::double_;
 45    using spirit::double__type;
 46    using spirit::long_double;
 47    using spirit::long_double_type;
 48
 49    ///////////////////////////////////////////////////////////////////////////
 50    // This is the actual real number parser
 51    ///////////////////////////////////////////////////////////////////////////
 52    template <
 53        typename T = double,
 54        typename RealPolicies = real_policies<T>
 55    >
 56    struct real_parser_impl
 57      : primitive_parser<real_parser_impl<T, RealPolicies> >
 58    {
 59        template <typename Context, typename Iterator>
 60        struct attribute
 61        {
 62            typedef T type;
 63        };
 64
 65        template <typename Iterator, typename Context, typename Skipper>
 66        bool parse(Iterator& first, Iterator const& last
 67          , Context& /*context*/, Skipper const& skipper
 68          , T& attr) const
 69        {
 70            qi::skip_over(first, last, skipper);
 71            return detail::real_impl<T, RealPolicies>::
 72                parse(first, last, attr, RealPolicies());
 73        }
 74
 75        template <typename Iterator, typename Context
 76          , typename Skipper, typename Attribute>
 77        bool parse(Iterator& first, Iterator const& last
 78          , Context& context, Skipper const& skipper
 79          , Attribute& attr_) const
 80        {
 81            // this case is called when Attribute is not T
 82            T attr;
 83            if (parse(first, last, context, skipper, attr))
 84            {
 85                traits::assign_to(attr, attr_);
 86                return true;
 87            }
 88            return false;
 89        }
 90
 91        template <typename Context>
 92        info what(Context& /*context*/) const
 93        {
 94            return info("real-number");
 95        }
 96    };
 97
 98    ///////////////////////////////////////////////////////////////////////////
 99    // This one is the class that the user can instantiate directly
100    ///////////////////////////////////////////////////////////////////////////
101    template <
102        typename T,
103        typename RealPolicies = real_policies<T>
104    >
105    struct real_parser
106      : proto::terminal<real_parser_impl<T, RealPolicies> >::type
107    {
108    };
109
110    ///////////////////////////////////////////////////////////////////////////
111    // Parser generators: make_xxx function (objects)
112    ///////////////////////////////////////////////////////////////////////////
113    template <typename T>
114    struct make_real
115    {
116        typedef real_parser_impl<T, real_policies<T> > result_type;
117        result_type operator()(unused_type, unused_type) const
118        {
119            return result_type();
120        }
121    };
122
123    template <typename Modifiers>
124    struct make_primitive<tag::float_, Modifiers> : make_real<float> {};
125
126    template <typename Modifiers>
127    struct make_primitive<tag::double_, Modifiers> : make_real<double> {};
128
129    template <typename Modifiers>
130    struct make_primitive<tag::long_double, Modifiers> : make_real<long double> {};
131}}}
132
133#endif