/Src/Dependencies/Boost/boost/spirit/home/phoenix/core/argument.hpp

http://hadesmem.googlecode.com/ · C++ Header · 99 lines · 78 code · 11 blank · 10 comment · 0 complexity · 08028452fca9d56f13c28a68afcabf91 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. typedef actor<argument<n> > \
  23. BOOST_PP_CAT(BOOST_PP_CAT(arg, BOOST_PP_INC(n)), _type); \
  24. actor<argument<n> > const \
  25. BOOST_PP_CAT(arg, BOOST_PP_INC(n)) = argument<n>(); \
  26. typedef actor<argument<n> > \
  27. BOOST_PP_CAT(BOOST_PP_CAT(_, BOOST_PP_INC(n)), _type); \
  28. actor<argument<n> > const \
  29. BOOST_PP_CAT(_, BOOST_PP_INC(n)) = argument<n>();
  30. namespace boost { namespace phoenix
  31. {
  32. namespace detail
  33. {
  34. template <typename Arg>
  35. struct error_argument_not_found {};
  36. inline void test_invalid_argument(int) {}
  37. }
  38. template <int N>
  39. struct argument
  40. {
  41. typedef mpl::true_ no_nullary;
  42. template <typename Env>
  43. struct result
  44. {
  45. typedef typename
  46. fusion::result_of::at<typename Env::tie_type, mpl::int_<N> >::type
  47. type;
  48. };
  49. template <typename Env>
  50. typename result<Env>::type
  51. eval(Env const& env) const
  52. {
  53. typedef typename
  54. mpl::if_<
  55. mpl::less<mpl::int_<N>, mpl::size<typename Env::args_type> >
  56. , int
  57. , detail::error_argument_not_found<argument<N> >
  58. >::type
  59. check_out_of_bounds;
  60. detail::test_invalid_argument(check_out_of_bounds());
  61. return fusion::at_c<N>(env.args());
  62. }
  63. };
  64. namespace arg_names
  65. {
  66. // Phoenix style names
  67. typedef actor<argument<0> > arg1_type;
  68. actor<argument<0> > const arg1 = argument<0>();
  69. typedef actor<argument<1> > arg2_type;
  70. actor<argument<1> > const arg2 = argument<1>();
  71. typedef actor<argument<2> > arg3_type;
  72. actor<argument<2> > const arg3 = argument<2>();
  73. // BLL style names
  74. typedef actor<argument<0> > _1_type;
  75. actor<argument<0> > const _1 = argument<0>();
  76. typedef actor<argument<1> > _2_type;
  77. actor<argument<1> > const _2 = argument<1>();
  78. typedef actor<argument<2> > _3_type;
  79. actor<argument<2> > const _3 = argument<2>();
  80. // Bring in the rest or the Phoenix style arguments (arg4 .. argN+1)
  81. // and BLL style arguments (_4 .. _N+1), using PP
  82. BOOST_PP_REPEAT_FROM_TO(
  83. 3, PHOENIX_ARG_LIMIT, PHOENIX_DECLARE_ARG, _)
  84. }
  85. }}
  86. #undef PHOENIX_DECLARE_ARG
  87. #endif