From 70e7f111e8bde31a479f9d23e73fbe9e09ae809a Mon Sep 17 00:00:00 2001 From: Joel de Guzman Date: Mon, 16 Sep 2002 00:25:27 +0000 Subject: [PATCH] Replaced mpl::at with mpl iterators and changed some PP_ADD to PP_INC in the process. [SVN r15350] --- include/boost/python/class.hpp | 89 ++------------------ include/boost/python/def.hpp | 2 +- include/boost/python/detail/defaults_gen.hpp | 41 +++++---- include/boost/python/init.hpp | 4 +- 4 files changed, 35 insertions(+), 101 deletions(-) diff --git a/include/boost/python/class.hpp b/include/boost/python/class.hpp index 196126e9..9c4d01c2 100644 --- a/include/boost/python/class.hpp +++ b/include/boost/python/class.hpp @@ -157,45 +157,24 @@ class class_ : public objects::class_base // Construct with class name, docstring, and no init() function class_(char const* name, char const* doc, no_init_t); -// template -// inline class_(char const* name, detail::args_base const&) -// : base(name, id_vector::size, id_vector().ids) -// { -// this->register_(); -// this->def_init(InitArgs()); -// this->set_instance_size(holder_selector::additional_size()); -// } -// -// -// template -// inline class_(char const* name, char const* doc, detail::args_base const&, char const* initdoc = 0) -// : base(name, id_vector::size, id_vector().ids, doc) -// { -// this->register_(); -// this->def_init(InitArgs(), initdoc); -// this->set_instance_size(holder_selector::additional_size()); -// } - - template - inline class_(char const* name, init_base const& init) + inline class_(char const* name, init_base const& i) : base(name, id_vector::size, id_vector().ids) { this->register_(); - define_init(*this, init.derived()); + define_init(*this, i.derived()); this->set_instance_size(holder_selector::additional_size()); } template - inline class_(char const* name, char const* doc, init_base const& init) + inline class_(char const* name, char const* doc, init_base const& i) : base(name, id_vector::size, id_vector().ids, doc) { this->register_(); - define_init(*this, init.derived()); + define_init(*this, i.derived()); this->set_instance_size(holder_selector::additional_size()); } - // Wrap a member function or a non-member function which can take // a T, T cv&, or T cv* as its first parameter, or a callable // python object. @@ -206,35 +185,13 @@ class class_ : public objects::class_base return *this; } -// template -// self& def(init const& i) -// { -// define_init(*this, i, default_call_policies()); -// return *this; -// } - template - self& def(init_base const& init) + self& def(init_base const& i) { - define_init(*this, init.derived()); + define_init(*this, i.derived()); return *this; } - - -// template -// self& def( -// init const& i, -// CallPolicyOrDoc const& policy_or_doc, -// char const* doc = 0) -// { -// typedef detail::def_helper helper; -// define_init(*this, i, -// helper::get_policy(policy_or_doc), -// helper::get_doc(policy_or_doc, doc)); -// return *this; -// } - template self& def(char const* name, Arg1T arg1, Arg2T const& arg2) { @@ -252,24 +209,12 @@ 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, doc_string, policy) + // def(name, function, policy, doc_string) // TODO: exchange policy, doc_string position dispatch_def(&arg2, name, arg1, arg2, arg3); return *this; } -// template -// self& def(char const* name, Arg1T arg1, Arg2T const& arg2, Arg3T const& arg3, char const* doc) -// { -// // The arguments are definitely: -// // arg1: signature -// // arg2: stubs -// // arg3: policy -// -// dispatch_def(&arg2, name, arg1, arg2, arg3, doc); -// return *this; -// } - template self& def(detail::operator_ const& op) { @@ -435,26 +380,6 @@ inline void class_::register_() const ); } - - -//template -//inline class_::class_() -// : base(typeid(T).name(), id_vector::size, id_vector().ids) -//{ -// this->register_(); -// detail::force_instantiate(sizeof(detail::assert_default_constructible(T()))); -// this->def_init(); -// this->set_instance_size(holder_selector::additional_size()); -//} - -//template -//inline class_::class_(no_init_t) -// : base(typeid(T).name(), id_vector::size, id_vector().ids) -//{ -// this->register_(); -// this->def_no_init(); -//} - template inline class_::class_(char const* name, char const* doc) : base(name, id_vector::size, id_vector().ids, doc) diff --git a/include/boost/python/def.hpp b/include/boost/python/def.hpp index a79617b2..c581e7f6 100644 --- a/include/boost/python/def.hpp +++ b/include/boost/python/def.hpp @@ -73,7 +73,7 @@ template void def(char const* name, Arg1T arg1, Arg2T const& arg2, Arg3T const& arg3) { // The arguments are definitely: - // def(name, function, doc_string, policy) + // def(name, function, policy, doc_string) // TODO: exchange policy, doc_string position detail::dispatch_def(&arg2, name, arg1, arg2, arg3); } diff --git a/include/boost/python/detail/defaults_gen.hpp b/include/boost/python/detail/defaults_gen.hpp index 1e0a405a..b781fbf3 100644 --- a/include/boost/python/detail/defaults_gen.hpp +++ b/include/boost/python/detail/defaults_gen.hpp @@ -61,13 +61,11 @@ struct func_stubs_with_call_policies }} // namespace boost::python - - /////////////////////////////////////////////////////////////////////////////// #define BOOST_PYTHON_TYPEDEF_GEN(z, index, data) \ - typedef typename ::boost::mpl::at_c< \ - BOOST_PP_ADD_D(1, index, data), \ - SigT>::type BOOST_PP_CAT(T, index); \ + typedef typename BOOST_PP_CAT(iter, index)::next \ + BOOST_PP_CAT(iter, BOOST_PP_INC(index)); \ + typedef typename BOOST_PP_CAT(iter, index)::type BOOST_PP_CAT(T, index); \ #define BOOST_PYTHON_FUNC_WRAPPER_GEN(z, index, data) \ static RT BOOST_PP_CAT(func_, index) ( \ @@ -90,12 +88,14 @@ struct func_stubs_with_call_policies template \ struct gen { \ \ - typedef typename ::boost::mpl::front::type RT; \ + typedef typename ::boost::mpl::begin::type rt_iter; \ + typedef typename rt_iter::type RT; \ + typedef typename rt_iter::next iter0; \ \ BOOST_PP_REPEAT_2ND( \ n_args, \ BOOST_PYTHON_TYPEDEF_GEN, \ - 1) \ + 0) \ \ BOOST_PP_REPEAT_2ND( \ BOOST_PP_INC(n_dflts), \ @@ -128,13 +128,17 @@ struct func_stubs_with_call_policies template \ struct gen { \ \ - typedef typename ::boost::mpl::front::type RT; \ - typedef typename ::boost::mpl::at_c<1, SigT>::type ClassT; \ + typedef typename ::boost::mpl::begin::type rt_iter; \ + typedef typename rt_iter::type RT; \ + \ + typedef typename rt_iter::next class_iter; \ + typedef typename class_iter::type ClassT; \ + typedef typename class_iter::next iter0; \ \ BOOST_PP_REPEAT_2ND( \ n_args, \ BOOST_PYTHON_TYPEDEF_GEN, \ - 2) \ + 0) \ \ BOOST_PP_REPEAT_2ND( \ BOOST_PP_INC(n_dflts), \ @@ -143,7 +147,6 @@ struct func_stubs_with_call_policies }; \ }; - /////////////////////////////////////////////////////////////////////////////// #if defined(BOOST_MSVC) @@ -319,11 +322,17 @@ struct func_stubs_with_call_policies // template // struct gen { // -// typedef typename ::boost::mpl::at_c<0, SigT>::type RT; -// typedef typename ::boost::mpl::at_c<1, SigT>::type T0; -// typedef typename ::boost::mpl::at_c<2, SigT>::type T1; -// typedef typename ::boost::mpl::at_c<3, SigT>::type T2; -// typedef typename ::boost::mpl::at_c<4, SigT>::type T3; +// typedef typename ::boost::mpl::begin::type rt_iter; +// typedef typename rt_iter::type RT; +// typedef typename rt_iter::next iter0; +// typedef typename iter0::type T0; +// typedef typename iter0::next iter1; +// typedef typename iter1::type T1; +// typedef typename iter1::next iter2; +// typedef typename iter2::type T2; +// typedef typename iter2::next iter3; +// typedef typename iter3::type T3; +// typedef typename iter3::next iter4; // // static RT func_0(T0 arg0) // { return foo(arg0); } diff --git a/include/boost/python/init.hpp b/include/boost/python/init.hpp index cce71ef8..824b72f0 100644 --- a/include/boost/python/init.hpp +++ b/include/boost/python/init.hpp @@ -341,11 +341,11 @@ namespace detail /////////////////////////////////////////////////////////////////////////////// template void -define_init(ClassT& cl, InitT const& init) +define_init(ClassT& cl, InitT const& i) { typedef typename InitT::reversed_args reversed_args; detail::define_class_init_helper::apply( - cl, init.call_policies(), reversed_args(), init.doc_string()); + cl, i.call_policies(), reversed_args(), i.doc_string()); } }} // namespace boost::python