invoker_iterate.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // Copyright Daniel Wallin 2005. Use, modification and distribution is
  2. // subject to the Boost Software License, Version 1.0. (See accompanying
  3. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. #include <boost/preprocessor/cat.hpp>
  5. #include <boost/preprocessor/dec.hpp>
  6. #include <boost/preprocessor/repetition/enum_binary_params.hpp>
  7. #include <boost/preprocessor/repetition/repeat_from_to.hpp>
  8. #define N BOOST_PP_ITERATION()
  9. #define BOOST_PARAMETER_PY_ARG_TYPES(z, n, _) \
  10. typedef typename mpl::next< \
  11. BOOST_PP_CAT(iter,BOOST_PP_DEC(n)) \
  12. >::type BOOST_PP_CAT(iter,n); \
  13. \
  14. typedef typename mpl::deref<BOOST_PP_CAT(iter,n)>::type BOOST_PP_CAT(spec,n); \
  15. typedef typename mpl::if_< \
  16. mpl::and_< \
  17. mpl::not_<typename BOOST_PP_CAT(spec,n)::required> \
  18. , typename BOOST_PP_CAT(spec,n)::optimized_default \
  19. > \
  20. , parameter::aux::maybe<typename BOOST_PP_CAT(spec,n)::type> \
  21. , typename BOOST_PP_CAT(spec,n)::type \
  22. >::type BOOST_PP_CAT(arg,n); \
  23. typedef typename BOOST_PP_CAT(spec,n)::keyword BOOST_PP_CAT(kw,n);
  24. #if BOOST_PP_ITERATION_FLAGS() == 1
  25. template <class M, class R, class Args>
  26. struct invoker<N, M, R, Args>
  27. #elif BOOST_PP_ITERATION_FLAGS() == 2
  28. template <class T, class R, class Args>
  29. struct call_invoker<N, T, R, Args>
  30. #elif BOOST_PP_ITERATION_FLAGS() == 3
  31. template <class T, class Args>
  32. struct init_invoker<N, T, Args>
  33. #elif BOOST_PP_ITERATION_FLAGS() == 4
  34. template <class M, class R, class T, class Args>
  35. struct member_invoker<N, M, R, T, Args>
  36. #endif
  37. {
  38. typedef typename mpl::begin<Args>::type iter0;
  39. typedef typename mpl::deref<iter0>::type spec0;
  40. typedef typename mpl::if_<
  41. mpl::and_<
  42. mpl::not_<typename spec0::required>
  43. , typename spec0::optimized_default
  44. >
  45. , parameter::aux::maybe<typename spec0::type>
  46. , typename spec0::type
  47. >::type arg0;
  48. typedef typename spec0::keyword kw0;
  49. BOOST_PP_REPEAT_FROM_TO(1, N, BOOST_PARAMETER_PY_ARG_TYPES, ~)
  50. static
  51. #if BOOST_PP_ITERATION_FLAGS() == 3
  52. T*
  53. #else
  54. R
  55. #endif
  56. execute(
  57. #if BOOST_PP_ITERATION_FLAGS() == 2 || BOOST_PP_ITERATION_FLAGS() == 4
  58. T& self
  59. ,
  60. #endif
  61. BOOST_PP_ENUM_BINARY_PARAMS(N, arg, a)
  62. )
  63. {
  64. return
  65. #if BOOST_PP_ITERATION_FLAGS() == 1 || BOOST_PP_ITERATION_FLAGS() == 4
  66. M()(
  67. boost::type<R>()
  68. # if BOOST_PP_ITERATION_FLAGS() == 4
  69. , self
  70. # endif
  71. , BOOST_PP_ENUM_BINARY_PARAMS(N, parameter::keyword<kw, >::get() = a)
  72. );
  73. #elif BOOST_PP_ITERATION_FLAGS() == 2
  74. self(
  75. BOOST_PP_ENUM_BINARY_PARAMS(N, parameter::keyword<kw, >::get() = a)
  76. );
  77. #elif BOOST_PP_ITERATION_FLAGS() == 3
  78. new T(
  79. BOOST_PP_ENUM_BINARY_PARAMS(N, parameter::keyword<kw, >::get() = a)
  80. );
  81. #endif
  82. }
  83. };
  84. #undef BOOST_PARAMETER_PY_ARG_TYPES
  85. #undef N