2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-26 18:52:26 +00:00

API changes + signature template and get_signature(sig) functions

[SVN r14807]
This commit is contained in:
Joel de Guzman
2002-08-13 10:06:27 +00:00
parent 502e67c114
commit e56f6833e6
6 changed files with 151 additions and 21 deletions

View File

@@ -29,6 +29,7 @@
# include <boost/python/object/add_to_namespace.hpp>
# include <boost/python/detail/def_helper.hpp>
# include <boost/python/detail/defaults_def.hpp>
# include <boost/python/signature.hpp>
namespace boost { namespace python {
@@ -130,6 +131,16 @@ class class_ : public objects::class_base
return this->def(op.name(), &op_t::template apply<T>::execute);
}
template <typename DerivedT, typename SigT>
self& def(detail::func_stubs_base<DerivedT> const& stubs, signature<SigT> sig)
{
// JDG 8-12-2002
detail::define_with_defaults(stubs.derived(), *this, detail::get_signature(sig));
return *this;
}
/*
template <typename DerivedT, typename ArgsT>
self& def(detail::func_stubs_base<DerivedT> 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.

View File

@@ -15,8 +15,6 @@
#include <boost/mpl/int_t.hpp>
#include <boost/mpl/size.hpp>
#include <boost/static_assert.hpp>
#include <boost/python/class.hpp>
#include <boost/python/module.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace boost { namespace python {
@@ -67,22 +65,22 @@ BOOST_PP_REPEAT(BOOST_PYTHON_MAX_ARITY, BPL_IMPL_STUB_FUNC_DEF, BOOST_PP_EMPTY)
};
///////////////////////////////////////////////////////////////////////////////
template <typename StubsT, typename HolderT, typename ArgsT>
template <typename StubsT, typename HolderT, typename SigT>
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<void, typename mpl::at<0, ArgsT>::type>::value,
boost::is_same<void, typename mpl::at<0, SigT>::type>::value,
typename StubsT::v_type,
typename StubsT::nv_type
>
::type stubs_type;
BOOST_STATIC_ASSERT(
(stubs_type::max_args + 1) == boost::mpl::size<ArgsT>::value);
(stubs_type::max_args + 1) == boost::mpl::size<SigT>::value);
typedef stubs_type::template gen<ArgsT> gen_type;
typedef stubs_type::template gen<SigT> gen_type;
define_with_defaults_helper<stubs_type::n_funcs-1>::def
(stubs_type::name(), gen_type(), holder);
}

View File

@@ -10,7 +10,6 @@
#ifndef DEFAULTS_GEN_JDG20020807_HPP
#define DEFAULTS_GEN_JDG20020807_HPP
#include <boost/preprocessor/repeat_2nd.hpp>
#include <boost/preprocessor/repeat.hpp>
#include <boost/preprocessor/enum.hpp>
#include <boost/preprocessor/enum_params.hpp>
@@ -22,8 +21,6 @@
#include <boost/preprocessor/inc.hpp>
#include <boost/preprocessor/empty.hpp>
#include <boost/config.hpp>
#include <boost/python/class.hpp>
#include <boost/python/module.hpp>
///////////////////////////////////////////////////////////////////////////////
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 <typename ArgsT> \
template <typename SigT> \
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 <typename ArgsT> \
template <typename SigT> \
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 \
( \

View File

@@ -15,6 +15,7 @@
# include <boost/python/object_core.hpp>
# include <boost/python/detail/def_helper.hpp>
# include <boost/python/detail/defaults_def.hpp>
# include <boost/python/signature.hpp>
namespace boost { namespace python {
@@ -70,6 +71,15 @@ class module : public detail::module_base
return *this;
}
template <typename DerivedT, typename SigT>
module& def(detail::func_stubs_base<DerivedT> const& stubs, signature<SigT> sig)
{
// JDG 8-12-2002
detail::define_with_defaults(stubs.derived(), *this, detail::get_signature(sig));
return *this;
}
/*
template <typename DerivedT, typename ArgsT>
module& def(detail::func_stubs_base<DerivedT> const& stubs, ArgsT args)
{
@@ -77,6 +87,7 @@ class module : public detail::module_base
detail::define_with_defaults(stubs.derived(), *this, args);
return *this;
}
*/
};
//

View File

@@ -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 <boost/preprocessor/repeat.hpp>
#include <boost/preprocessor/enum.hpp>
#include <boost/preprocessor/enum_params.hpp>
#include <boost/preprocessor/empty.hpp>
#include <boost/preprocessor/arithmetic/sub.hpp>
#include <boost/mpl/type_list.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace boost { namespace python {
template <typename T>
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<RT(*)(BOOST_PP_ENUM_PARAMS(INDEX, T))>) \
{ \
return boost::mpl::type_list \
<RT BOOST_PP_COMMA_IF(INDEX) BOOST_PP_ENUM_PARAMS(INDEX, T)>(); \
} \
///////////////////////////////////////////////////////////////////////////////
#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<RT(ClassT::*)(BOOST_PP_ENUM_PARAMS(INDEX, T))>) \
{ \
return boost::mpl::type_list \
<RT, ClassT BOOST_PP_COMMA_IF(INDEX) BOOST_PP_ENUM_PARAMS(INDEX, T)>\
(); \
} \
///////////////////////////////////////////////////////////////////////////////
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

View File

@@ -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<std::string, int, char, std::string, double>());
m.def(foo_stubs(), signature<std::string(*)(int, char, std::string, double)>());
class_<X> xc("X");
m.add(xc);
xc.def_init();
xc.def(X_bar_stubs(), args<std::string, X const&, int, char, std::string, double>());
xc.def(X_bar_stubs(), signature<std::string(X::*)(int, char, std::string, double)>());
}
#include "module_tail.cpp"