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