os/ossrv/ossrv_pub/boost_apis/boost/python/signature.hpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
///////////////////////////////////////////////////////////////////////////////
sl@0
     2
//
sl@0
     3
// Copyright David Abrahams 2002, Joel de Guzman, 2002.
sl@0
     4
// Distributed under the Boost Software License, Version 1.0. (See
sl@0
     5
// accompanying file LICENSE_1_0.txt or copy at
sl@0
     6
// http://www.boost.org/LICENSE_1_0.txt)
sl@0
     7
//
sl@0
     8
///////////////////////////////////////////////////////////////////////////////
sl@0
     9
#if !defined(BOOST_PP_IS_ITERATING)
sl@0
    10
sl@0
    11
# ifndef SIGNATURE_JDG20020813_HPP
sl@0
    12
#  define SIGNATURE_JDG20020813_HPP
sl@0
    13
sl@0
    14
# include <boost/python/detail/prefix.hpp>
sl@0
    15
sl@0
    16
# include <boost/mpl/if.hpp>
sl@0
    17
# include <boost/type_traits/is_convertible.hpp>
sl@0
    18
sl@0
    19
#  include <boost/python/detail/preprocessor.hpp>
sl@0
    20
#  include <boost/preprocessor/repeat.hpp>
sl@0
    21
#  include <boost/preprocessor/enum.hpp>
sl@0
    22
#  include <boost/preprocessor/enum_params.hpp>
sl@0
    23
#  include <boost/preprocessor/empty.hpp>
sl@0
    24
#  include <boost/preprocessor/arithmetic/sub.hpp>
sl@0
    25
#  include <boost/preprocessor/iterate.hpp>
sl@0
    26
#  include <boost/python/detail/type_list.hpp>
sl@0
    27
sl@0
    28
#  include <boost/preprocessor/debug/line.hpp>
sl@0
    29
#  include <boost/preprocessor/arithmetic/sub.hpp>
sl@0
    30
#  include <boost/preprocessor/arithmetic/inc.hpp>
sl@0
    31
#  include <boost/preprocessor/repetition/enum_trailing_params.hpp>
sl@0
    32
sl@0
    33
# define BOOST_PYTHON_LIST_INC(n)        \
sl@0
    34
   BOOST_PP_CAT(mpl::vector, BOOST_PP_INC(n))
sl@0
    35
sl@0
    36
///////////////////////////////////////////////////////////////////////////////
sl@0
    37
namespace boost { namespace python { namespace detail {
sl@0
    38
sl@0
    39
// A metafunction returning C1 if C1 is derived from C2, and C2
sl@0
    40
// otherwise
sl@0
    41
template <class C1, class C2>
sl@0
    42
struct most_derived
sl@0
    43
{
sl@0
    44
    typedef typename mpl::if_<
sl@0
    45
        is_convertible<C1*,C2*>
sl@0
    46
      , C1
sl@0
    47
      , C2
sl@0
    48
    >::type type;
sl@0
    49
};
sl@0
    50
sl@0
    51
//  The following macros generate expansions for::
sl@0
    52
//
sl@0
    53
//      template <class RT, class T0... class TN>
sl@0
    54
//      inline mpl::vector<RT, T0...TN>
sl@0
    55
//      get_signature(RT(*)(T0...TN), void* = 0)
sl@0
    56
//      {
sl@0
    57
//          return mpl::list<RT, T0...TN>();
sl@0
    58
//      }
sl@0
    59
//
sl@0
    60
//   And, for an appropriate assortment of cv-qualifications::
sl@0
    61
//
sl@0
    62
//      template <class RT, class ClassT, class T0... class TN>
sl@0
    63
//      inline mpl::vector<RT, ClassT&, T0...TN>
sl@0
    64
//      get_signature(RT(ClassT::*)(T0...TN) cv))
sl@0
    65
//      {
sl@0
    66
//          return mpl::list<RT, ClassT&, T0...TN>();
sl@0
    67
//      }
sl@0
    68
//
sl@0
    69
//      template <class Target, class RT, class ClassT, class T0... class TN>
sl@0
    70
//      inline mpl::vector<
sl@0
    71
//          RT
sl@0
    72
//        , typename most_derived<Target, ClassT>::type&
sl@0
    73
//        , T0...TN
sl@0
    74
//      >
sl@0
    75
//      get_signature(RT(ClassT::*)(T0...TN) cv), Target*)
sl@0
    76
//      {
sl@0
    77
//          return mpl::list<RT, ClassT&, T0...TN>();
sl@0
    78
//      }
sl@0
    79
//
sl@0
    80
//  There are two forms for invoking get_signature::
sl@0
    81
//
sl@0
    82
//      get_signature(f)
sl@0
    83
//
sl@0
    84
//  and ::
sl@0
    85
//
sl@0
    86
//      get_signature(f,(Target*)0)
sl@0
    87
//
sl@0
    88
//  These functions extract the return type, class (for member
sl@0
    89
//  functions) and arguments of the input signature and stuff them in
sl@0
    90
//  an mpl type sequence.  Note that cv-qualification is dropped from
sl@0
    91
//  the "hidden this" argument of member functions; that is a
sl@0
    92
//  necessary sacrifice to ensure that an lvalue from_python converter
sl@0
    93
//  is used.  A pointer is not used so that None will be rejected for
sl@0
    94
//  overload resolution.
sl@0
    95
//
sl@0
    96
//  The second form of get_signature essentially downcasts the "hidden
sl@0
    97
//  this" argument of member functions to Target, because the function
sl@0
    98
//  may actually be a member of a base class which is not wrapped, and
sl@0
    99
//  in that case conversion from python would fail.
sl@0
   100
//
sl@0
   101
// @group {
sl@0
   102
sl@0
   103
#  define BOOST_PP_ITERATION_PARAMS_1                                   \
sl@0
   104
    (3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/signature.hpp>))
sl@0
   105
sl@0
   106
#  include BOOST_PP_ITERATE()
sl@0
   107
#  undef BOOST_PYTHON_LIST_INC
sl@0
   108
sl@0
   109
// }
sl@0
   110
sl@0
   111
}}} // namespace boost::python::detail
sl@0
   112
