Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:50:42

0001 ///////////////////////////////////////////////////////////////////////////////
0002 //
0003 // Copyright David Abrahams 2002, Joel de Guzman, 2002.
0004 // Distributed under the Boost Software License, Version 1.0. (See
0005 // accompanying file LICENSE_1_0.txt or copy at
0006 // http://www.boost.org/LICENSE_1_0.txt)
0007 //
0008 ///////////////////////////////////////////////////////////////////////////////
0009 #if !defined(BOOST_PP_IS_ITERATING)
0010 
0011 # ifndef SIGNATURE_JDG20020813_HPP
0012 #  define SIGNATURE_JDG20020813_HPP
0013 
0014 # include <boost/python/detail/prefix.hpp>
0015 
0016 # include <boost/mpl/if.hpp>
0017 
0018 #  include <boost/python/detail/preprocessor.hpp>
0019 #  include <boost/python/detail/type_traits.hpp>
0020 #  include <boost/preprocessor/repeat.hpp>
0021 #  include <boost/preprocessor/enum.hpp>
0022 #  include <boost/preprocessor/enum_params.hpp>
0023 #  include <boost/preprocessor/empty.hpp>
0024 #  include <boost/preprocessor/arithmetic/sub.hpp>
0025 #  include <boost/preprocessor/iterate.hpp>
0026 #  include <boost/python/detail/type_list.hpp>
0027 
0028 #  include <boost/preprocessor/debug/line.hpp>
0029 #  include <boost/preprocessor/arithmetic/sub.hpp>
0030 #  include <boost/preprocessor/arithmetic/inc.hpp>
0031 #  include <boost/preprocessor/repetition/enum_trailing_params.hpp>
0032 
0033 # define BOOST_PYTHON_LIST_INC(n)        \
0034    BOOST_PP_CAT(mpl::vector, BOOST_PP_INC(n))
0035 
0036 ///////////////////////////////////////////////////////////////////////////////
0037 namespace boost { namespace python { namespace detail {
0038 
0039 // A metafunction returning C1 if C1 is derived from C2, and C2
0040 // otherwise
0041 template <class C1, class C2>
0042 struct most_derived
0043 {
0044     typedef typename mpl::if_<
0045         detail::is_convertible<C1*,C2*>
0046       , C1
0047       , C2
0048     >::type type;
0049 };
0050 
0051 //  The following macros generate expansions for::
0052 //
0053 //      template <class RT, class T0... class TN>
0054 //      inline mpl::vector<RT, T0...TN>
0055 //      get_signature(RT(BOOST_PYTHON_FN_CC *)(T0...TN), void* = 0)
0056 //      {
0057 //          return mpl::list<RT, T0...TN>();
0058 //      }
0059 //
0060 //    where BOOST_PYTHON_FN_CC is a calling convention keyword, can be
0061 //
0062 //        empty, for default calling convention
0063 //        __cdecl (if BOOST_PYTHON_ENABLE_CDECL is defined)
0064 //        __stdcall (if BOOST_PYTHON_ENABLE_STDCALL is defined)
0065 //        __fastcall (if BOOST_PYTHON_ENABLE_FASTCALL is defined)
0066 //
0067 //   And, for an appropriate assortment of cv-qualifications::
0068 //
0069 //      template <class RT, class ClassT, class T0... class TN>
0070 //      inline mpl::vector<RT, ClassT&, T0...TN>
0071 //      get_signature(RT(BOOST_PYTHON_FN_CC ClassT::*)(T0...TN) cv))
0072 //      {
0073 //          return mpl::list<RT, ClassT&, T0...TN>();
0074 //      }
0075 //
0076 //      template <class Target, class RT, class ClassT, class T0... class TN>
0077 //      inline mpl::vector<
0078 //          RT
0079 //        , typename most_derived<Target, ClassT>::type&
0080 //        , T0...TN
0081 //      >
0082 //      get_signature(RT(BOOST_PYTHON_FN_CC ClassT::*)(T0...TN) cv), Target*)
0083 //      {
0084 //          return mpl::list<RT, ClassT&, T0...TN>();
0085 //      }
0086 //
0087 //  There are two forms for invoking get_signature::
0088 //
0089 //      get_signature(f)
0090 //
0091 //  and ::
0092 //
0093 //      get_signature(f,(Target*)0)
0094 //
0095 //  These functions extract the return type, class (for member
0096 //  functions) and arguments of the input signature and stuff them in
0097 //  an mpl type sequence (the calling convention is dropped).
0098 //  Note that cv-qualification is dropped from
0099 //  the "hidden this" argument of member functions; that is a
0100 //  necessary sacrifice to ensure that an lvalue from_python converter
0101 //  is used.  A pointer is not used so that None will be rejected for
0102 //  overload resolution.
0103 //
0104 //  The second form of get_signature essentially downcasts the "hidden
0105 //  this" argument of member functions to Target, because the function
0106 //  may actually be a member of a base class which is not wrapped, and
0107 //  in that case conversion from python would fail.
0108 //
0109 // @group {
0110 
0111 // 'default' calling convention
0112 
0113 #  define BOOST_PYTHON_FN_CC
0114 
0115 #  define BOOST_PP_ITERATION_PARAMS_1                                   \
0116     (3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/signature.hpp>))
0117 
0118 #  include BOOST_PP_ITERATE()
0119 
0120 #  undef BOOST_PYTHON_FN_CC
0121 
0122 // __cdecl calling convention
0123 
0124 #  if defined(BOOST_PYTHON_ENABLE_CDECL)
0125 
0126 #   define BOOST_PYTHON_FN_CC __cdecl
0127 #   define BOOST_PYTHON_FN_CC_IS_CDECL
0128 
0129 #   define BOOST_PP_ITERATION_PARAMS_1                                   \
0130      (3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/signature.hpp>))
0131 
0132 #   include BOOST_PP_ITERATE()
0133 
0134 #   undef BOOST_PYTHON_FN_CC
0135 #   undef BOOST_PYTHON_FN_CC_IS_CDECL
0136 
0137 #  endif // defined(BOOST_PYTHON_ENABLE_CDECL)
0138 
0139 // __stdcall calling convention
0140 
0141 #  if defined(BOOST_PYTHON_ENABLE_STDCALL)
0142 
0143 #   define BOOST_PYTHON_FN_CC __stdcall
0144 
0145 #   define BOOST_PP_ITERATION_PARAMS_1                                   \
0146      (3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/signature.hpp>))
0147 
0148 #   include BOOST_PP_ITERATE()
0149 
0150 #   undef BOOST_PYTHON_FN_CC
0151 
0152 #  endif // defined(BOOST_PYTHON_ENABLE_STDCALL)
0153 
0154 // __fastcall calling convention
0155 
0156 #  if defined(BOOST_PYTHON_ENABLE_FASTCALL)
0157 
0158 #   define BOOST_PYTHON_FN_CC __fastcall
0159 
0160 #   define BOOST_PP_ITERATION_PARAMS_1                                   \
0161      (3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/signature.hpp>))
0162 
0163 #   include BOOST_PP_ITERATE()
0164 
0165 #   undef BOOST_PYTHON_FN_CC
0166 
0167 #  endif // defined(BOOST_PYTHON_ENABLE_FASTCALL)
0168 
0169 #  undef BOOST_PYTHON_LIST_INC
0170 
0171 // }
0172 
0173 }}} // namespace boost::python::detail
0174 
0175 
0176 # endif // SIGNATURE_JDG20020813_HPP
0177 
0178 // For gcc 4.4 compatability, we must include the
0179 // BOOST_PP_ITERATION_DEPTH test inside an #else clause.
0180 #else // BOOST_PP_IS_ITERATING
0181 #if BOOST_PP_ITERATION_DEPTH() == 1 // defined(BOOST_PP_IS_ITERATING)
0182 
0183 # define N BOOST_PP_ITERATION()
0184 
0185    // as 'get_signature(RT(*)(T0...TN), void* = 0)' is the same
0186    // function as 'get_signature(RT(__cdecl *)(T0...TN), void* = 0)',
0187    // we don't define it twice
0188 #  if !defined(BOOST_PYTHON_FN_CC_IS_CDECL)
0189 
0190 template <
0191     class RT BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class T)>
0192 inline BOOST_PYTHON_LIST_INC(N)<
0193     RT BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, T)>
0194 get_signature(RT(BOOST_PYTHON_FN_CC *)(BOOST_PP_ENUM_PARAMS_Z(1, N, T)), void* = 0)
0195 {
0196     return BOOST_PYTHON_LIST_INC(N)<
0197             RT BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, T)
0198         >();
0199 }
0200 
0201 #  endif // !defined(BOOST_PYTHON_FN_CC_IS_CDECL)
0202 
0203 # undef N
0204 
0205 # define BOOST_PP_ITERATION_PARAMS_2 \
0206     (3, (0, 3, <boost/python/signature.hpp>))
0207 # include BOOST_PP_ITERATE()
0208 
0209 #else
0210 
0211 # define N BOOST_PP_RELATIVE_ITERATION(1)
0212 # define Q BOOST_PYTHON_CV_QUALIFIER(BOOST_PP_ITERATION())
0213 
0214 template <
0215     class RT, class ClassT BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class T)>
0216 inline BOOST_PYTHON_LIST_INC(BOOST_PP_INC(N))<
0217     RT, ClassT& BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, T)>
0218 get_signature(RT(BOOST_PYTHON_FN_CC ClassT::*)(BOOST_PP_ENUM_PARAMS_Z(1, N, T)) Q)
0219 {
0220     return BOOST_PYTHON_LIST_INC(BOOST_PP_INC(N))<
0221             RT, ClassT& BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, T)
0222         >();
0223 }
0224 
0225 template <
0226     class Target
0227   , class RT
0228   , class ClassT
0229     BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class T)
0230 >
0231 inline BOOST_PYTHON_LIST_INC(BOOST_PP_INC(N))<
0232     RT
0233   , typename most_derived<Target, ClassT>::type&
0234     BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, T)
0235 >
0236 get_signature(
0237     RT(BOOST_PYTHON_FN_CC ClassT::*)(BOOST_PP_ENUM_PARAMS_Z(1, N, T)) Q
0238   , Target*
0239 )
0240 {
0241     return BOOST_PYTHON_LIST_INC(BOOST_PP_INC(N))<
0242         RT
0243       , BOOST_DEDUCED_TYPENAME most_derived<Target, ClassT>::type&
0244         BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, T)
0245     >();
0246 }
0247 
0248 # undef Q
0249 # undef N
0250 
0251 #endif // BOOST_PP_ITERATION_DEPTH()
0252 #endif // !defined(BOOST_PP_IS_ITERATING)