From edb5b4547ee024a3c9343f3bb805b05fddc298c2 Mon Sep 17 00:00:00 2001 From: Daniel Wallin Date: Fri, 7 Jul 2006 17:39:20 +0000 Subject: [PATCH] Added support for CallPolicies. [SVN r34475] --- include/boost/parameter/python.hpp | 96 +++++++++++++++++++++++------- 1 file changed, 73 insertions(+), 23 deletions(-) diff --git a/include/boost/parameter/python.hpp b/include/boost/parameter/python.hpp index 93d335c..5fc9fbf 100755 --- a/include/boost/parameter/python.hpp +++ b/include/boost/parameter/python.hpp @@ -323,7 +323,29 @@ namespace aux Def, Specs*, End, End, Invoker*) {} - template + struct not_specified {}; + + template + struct call_policies_as_options + { + call_policies_as_options(CallPolicies const& call_policies) + : call_policies(call_policies) + {} + + CallPolicies const& policies() const + { + return call_policies; + } + + char const* doc() const + { + return 0; + } + + CallPolicies call_policies; + }; + + template struct def_class { def_class(Class& cl, char const* name, Options options = Options()) @@ -351,7 +373,7 @@ namespace aux } template - void def(F f, Keywords const& keywords, int const*) const + void def(F f, Keywords const& keywords, not_specified const*) const { cl.def(name, f, keywords); } @@ -373,11 +395,12 @@ namespace aux Options options; }; - template + template struct def_init { - def_init(Class& cl) + def_init(Class& cl, CallPolicies call_policies = CallPolicies()) : cl(cl) + , call_policies(call_policies) {} template @@ -385,7 +408,7 @@ namespace aux { cl.def( "__init__" - , boost::python::make_constructor(f) + , boost::python::make_constructor(f, call_policies) ); } @@ -394,13 +417,12 @@ namespace aux { cl.def( "__init__" - , boost::python::make_constructor( - f, boost::python::default_call_policies(), keywords - ) + , boost::python::make_constructor(f, call_policies, keywords) ); } Class& cl; + CallPolicies call_policies; }; struct def_function @@ -555,15 +577,26 @@ namespace aux } // namespace aux -template +template struct init - : boost::python::def_visitor > + : boost::python::def_visitor > { + init(CallPolicies call_policies = CallPolicies()) + : call_policies(call_policies) + {} + + template + init + operator[](CallPolicies1 const& call_policies) const + { + return init(call_policies); + } + template void visit(Class& cl) const { typedef typename mpl::transform< - Signature + ParameterSpecs , aux::make_kw_spec , mpl::back_inserter > >::type arg_specs; @@ -576,30 +609,43 @@ struct init typedef typename mpl::shift_left, optional_arity>::type upper; aux::def_combinations( - aux::def_init(cl) + aux::def_init(cl, call_policies) , (arg_specs*)0 , mpl::long_<0>() , mpl::long_() , (aux::make_init_invoker*)0 ); } + + CallPolicies call_policies; }; -template +template struct call - : boost::python::def_visitor > + : boost::python::def_visitor > { + call(CallPolicies const& call_policies = CallPolicies()) + : call_policies(call_policies) + {} + + template + call + operator[](CallPolicies1 const& call_policies) const + { + return call(call_policies); + } + template void visit(Class& cl) const { typedef mpl::iterator_range< typename mpl::next< - typename mpl::begin::type + typename mpl::begin::type >::type - , typename mpl::end::type + , typename mpl::end::type > arg_types; - typedef typename mpl::front::type result_type; + typedef typename mpl::front::type result_type; typedef typename mpl::transform< arg_types @@ -614,31 +660,35 @@ struct call typedef typename mpl::shift_left, optional_arity>::type upper; + typedef aux::call_policies_as_options options; + aux::def_combinations( - aux::def_class(cl, "__call__") + aux::def_class(cl, "__call__", options(call_policies)) , (arg_specs*)0 , mpl::long_<0>() , mpl::long_() , (aux::make_call_invoker*)0 ); } + + CallPolicies call_policies; }; -template +template struct function - : boost::python::def_visitor > + : boost::python::def_visitor > { template void visit(Class& cl, char const* name, Options const& options) const { typedef mpl::iterator_range< typename mpl::next< - typename mpl::begin::type + typename mpl::begin::type >::type - , typename mpl::end::type + , typename mpl::end::type > arg_types; - typedef typename mpl::front::type result_type; + typedef typename mpl::front::type result_type; typedef typename mpl::transform< arg_types