/src/contrib/boost/spirit/home/qi/detail/parse_auto.hpp

http://pythonocc.googlecode.com/ · C++ Header · 183 lines · 139 code · 20 blank · 24 comment · 0 complexity · d38bf7ffe6f9df7564b6bd19920a83dd MD5 · raw file

  1. /*=============================================================================
  2. Copyright (c) 2001-2010 Hartmut Kaiser
  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_DETAIL_PARSE_AUTO_DEC_02_2009_0426PM)
  7. #define BOOST_SPIRIT_DETAIL_PARSE_AUTO_DEC_02_2009_0426PM
  8. #if defined(_MSC_VER)
  9. #pragma once
  10. #endif
  11. #include <boost/spirit/home/qi/parse.hpp>
  12. #include <boost/spirit/home/qi/auto/create_parser.hpp>
  13. #include <boost/utility/enable_if.hpp>
  14. #include <boost/mpl/not.hpp>
  15. #include <boost/mpl/and.hpp>
  16. namespace boost { namespace spirit { namespace qi { namespace detail
  17. {
  18. ///////////////////////////////////////////////////////////////////////////
  19. template <typename Expr>
  20. struct parse_impl<Expr
  21. , typename enable_if<traits::meta_create_exists<qi::domain, Expr> >::type>
  22. {
  23. template <typename Iterator>
  24. static bool call(Iterator& first, Iterator last, Expr& expr)
  25. {
  26. return qi::parse(first, last, create_parser<Expr>(), expr);
  27. }
  28. template <typename Iterator>
  29. static bool call(Iterator& first, Iterator last, Expr const& expr)
  30. {
  31. return qi::parse(first, last, create_parser<Expr>()
  32. , const_cast<Expr&>(expr));
  33. }
  34. };
  35. // the following specializations are needed to explicitly disambiguate
  36. // the two possible specializations for parse_impl<char> and
  37. // parse_impl<wchar_t>
  38. template <>
  39. struct parse_impl<char>
  40. {
  41. template <typename Iterator>
  42. static bool call(Iterator& first, Iterator last, char& expr)
  43. {
  44. return qi::parse(first, last, create_parser<char>(), expr);
  45. }
  46. template <typename Iterator>
  47. static bool call(Iterator& first, Iterator last, char const&)
  48. {
  49. return qi::parse(first, last, create_parser<char>());
  50. }
  51. };
  52. template <>
  53. struct parse_impl<wchar_t>
  54. {
  55. template <typename Iterator>
  56. static bool call(Iterator& first, Iterator last, wchar_t& expr)
  57. {
  58. return qi::parse(first, last, create_parser<wchar_t>(), expr);
  59. }
  60. template <typename Iterator>
  61. static bool call(Iterator& first, Iterator last, wchar_t const&)
  62. {
  63. return qi::parse(first, last, create_parser<wchar_t>());
  64. }
  65. };
  66. ///////////////////////////////////////////////////////////////////////////
  67. template <typename Expr>
  68. struct phrase_parse_impl<Expr
  69. , typename enable_if<traits::meta_create_exists<qi::domain, Expr> >::type>
  70. {
  71. template <typename Iterator, typename Skipper>
  72. static bool call(Iterator& first, Iterator last, Expr& expr
  73. , Skipper const& skipper, BOOST_SCOPED_ENUM(skip_flag) post_skip)
  74. {
  75. return qi::phrase_parse(first, last, create_parser<Expr>()
  76. , skipper, post_skip, expr);
  77. }
  78. template <typename Iterator, typename Skipper>
  79. static bool call(Iterator& first, Iterator last, Expr const& expr
  80. , Skipper const& skipper, BOOST_SCOPED_ENUM(skip_flag) post_skip)
  81. {
  82. return qi::phrase_parse(first, last, create_parser<Expr>()
  83. , skipper, post_skip, const_cast<Expr&>(expr));
  84. }
  85. };
  86. // the following specializations are needed to explicitly disambiguate
  87. // the two possible specializations for phrase_parse_impl<char> and
  88. // phrase_parse_impl<wchar_t>
  89. template <>
  90. struct phrase_parse_impl<char>
  91. {
  92. template <typename Iterator, typename Skipper>
  93. static bool call(Iterator& first, Iterator last, char& expr
  94. , Skipper const& skipper, BOOST_SCOPED_ENUM(skip_flag) post_skip)
  95. {
  96. return qi::phrase_parse(first, last, create_parser<char>()
  97. , skipper, post_skip, expr);
  98. }
  99. template <typename Iterator, typename Skipper>
  100. static bool call(Iterator& first, Iterator last, char const&
  101. , Skipper const& skipper, BOOST_SCOPED_ENUM(skip_flag) post_skip)
  102. {
  103. return qi::phrase_parse(first, last, create_parser<char>()
  104. , skipper, post_skip);
  105. }
  106. };
  107. template <>
  108. struct phrase_parse_impl<wchar_t>
  109. {
  110. template <typename Iterator, typename Skipper>
  111. static bool call(Iterator& first, Iterator last, wchar_t& expr
  112. , Skipper const& skipper, BOOST_SCOPED_ENUM(skip_flag) post_skip)
  113. {
  114. return qi::phrase_parse(first, last, create_parser<wchar_t>()
  115. , skipper, post_skip, expr);
  116. }
  117. template <typename Iterator, typename Skipper>
  118. static bool call(Iterator& first, Iterator last, wchar_t const&
  119. , Skipper const& skipper, BOOST_SCOPED_ENUM(skip_flag) post_skip)
  120. {
  121. return qi::phrase_parse(first, last, create_parser<wchar_t>()
  122. , skipper, post_skip);
  123. }
  124. };
  125. }}}}
  126. namespace boost { namespace spirit { namespace qi
  127. {
  128. ///////////////////////////////////////////////////////////////////////////
  129. template <typename Iterator, typename Expr>
  130. inline bool
  131. parse(
  132. Iterator& first
  133. , Iterator last
  134. , Expr& expr)
  135. {
  136. // Make sure the iterator is at least a forward_iterator. If you got a
  137. // compilation error here, then you are using an input_iterator while
  138. // calling this function, you need to supply at least a
  139. // forward_iterator instead.
  140. BOOST_CONCEPT_ASSERT((ForwardIterator<Iterator>));
  141. return detail::parse_impl<Expr>::call(first, last, expr);
  142. }
  143. ///////////////////////////////////////////////////////////////////////////
  144. template <typename Iterator, typename Expr, typename Skipper>
  145. inline bool
  146. phrase_parse(
  147. Iterator& first
  148. , Iterator last
  149. , Expr& expr
  150. , Skipper const& skipper
  151. , BOOST_SCOPED_ENUM(skip_flag) post_skip = skip_flag::postskip)
  152. {
  153. // Make sure the iterator is at least a forward_iterator. If you got a
  154. // compilation error here, then you are using an input_iterator while
  155. // calling this function, you need to supply at least a
  156. // forward_iterator instead.
  157. BOOST_CONCEPT_ASSERT((ForwardIterator<Iterator>));
  158. return detail::phrase_parse_impl<Expr>::call(
  159. first, last, expr, skipper, post_skip);
  160. }
  161. }}}
  162. #endif