diff --git a/include/boost/python/class.hpp b/include/boost/python/class.hpp index cf918ed6..572d275e 100644 --- a/include/boost/python/class.hpp +++ b/include/boost/python/class.hpp @@ -29,6 +29,7 @@ # include # include # include +# include namespace boost { namespace python { @@ -130,6 +131,16 @@ class class_ : public objects::class_base return this->def(op.name(), &op_t::template apply::execute); } + + template + self& def(detail::func_stubs_base const& stubs, signature sig) + { + // JDG 8-12-2002 + detail::define_with_defaults(stubs.derived(), *this, detail::get_signature(sig)); + return *this; + } + +/* template self& def(detail::func_stubs_base const& stubs, ArgsT args) { @@ -137,6 +148,7 @@ class class_ : public objects::class_base detail::define_with_defaults(stubs.derived(), *this, args); return *this; } +*/ // Define the constructor with the given Args, which should be an // MPL sequence of types. diff --git a/include/boost/python/detail/defaults_def.hpp b/include/boost/python/detail/defaults_def.hpp index 6563bed0..fd0691c3 100644 --- a/include/boost/python/detail/defaults_def.hpp +++ b/include/boost/python/detail/defaults_def.hpp @@ -15,8 +15,6 @@ #include #include #include -#include -#include /////////////////////////////////////////////////////////////////////////////// namespace boost { namespace python { @@ -67,22 +65,22 @@ BOOST_PP_REPEAT(BOOST_PYTHON_MAX_ARITY, BPL_IMPL_STUB_FUNC_DEF, BOOST_PP_EMPTY) }; /////////////////////////////////////////////////////////////////////////////// - template + template inline void - define_with_defaults(StubsT, HolderT& holder, ArgsT args) + define_with_defaults(StubsT, HolderT& holder, SigT sig) { typedef typename mpl::select_type < - boost::is_same::type>::value, + boost::is_same::type>::value, typename StubsT::v_type, typename StubsT::nv_type > ::type stubs_type; BOOST_STATIC_ASSERT( - (stubs_type::max_args + 1) == boost::mpl::size::value); + (stubs_type::max_args + 1) == boost::mpl::size::value); - typedef stubs_type::template gen gen_type; + typedef stubs_type::template gen gen_type; define_with_defaults_helper::def (stubs_type::name(), gen_type(), holder); } diff --git a/include/boost/python/detail/defaults_gen.hpp b/include/boost/python/detail/defaults_gen.hpp index eee45d59..aeb8bd2c 100644 --- a/include/boost/python/detail/defaults_gen.hpp +++ b/include/boost/python/detail/defaults_gen.hpp @@ -10,7 +10,6 @@ #ifndef DEFAULTS_GEN_JDG20020807_HPP #define DEFAULTS_GEN_JDG20020807_HPP -#include #include #include #include @@ -22,8 +21,6 @@ #include #include #include -#include -#include /////////////////////////////////////////////////////////////////////////////// namespace boost { namespace python { namespace detail { @@ -45,18 +42,18 @@ struct func_stubs_base { /////////////////////////////////////////////////////////////////////////////// // Temporary BOOST_PP fix before the CVS stabalizes /*$$$ FIX ME $$$*/ +#ifndef BOOST_PP_FIX_REPEAT_2ND #define BOOST_PP_FIX_REPEAT_2ND(c, m, d) /* ... */ \ BOOST_PP_CAT(BOOST_PP_R2_, c)(m, d) \ /**/ +#endif /////////////////////////////////////////////////////////////////////////////// -#define BPL_IMPL_TEMPLATE_GEN(INDEX, DATA) typename BOOST_PP_CAT(T, INDEX) - #define BPL_IMPL_TYPEDEF_GEN(INDEX, DATA) \ typedef typename boost::mpl::at \ < \ BOOST_PP_ADD(INDEX, DATA), \ - ArgsT \ + SigT \ >::type BOOST_PP_CAT(T, INDEX); \ #define BPL_IMPL_ARGS_GEN(INDEX, DATA) \ @@ -93,10 +90,10 @@ struct func_stubs_base { static char const* \ name() { return BOOST_PP_STRINGIZE(FNAME); } \ \ - template \ + template \ struct gen { \ \ - typedef typename boost::mpl::at<0, ArgsT>::type RT; \ + typedef typename boost::mpl::at<0, SigT>::type RT; \ \ BOOST_PP_FIX_REPEAT_2ND \ ( \ @@ -118,7 +115,7 @@ struct func_stubs_base { #define BPL_IMPL_MEM_FUNC_WRAPPER_GEN(INDEX, DATA) \ static RT BOOST_PP_CAT(func_, INDEX) \ ( \ - ClassT obj, \ + ClassT& obj, \ BOOST_PP_ENUM \ ( \ BOOST_PP_ADD(BOOST_PP_TUPLE_ELEM(3, 1, DATA), INDEX), \ @@ -147,11 +144,11 @@ struct func_stubs_base { static char const* \ name() { return BOOST_PP_STRINGIZE(FNAME); } \ \ - template \ + template \ struct gen { \ \ - typedef typename boost::mpl::at<0, ArgsT>::type RT; \ - typedef typename boost::mpl::at<1, ArgsT>::type ClassT; \ + typedef typename boost::mpl::at<0, SigT>::type RT; \ + typedef typename boost::mpl::at<1, SigT>::type ClassT; \ \ BOOST_PP_FIX_REPEAT_2ND \ ( \ diff --git a/include/boost/python/module.hpp b/include/boost/python/module.hpp index 1277c576..d5e47477 100644 --- a/include/boost/python/module.hpp +++ b/include/boost/python/module.hpp @@ -15,6 +15,7 @@ # include # include # include +# include namespace boost { namespace python { @@ -70,6 +71,15 @@ class module : public detail::module_base return *this; } + template + module& def(detail::func_stubs_base const& stubs, signature sig) + { + // JDG 8-12-2002 + detail::define_with_defaults(stubs.derived(), *this, detail::get_signature(sig)); + return *this; + } + +/* template module& def(detail::func_stubs_base const& stubs, ArgsT args) { @@ -77,6 +87,7 @@ class module : public detail::module_base detail::define_with_defaults(stubs.derived(), *this, args); return *this; } +*/ }; // diff --git a/include/boost/python/signature.hpp b/include/boost/python/signature.hpp new file mode 100644 index 00000000..a885224b --- /dev/null +++ b/include/boost/python/signature.hpp @@ -0,0 +1,112 @@ +/////////////////////////////////////////////////////////////////////////////// +// +// Copyright David Abrahams 2002. Permission to copy, use, +// modify, sell and distribute this software is granted provided this +// copyright notice appears in all copies. This software is provided +// "as is" without express or implied warranty, and with no claim as +// to its suitability for any purpose. +// +/////////////////////////////////////////////////////////////////////////////// +#ifndef SIGNATURE_JDG20020813_HPP +#define SIGNATURE_JDG20020813_HPP + +#include +#include +#include +#include +#include +#include + +/////////////////////////////////////////////////////////////////////////////// +namespace boost { namespace python { + +template +struct signature {}; + +namespace detail { + +/////////////////////////////////////////////////////////////////////////////// +// Temporary BOOST_PP fix before the CVS stabalizes /*$$$ FIX ME $$$*/ + +#ifndef BOOST_PP_FIX_REPEAT_2ND +#define BOOST_PP_FIX_REPEAT_2ND(c, m, d) /* ... */ \ + BOOST_PP_CAT(BOOST_PP_R2_, c)(m, d) \ + /**/ +#endif + +/////////////////////////////////////////////////////////////////////////////// +#define BPL_IMPL_TEMPLATE_GEN(INDEX, DATA) typename BOOST_PP_CAT(T, INDEX) + +/////////////////////////////////////////////////////////////////////////////// +#define BPL_IMPL_GET_FUNCTION_SIGNATURE(INDEX, DATA) \ + \ + template \ + < \ + typename RT BOOST_PP_COMMA_IF(INDEX) \ + BOOST_PP_ENUM \ + ( \ + INDEX, \ + BPL_IMPL_TEMPLATE_GEN, \ + BOOST_PP_EMPTY \ + ) \ + > \ + inline boost::mpl::type_list \ + < \ + RT BOOST_PP_COMMA_IF(INDEX) BOOST_PP_ENUM_PARAMS(INDEX, T) \ + > \ + get_signature(signature) \ + { \ + return boost::mpl::type_list \ + (); \ + } \ + +/////////////////////////////////////////////////////////////////////////////// +#define BPL_IMPL_GET_MEMBER_FUNCTION_SIGNATURE(INDEX, DATA) \ + \ + template \ + < \ + typename RT, typename ClassT BOOST_PP_COMMA_IF(INDEX) \ + BOOST_PP_ENUM \ + ( \ + INDEX, \ + BPL_IMPL_TEMPLATE_GEN, \ + BOOST_PP_EMPTY \ + ) \ + > \ + inline boost::mpl::type_list \ + < \ + RT, ClassT BOOST_PP_COMMA_IF(INDEX) BOOST_PP_ENUM_PARAMS(INDEX, T) \ + > \ + get_signature(signature) \ + { \ + return boost::mpl::type_list \ + \ + (); \ + } \ + +/////////////////////////////////////////////////////////////////////////////// + +BOOST_PP_FIX_REPEAT_2ND \ +( \ + BOOST_PP_SUB(BOOST_PYTHON_MAX_ARITY, 1), \ + BPL_IMPL_GET_FUNCTION_SIGNATURE, BOOST_PP_EMPTY \ +) + +BOOST_PP_FIX_REPEAT_2ND \ +( \ + BOOST_PP_SUB(BOOST_PYTHON_MAX_ARITY, 2), \ + BPL_IMPL_GET_MEMBER_FUNCTION_SIGNATURE, BOOST_PP_EMPTY \ +) + +#undef BPL_IMPL_GET_FUNCTION_SIGNATURE +#undef BPL_IMPL_GET_MEMBER_FUNCTION_SIGNATURE +#undef BPL_IMPL_TEMPLATE_GEN + +} + +}} // namespace boost::python + +/////////////////////////////////////////////////////////////////////////////// +#endif // SIGNATURE_JDG20020813_HPP + + diff --git a/test/defaults.cpp b/test/defaults.cpp index e64a4349..c49ed91d 100644 --- a/test/defaults.cpp +++ b/test/defaults.cpp @@ -52,13 +52,13 @@ BOOST_PYTHON_MEMBER_FUNCTION_GEN(X_bar_stubs, bar, 1, 4) BOOST_PYTHON_MODULE_INIT(defaults_ext) { module m("defaults_ext"); - m.def(foo_stubs(), args()); + m.def(foo_stubs(), signature()); class_ xc("X"); m.add(xc); xc.def_init(); - xc.def(X_bar_stubs(), args()); + xc.def(X_bar_stubs(), signature()); } #include "module_tail.cpp"