// Copyright 2014, Peter Hatina // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #ifndef MAKE_METHOD_HPP #define MAKE_METHOD_HPP #include #include #include #include #include #include #include namespace boost { namespace python { namespace detail { template class raw_method_dispatcher { public: raw_method_dispatcher(M method): m_method(method) {} PyObject* operator()(PyObject* args, PyObject* kwds) { detail::borrowed_reference_t *rargs = detail::borrowed_reference(args); object args_obj(rargs); // Extract a C++ reference to object, which is about to call raw method C &obj = extract(object(args_obj[0])); // Return boost::python object containing the raw method call return incref( object( (obj.*m_method)( tuple(args_obj.slice(1, len(args_obj))), kwds ? dict(detail::borrowed_reference(kwds)) : dict()) ).ptr() ); } private: M m_method; }; } template object raw_method(M method, std::size_t min_args = 0) { return detail::make_raw_function( objects::py_function( detail::raw_method_dispatcher(method), boost::mpl::vector1(), min_args, (std::numeric_limits::max)()) ); } }} #endif // MAKE_METHOD_HPP