From d52bc525150f512a4516a51fcb8ba77f1a41aa17 Mon Sep 17 00:00:00 2001 From: Joel de Guzman Date: Tue, 13 Aug 2002 12:41:51 +0000 Subject: [PATCH] More comments... [SVN r14811] --- include/boost/python/class.hpp | 14 ++------ include/boost/python/detail/defaults_def.hpp | 18 ++++++++-- include/boost/python/module.hpp | 14 ++------ include/boost/python/signature.hpp | 35 ++++++++++++++++++++ 4 files changed, 57 insertions(+), 24 deletions(-) diff --git a/include/boost/python/class.hpp b/include/boost/python/class.hpp index 572d275e..a924b8fd 100644 --- a/include/boost/python/class.hpp +++ b/include/boost/python/class.hpp @@ -135,21 +135,13 @@ class class_ : public objects::class_base template self& def(detail::func_stubs_base const& stubs, signature sig) { - // JDG 8-12-2002 + // convert sig to a type_list (see signature.hpp) and call + // detail::define_with_defaults passing in the stubs (see defaults_gen.hpp), + // this instance, and the converted sig type_list. detail::define_with_defaults(stubs.derived(), *this, detail::get_signature(sig)); return *this; } -/* - template - self& def(detail::func_stubs_base const& stubs, ArgsT args) - { - // JDG 8-12-2002 - 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. template diff --git a/include/boost/python/detail/defaults_def.hpp b/include/boost/python/detail/defaults_def.hpp index 6b2d8159..5f2e7d11 100644 --- a/include/boost/python/detail/defaults_def.hpp +++ b/include/boost/python/detail/defaults_def.hpp @@ -66,10 +66,10 @@ BOOST_PP_REPEAT(BOOST_PYTHON_MAX_ARITY, BPL_IMPL_STUB_FUNC_DEF, BOOST_PP_EMPTY) // // define_with_defaults_helper // -// This helper template struct does the actual recursive definition +// This helper template struct does the actual recursive definition. // There's a generic version define_with_defaults_helper and a // terminal case define_with_defaults_helper<0>. The struct and its -// specialization has a sole static member function def that expect: +// specialization has a sole static member function def that expects: // // 1. char const* name: a python function name // 2. StubsT: a function stubs struct (see defaults_gen.hpp) @@ -109,6 +109,20 @@ BOOST_PP_REPEAT(BOOST_PYTHON_MAX_ARITY, BPL_IMPL_STUB_FUNC_DEF, BOOST_PP_EMPTY) } }; +/////////////////////////////////////////////////////////////////////////////// +// +// define_with_defaults +// +// This is the main entry point. This function recursively defines all +// stub functions of StubT (see defaults_gen.hpp) in HolderT holder which +// can be either a python::class_ or a python::module. The sig argument +// is a typelist that specifies the return type, the class (for member +// functions, and the arguments. Here are some SigT examples: +// +// int foo(int) mpl::type_list +// void bar(int, int) mpl::type_list +// void C::foo(int) mpl::type_list +// /////////////////////////////////////////////////////////////////////////////// template inline void diff --git a/include/boost/python/module.hpp b/include/boost/python/module.hpp index d5e47477..b477b91d 100644 --- a/include/boost/python/module.hpp +++ b/include/boost/python/module.hpp @@ -74,20 +74,12 @@ class module : public detail::module_base template module& def(detail::func_stubs_base const& stubs, signature sig) { - // JDG 8-12-2002 + // convert sig to a type_list (see signature.hpp) and call + // detail::define_with_defaults passing in the stubs (see defaults_gen.hpp), + // this instance, and the converted sig type_list. detail::define_with_defaults(stubs.derived(), *this, detail::get_signature(sig)); return *this; } - -/* - template - module& def(detail::func_stubs_base const& stubs, ArgsT args) - { - // JDG 8-12-2002 - detail::define_with_defaults(stubs.derived(), *this, args); - return *this; - } -*/ }; // diff --git a/include/boost/python/signature.hpp b/include/boost/python/signature.hpp index a885224b..87b8695f 100644 --- a/include/boost/python/signature.hpp +++ b/include/boost/python/signature.hpp @@ -20,6 +20,20 @@ /////////////////////////////////////////////////////////////////////////////// namespace boost { namespace python { +/////////////////////////////////////////////////////////////////////////////// +// +// signature +// +// This template struct acts as a type holder for the signature of a +// function or member function. This struct is used to pass in the +// return type, class (for member functions) and arguments of a +// function or member function. Examples: +// +// signature int foo(int) +// signature void foo(int, int) +// signature void C::foo(int, int) +// +/////////////////////////////////////////////////////////////////////////////// template struct signature {}; @@ -34,6 +48,27 @@ namespace detail { /**/ #endif +/////////////////////////////////////////////////////////////////////////////// +// +// The following macros generate expansions for: +// +// template +// inline boost::mpl::type_list +// get_signature(signature) +// { +// return boost::mpl::type_list(); +// } +// +// template +// inline boost::mpl::type_list +// get_signature(signature) +// { +// return boost::mpl::type_list(); +// } +// +// These functions extract the return type, class (for member functions) +// and arguments of the input signature and stuffs them in an mpl::type_list. +// /////////////////////////////////////////////////////////////////////////////// #define BPL_IMPL_TEMPLATE_GEN(INDEX, DATA) typename BOOST_PP_CAT(T, INDEX)