sl@0
   113
sl@0
   114
# endif // SIGNATURE_JDG20020813_HPP
sl@0
   115
sl@0
   116
#elif BOOST_PP_ITERATION_DEPTH() == 1 // defined(BOOST_PP_IS_ITERATING)
sl@0
   117
sl@0
   118
# define N BOOST_PP_ITERATION()
sl@0
   119
sl@0
   120
template <
sl@0
   121
    class RT BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class T)>
sl@0
   122
inline BOOST_PYTHON_LIST_INC(N)<
sl@0
   123
    RT BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, T)>
sl@0
   124
get_signature(RT(*)(BOOST_PP_ENUM_PARAMS_Z(1, N, T)), void* = 0)
sl@0
   125
{
sl@0
   126
    return BOOST_PYTHON_LIST_INC(N)<
sl@0
   127
            RT BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, T)
sl@0
   128
        >();
sl@0
   129
}
sl@0
   130
sl@0
   131
# undef N
sl@0
   132
sl@0
   133
# define BOOST_PP_ITERATION_PARAMS_2 \
sl@0
   134
    (3, (0, 3, <boost/python/signature.hpp>))
sl@0
   135
# include BOOST_PP_ITERATE()
sl@0
   136
sl@0
   137
#else
sl@0
   138
sl@0
   139
# define N BOOST_PP_RELATIVE_ITERATION(1)
sl@0
   140
# define Q BOOST_PYTHON_CV_QUALIFIER(BOOST_PP_ITERATION())
sl@0
   141
sl@0
   142
template <
sl@0
   143
    class RT, class ClassT BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class T)>
sl@0
   144
inline BOOST_PYTHON_LIST_INC(BOOST_PP_INC(N))<
sl@0
   145
    RT, ClassT& BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, T)>
sl@0
   146
get_signature(RT(ClassT::*)(BOOST_PP_ENUM_PARAMS_Z(1, N, T)) Q)
sl@0
   147
{
sl@0
   148
    return BOOST_PYTHON_LIST_INC(BOOST_PP_INC(N))<
sl@0
   149
            RT, ClassT& BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, T)
sl@0
   150
        >();
sl@0
   151
}
sl@0
   152
sl@0
   153
template <
sl@0
   154
    class Target
sl@0
   155
  , class RT
sl@0
   156
  , class ClassT
sl@0
   157
    BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class T)
sl@0
   158
>
sl@0
   159
inline BOOST_PYTHON_LIST_INC(BOOST_PP_INC(N))<
sl@0
   160
    RT
sl@0
   161
  , typename most_derived<Target, ClassT>::type&
sl@0
   162
    BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, T)
sl@0
   163
>
sl@0
   164
get_signature(
sl@0
   165
    RT(ClassT::*)(BOOST_PP_ENUM_PARAMS_Z(1, N, T)) Q
sl@0
   166
  , Target*
sl@0
   167
)
sl@0
   168
{
sl@0
   169
    return BOOST_PYTHON_LIST_INC(BOOST_PP_INC(N))<
sl@0
   170
        RT
sl@0
   171
      , BOOST_DEDUCED_TYPENAME most_derived<Target, ClassT>::type&
sl@0
   172
        BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, T)
sl@0
   173
    >();
sl@0
   174
}
sl@0
   175
sl@0
   176
# undef Q
sl@0
   177
# undef N
sl@0
   178
sl@0
   179
#endif // !defined(BOOST_PP_IS_ITERATING)