Skip to content

Commit 931aab2

Browse files
committed
Use Paul M's preprocessor iteration
[SVN r14384]
1 parent 6cb4fbb commit 931aab2

19 files changed

+992
-738
lines changed

include/boost/python/args.hpp

Lines changed: 63 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,41 @@
1+
#if !defined(BOOST_PP_IS_ITERATING)
2+
13
// Copyright David Abrahams 2002. Permission to copy, use,
24
// modify, sell and distribute this software is granted provided this
35
// copyright notice appears in all copies. This software is provided
46
// "as is" without express or implied warranty, and with no claim as
57
// to its suitability for any purpose.
68
#ifndef ARGS_DWA2002323_HPP
79
# define ARGS_DWA2002323_HPP
8-
# include <boost/config.hpp>
9-
# include <boost/mpl/type_list.hpp>
10-
# include <boost/python/detail/preprocessor.hpp>
11-
# include <boost/preprocessor/enum_params.hpp>
12-
# include <boost/preprocessor/enum_params_with_a_default.hpp>
13-
# include <boost/preprocessor/comma_if.hpp>
10+
# include <boost/config.hpp>
11+
12+
# include <boost/python/detail/preprocessor.hpp>
13+
14+
# include <boost/mpl/type_list.hpp>
1415

15-
# if !defined(__EDG_VERSION__) || __EDG_VERSION__ > 245
16-
namespace boost { namespace python {
16+
# include <boost/preprocessor/cat.hpp>
17+
# include <boost/preprocessor/iterate.hpp>
1718

19+
# if !defined(__EDG_VERSION__) || __EDG_VERSION__ > 245
20+
21+
namespace boost { namespace python {
1822

1923
// A type list for specifying arguments
20-
template < BOOST_MPL_LIST_DEFAULT_PARAMETERS(typename A, boost::mpl::null_argument) >
21-
struct args : boost::mpl::type_list< BOOST_MPL_LIST_PARAMETERS(A) >::type
24+
template < BOOST_PYTHON_ENUM_WITH_DEFAULT(BOOST_PYTHON_MAX_ARITY, typename A, boost::mpl::null_argument) >
25+
struct args : boost::mpl::type_list< BOOST_PYTHON_UNARY_ENUM(BOOST_PYTHON_MAX_ARITY, A) >::type
2226
{};
2327

2428
}} // namespace boost::python
2529

26-
# else // slow template instantiators need this other version with
27-
// explicit specializations of mpl::size<> and
28-
// mpl::at<>. Eventually, however, inheritance from mpl::list
29-
// *should* be eliminated and the two versions unified, just in
30-
// order to get true arity independence
30+
# else // slow template instantiators need this other version with
31+
// explicit specializations of mpl::size<> and
32+
// mpl::at<>. Eventually, however, inheritance from mpl::list
33+
// *should* be eliminated and the two versions unified, just in
34+
// order to get true arity independence
3135

32-
namespace boost { namespace python {
36+
namespace boost { namespace python {
3337

34-
template < BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(BOOST_PYTHON_MAX_ARITY, class A, boost::mpl::null_argument) >
38+
template < BOOST_PYTHON_ENUM_WITH_DEFAULT(BOOST_PYTHON_MAX_ARITY, typename A, boost::mpl::null_argument) >
3539
struct args
3640
{};
3741

@@ -42,32 +46,45 @@ namespace boost { namespace mpl {
4246
template <class T> struct size;
4347
template <long N, class Seq> struct at;
4448

45-
# ifndef BOOST_PYTHON_GENERATE_CODE
46-
# include <boost/python/preprocessed/args.hpp>
47-
# endif
48-
49-
# define BOOST_PYTHON_ARGS_SIZE(index,ignored) \
50-
template <BOOST_PP_ENUM_PARAMS(index, class A)> \
51-
struct size<boost::python::args<BOOST_PP_ENUM_PARAMS(index, A)> > \
52-
{ \
53-
BOOST_STATIC_CONSTANT(long, value = index); \
54-
}; \
55-
56-
BOOST_PYTHON_REPEAT_ARITY_2ND(BOOST_PYTHON_ARGS_SIZE, nil)
57-
58-
# define BOOST_PYTHON_ARGS_AT(index,ignored) \
59-
template < \
60-
BOOST_PP_ENUM_PARAMS(BOOST_PP_DEC(BOOST_PYTHON_ARITY_FINISH), class A)> \
61-
struct at<index, boost::python::args< \
62-
BOOST_PP_ENUM_PARAMS(BOOST_PP_DEC(BOOST_PYTHON_ARITY_FINISH), A)> > \
63-
{ \
64-
typedef BOOST_PP_CAT(A,index) type; \
65-
}; \
66-
67-
BOOST_PP_REPEAT_FROM_TO_2ND(
68-
BOOST_PP_DEC(BOOST_PYTHON_ARITY_START), BOOST_PP_DEC(BOOST_PYTHON_ARITY_FINISH)
69-
, BOOST_PYTHON_ARGS_AT, data)
70-
71-
}}
72-
# endif
73-
#endif // ARGS_DWA2002323_HPP
49+
# define BOOST_PP_ITERATION_PARAMS_1 4, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/args.hpp>, 1)
50+
# include BOOST_PP_ITERATE()
51+
52+
# define BOOST_PP_ITERATION_PARAMS_1 4, (0, BOOST_PYTHON_MAX_ARITY - 1, <boost/python/args.hpp>, 2)
53+
# include BOOST_PP_ITERATE()
54+
55+
56+
}} // namespace boost::mpl
57+
58+
# endif // __EDG_VERSION__
59+
60+
# endif // ARGS_DWA2002323_HPP
61+
62+
/* ---------- size ---------- */
63+
#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == 1
64+
# line BOOST_PP_LINE(__LINE__, args.hpp(size))
65+
66+
# define N BOOST_PP_ITERATION()
67+
68+
template <BOOST_PYTHON_UNARY_ENUM(N, class A)>
69+
struct size<boost::python::args<BOOST_PYTHON_UNARY_ENUM(N, A)> >
70+
{
71+
BOOST_STATIC_CONSTANT(long, value = N);
72+
};
73+
74+
# undef N
75+
76+
/* ---------- at ---------- */
77+
#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == 2
78+
# line BOOST_PP_LINE(__LINE__, args.hpp(at))
79+
80+
# define N BOOST_PP_ITERATION()
81+
82+
template <BOOST_PYTHON_UNARY_ENUM(BOOST_PYTHON_MAX_ARITY, class A)>
83+
struct at<N, boost::python::args<BOOST_PYTHON_UNARY_ENUM(BOOST_PYTHON_MAX_ARITY, A)> >
84+
{
85+
typedef BOOST_PP_CAT(A, N) type;
86+
};
87+
88+
# undef N
89+
90+
#endif

include/boost/python/call.hpp

Lines changed: 54 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,63 @@
1+
#if !defined(BOOST_PP_IS_ITERATING)
2+
13
// Copyright David Abrahams 2002. Permission to copy, use,
24
// modify, sell and distribute this software is granted provided this
35
// copyright notice appears in all copies. This software is provided
46
// "as is" without express or implied warranty, and with no claim as
57
// to its suitability for any purpose.
6-
#ifndef CALL_DWA2002411_HPP
7-
# define CALL_DWA2002411_HPP
8-
9-
# include <boost/python/converter/arg_to_python.hpp>
10-
# include <boost/python/converter/return_from_python.hpp>
11-
# include <boost/python/detail/preprocessor.hpp>
12-
# include <boost/preprocessor/comma_if.hpp>
13-
# include <boost/preprocessor/enum.hpp>
14-
# include <boost/preprocessor/enum_params.hpp>
15-
# include <boost/preprocessor/repeat.hpp>
16-
# include <boost/preprocessor/cat.hpp>
17-
# include <boost/python/detail/void_return.hpp>
18-
# include <boost/type.hpp>
19-
20-
namespace boost { namespace python {
21-
22-
# ifndef BOOST_PYTHON_GENERATE_CODE
23-
# include <boost/python/preprocessed/call.hpp>
24-
# endif
25-
26-
# define BOOST_PYTHON_CALL_FUNCTION(nargs,ignored) \
27-
template < \
28-
class R \
29-
BOOST_PP_COMMA_IF(nargs) BOOST_PP_ENUM_PARAMS(nargs, class A) \
30-
> \
31-
typename detail::returnable<R>::type \
32-
call(PyObject* callable \
33-
BOOST_PP_COMMA_IF(nargs) BOOST_PYTHON_ENUM_PARAMS2(nargs, (A,const& a)) \
34-
, boost::type<R>* = 0 \
35-
) \
36-
{ \
37-
converter::return_from_python<R> converter; \
38-
return converter( \
39-
PyEval_CallFunction( \
40-
callable \
41-
, const_cast<char*>(BOOST_PYTHON_ARG_STRING(nargs)) \
42-
BOOST_PP_COMMA_IF(nargs) \
43-
BOOST_PP_ENUM(nargs,BOOST_PYTHON_ARG_TO_PYTHON_GET,nil) \
44-
)); \
45-
}
468

47-
BOOST_PYTHON_REPEAT_ARITY_2ND(BOOST_PYTHON_CALL_FUNCTION,data)
9+
# ifndef CALL_DWA2002411_HPP
10+
# define CALL_DWA2002411_HPP
11+
12+
# include <boost/type.hpp>
13+
14+
# include <boost/python/converter/arg_to_python.hpp>
15+
# include <boost/python/converter/return_from_python.hpp>
16+
# include <boost/python/detail/preprocessor.hpp>
17+
# include <boost/python/detail/void_return.hpp>
18+
19+
# include <boost/preprocessor/comma_if.hpp>
20+
# include <boost/preprocessor/iterate.hpp>
21+
# include <boost/preprocessor/repeat.hpp>
22+
23+
namespace boost { namespace python {
24+
25+
# define BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET(n, _) \
26+
, converter::arg_to_python<A##n>(a##n).get()
27+
28+
# define BOOST_PP_ITERATION_PARAMS_1 3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/call.hpp>)
29+
# include BOOST_PP_ITERATE()
30+
31+
# undef BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET
4832

4933
}} // namespace boost::python
5034

51-
#endif // CALL_DWA2002411_HPP
35+
# endif // CALL_DWA2002411_HPP
36+
37+
#elif BOOST_PP_ITERATION_DEPTH() == 1
38+
# line BOOST_PP_LINE(__LINE__, call.hpp)
39+
40+
# define N BOOST_PP_ITERATION()
41+
42+
template <
43+
class R
44+
BOOST_PP_COMMA_IF(N) BOOST_PYTHON_UNARY_ENUM(N, class A)
45+
>
46+
typename detail::returnable<R>::type
47+
call(PyObject* callable
48+
BOOST_PP_COMMA_IF(N) BOOST_PYTHON_BINARY_ENUM(N, A, const& a)
49+
, boost::type<R>* = 0
50+
)
51+
{
52+
converter::return_from_python<R> converter;
53+
return converter(
54+
PyEval_CallFunction(
55+
callable
56+
, const_cast<char*>("(" BOOST_PP_REPEAT(N, BOOST_PYTHON_FIXED, "O") ")")
57+
BOOST_PP_REPEAT(N, BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET, nil)
58+
));
59+
}
60+
61+
# undef N
62+
63+
#endif
Lines changed: 54 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,63 @@
1+
#if !defined(BOOST_PP_IS_ITERATING)
2+
13
// Copyright David Abrahams 2002. Permission to copy, use,
24
// modify, sell and distribute this software is granted provided this
35
// copyright notice appears in all copies. This software is provided
46
// "as is" without express or implied warranty, and with no claim as
57
// to its suitability for any purpose.
6-
#ifndef CALL_METHOD_DWA2002411_HPP
7-
# define CALL_METHOD_DWA2002411_HPP
8-
9-
# include <boost/python/converter/arg_to_python.hpp>
10-
# include <boost/python/converter/return_from_python.hpp>
11-
# include <boost/python/detail/preprocessor.hpp>
12-
# include <boost/preprocessor/comma_if.hpp>
13-
# include <boost/preprocessor/enum.hpp>
14-
# include <boost/preprocessor/enum_params.hpp>
15-
# include <boost/preprocessor/repeat.hpp>
16-
# include <boost/preprocessor/cat.hpp>
17-
# include <boost/python/detail/void_return.hpp>
18-
# include <boost/type.hpp>
19-
20-
namespace boost { namespace python {
21-
22-
# ifndef BOOST_PYTHON_GENERATE_CODE
23-
# include <boost/python/preprocessed/call_method.hpp>
24-
# endif
25-
26-
# define BOOST_PYTHON_CALL_METHOD_FUNCTION(nargs,ignored) \
27-
template < \
28-
class R \
29-
BOOST_PP_COMMA_IF(nargs) BOOST_PP_ENUM_PARAMS(nargs, class A) \
30-
> \
31-
typename detail::returnable<R>::type \
32-
call_method(PyObject* self, char const* name \
33-
BOOST_PP_COMMA_IF(nargs) BOOST_PYTHON_ENUM_PARAMS2(nargs, (A,const& a)) \
34-
, boost::type<R>* = 0 \
35-
) \
36-
{ \
37-
converter::return_from_python<R> converter; \
38-
return converter( \
39-
PyEval_CallMethod( \
40-
self \
41-
, const_cast<char*>(name) \
42-
, const_cast<char*>(BOOST_PYTHON_ARG_STRING(nargs)) \
43-
BOOST_PP_COMMA_IF(nargs) \
44-
BOOST_PP_ENUM(nargs,BOOST_PYTHON_ARG_TO_PYTHON_GET,nil) \
45-
)); \
46-
}
8+
# ifndef CALL_METHOD_DWA2002411_HPP
9+
# define CALL_METHOD_DWA2002411_HPP
10+
11+
# include <boost/type.hpp>
12+
13+
# include <boost/python/converter/arg_to_python.hpp>
14+
# include <boost/python/converter/return_from_python.hpp>
15+
# include <boost/python/detail/preprocessor.hpp>
16+
# include <boost/python/detail/void_return.hpp>
17+
18+
# include <boost/preprocessor/comma_if.hpp>
19+
# include <boost/preprocessor/iterate.hpp>
20+
# include <boost/preprocessor/repeat.hpp>
21+
22+
namespace boost { namespace python {
23+
24+
# define BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET(n, _) \
25+
, converter::arg_to_python<A##n>(a##n).get()
4726

48-
BOOST_PYTHON_REPEAT_ARITY_2ND(BOOST_PYTHON_CALL_METHOD_FUNCTION,data)
27+
# define BOOST_PP_ITERATION_PARAMS_1 3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/call_method.hpp>)
28+
# include BOOST_PP_ITERATE()
29+
30+
# undef BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET
4931

5032
}} // namespace boost::python
5133

52-
#endif // CALL_METHOD_DWA2002411_HPP
34+
# endif // CALL_METHOD_DWA2002411_HPP
35+
36+
#elif BOOST_PP_ITERATION_DEPTH() == 1
37+
# line BOOST_PP_LINE(__LINE__, call_method.hpp)
38+
39+
# define N BOOST_PP_ITERATION()
40+
41+
template <
42+
class R
43+
BOOST_PP_COMMA_IF(N) BOOST_PYTHON_UNARY_ENUM(N, class A)
44+
>
45+
typename detail::returnable<R>::type
46+
call_method(PyObject* self, char const* name
47+
BOOST_PP_COMMA_IF(N) BOOST_PYTHON_BINARY_ENUM(N, A, const& a)
48+
, boost::type<R>* = 0
49+
)
50+
{
51+
converter::return_from_python<R> converter;
52+
return converter(
53+
PyEval_CallMethod(
54+
self
55+
, const_cast<char*>(name)
56+
, const_cast<char*>("(" BOOST_PP_REPEAT(N, BOOST_PYTHON_FIXED, "O") ")")
57+
BOOST_PP_REPEAT(N, BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET, nil)
58+
));
59+
}
60+
61+
# undef N
62+
63+
#endif // BOOST_PP_IS_ITERATING
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright David Abrahams 2002. Permission to copy, use,
2+
// modify, sell and distribute this software is granted provided this
3+
// copyright notice appears in all copies. This software is provided
4+
// "as is" without express or implied warranty, and with no claim as
5+
// to its suitability for any purpose.
6+
#ifndef CONVERTIBLE_FUNCTION_DWA200278_HPP
7+
# define CONVERTIBLE_FUNCTION_DWA200278_HPP
8+
9+
namespace boost { namespace python { namespace converter {
10+
11+
typedef void* (*convertible_function)(PyObject*);
12+
13+
}}} // namespace boost::python::converter
14+
15+
#endif // CONVERTIBLE_FUNCTION_DWA200278_HPP

include/boost/python/converter/registrations.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@
66
#ifndef REGISTRATIONS_DWA2002223_HPP
77
# define REGISTRATIONS_DWA2002223_HPP
88

9+
# include <boost/python/converter/convertible_function.hpp>
910
# include <boost/python/converter/constructor_function.hpp>
1011

1112
namespace boost { namespace python { namespace converter {
1213

1314
struct lvalue_from_python_registration
1415
{
15-
void* (*convert)(PyObject* source);
16+
convertible_function convert;
1617
lvalue_from_python_registration* next;
1718
};
1819

1920
struct rvalue_from_python_registration
2021
{
21-
void* (*convertible)(PyObject*);
22+
convertible_function convertible;
2223
constructor_function construct;
2324
rvalue_from_python_registration* next;
2425
};

0 commit comments

Comments
 (0)