make_holder.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #if !defined(BOOST_PP_IS_ITERATING)
  2. // Copyright David Abrahams 2001.
  3. // Distributed under the Boost Software License, Version 1.0. (See
  4. // accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. # ifndef MAKE_HOLDER_DWA20011215_HPP
  7. # define MAKE_HOLDER_DWA20011215_HPP
  8. # include <boost/python/detail/prefix.hpp>
  9. # include <boost/python/object/instance.hpp>
  10. # include <boost/python/converter/registry.hpp>
  11. #if !defined( BOOST_PYTHON_NO_PY_SIGNATURES) && defined( BOOST_PYTHON_PY_SIGNATURES_PROPER_INIT_SELF_TYPE)
  12. # include <boost/python/detail/python_type.hpp>
  13. #endif
  14. # include <boost/python/object/forward.hpp>
  15. # include <boost/python/detail/preprocessor.hpp>
  16. # include <boost/mpl/next.hpp>
  17. # include <boost/mpl/begin_end.hpp>
  18. # include <boost/mpl/deref.hpp>
  19. # include <boost/preprocessor/iterate.hpp>
  20. # include <boost/preprocessor/iteration/local.hpp>
  21. # include <boost/preprocessor/repeat.hpp>
  22. # include <boost/preprocessor/debug/line.hpp>
  23. # include <boost/preprocessor/repetition/enum_trailing_binary_params.hpp>
  24. # include <cstddef>
  25. namespace boost { namespace python { namespace objects {
  26. template <int nargs> struct make_holder;
  27. # define BOOST_PYTHON_DO_FORWARD_ARG(z, index, _) , f##index(a##index)
  28. // specializations...
  29. # define BOOST_PP_ITERATION_PARAMS_1 (3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/object/make_holder.hpp>))
  30. # include BOOST_PP_ITERATE()
  31. # undef BOOST_PYTHON_DO_FORWARD_ARG
  32. }}} // namespace boost::python::objects
  33. # endif // MAKE_HOLDER_DWA20011215_HPP
  34. // For gcc 4.4 compatability, we must include the
  35. // BOOST_PP_ITERATION_DEPTH test inside an #else clause.
  36. #else // BOOST_PP_IS_ITERATING
  37. #if BOOST_PP_ITERATION_DEPTH() == 1
  38. # if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100) \
  39. && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201)))
  40. # line BOOST_PP_LINE(__LINE__, make_holder.hpp)
  41. # endif
  42. # define N BOOST_PP_ITERATION()
  43. template <>
  44. struct make_holder<N>
  45. {
  46. template <class Holder, class ArgList>
  47. struct apply
  48. {
  49. # if N
  50. // Unrolled iteration through each argument type in ArgList,
  51. // choosing the type that will be forwarded on to the holder's
  52. // templated constructor.
  53. typedef typename mpl::begin<ArgList>::type iter0;
  54. # define BOOST_PP_LOCAL_MACRO(n) \
  55. typedef typename mpl::deref<iter##n>::type t##n; \
  56. typedef typename forward<t##n>::type f##n; \
  57. typedef typename mpl::next<iter##n>::type \
  58. BOOST_PP_CAT(iter,BOOST_PP_INC(n)); // Next iterator type
  59. # define BOOST_PP_LOCAL_LIMITS (0, N-1)
  60. # include BOOST_PP_LOCAL_ITERATE()
  61. # endif
  62. static void execute(
  63. #if !defined( BOOST_PYTHON_NO_PY_SIGNATURES) && defined( BOOST_PYTHON_PY_SIGNATURES_PROPER_INIT_SELF_TYPE)
  64. boost::python::detail::python_class<BOOST_DEDUCED_TYPENAME Holder::value_type> *p
  65. #else
  66. PyObject *p
  67. #endif
  68. BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z(1, N, t, a))
  69. {
  70. typedef instance<Holder> instance_t;
  71. void* memory = Holder::allocate(p, offsetof(instance_t, storage), sizeof(Holder));
  72. try {
  73. (new (memory) Holder(
  74. p BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_DO_FORWARD_ARG, nil)))->install(p);
  75. }
  76. catch(...) {
  77. Holder::deallocate(p, memory);
  78. throw;
  79. }
  80. }
  81. };
  82. };
  83. # undef N
  84. #endif // BOOST_PP_ITERATION_DEPTH()
  85. #endif