os/ossrv/ossrv_pub/boost_apis/boost/python/detail/invoke.hpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
#if !defined(BOOST_PP_IS_ITERATING)
sl@0
     2
sl@0
     3
// Copyright David Abrahams 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
# ifndef INVOKE_DWA20021122_HPP
sl@0
     8
#  define INVOKE_DWA20021122_HPP
sl@0
     9
sl@0
    10
#  include <boost/python/detail/prefix.hpp>
sl@0
    11
#  include <boost/python/detail/preprocessor.hpp>
sl@0
    12
#  include <boost/python/detail/none.hpp>
sl@0
    13
sl@0
    14
#  include <boost/type_traits/is_member_function_pointer.hpp>
sl@0
    15
sl@0
    16
#  include <boost/preprocessor/iterate.hpp>
sl@0
    17
#  include <boost/preprocessor/facilities/intercept.hpp>
sl@0
    18
#  include <boost/preprocessor/repetition/enum_trailing_params.hpp>
sl@0
    19
#  include <boost/preprocessor/repetition/enum_trailing_binary_params.hpp>
sl@0
    20
#  include <boost/preprocessor/repetition/enum_binary_params.hpp>
sl@0
    21
#  include <boost/python/to_python_value.hpp>
sl@0
    22
sl@0
    23
// This file declares a series of overloaded invoke(...)  functions,
sl@0
    24
// used to invoke wrapped C++ function (object)s from Python. Each one
sl@0
    25
// accepts:
sl@0
    26
//
sl@0
    27
//   - a tag which identifies the invocation syntax (e.g. member
sl@0
    28
//   functions must be invoked with a different syntax from regular
sl@0
    29
//   functions)
sl@0
    30
//
sl@0
    31
//   - a pointer to a result converter type, used solely as a way of
sl@0
    32
//   transmitting the type of the result converter to the function (or
sl@0
    33
//   an int, if the return type is void).
sl@0
    34
//
sl@0
    35
//   - the "function", which may be a function object, a function or
sl@0
    36
//   member function pointer, or a defaulted_virtual_fn.
sl@0
    37
//
sl@0
    38
//   - The arg_from_python converters for each of the arguments to be
sl@0
    39
//   passed to the function being invoked.
sl@0
    40
sl@0
    41
namespace boost { namespace python { namespace detail { 
sl@0
    42
sl@0
    43
// This "result converter" is really just used as a dispatch tag to
sl@0
    44
// invoke(...), selecting the appropriate implementation
sl@0
    45
typedef int void_result_to_python;
sl@0
    46
sl@0
    47
template <bool void_return, bool member>
sl@0
    48
struct invoke_tag_ {};
sl@0
    49
sl@0
    50
// A metafunction returning the appropriate tag type for invoking an
sl@0
    51
// object of type F with return type R.
sl@0
    52
template <class R, class F>
sl@0
    53
struct invoke_tag
sl@0
    54
  : invoke_tag_<
sl@0
    55
        is_same<R,void>::value
sl@0
    56
      , is_member_function_pointer<F>::value
sl@0
    57
    >
sl@0
    58
{
sl@0
    59
};
sl@0
    60
sl@0
    61
#  define BOOST_PP_ITERATION_PARAMS_1                                            \
sl@0
    62
        (3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/detail/invoke.hpp>))
sl@0
    63
#  include BOOST_PP_ITERATE()
sl@0
    64
sl@0
    65
}}} // namespace boost::python::detail
sl@0
    66
sl@0
    67
# endif // INVOKE_DWA20021122_HPP
sl@0
    68
#else 
sl@0
    69
sl@0
    70
# define N BOOST_PP_ITERATION()
sl@0
    71
sl@0
    72
template <class RC, class F BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class AC)>
sl@0
    73
inline PyObject* invoke(invoke_tag_<false,false>, RC const& rc, F& f BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z(1, N, AC, & ac) )
sl@0
    74
{
sl@0
    75
    return rc(f( BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, ac, () BOOST_PP_INTERCEPT) ));
sl@0
    76
}
sl@0
    77
                 
sl@0
    78
template <class RC, class F BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class AC)>
sl@0
    79
inline PyObject* invoke(invoke_tag_<true,false>, RC const&, F& f BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z(1, N, AC, & ac) )
sl@0
    80
{
sl@0
    81
    f( BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, ac, () BOOST_PP_INTERCEPT) );
sl@0
    82
    return none();
sl@0
    83
}
sl@0
    84
sl@0
    85
template <class RC, class F, class TC BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class AC)>
sl@0
    86
inline PyObject* invoke(invoke_tag_<false,true>, RC const& rc, F& f, TC& tc BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z(1, N, AC, & ac) )
sl@0
    87
{
sl@0
    88
    return rc( (tc().*f)(BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, ac, () BOOST_PP_INTERCEPT)) );
sl@0
    89
}
sl@0
    90
                 
sl@0
    91
template <class RC, class F, class TC BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class AC)>
sl@0
    92
inline PyObject* invoke(invoke_tag_<true,true>, RC const&, F& f, TC& tc BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z(1, N, AC, & ac) )
sl@0
    93
{
sl@0
    94
    (tc().*f)(BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, ac, () BOOST_PP_INTERCEPT));
sl@0
    95
    return none();
sl@0
    96
}
sl@0
    97
sl@0
    98
# undef N
sl@0
    99
sl@0
   100
#endif // BOOST_PP_IS_ITERATING