sl@0: // Copyright David Abrahams 2002. sl@0: // Distributed under the Boost Software License, Version 1.0. (See sl@0: // accompanying file LICENSE_1_0.txt or copy at sl@0: // http://www.boost.org/LICENSE_1_0.txt) sl@0: #ifndef DEF_DWA200292_HPP sl@0: # define DEF_DWA200292_HPP sl@0: sl@0: # include sl@0: sl@0: # include sl@0: # include sl@0: # include sl@0: # include sl@0: # include sl@0: # include sl@0: # include sl@0: sl@0: namespace boost { namespace python { sl@0: sl@0: namespace detail sl@0: { sl@0: namespace error sl@0: { sl@0: // Compile-time error messages sl@0: template struct multiple_functions_passed_to_def; sl@0: template <> struct multiple_functions_passed_to_def { typedef char type; }; sl@0: } sl@0: sl@0: // sl@0: // def_from_helper -- sl@0: // sl@0: // Use a def_helper to define a regular wrapped function in the current scope. sl@0: template sl@0: void def_from_helper( sl@0: char const* name, F const& fn, Helper const& helper) sl@0: { sl@0: // Must not try to use default implementations except with method definitions. sl@0: typedef typename error::multiple_functions_passed_to_def< sl@0: Helper::has_default_implementation sl@0: >::type assertion; sl@0: sl@0: detail::scope_setattr_doc( sl@0: name, boost::python::make_function( sl@0: fn sl@0: , helper.policies() sl@0: , helper.keywords()) sl@0: , helper.doc() sl@0: ); sl@0: } sl@0: sl@0: // sl@0: // These two overloads discriminate between def() as applied to sl@0: // regular functions and def() as applied to the result of sl@0: // BOOST_PYTHON_FUNCTION_OVERLOADS(). The final argument is used to sl@0: // discriminate. sl@0: // sl@0: template sl@0: void sl@0: def_maybe_overloads( sl@0: char const* name sl@0: , Fn fn sl@0: , A1 const& a1 sl@0: , ...) sl@0: { sl@0: detail::def_from_helper(name, fn, def_helper(a1)); sl@0: } sl@0: sl@0: template sl@0: void def_maybe_overloads( sl@0: char const* name sl@0: , SigT sig sl@0: , StubsT const& stubs sl@0: , detail::overloads_base const*) sl@0: { sl@0: scope current; sl@0: sl@0: detail::define_with_defaults( sl@0: name, stubs, current, detail::get_signature(sig)); sl@0: } sl@0: sl@0: template sl@0: object make_function1(T fn, ...) { return make_function(fn); } sl@0: sl@0: inline sl@0: object make_function1(object const& x, object const*) { return x; } sl@0: } sl@0: sl@0: template sl@0: void def(char const* name, Fn fn) sl@0: { sl@0: detail::scope_setattr_doc(name, detail::make_function1(fn, &fn), 0); sl@0: } sl@0: sl@0: template sl@0: void def(char const* name, Arg1T arg1, Arg2T const& arg2) sl@0: { sl@0: detail::def_maybe_overloads(name, arg1, arg2, &arg2); sl@0: } sl@0: sl@0: template sl@0: void def(char const* name, F f, A1 const& a1, A2 const& a2) sl@0: { sl@0: detail::def_from_helper(name, f, detail::def_helper(a1,a2)); sl@0: } sl@0: sl@0: template sl@0: void def(char const* name, F f, A1 const& a1, A2 const& a2, A3 const& a3) sl@0: { sl@0: detail::def_from_helper(name, f, detail::def_helper(a1,a2,a3)); sl@0: } sl@0: sl@0: }} // namespace boost::python sl@0: sl@0: #endif // DEF_DWA200292_HPP