/src/contrib/boost/spirit/home/phoenix/core/argument.hpp

http://pythonocc.googlecode.com/ · C++ Header · 89 lines · 68 code · 11 blank · 10 comment · 0 complexity · dbbbdedf578db8cc54174270a4f86b25 MD5 · raw file

  1. /*=============================================================================
  2. Copyright (c) 2001-2007 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. #ifndef PHOENIX_CORE_ARGUMENT_HPP
  7. #define PHOENIX_CORE_ARGUMENT_HPP
  8. #include <boost/preprocessor/repetition/repeat_from_to.hpp>
  9. #include <boost/preprocessor/inc.hpp>
  10. #include <boost/spirit/home/phoenix/core/actor.hpp>
  11. #include <boost/fusion/include/at.hpp>
  12. #include <boost/mpl/if.hpp>
  13. #include <boost/mpl/eval_if.hpp>
  14. #include <boost/mpl/identity.hpp>
  15. #include <boost/mpl/less.hpp>
  16. #include <boost/mpl/bool.hpp>
  17. #include <boost/mpl/int.hpp>
  18. #include <boost/mpl/at.hpp>
  19. #include <boost/mpl/size.hpp>
  20. #include <boost/type_traits/add_reference.hpp>
  21. #define PHOENIX_DECLARE_ARG(z, n, data) \
  22. actor<argument<n> > const \
  23. BOOST_PP_CAT(arg, BOOST_PP_INC(n)) = argument<n>(); \
  24. actor<argument<n> > const \
  25. BOOST_PP_CAT(_, BOOST_PP_INC(n)) = argument<n>();
  26. namespace boost { namespace phoenix
  27. {
  28. namespace detail
  29. {
  30. template <typename Arg>
  31. struct error_argument_not_found {};
  32. inline void test_invalid_argument(int) {}
  33. }
  34. template <int N>
  35. struct argument
  36. {
  37. typedef mpl::true_ no_nullary;
  38. template <typename Env>
  39. struct result
  40. {
  41. typedef typename
  42. fusion::result_of::at<typename Env::tie_type, mpl::int_<N> >::type
  43. type;
  44. };
  45. template <typename Env>
  46. typename result<Env>::type
  47. eval(Env const& env) const
  48. {
  49. typedef typename
  50. mpl::if_<
  51. mpl::less<mpl::int_<N>, mpl::size<typename Env::args_type> >
  52. , int
  53. , detail::error_argument_not_found<argument<N> >
  54. >::type
  55. check_out_of_bounds;
  56. detail::test_invalid_argument(check_out_of_bounds());
  57. return fusion::at_c<N>(env.args());
  58. }
  59. };
  60. namespace arg_names
  61. {
  62. // Phoenix style names
  63. actor<argument<0> > const arg1 = argument<0>();
  64. actor<argument<1> > const arg2 = argument<1>();
  65. actor<argument<2> > const arg3 = argument<2>();
  66. // BLL style names
  67. actor<argument<0> > const _1 = argument<0>();
  68. actor<argument<1> > const _2 = argument<1>();
  69. actor<argument<2> > const _3 = argument<2>();
  70. // Bring in the rest or the Phoenix style arguments (arg4 .. argN+1)
  71. // and BLL style arguments (_4 .. _N+1), using PP
  72. BOOST_PP_REPEAT_FROM_TO(
  73. 3, PHOENIX_ARG_LIMIT, PHOENIX_DECLARE_ARG, _)
  74. }
  75. }}
  76. #undef PHOENIX_DECLARE_ARG
  77. #endif