From 9230705eeacdb94bea3907bec4ad85ee28a03fad Mon Sep 17 00:00:00 2001 From: Joel de Guzman Date: Tue, 17 Sep 2002 06:09:23 +0000 Subject: [PATCH] factored out redundant code into base class [SVN r15399] --- include/boost/python/detail/defaults_gen.hpp | 177 ++++++++----------- 1 file changed, 75 insertions(+), 102 deletions(-) diff --git a/include/boost/python/detail/defaults_gen.hpp b/include/boost/python/detail/defaults_gen.hpp index 65335e26..01c22904 100644 --- a/include/boost/python/detail/defaults_gen.hpp +++ b/include/boost/python/detail/defaults_gen.hpp @@ -28,16 +28,28 @@ namespace boost { namespace python { -/////////////////////////////////////////////////////////////////////////////// -// -// func_stubs_base is used as a base class for all function stubs. -// -/////////////////////////////////////////////////////////////////////////////// + // func_stubs_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 func_stubs_base + { + func_stubs_base(char const* doc_) + : doc(doc_) {} + + char const* doc_string() const + { return doc; } + + char const* doc; + }; } +// func_stubs_with_call_policies is generated by the +// func_stubs_with_default_call_policies operator[] +// (see below). This class holds a user defined call policies +// of the stubs. + template struct func_stubs_with_call_policies : public detail::func_stubs_base @@ -45,18 +57,40 @@ struct func_stubs_with_call_policies typedef typename StubsT::nv_type nv_type; typedef typename StubsT::v_type v_type; - func_stubs_with_call_policies(CallPoliciesT const& policies_, char const* doc_) - : policies(policies_), doc(doc_) {} - - char const* doc_string() const - { return doc; } + func_stubs_with_call_policies(CallPoliciesT const& policies_, char const* doc) + : detail::func_stubs_base(doc), policies(policies_) {} CallPoliciesT call_policies() const { return policies; } CallPoliciesT policies; - char const* doc; +}; + +// func_stubs_with_default_call_policies 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_with_call_policies however +// through its operator[] + +template +struct func_stubs_with_default_call_policies +: public detail::func_stubs_base { + + func_stubs_with_default_call_policies(char const* doc) + : detail::func_stubs_base(doc) {} + + default_call_policies + call_policies() const + { return default_call_policies(); } + + template + ::boost::python::func_stubs_with_call_policies + operator[](CallPoliciesT const& policies) const + { + return func_stubs_with_call_policies + (policies, doc); + } }; }} // namespace boost::python @@ -149,7 +183,7 @@ struct func_stubs_with_call_policies }; /////////////////////////////////////////////////////////////////////////////// -#if defined(BOOST_MSVC) +#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) #define BOOST_PYTHON_GEN_FUNCTION_STUB(fname, fstubs_name, n_args, n_dflts) \ BOOST_PYTHON_GEN_FUNCTION \ @@ -157,31 +191,14 @@ struct func_stubs_with_call_policies BOOST_PYTHON_GEN_FUNCTION \ (fname, BOOST_PP_CAT(fstubs_name, _V), n_args, n_dflts, ;) \ struct fstubs_name \ - : public boost::python::detail::func_stubs_base { \ - \ + : public boost::python::func_stubs_with_default_call_policies \ + { \ typedef BOOST_PP_CAT(fstubs_name, _NV) nv_type; \ typedef BOOST_PP_CAT(fstubs_name, _V) v_type; \ - typedef fstubs_name self_t; \ \ - fstubs_name(char const* doc_ = 0) \ - : doc(doc_) {} \ - \ - char const* doc_string() const \ - { return doc; } \ - \ - ::boost::python::default_call_policies \ - call_policies() const \ - { return ::boost::python::default_call_policies(); } \ - \ - template \ - ::boost::python::func_stubs_with_call_policies \ - operator[](CallPoliciesT const& policies) const \ - { \ - return ::boost::python::func_stubs_with_call_policies \ - (policies, doc); \ - } \ - \ - char const* doc; \ + fstubs_name(char const* doc = 0) \ + : boost::python:: \ + func_stubs_with_default_call_policies(doc) {} \ }; \ /////////////////////////////////////////////////////////////////////////////// @@ -191,31 +208,14 @@ struct func_stubs_with_call_policies BOOST_PYTHON_GEN_MEM_FUNCTION \ (fname, BOOST_PP_CAT(fstubs_name, _V), n_args, n_dflts, ;) \ struct fstubs_name \ - : public boost::python::detail::func_stubs_base { \ - \ + : public boost::python::func_stubs_with_default_call_policies \ + { \ typedef BOOST_PP_CAT(fstubs_name, _NV) nv_type; \ typedef BOOST_PP_CAT(fstubs_name, _V) v_type; \ - typedef fstubs_name self_t; \ \ - fstubs_name(char const* doc_ = 0) \ - : doc(doc_) {} \ - \ - char const* doc_string() const \ - { return doc; } \ - \ - ::boost::python::default_call_policies \ - call_policies() const \ - { return ::boost::python::default_call_policies(); } \ - \ - template \ - ::boost::python::func_stubs_with_call_policies \ - operator[](CallPoliciesT const& policies) const \ - { \ - return ::boost::python::func_stubs_with_call_policies \ - (policies, doc); \ - } \ - \ - char const* doc; \ + fstubs_name(char const* doc = 0) \ + : boost::python:: \ + func_stubs_with_default_call_policies(doc) {} \ }; \ #else @@ -225,31 +225,14 @@ struct func_stubs_with_call_policies BOOST_PYTHON_GEN_FUNCTION \ (fname, BOOST_PP_CAT(fstubs_name, _NV), n_args, n_dflts, return) \ struct fstubs_name \ - : public boost::python::detail::func_stubs_base { \ - \ + : public boost::python::func_stubs_with_default_call_policies \ + { \ typedef BOOST_PP_CAT(fstubs_name, _NV) nv_type; \ typedef BOOST_PP_CAT(fstubs_name, _NV) v_type; \ - typedef fstubs_name self_t; \ \ - fstubs_name(char const* doc_ = 0) \ - : doc(doc_) {} \ - \ - char const* doc_string() const \ - { return doc; } \ - \ - ::boost::python::default_call_policies \ - call_policies() const \ - { return ::boost::python::default_call_policies(); } \ - \ - template \ - ::boost::python::func_stubs_with_call_policies \ - operator[](CallPoliciesT const& policies) const \ - { \ - return ::boost::python::func_stubs_with_call_policies \ - (policies, doc); \ - } \ - \ - char const* doc; \ + fstubs_name(char const* doc = 0) \ + : boost::python:: \ + func_stubs_with_default_call_policies(doc) {} \ }; \ /////////////////////////////////////////////////////////////////////////////// @@ -257,31 +240,14 @@ struct func_stubs_with_call_policies BOOST_PYTHON_GEN_MEM_FUNCTION \ (fname, BOOST_PP_CAT(fstubs_name, _NV), n_args, n_dflts, return) \ struct fstubs_name \ - : public boost::python::detail::func_stubs_base { \ - \ + : public boost::python::func_stubs_with_default_call_policies \ + { \ typedef BOOST_PP_CAT(fstubs_name, _NV) nv_type; \ typedef BOOST_PP_CAT(fstubs_name, _NV) v_type; \ - typedef fstubs_name self_t; \ \ - fstubs_name(char const* doc_ = 0) \ - : doc(doc_) {} \ - \ - char const* doc_string() const \ - { return doc; } \ - \ - ::boost::python::default_call_policies \ - call_policies() const \ - { return ::boost::python::default_call_policies(); } \ - \ - template \ - ::boost::python::func_stubs_with_call_policies \ - operator[](CallPoliciesT const& policies) const \ - { \ - return ::boost::python::func_stubs_with_call_policies \ - (policies, doc); \ - } \ - \ - char const* doc; \ + fstubs_name(char const* doc = 0) \ + : boost::python:: \ + func_stubs_with_default_call_policies(doc) {} \ }; \ #endif // defined(BOOST_MSVC) @@ -350,10 +316,14 @@ struct func_stubs_with_call_policies // }; // // struct foo_stubs -// : public boost::python::detail::func_stubs_base { +// : public boost::python::func_stubs_with_default_call_policies // // typedef foo_stubs_NV nv_type; // typedef foo_stubs_NV v_type; +// +// fstubs_name(char const* doc = 0) +// : boost::python:: +// func_stubs_with_default_call_policies(doc) {} // }; // // The typedefs nv_type and v_type are used to handle compilers that @@ -363,6 +333,9 @@ struct func_stubs_with_call_policies // 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_with_default_call_policies above for a description +// of the foo_stubs' base class. +// /////////////////////////////////////////////////////////////////////////////// #define BOOST_PYTHON_FUNCTION_OVERLOADS(generator_name, fname, min_args, max_args) \ BOOST_PYTHON_GEN_FUNCTION_STUB( \