author | sl |
Tue, 10 Jun 2014 14:32:02 +0200 | |
changeset 1 | 260cb5ec6c19 |
permissions | -rw-r--r-- |
sl@0 | 1 |
// Copyright David Abrahams 2003. |
sl@0 | 2 |
// Distributed under the Boost Software License, Version 1.0. (See |
sl@0 | 3 |
// accompanying file LICENSE_1_0.txt or copy at |
sl@0 | 4 |
// http://www.boost.org/LICENSE_1_0.txt) |
sl@0 | 5 |
#ifndef RAW_FUNCTION_DWA200336_HPP |
sl@0 | 6 |
# define RAW_FUNCTION_DWA200336_HPP |
sl@0 | 7 |
|
sl@0 | 8 |
# include <boost/python/detail/prefix.hpp> |
sl@0 | 9 |
|
sl@0 | 10 |
# include <boost/python/tuple.hpp> |
sl@0 | 11 |
# include <boost/python/dict.hpp> |
sl@0 | 12 |
# include <boost/python/object/py_function.hpp> |
sl@0 | 13 |
# include <boost/mpl/vector/vector10.hpp> |
sl@0 | 14 |
|
sl@0 | 15 |
# include <boost/limits.hpp> |
sl@0 | 16 |
# include <cstddef> |
sl@0 | 17 |
|
sl@0 | 18 |
namespace boost { namespace python { |
sl@0 | 19 |
|
sl@0 | 20 |
namespace detail |
sl@0 | 21 |
{ |
sl@0 | 22 |
template <class F> |
sl@0 | 23 |
struct raw_dispatcher |
sl@0 | 24 |
{ |
sl@0 | 25 |
raw_dispatcher(F f) : f(f) {} |
sl@0 | 26 |
|
sl@0 | 27 |
PyObject* operator()(PyObject* args, PyObject* keywords) |
sl@0 | 28 |
{ |
sl@0 | 29 |
return incref( |
sl@0 | 30 |
object( |
sl@0 | 31 |
f( |
sl@0 | 32 |
tuple(borrowed_reference(args)) |
sl@0 | 33 |
, keywords ? dict(borrowed_reference(keywords)) : dict() |
sl@0 | 34 |
) |
sl@0 | 35 |
).ptr() |
sl@0 | 36 |
); |
sl@0 | 37 |
} |
sl@0 | 38 |
|
sl@0 | 39 |
private: |
sl@0 | 40 |
F f; |
sl@0 | 41 |
}; |
sl@0 | 42 |
|
sl@0 | 43 |
object BOOST_PYTHON_DECL make_raw_function(objects::py_function); |
sl@0 | 44 |
} |
sl@0 | 45 |
|
sl@0 | 46 |
template <class F> |
sl@0 | 47 |
object raw_function(F f, std::size_t min_args = 0) |
sl@0 | 48 |
{ |
sl@0 | 49 |
return detail::make_raw_function( |
sl@0 | 50 |
objects::py_function( |
sl@0 | 51 |
detail::raw_dispatcher<F>(f) |
sl@0 | 52 |
, mpl::vector1<PyObject*>() |
sl@0 | 53 |
, min_args |
sl@0 | 54 |
, (std::numeric_limits<unsigned>::max)() |
sl@0 | 55 |
) |
sl@0 | 56 |
); |
sl@0 | 57 |
} |
sl@0 | 58 |
|
sl@0 | 59 |
}} // namespace boost::python |
sl@0 | 60 |
|
sl@0 | 61 |
#endif // RAW_FUNCTION_DWA200336_HPP |