diff --git a/include/boost/python/class.hpp b/include/boost/python/class.hpp index de66ddcf..76646b41 100644 --- a/include/boost/python/class.hpp +++ b/include/boost/python/class.hpp @@ -209,7 +209,8 @@ class class_ : public objects::class_base self& def(char const* name, Arg1T arg1, Arg2T const& arg2, Arg3T const& arg3) { // The arguments are definitely: - // def(name, function, policy, doc_string) // TODO: exchange policy, doc_string position + // def(name, function, policy, doc_string) + // def(name, function, doc_string, policy) dispatch_def(&arg2, name, arg1, arg2, arg3); return *this; @@ -334,25 +335,9 @@ class class_ : public objects::class_base inline void register_() const; - template - void dispatch_def( - void const*, - char const* name, - Fn fn, - CallPolicyOrDoc const& policy_or_doc, - char const* doc = 0) - { - typedef detail::def_helper helper; - - this->def_impl( - name, fn, helper::get_policy(policy_or_doc), - helper::get_doc(policy_or_doc, doc), &fn); - - } - template void dispatch_def( - detail::func_stubs_base const*, + detail::overloads_base const*, char const* name, SigT sig, StubsT const& stubs) @@ -362,6 +347,35 @@ class class_ : public objects::class_base detail::define_with_defaults( name, stubs, *this, detail::get_signature(sig)); } + + template + void dispatch_def( + void const*, + char const* name, + Fn fn, + CallPolicyOrDoc const& policy_or_doc) + { + typedef detail::def_helper helper; + this->def_impl( + name, fn, helper::get_policy(policy_or_doc), + helper::get_doc(policy_or_doc, 0), &fn); + + } + + template + void dispatch_def( + void const*, + char const* name, + Fn fn, + CallPolicyOrDoc1 const& policy_or_doc1, + CallPolicyOrDoc2 const& policy_or_doc2) + { + typedef detail::def_helper helper; + + this->def_impl( + name, fn, helper::get_policy(policy_or_doc1, policy_or_doc2), + helper::get_doc(policy_or_doc1, policy_or_doc2), &fn); + } }; diff --git a/include/boost/python/def.hpp b/include/boost/python/def.hpp index c581e7f6..117a555f 100644 --- a/include/boost/python/def.hpp +++ b/include/boost/python/def.hpp @@ -19,25 +19,40 @@ namespace detail { void BOOST_PYTHON_DECL scope_setattr_doc(char const* name, object const& obj, char const* doc); - template - void - dispatch_def( - void const*, - char const* name, - Fn fn, - CallPolicyOrDoc const& policy_or_doc, - char const* doc = 0) - { - typedef detail::def_helper helper; + template + void + dispatch_def( + void const*, + char const* name, + Fn fn, + CallPolicyOrDoc const& policy_or_doc) + { + typedef detail::def_helper helper; - detail::scope_setattr_doc( - name, boost::python::make_function(fn, helper::get_policy(policy_or_doc)), - helper::get_doc(policy_or_doc, doc)); - } + detail::scope_setattr_doc( + name, boost::python::make_function(fn, helper::get_policy(policy_or_doc)), + helper::get_doc(policy_or_doc, 0)); + } + + template + void dispatch_def( + void const*, + char const* name, + Fn fn, + CallPolicyOrDoc1 const& policy_or_doc1, + CallPolicyOrDoc2 const& policy_or_doc2) + { + typedef detail::def_helper helper; + + detail::scope_setattr_doc( + name, boost::python::make_function( + fn, helper::get_policy(policy_or_doc1, policy_or_doc2)), + helper::get_doc(policy_or_doc1, policy_or_doc2)); + } template void dispatch_def( - detail::func_stubs_base const*, + detail::overloads_base const*, char const* name, SigT sig, StubsT const& stubs) diff --git a/include/boost/python/detail/def_helper.hpp b/include/boost/python/detail/def_helper.hpp index 1222f71b..d0744b23 100644 --- a/include/boost/python/detail/def_helper.hpp +++ b/include/boost/python/detail/def_helper.hpp @@ -10,7 +10,7 @@ # include # include -namespace boost { namespace python { namespace detail { +namespace boost { namespace python { namespace detail { // // def_helper -- @@ -32,19 +32,35 @@ template struct def_helper_impl { template - static P const& get_policy(P const& x) { return x; } - + static P const& + get_policy(P const& x) { return x; } + + template + static P1 const& + get_policy(P1 const& x, P2 const&) { return x; } // select left + template - static char const* get_doc(P const&, char const* doc) { return doc; } + static char const* + get_doc(P const&, char const* doc) { return doc; } // select right }; template <> struct def_helper_impl { - static python::default_call_policies get_policy(char const*) { return default_call_policies(); } - static char const* get_doc(char const* doc, char const*) { return doc; } + static python::default_call_policies + get_policy(char const*) + { return default_call_policies(); } + + template + static P2 const& + get_policy(P1 const&, P2 const& y) { return y; } // select right + + template + static char const* + get_doc(char const* doc, P const&) // select left + { return doc; } }; - + template struct def_helper : def_helper_impl< diff --git a/include/boost/python/detail/defaults_def.hpp b/include/boost/python/detail/defaults_def.hpp index a8e32c8a..721fc37f 100644 --- a/include/boost/python/detail/defaults_def.hpp +++ b/include/boost/python/detail/defaults_def.hpp @@ -200,13 +200,13 @@ struct define_stub_function {}; SigT sig) { typedef typename mpl::front::type return_type; - typedef typename StubsT::v_type v_type; - typedef typename StubsT::nv_type nv_type; + typedef typename StubsT::void_return_type void_return_type; + typedef typename StubsT::non_void_return_type non_void_return_type; typedef typename mpl::if_c< boost::is_same::value - , v_type - , nv_type + , void_return_type + , non_void_return_type >::type stubs_type; BOOST_STATIC_ASSERT( diff --git a/include/boost/python/detail/defaults_gen.hpp b/include/boost/python/detail/defaults_gen.hpp index 78f341f7..251eb742 100644 --- a/include/boost/python/detail/defaults_gen.hpp +++ b/include/boost/python/detail/defaults_gen.hpp @@ -28,14 +28,14 @@ namespace boost { namespace python { - // func_stubs_base is used as a base class for all function + // overloads_base is used as a base class for all function // stubs. This class holds the doc_string of the stubs. namespace detail { - struct func_stubs_base + struct overloads_base { - func_stubs_base(char const* doc_) + overloads_base(char const* doc_) : doc(doc_) {} char const* doc_string() const @@ -45,18 +45,18 @@ namespace boost { namespace python { }; } -// func_stubs_proxy is generated by the func_stubs_common operator[] (see +// overloads_proxy is generated by the overloads_common operator[] (see // below). This class holds a user defined call policies of the stubs. -template -struct func_stubs_proxy -: public detail::func_stubs_base +template +struct overloads_proxy +: public detail::overloads_base { - typedef typename StubsT::nv_type nv_type; - typedef typename StubsT::v_type v_type; + typedef typename OverloadsT::non_void_return_type non_void_return_type; + typedef typename OverloadsT::void_return_type void_return_type; - func_stubs_proxy(CallPoliciesT const& policies_, char const* doc) - : detail::func_stubs_base(doc), policies(policies_) {} + overloads_proxy(CallPoliciesT const& policies_, char const* doc) + : detail::overloads_base(doc), policies(policies_) {} CallPoliciesT call_policies() const @@ -65,26 +65,26 @@ struct func_stubs_proxy CallPoliciesT policies; }; -// func_stubs_common is our default function stubs base class. This class +// overloads_common is our default function stubs base class. This class // returns the default_call_policies in its call_policies() member function. -// It can generate a func_stubs_proxy however through its operator[] +// It can generate a overloads_proxy however through its operator[] template -struct func_stubs_common -: public detail::func_stubs_base { +struct overloads_common +: public detail::overloads_base { - func_stubs_common(char const* doc) - : detail::func_stubs_base(doc) {} + overloads_common(char const* doc) + : detail::overloads_base(doc) {} default_call_policies call_policies() const { return default_call_policies(); } template - ::boost::python::func_stubs_proxy + ::boost::python::overloads_proxy operator[](CallPoliciesT const& policies) const { - return func_stubs_proxy + return overloads_proxy (policies, doc); } }; @@ -179,7 +179,7 @@ struct func_stubs_common }; /////////////////////////////////////////////////////////////////////////////// -#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) +#if defined(BOOST_NO_VOID_RETURNS) #define BOOST_PYTHON_GEN_FUNCTION_STUB(fname, fstubs_name, n_args, n_dflts) \ BOOST_PYTHON_GEN_FUNCTION \ @@ -187,14 +187,14 @@ struct func_stubs_common BOOST_PYTHON_GEN_FUNCTION \ (fname, BOOST_PP_CAT(fstubs_name, _V), n_args, n_dflts, ;) \ struct fstubs_name \ - : public boost::python::func_stubs_common \ + : public boost::python::overloads_common \ { \ - typedef BOOST_PP_CAT(fstubs_name, _NV) nv_type; \ - typedef BOOST_PP_CAT(fstubs_name, _V) v_type; \ + typedef BOOST_PP_CAT(fstubs_name, _NV) non_void_return_type; \ + typedef BOOST_PP_CAT(fstubs_name, _V) void_return_type; \ \ fstubs_name(char const* doc = 0) \ : boost::python:: \ - func_stubs_common(doc) {} \ + overloads_common(doc) {} \ }; \ /////////////////////////////////////////////////////////////////////////////// @@ -204,14 +204,14 @@ struct func_stubs_common BOOST_PYTHON_GEN_MEM_FUNCTION \ (fname, BOOST_PP_CAT(fstubs_name, _V), n_args, n_dflts, ;) \ struct fstubs_name \ - : public boost::python::func_stubs_common \ + : public boost::python::overloads_common \ { \ - typedef BOOST_PP_CAT(fstubs_name, _NV) nv_type; \ - typedef BOOST_PP_CAT(fstubs_name, _V) v_type; \ + typedef BOOST_PP_CAT(fstubs_name, _NV) non_void_return_type; \ + typedef BOOST_PP_CAT(fstubs_name, _V) void_return_type; \ \ fstubs_name(char const* doc = 0) \ : boost::python:: \ - func_stubs_common(doc) {} \ + overloads_common(doc) {} \ }; \ #else @@ -221,14 +221,14 @@ struct func_stubs_common BOOST_PYTHON_GEN_FUNCTION \ (fname, BOOST_PP_CAT(fstubs_name, _NV), n_args, n_dflts, return) \ struct fstubs_name \ - : public boost::python::func_stubs_common \ + : public boost::python::overloads_common \ { \ - typedef BOOST_PP_CAT(fstubs_name, _NV) nv_type; \ - typedef BOOST_PP_CAT(fstubs_name, _NV) v_type; \ + typedef BOOST_PP_CAT(fstubs_name, _NV) non_void_return_type; \ + typedef BOOST_PP_CAT(fstubs_name, _NV) void_return_type; \ \ fstubs_name(char const* doc = 0) \ : boost::python:: \ - func_stubs_common(doc) {} \ + overloads_common(doc) {} \ }; \ /////////////////////////////////////////////////////////////////////////////// @@ -236,14 +236,14 @@ struct func_stubs_common BOOST_PYTHON_GEN_MEM_FUNCTION \ (fname, BOOST_PP_CAT(fstubs_name, _NV), n_args, n_dflts, return) \ struct fstubs_name \ - : public boost::python::func_stubs_common \ + : public boost::python::overloads_common \ { \ - typedef BOOST_PP_CAT(fstubs_name, _NV) nv_type; \ - typedef BOOST_PP_CAT(fstubs_name, _NV) v_type; \ + typedef BOOST_PP_CAT(fstubs_name, _NV) non_void_return_type; \ + typedef BOOST_PP_CAT(fstubs_name, _NV) void_return_type; \ \ fstubs_name(char const* doc = 0) \ : boost::python:: \ - func_stubs_common(doc) {} \ + overloads_common(doc) {} \ }; \ #endif // defined(BOOST_MSVC) @@ -312,24 +312,24 @@ struct func_stubs_common // }; // // struct foo_stubs -// : public boost::python::func_stubs_common +// : public boost::python::overloads_common // -// typedef foo_stubs_NV nv_type; -// typedef foo_stubs_NV v_type; +// typedef foo_stubs_NV non_void_return_type; +// typedef foo_stubs_NV void_return_type; // // fstubs_name(char const* doc = 0) // : boost::python:: -// func_stubs_common(doc) {} +// overloads_common(doc) {} // }; // -// The typedefs nv_type and v_type are used to handle compilers that -// do not support void returns. The example above typedefs nv_type -// and v_type to foo_stubs_NV. On compilers that do not support +// The typedefs non_void_return_type and void_return_type are used to handle compilers that +// do not support void returns. The example above typedefs non_void_return_type +// and void_return_type to foo_stubs_NV. On compilers that do not support // void returns, there are two versions: foo_stubs_NV and foo_stubs_V. // The "V" version is almost identical to the "NV" version except // for the return type (void) and the lack of the return keyword. // -// See the func_stubs_common above for a description of the foo_stubs' +// See the overloads_common above for a description of the foo_stubs' // base class. // /////////////////////////////////////////////////////////////////////////////// diff --git a/include/boost/python/module.hpp b/include/boost/python/module.hpp index 9f5f4d21..2bf923c0 100644 --- a/include/boost/python/module.hpp +++ b/include/boost/python/module.hpp @@ -85,7 +85,7 @@ class module : public detail::module_base SigT sig, StubsT const& stubs, char const* doc, - detail::func_stubs_base const*) + detail::overloads_base const*) { // convert sig to a type_list (see detail::get_signature in signature.hpp) // before calling detail::define_with_defaults.