Update contrib.
1 // Copyright David Abrahams 2002.
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 DEF_DWA200292_HPP
6 # define DEF_DWA200292_HPP
8 # include <boost/python/detail/prefix.hpp>
10 # include <boost/python/object_fwd.hpp>
11 # include <boost/python/make_function.hpp>
12 # include <boost/python/detail/def_helper.hpp>
13 # include <boost/python/detail/overloads_fwd.hpp>
14 # include <boost/python/scope.hpp>
15 # include <boost/python/signature.hpp>
16 # include <boost/python/detail/scope.hpp>
18 namespace boost { namespace python {
24 // Compile-time error messages
25 template <bool> struct multiple_functions_passed_to_def;
26 template <> struct multiple_functions_passed_to_def<false> { typedef char type; };
32 // Use a def_helper to define a regular wrapped function in the current scope.
33 template <class F, class Helper>
35 char const* name, F const& fn, Helper const& helper)
37 // Must not try to use default implementations except with method definitions.
38 typedef typename error::multiple_functions_passed_to_def<
39 Helper::has_default_implementation
42 detail::scope_setattr_doc(
43 name, boost::python::make_function(
52 // These two overloads discriminate between def() as applied to
53 // regular functions and def() as applied to the result of
54 // BOOST_PYTHON_FUNCTION_OVERLOADS(). The final argument is used to
57 template <class Fn, class A1>
65 detail::def_from_helper(name, fn, def_helper<A1>(a1));
68 template <class StubsT, class SigT>
69 void def_maybe_overloads(
73 , detail::overloads_base const*)
77 detail::define_with_defaults(
78 name, stubs, current, detail::get_signature(sig));
82 object make_function1(T fn, ...) { return make_function(fn); }
85 object make_function1(object const& x, object const*) { return x; }
89 void def(char const* name, Fn fn)
91 detail::scope_setattr_doc(name, detail::make_function1(fn, &fn), 0);
94 template <class Arg1T, class Arg2T>
95 void def(char const* name, Arg1T arg1, Arg2T const& arg2)
97 detail::def_maybe_overloads(name, arg1, arg2, &arg2);
100 template <class F, class A1, class A2>
101 void def(char const* name, F f, A1 const& a1, A2 const& a2)
103 detail::def_from_helper(name, f, detail::def_helper<A1,A2>(a1,a2));
106 template <class F, class A1, class A2, class A3>
107 void def(char const* name, F f, A1 const& a1, A2 const& a2, A3 const& a3)
109 detail::def_from_helper(name, f, detail::def_helper<A1,A2,A3>(a1,a2,a3));
112 }} // namespace boost::python
114 #endif // DEF_DWA200292_HPP