Skip to content

Commit 60924e8

Browse files
committed
On our way to polymorphism
[SVN r16374]
1 parent 75bd427 commit 60924e8

4 files changed

Lines changed: 67 additions & 54 deletions

File tree

include/boost/python/arg_from_python.hpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# define ARG_FROM_PYTHON_DWA2002128_HPP
88

99
# include <boost/python/converter/arg_from_python.hpp>
10+
# include <boost/python/detail/indirect_traits.hpp>
1011

1112
namespace boost { namespace python {
1213

@@ -38,6 +39,37 @@ struct arg_from_python<PyObject* const&>
3839
PyObject*const& operator()(PyObject*const& source) const { return source; }
3940
};
4041

42+
namespace detail
43+
{
44+
//
45+
// Meta-iterators for use with caller<>
46+
//
47+
48+
// temporary hack
49+
template <class T> struct nullary : T
50+
{
51+
nullary(PyObject* x) : T(x), m_p(x) {}
52+
typename T::result_type operator()() { return this->T::operator()(m_p); }
53+
PyObject* m_p;
54+
};
55+
56+
// An MPL metafunction class which returns arg_from_python<ArgType>
57+
struct gen_arg_from_python
58+
{
59+
template <class ArgType> struct apply
60+
{
61+
typedef nullary<arg_from_python<ArgType> > type;
62+
};
63+
};
64+
65+
// An MPL iterator over an endless sequence of gen_arg_from_python
66+
struct args_from_python
67+
{
68+
typedef gen_arg_from_python type;
69+
typedef args_from_python next;
70+
};
71+
}
72+
4173
//
4274
// implementations
4375
//

include/boost/python/converter/arg_from_python.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,11 @@ struct select_arg_from_python
159159
= boost::python::detail::is_reference_to_pointer<T>::value
160160
&& boost::python::detail::is_reference_to_const<T>::value
161161
&& !boost::python::detail::is_reference_to_volatile<T>::value);
162-
162+
163163

164164
BOOST_STATIC_CONSTANT(
165165
bool, ref =
166-
boost::python::detail::is_reference_to_non_const<T>::value
166+
boost::python::detail::is_reference_to_non_const<T>::value
167167
|| boost::python::detail::is_reference_to_volatile<T>::value);
168168

