Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // Chris@16: // Copyright David Abrahams 2002, Joel de Guzman, 2002. Chris@16: // Distributed under the Boost Software License, Version 1.0. (See Chris@16: // accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: #if !defined(BOOST_PP_IS_ITERATING) Chris@16: Chris@16: # ifndef SIGNATURE_JDG20020813_HPP Chris@16: # define SIGNATURE_JDG20020813_HPP Chris@16: Chris@16: # include Chris@16: Chris@16: # include Chris@16: # include Chris@16: Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: Chris@16: # define BOOST_PYTHON_LIST_INC(n) \ Chris@16: BOOST_PP_CAT(mpl::vector, BOOST_PP_INC(n)) Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: namespace boost { namespace python { namespace detail { Chris@16: Chris@16: // A metafunction returning C1 if C1 is derived from C2, and C2 Chris@16: // otherwise Chris@16: template Chris@16: struct most_derived Chris@16: { Chris@16: typedef typename mpl::if_< Chris@16: is_convertible Chris@16: , C1 Chris@16: , C2 Chris@16: >::type type; Chris@16: }; Chris@16: Chris@16: // The following macros generate expansions for:: Chris@16: // Chris@16: // template Chris@16: // inline mpl::vector Chris@16: // get_signature(RT(BOOST_PYTHON_FN_CC *)(T0...TN), void* = 0) Chris@16: // { Chris@16: // return mpl::list(); Chris@16: // } Chris@16: // Chris@16: // where BOOST_PYTHON_FN_CC is a calling convention keyword, can be Chris@16: // Chris@16: // empty, for default calling convention Chris@16: // __cdecl (if BOOST_PYTHON_ENABLE_CDECL is defined) Chris@16: // __stdcall (if BOOST_PYTHON_ENABLE_STDCALL is defined) Chris@16: // __fastcall (if BOOST_PYTHON_ENABLE_FASTCALL is defined) Chris@16: // Chris@16: // And, for an appropriate assortment of cv-qualifications:: Chris@16: // Chris@16: // template Chris@16: // inline mpl::vector Chris@16: // get_signature(RT(BOOST_PYTHON_FN_CC ClassT::*)(T0...TN) cv)) Chris@16: // { Chris@16: // return mpl::list(); Chris@16: // } Chris@16: // Chris@16: // template Chris@16: // inline mpl::vector< Chris@16: // RT Chris@16: // , typename most_derived::type& Chris@16: // , T0...TN Chris@16: // > Chris@16: // get_signature(RT(BOOST_PYTHON_FN_CC ClassT::*)(T0...TN) cv), Target*) Chris@16: // { Chris@16: // return mpl::list(); Chris@16: // } Chris@16: // Chris@16: // There are two forms for invoking get_signature:: Chris@16: // Chris@16: // get_signature(f) Chris@16: // Chris@16: // and :: Chris@16: // Chris@16: // get_signature(f,(Target*)0) Chris@16: // Chris@16: // These functions extract the return type, class (for member Chris@16: // functions) and arguments of the input signature and stuff them in Chris@16: // an mpl type sequence (the calling convention is dropped). Chris@16: // Note that cv-qualification is dropped from Chris@16: // the "hidden this" argument of member functions; that is a Chris@16: // necessary sacrifice to ensure that an lvalue from_python converter Chris@16: // is used. A pointer is not used so that None will be rejected for Chris@16: // overload resolution. Chris@16: // Chris@16: // The second form of get_signature essentially downcasts the "hidden Chris@16: // this" argument of member functions to Target, because the function Chris@16: // may actually be a member of a base class which is not wrapped, and Chris@16: // in that case conversion from python would fail. Chris@16: // Chris@16: // @group { Chris@16: Chris@16: // 'default' calling convention Chris@16: Chris@16: # define BOOST_PYTHON_FN_CC Chris@16: Chris@16: # define BOOST_PP_ITERATION_PARAMS_1 \ Chris@16: (3, (0, BOOST_PYTHON_MAX_ARITY, )) Chris@16: Chris@16: # include BOOST_PP_ITERATE() Chris@16: Chris@16: # undef BOOST_PYTHON_FN_CC Chris@16: Chris@16: // __cdecl calling convention Chris@16: Chris@16: # if defined(BOOST_PYTHON_ENABLE_CDECL) Chris@16: Chris@16: # define BOOST_PYTHON_FN_CC __cdecl Chris@16: # define BOOST_PYTHON_FN_CC_IS_CDECL Chris@16: Chris@16: # define BOOST_PP_ITERATION_PARAMS_1 \ Chris@16: (3, (0, BOOST_PYTHON_MAX_ARITY, )) Chris@16: Chris@16: # include BOOST_PP_ITERATE() Chris@16: Chris@16: # undef BOOST_PYTHON_FN_CC Chris@16: # undef BOOST_PYTHON_FN_CC_IS_CDECL Chris@16: Chris@16: # endif // defined(BOOST_PYTHON_ENABLE_CDECL) Chris@16: Chris@16: // __stdcall calling convention Chris@16: Chris@16: # if defined(BOOST_PYTHON_ENABLE_STDCALL) Chris@16: Chris@16: # define BOOST_PYTHON_FN_CC __stdcall Chris@16: Chris@16: # define BOOST_PP_ITERATION_PARAMS_1 \ Chris@16: (3, (0, BOOST_PYTHON_MAX_ARITY, )) Chris@16: Chris@16: # include BOOST_PP_ITERATE() Chris@16: Chris@16: # undef BOOST_PYTHON_FN_CC Chris@16: Chris@16: # endif // defined(BOOST_PYTHON_ENABLE_STDCALL) Chris@16: Chris@16: // __fastcall calling convention Chris@16: Chris@16: # if defined(BOOST_PYTHON_ENABLE_FASTCALL) Chris@16: Chris@16: # define BOOST_PYTHON_FN_CC __fastcall Chris@16: Chris@16: # define BOOST_PP_ITERATION_PARAMS_1 \ Chris@16: (3, (0, BOOST_PYTHON_MAX_ARITY, )) Chris@16: Chris@16: # include BOOST_PP_ITERATE() Chris@16: Chris@16: # undef BOOST_PYTHON_FN_CC Chris@16: Chris@16: # endif // defined(BOOST_PYTHON_ENABLE_FASTCALL) Chris@16: Chris@16: # undef BOOST_PYTHON_LIST_INC Chris@16: Chris@16: // } Chris@16: Chris@16: }}} // namespace boost::python::detail Chris@16: Chris@16: Chris@16: # endif // SIGNATURE_JDG20020813_HPP Chris@16: Chris@16: // For gcc 4.4 compatability, we must include the Chris@16: // BOOST_PP_ITERATION_DEPTH test inside an #else clause. Chris@16: #else // BOOST_PP_IS_ITERATING Chris@16: #if BOOST_PP_ITERATION_DEPTH() == 1 // defined(BOOST_PP_IS_ITERATING) Chris@16: Chris@16: # define N BOOST_PP_ITERATION() Chris@16: Chris@16: // as 'get_signature(RT(*)(T0...TN), void* = 0)' is the same Chris@16: // function as 'get_signature(RT(__cdecl *)(T0...TN), void* = 0)', Chris@16: // we don't define it twice Chris@16: # if !defined(BOOST_PYTHON_FN_CC_IS_CDECL) Chris@16: Chris@16: template < Chris@16: class RT BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class T)> Chris@16: inline BOOST_PYTHON_LIST_INC(N)< Chris@16: RT BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, T)> Chris@16: get_signature(RT(BOOST_PYTHON_FN_CC *)(BOOST_PP_ENUM_PARAMS_Z(1, N, T)), void* = 0) Chris@16: { Chris@16: return BOOST_PYTHON_LIST_INC(N)< Chris@16: RT BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, T) Chris@16: >(); Chris@16: } Chris@16: Chris@16: # endif // !defined(BOOST_PYTHON_FN_CC_IS_CDECL) Chris@16: Chris@16: # undef N Chris@16: Chris@16: # define BOOST_PP_ITERATION_PARAMS_2 \ Chris@16: (3, (0, 3, )) Chris@16: # include BOOST_PP_ITERATE() Chris@16: Chris@16: #else Chris@16: Chris@16: # define N BOOST_PP_RELATIVE_ITERATION(1) Chris@16: # define Q BOOST_PYTHON_CV_QUALIFIER(BOOST_PP_ITERATION()) Chris@16: Chris@16: template < Chris@16: class RT, class ClassT BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class T)> Chris@16: inline BOOST_PYTHON_LIST_INC(BOOST_PP_INC(N))< Chris@16: RT, ClassT& BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, T)> Chris@16: get_signature(RT(BOOST_PYTHON_FN_CC ClassT::*)(BOOST_PP_ENUM_PARAMS_Z(1, N, T)) Q) Chris@16: { Chris@16: return BOOST_PYTHON_LIST_INC(BOOST_PP_INC(N))< Chris@16: RT, ClassT& BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, T) Chris@16: >(); Chris@16: } Chris@16: Chris@16: template < Chris@16: class Target Chris@16: , class RT Chris@16: , class ClassT Chris@16: BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class T) Chris@16: > Chris@16: inline BOOST_PYTHON_LIST_INC(BOOST_PP_INC(N))< Chris@16: RT Chris@16: , typename most_derived::type& Chris@16: BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, T) Chris@16: > Chris@16: get_signature( Chris@16: RT(BOOST_PYTHON_FN_CC ClassT::*)(BOOST_PP_ENUM_PARAMS_Z(1, N, T)) Q Chris@16: , Target* Chris@16: ) Chris@16: { Chris@16: return BOOST_PYTHON_LIST_INC(BOOST_PP_INC(N))< Chris@16: RT Chris@16: , BOOST_DEDUCED_TYPENAME most_derived::type& Chris@16: BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, T) Chris@16: >(); Chris@16: } Chris@16: Chris@16: # undef Q Chris@16: # undef N Chris@16: Chris@16: #endif // BOOST_PP_ITERATION_DEPTH() Chris@16: #endif // !defined(BOOST_PP_IS_ITERATING)