os/ossrv/ossrv_pub/boost_apis/boost/python/call_method.hpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/python/call_method.hpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,79 @@
     1.4 +#if !defined(BOOST_PP_IS_ITERATING)
     1.5 +
     1.6 +// Copyright David Abrahams 2002.
     1.7 +// Distributed under the Boost Software License, Version 1.0. (See
     1.8 +// accompanying file LICENSE_1_0.txt or copy at
     1.9 +// http://www.boost.org/LICENSE_1_0.txt)
    1.10 +# ifndef CALL_METHOD_DWA2002411_HPP
    1.11 +#  define CALL_METHOD_DWA2002411_HPP
    1.12 +
    1.13 +# include <boost/python/detail/prefix.hpp>
    1.14 +
    1.15 +#  include <boost/type.hpp>
    1.16 +
    1.17 +#  include <boost/python/converter/arg_to_python.hpp>
    1.18 +#  include <boost/python/converter/return_from_python.hpp>
    1.19 +#  include <boost/python/detail/preprocessor.hpp>
    1.20 +#  include <boost/python/detail/void_return.hpp>
    1.21 +
    1.22 +#  include <boost/preprocessor/comma_if.hpp>
    1.23 +#  include <boost/preprocessor/iterate.hpp>
    1.24 +#  include <boost/preprocessor/repeat.hpp>
    1.25 +#  include <boost/preprocessor/debug/line.hpp>
    1.26 +#  include <boost/preprocessor/repetition/enum_trailing_params.hpp>
    1.27 +#  include <boost/preprocessor/repetition/enum_binary_params.hpp>
    1.28 +
    1.29 +namespace boost { namespace python {
    1.30 +
    1.31 +# define BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET(z, n, _) \
    1.32 +    , converter::arg_to_python<A##n>(a##n).get()
    1.33 +
    1.34 +# define BOOST_PP_ITERATION_PARAMS_1 (3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/call_method.hpp>))
    1.35 +# include BOOST_PP_ITERATE()
    1.36 +
    1.37 +# undef BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET
    1.38 +
    1.39 +}} // namespace boost::python
    1.40 +
    1.41 +# endif // CALL_METHOD_DWA2002411_HPP
    1.42 +
    1.43 +#elif BOOST_PP_ITERATION_DEPTH() == 1
    1.44 +# if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100)                      \
    1.45 +        && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201)))
    1.46 +#  line BOOST_PP_LINE(__LINE__, call_method.hpp)
    1.47 +# endif 
    1.48 +
    1.49 +# define N BOOST_PP_ITERATION()
    1.50 +
    1.51 +template <
    1.52 +    class R
    1.53 +    BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class A)
    1.54 +    >
    1.55 +typename detail::returnable<R>::type
    1.56 +call_method(PyObject* self, char const* name
    1.57 +    BOOST_PP_COMMA_IF(N) BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, A, const& a)
    1.58 +    , boost::type<R>* = 0
    1.59 +    )
    1.60 +{
    1.61 +    PyObject* const result = 
    1.62 +        PyEval_CallMethod(
    1.63 +            self
    1.64 +            , const_cast<char*>(name)
    1.65 +            , const_cast<char*>("(" BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_FIXED, "O") ")")
    1.66 +            BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET, nil)
    1.67 +            );
    1.68 +    
    1.69 +    // This conversion *must not* be done in the same expression as
    1.70 +    // the call, because, in the special case where the result is a
    1.71 +    // reference a Python object which was created by converting a C++
    1.72 +    // argument for passing to PyEval_CallFunction, its reference
    1.73 +    // count will be 2 until the end of the full expression containing
    1.74 +    // the conversion, and that interferes with dangling
    1.75 +    // pointer/reference detection.
    1.76 +    converter::return_from_python<R> converter;
    1.77 +    return converter(result);
    1.78 +}
    1.79 +
    1.80 +# undef N
    1.81 +
    1.82 +#endif // BOOST_PP_IS_ITERATING