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