169169
BOOST_STATIC_CONSTANT(

include/boost/python/detail/defaults_gen.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ namespace detail
162162
#define BOOST_PYTHON_MEM_FUNC_WRAPPER_GEN(z, index, data) \
163163
static RT BOOST_PP_CAT(func_, \
164164
BOOST_PP_SUB_D(1, index, BOOST_PP_TUPLE_ELEM(3, 1, data))) ( \
165-
ClassT& obj BOOST_PP_COMMA_IF(index) \
165+
ClassT obj BOOST_PP_COMMA_IF(index) \
166166
BOOST_PP_ENUM_BINARY_PARAMS_Z(1, index, T, arg) \
167167
) \
168168
{ \

include/boost/python/signature.hpp

Lines changed: 32 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,9 @@
2626
# include <boost/preprocessor/arithmetic/inc.hpp>
2727
# include <boost/preprocessor/repetition/enum_trailing_params.hpp>
2828

29-
# define BOOST_PYTHON_FUNCTION_SIGNATURE_LIST(n) \
29+
# define BOOST_PYTHON_LIST_INC(n) \
3030
BOOST_PP_CAT(mpl::list, BOOST_PP_INC(n))
3131

32-
# define BOOST_PYTHON_MEMBER_FUNCTION_SIGNATURE_LIST(n) \
33-
BOOST_PP_CAT(mpl::list, BOOST_PP_INC(BOOST_PP_INC(n)))
34-
35-
3632
///////////////////////////////////////////////////////////////////////////////
3733
namespace boost { namespace python { namespace detail {
3834

@@ -47,18 +43,13 @@ namespace boost { namespace python { namespace detail {
4743
// return mpl::list<RT, T0...TN>();
4844
// }
4945
//
50-
// template <class RT, class ClassT, class T0... class TN>
51-
// inline mpl::list<RT, ClassT, T0...TN>
52-
// get_signature(RT(ClassT::*)(T0...TN)))
53-
// {
54-
// return mpl::list<RT, ClassT, T0...TN>();
55-
// }
46+
// And, for an appropriate assortment of cv-qualifications
5647
//
5748
// template <class RT, class ClassT, class T0... class TN>
58-
// inline mpl::list<RT, ClassT, T0...TN>
59-
// get_signature(RT(ClassT::*)(T0...TN) const))
49+
// inline mpl::list<RT, ClassT cv&, T0...TN>
50+
// get_signature(RT(ClassT::*)(T0...TN) cv))
6051
// {
61-
// return mpl::list<RT, ClassT const, T0...TN>();
52+
// return mpl::list<RT, ClassT&, T0...TN>();
6253
// }
6354
//
6455
// These functions extract the return type, class (for member functions)
@@ -68,7 +59,7 @@ namespace boost { namespace python { namespace detail {
6859

6960
///////////////////////////////////////////////////////////////////////////////
7061
# define BOOST_PP_ITERATION_PARAMS_1 \
71-
(3, (0, BOOST_PYTHON_MAX_ARITY-1, <boost/python/signature.hpp>))
62+
(3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/signature.hpp>))
7263

7364
# include BOOST_PP_ITERATE()
7465

@@ -77,59 +68,49 @@ namespace boost { namespace python { namespace detail {
7768
}} // namespace boost::python
7869

7970

80-
# undef BOOST_PYTHON_FUNCTION_SIGNATURE_LIST
81-
# undef BOOST_PYTHON_MEMBER_FUNCTION_SIGNATURE_LIST
71+
# undef BOOST_PYTHON_LIST_INC
8272

8373
///////////////////////////////////////////////////////////////////////////////
8474
# endif // SIGNATURE_JDG20020813_HPP
8575

86-
#else // defined(BOOST_PP_IS_ITERATING)
76+
#elif BOOST_PP_ITERATION_DEPTH() == 1 // defined(BOOST_PP_IS_ITERATING)
8777

8878
# define N BOOST_PP_ITERATION()
8979

90-
# define BOOST_PYTHON_SIGNATURE_PARAMS BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class T)
91-
# define BOOST_PYTHON_SIGNATURE_TYPES BOOST_PP_ENUM_PARAMS_Z(1, N, T)
92-
# define BOOST_PYTHON_TRAILING_SIGNATURE_TYPES BOOST_PP_COMMA_IF(N) BOOST_PYTHON_SIGNATURE_TYPES
93-
9480
template <
95-
class RT BOOST_PYTHON_SIGNATURE_PARAMS>
96-
inline BOOST_PYTHON_FUNCTION_SIGNATURE_LIST(N)<
97-
RT BOOST_PYTHON_TRAILING_SIGNATURE_TYPES>
98-
get_signature(RT(*)(BOOST_PYTHON_SIGNATURE_TYPES))
81+
class RT BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class T)>
82+
inline BOOST_PYTHON_LIST_INC(N)<
83+
RT BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, T)>
84+
get_signature(RT(*)(BOOST_PP_ENUM_PARAMS_Z(1, N, T)))
9985
{
100-
return BOOST_PYTHON_FUNCTION_SIGNATURE_LIST(N)<
101-
RT BOOST_PYTHON_TRAILING_SIGNATURE_TYPES
86+
return BOOST_PYTHON_LIST_INC(N)<
87+
RT BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, T)
10288
>();
10389
}
10490

105-
///////////////////////////////////////////////////////////////////////////////
106-
#if N <= (BOOST_PYTHON_MAX_ARITY - 2)
91+
# undef N
10792

108-
template <
109-
class RT, class ClassT BOOST_PYTHON_SIGNATURE_PARAMS>
110-
inline BOOST_PYTHON_MEMBER_FUNCTION_SIGNATURE_LIST(N)<
111-
RT, ClassT BOOST_PYTHON_TRAILING_SIGNATURE_TYPES >
112-
get_signature(RT(ClassT::*)(BOOST_PYTHON_SIGNATURE_TYPES))
113-
{
114-
return BOOST_PYTHON_MEMBER_FUNCTION_SIGNATURE_LIST(N)<
115-
RT, ClassT BOOST_PYTHON_TRAILING_SIGNATURE_TYPES>();
116-
}
93+
# define BOOST_PP_ITERATION_PARAMS_2 \
94+
(3, (0, BOOST_PYTHON_CV_COUNT - 1, <boost/python/signature.hpp>))
95+
# include BOOST_PP_ITERATE()
96+
97+
#else
98+
99+
# define N BOOST_PP_RELATIVE_ITERATION(1)
100+
# define Q BOOST_PYTHON_CV_QUALIFIER(BOOST_PP_ITERATION())
117101

118-
///////////////////////////////////////
119102
template <
120-
class RT, class ClassT BOOST_PYTHON_SIGNATURE_PARAMS>
121-
inline BOOST_PYTHON_MEMBER_FUNCTION_SIGNATURE_LIST(N)<
122-
RT, ClassT const BOOST_PYTHON_TRAILING_SIGNATURE_TYPES>
123-
get_signature(RT(ClassT::*)(BOOST_PYTHON_SIGNATURE_TYPES) const)
103+
class RT, class ClassT BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class T)>
104+
inline BOOST_PYTHON_LIST_INC(BOOST_PP_INC(N))<
105+
RT, ClassT Q& BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, T)>
106+
get_signature(RT(ClassT::*)(BOOST_PP_ENUM_PARAMS_Z(1, N, T)) Q)
124107
{
125-
return BOOST_PYTHON_MEMBER_FUNCTION_SIGNATURE_LIST(N)<
126-
RT, ClassT const BOOST_PYTHON_TRAILING_SIGNATURE_TYPES>();
108+
return BOOST_PYTHON_LIST_INC(BOOST_PP_INC(N))<
109+
RT, ClassT Q & BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, T)
110+
>();
127111
}
128112

129-
#endif // N < (BOOST_PYTHON_MAX_ARITY - 2)
130-
131-
# undef BOOST_PYTHON_SIGNATURE_PARAMS
132-
# undef BOOST_PYTHON_SIGNATURE_TYPES
133-
# undef BOOST_PYTHON_TRAILING_SIGNATURE_TYPES
113+
# undef Q
114+
# undef N
134115

135116
#endif // !defined(BOOST_PP_IS_ITERATING)

0 commit comments

Comments
 (0)