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

source code of boost/boost/python/raw_function.hpp