annotate DEPENDENCIES/generic/include/boost/python/signature.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 ///////////////////////////////////////////////////////////////////////////////
Chris@16 2 //
Chris@16 3 // Copyright David Abrahams 2002, Joel de Guzman, 2002.
Chris@16 4 // Distributed under the Boost Software License, Version 1.0. (See
Chris@16 5 // accompanying file LICENSE_1_0.txt or copy at
Chris@16 6 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 7 //
Chris@16 8 ///////////////////////////////////////////////////////////////////////////////
Chris@16 9 #if !defined(BOOST_PP_IS_ITERATING)
Chris@16 10
Chris@16 11 # ifndef SIGNATURE_JDG20020813_HPP
Chris@16 12 # define SIGNATURE_JDG20020813_HPP
Chris@16 13
Chris@16 14 # include <boost/python/detail/prefix.hpp>
Chris@16 15
Chris@16 16 # include <boost/mpl/if.hpp>
Chris@16 17 # include <boost/type_traits/is_convertible.hpp>
Chris@16 18
Chris@16 19 # include <boost/python/detail/preprocessor.hpp>
Chris@16 20 # include <boost/preprocessor/repeat.hpp>
Chris@16 21 # include <boost/preprocessor/enum.hpp>
Chris@16 22 # include <boost/preprocessor/enum_params.hpp>
Chris@16 23 # include <boost/preprocessor/empty.hpp>
Chris@16 24 # include <boost/preprocessor/arithmetic/sub.hpp>
Chris@16 25 # include <boost/preprocessor/iterate.hpp>
Chris@16 26 # include <boost/python/detail/type_list.hpp>
Chris@16 27
Chris@16 28 # include <boost/preprocessor/debug/line.hpp>
Chris@16 29 # include <boost/preprocessor/arithmetic/sub.hpp>
Chris@16 30 # include <boost/preprocessor/arithmetic/inc.hpp>
Chris@16 31 # include <boost/preprocessor/repetition/enum_trailing_params.hpp>
Chris@16 32
Chris@16 33 # define BOOST_PYTHON_LIST_INC(n) \
Chris@16 34 BOOST_PP_CAT(mpl::vector, BOOST_PP_INC(n))
Chris@16 35
Chris@16 36 ///////////////////////////////////////////////////////////////////////////////
Chris@16 37 namespace boost { namespace python { namespace detail {
Chris@16 38
Chris@16 39 // A metafunction returning C1 if C1 is derived from C2, and C2
Chris@16 40 // otherwise
Chris@16 41 template <class C1, class C2>
Chris@16 42 struct most_derived
Chris@16 43 {
Chris@16 44 typedef typename mpl::if_<
Chris@16 45 is_convertible<C1*,C2*>
Chris@16 46 , C1
Chris@16 47 , C2
Chris@16 48 >::type type;
Chris@16 49 };
Chris@16 50
Chris@16 51 // The following macros generate expansions for::
Chris@16 52 //
Chris@16 53 // template <class RT, class T0... class TN>
Chris@16 54 // inline mpl::vector<RT, T0...TN>
Chris@16 55 // get_signature(RT(BOOST_PYTHON_FN_CC *)(T0...TN), void* = 0)
Chris@16 56 // {
Chris@16 57 // return mpl::list<RT, T0...TN>();
Chris@16 58 // }
Chris@16 59 //
Chris@16 60 // where BOOST_PYTHON_FN_CC is a calling convention keyword, can be
Chris@16 61 //
Chris@16 62 // empty, for default calling convention
Chris@16 63 // __cdecl (if BOOST_PYTHON_ENABLE_CDECL is defined)
Chris@16 64 // __stdcall (if BOOST_PYTHON_ENABLE_STDCALL is defined)
Chris@16 65 // __fastcall (if BOOST_PYTHON_ENABLE_FASTCALL is defined)
Chris@16 66 //
Chris@16 67 // And, for an appropriate assortment of cv-qualifications::
Chris@16 68 //
Chris@16 69 // template <class RT, class ClassT, class T0... class TN>
Chris@16 70 // inline mpl::vector<RT, ClassT&, T0...TN>
Chris@16 71 // get_signature(RT(BOOST_PYTHON_FN_CC ClassT::*)(T0...TN) cv))
Chris@16 72 // {
Chris@16 73 // return mpl::list<RT, ClassT&, T0...TN>();
Chris@16 74 // }
Chris@16 75 //
Chris@16 76 // template <class Target, class RT, class ClassT, class T0... class TN>
Chris@16 77 // inline mpl::vector<
Chris@16 78 // RT
Chris@16 79 // , typename most_derived<Target, ClassT>::type&
Chris@16 80 // , T0...TN
Chris@16 81 // >
Chris@16 82 // get_signature(RT(BOOST_PYTHON_FN_CC ClassT::*)(T0...TN) cv), Target*)
Chris@16 83 // {
Chris@16 84 // return mpl::list<RT, ClassT&, T0...TN>();
Chris@16 85 // }
Chris@16 86 //
Chris@16 87 // There are two forms for invoking get_signature::
Chris@16 88 //
Chris@16 89 // get_signature(f)
Chris@16 90 //
Chris@16 91 // and ::
Chris@16 92 //
Chris@16 93 // get_signature(f,(Target*)0)
Chris@16 94 //
Chris@16 95 // These functions extract the return type, class (for member
Chris@16 96 // functions) and arguments of the input signature and stuff them in
Chris@16 97 // an mpl type sequence (the calling convention is dropped).
Chris@16 98 // Note that cv-qualification is dropped from
Chris@16 99 // the "hidden this" argument of member functions; that is a
Chris@16 100 // necessary sacrifice to ensure that an lvalue from_python converter
Chris@16 101 // is used. A pointer is not used so that None will be rejected for
Chris@16 102 // overload resolution.
Chris@16 103 //
Chris@16 104 // The second form of get_signature essentially downcasts the "hidden
Chris@16 105 // this" argument of member functions to Target, because the function
Chris@16 106 // may actually be a member of a base class which is not wrapped, and
Chris@16 107 // in that case conversion from python would fail.
Chris@16 108 //
Chris@16 109 // @group {
Chris@16 110
Chris@16 111 // 'default' calling convention
Chris@16 112
Chris@16 113 # define BOOST_PYTHON_FN_CC
Chris@16 114
Chris@16 115 # define BOOST_PP_ITERATION_PARAMS_1 \
Chris@16 116 (3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/signature.hpp>))
Chris@16 117
Chris@16 118 # include BOOST_PP_ITERATE()
Chris@16 119
Chris@16 120 # undef BOOST_PYTHON_FN_CC
Chris@16 121
Chris@16 122 // __cdecl calling convention
Chris@16 123
Chris@16 124 # if defined(BOOST_PYTHON_ENABLE_CDECL)
Chris@16 125
Chris@16 126 # define BOOST_PYTHON_FN_CC __cdecl
Chris@16 127 # define BOOST_PYTHON_FN_CC_IS_CDECL
Chris@16 128
Chris@16 129 # define BOOST_PP_ITERATION_PARAMS_1 \
Chris@16 130 (3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/signature.hpp>))
Chris@16 131
Chris@16 132 # include BOOST_PP_ITERATE()
Chris@16 133
Chris@16 134 # undef BOOST_PYTHON_FN_CC
Chris@16 135 # undef BOOST_PYTHON_FN_CC_IS_CDECL
Chris@16 136
Chris@16 137 # endif // defined(BOOST_PYTHON_ENABLE_CDECL)
Chris@16 138
Chris@16 139 // __stdcall calling convention
Chris@16 140
Chris@16 141 # if defined(BOOST_PYTHON_ENABLE_STDCALL)
Chris@16 142
Chris@16 143 # define BOOST_PYTHON_FN_CC __stdcall
Chris@16 144
Chris@16 145 # define BOOST_PP_ITERATION_PARAMS_1 \
Chris@16 146 (3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/signature.hpp>))
Chris@16 147
Chris@16 148 # include BOOST_PP_ITERATE()
Chris@16 149
Chris@16 150 # undef BOOST_PYTHON_FN_CC
Chris@16 151
Chris@16 152 # endif // defined(BOOST_PYTHON_ENABLE_STDCALL)
Chris@16 153
Chris@16 154 // __fastcall calling convention
Chris@16 155
Chris@16 156 # if defined(BOOST_PYTHON_ENABLE_FASTCALL)
Chris@16 157
Chris@16 158 # define BOOST_PYTHON_FN_CC __fastcall
Chris@16 159
Chris@16 160 # define BOOST_PP_ITERATION_PARAMS_1 \
Chris@16 161 (3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/signature.hpp>))
Chris@16 162
Chris@16 163 # include BOOST_PP_ITERATE()
Chris@16 164
Chris@16 165 # undef BOOST_PYTHON_FN_CC
Chris@16 166
Chris@16 167 # endif // defined(BOOST_PYTHON_ENABLE_FASTCALL)
Chris@16 168
Chris@16 169 # undef BOOST_PYTHON_LIST_INC
Chris@16 170
Chris@16 171 // }
Chris@16 172
Chris@16 173 }}} // namespace boost::python::detail
Chris@16 174
Chris@16 175
Chris@16 176 # endif // SIGNATURE_JDG20020813_HPP
Chris@16 177
Chris@16 178 // For gcc 4.4 compatability, we must include the
Chris@16 179 // BOOST_PP_ITERATION_DEPTH test inside an #else clause.
Chris@16 180 #else // BOOST_PP_IS_ITERATING
Chris@16 181 #if BOOST_PP_ITERATION_DEPTH() == 1 // defined(BOOST_PP_IS_ITERATING)
Chris@16 182
Chris@16 183 # define N BOOST_PP_ITERATION()
Chris@16 184
Chris@16 185 // as 'get_signature(RT(*)(T0...TN), void* = 0)' is the same
Chris@16 186 // function as 'get_signature(RT(__cdecl *)(T0...TN), void* = 0)',
Chris@16 187 // we don't define it twice
Chris@16 188 # if !defined(BOOST_PYTHON_FN_CC_IS_CDECL)
Chris@16 189
Chris@16 190 template <
Chris@16 191 class RT BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class T)>
Chris@16 192 inline BOOST_PYTHON_LIST_INC(N)<
Chris@16 193 RT BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, T)>
Chris@16 194 get_signature(RT(BOOST_PYTHON_FN_CC *)(BOOST_PP_ENUM_PARAMS_Z(1, N, T)), void* = 0)
Chris@16 195 {
Chris@16 196 return BOOST_PYTHON_LIST_INC(N)<
Chris@16 197 RT BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, T)
Chris@16 198 >();
Chris@16 199 }
Chris@16 200
Chris@16 201 # endif // !defined(BOOST_PYTHON_FN_CC_IS_CDECL)
Chris@16 202
Chris@16 203 # undef N
Chris@16 204
Chris@16 205 # define BOOST_PP_ITERATION_PARAMS_2 \
Chris@16 206 (3, (0, 3, <boost/python/signature.hpp>))
Chris@16 207 # include BOOST_PP_ITERATE()
Chris@16 208
Chris@16 209 #else
Chris@16 210
Chris@16 211 # define N BOOST_PP_RELATIVE_ITERATION(1)
Chris@16 212 # define Q BOOST_PYTHON_CV_QUALIFIER(BOOST_PP_ITERATION())
Chris@16 213
Chris@16 214 template <
Chris@16 215 class RT, class ClassT BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class T)>
Chris@16 216 inline BOOST_PYTHON_LIST_INC(BOOST_PP_INC(N))<
Chris@16 217 RT, ClassT& BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, T)>
Chris@16 218 get_signature(RT(BOOST_PYTHON_FN_CC ClassT::*)(BOOST_PP_ENUM_PARAMS_Z(1, N, T)) Q)
Chris@16 219 {
Chris@16 220 return BOOST_PYTHON_LIST_INC(BOOST_PP_INC(N))<
Chris@16 221 RT, ClassT& BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, T)
Chris@16 222 >();
Chris@16 223 }
Chris@16 224
Chris@16 225 template <
Chris@16 226 class Target
Chris@16 227 , class RT
Chris@16 228 , class ClassT
Chris@16 229 BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class T)
Chris@16 230 >
Chris@16 231 inline BOOST_PYTHON_LIST_INC(BOOST_PP_INC(N))<
Chris@16 232 RT
Chris@16 233 , typename most_derived<Target, ClassT>::type&
Chris@16 234 BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, T)
Chris@16 235 >
Chris@16 236 get_signature(
Chris@16 237 RT(BOOST_PYTHON_FN_CC ClassT::*)(BOOST_PP_ENUM_PARAMS_Z(1, N, T)) Q
Chris@16 238 , Target*
Chris@16 239 )
Chris@16 240 {
Chris@16 241 return BOOST_PYTHON_LIST_INC(BOOST_PP_INC(N))<
Chris@16 242 RT
Chris@16 243 , BOOST_DEDUCED_TYPENAME most_derived<Target, ClassT>::type&
Chris@16 244 BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, T)
Chris@16 245 >();
Chris@16 246 }
Chris@16 247
Chris@16 248 # undef Q
Chris@16 249 # undef N
Chris@16 250
Chris@16 251 #endif // BOOST_PP_ITERATION_DEPTH()
Chris@16 252 #endif // !defined(BOOST_PP_IS_ITERATING)