|
10 | 10 | # include <boost/python/object/forward.hpp> |
11 | 11 | # include <boost/python/object/class.hpp> |
12 | 12 | # include <boost/python/detail/wrap_python.hpp> |
| 13 | +# include <boost/python/detail/preprocessor.hpp> |
| 14 | +# include <boost/preprocessor/repeat.hpp> |
| 15 | +# include <boost/preprocessor/enum.hpp> |
13 | 16 |
|
14 | 17 | namespace boost { namespace python { namespace objects { |
15 | 18 |
|
16 | 19 | template <int nargs> struct make_holder; |
17 | 20 |
|
18 | | -template <> |
19 | | -struct make_holder<0> |
20 | | -{ |
21 | | - template <class Holder, class ArgList> |
22 | | - struct apply |
23 | | - { |
24 | | - static void execute( |
25 | | - PyObject* p) |
26 | | - { |
27 | | - (new Holder(p))->install(p); |
28 | | - } |
29 | | - }; |
| 21 | +# ifndef BOOST_PYTHON_GENERATE_CODE |
| 22 | +# include <boost/python/preprocessed/make_holder.hpp> |
| 23 | +# endif |
| 24 | + |
| 25 | + |
| 26 | +# define BOOST_PYTHON_FORWARD_ARG(index, ignored) \ |
| 27 | + typedef typename mpl::at<index,ArgList>::type BOOST_PP_CAT(t,index); \ |
| 28 | + typedef typename forward<BOOST_PP_CAT(t,index)>::type BOOST_PP_CAT(f,index); |
| 29 | + |
| 30 | +# define BOOST_PYTHON_DO_FORWARD_ARG(index, ignored) \ |
| 31 | + BOOST_PP_CAT(f,index)(BOOST_PP_CAT(a, index)) |
| 32 | + |
| 33 | +# define BOOST_PYTHON_MAKE_HOLDER(nargs,ignored) \ |
| 34 | +template <> \ |
| 35 | +struct make_holder<nargs> \ |
| 36 | +{ \ |
| 37 | + template <class Holder, class ArgList> \ |
| 38 | + struct apply \ |
| 39 | + { \ |
| 40 | + BOOST_PP_REPEAT(nargs, BOOST_PYTHON_FORWARD_ARG, nil) \ |
| 41 | + \ |
| 42 | + static void execute( \ |
| 43 | + PyObject* p \ |
| 44 | + BOOST_PP_COMMA_IF(nargs) BOOST_PYTHON_ENUM_PARAMS2(nargs, (t,a)) ) \ |
| 45 | + { \ |
| 46 | + (new Holder( \ |
| 47 | + p \ |
| 48 | + BOOST_PP_COMMA_IF(nargs) BOOST_PP_ENUM( \ |
| 49 | + nargs,BOOST_PYTHON_DO_FORWARD_ARG,nil)))->install(p); \ |
| 50 | + } \ |
| 51 | + }; \ |
30 | 52 | }; |
31 | 53 |
|
32 | | - |
33 | | -template <> |
34 | | -struct make_holder<1> |
35 | | -{ |
36 | | - template <class Holder, class ArgList> |
37 | | - struct apply |
38 | | - { |
39 | | - typedef typename mpl::at<0,ArgList>::type t0; |
40 | | - typedef typename forward<t0>::type f0; |
41 | | - |
42 | | - static void execute( |
43 | | - PyObject* p |
44 | | - , t0 a0) |
45 | | - { |
46 | | - (new Holder(p, f0(a0)))->install(p); |
47 | | - } |
48 | | - }; |
49 | | -}; |
50 | | - |
51 | | -template <> |
52 | | -struct make_holder<2> |
53 | | -{ |
54 | | - template <class Holder, class ArgList> |
55 | | - struct apply |
56 | | - { |
57 | | - typedef typename mpl::at<0,ArgList>::type t0; |
58 | | - typedef typename forward<t0>::type f0; |
59 | | - typedef typename mpl::at<1,ArgList>::type t1; |
60 | | - typedef typename forward<t1>::type f1; |
61 | | - |
62 | | - static void execute( |
63 | | - PyObject* p, t0 a0, t1 a1) |
64 | | - { |
65 | | - (new Holder(p, f0(a0), f1(a1)))->install(p); |
66 | | - } |
67 | | - }; |
68 | | -}; |
69 | | - |
70 | | -template <> |
71 | | -struct make_holder<3> |
72 | | -{ |
73 | | - template <class Holder, class ArgList> |
74 | | - struct apply |
75 | | - { |
76 | | - typedef typename mpl::at<0,ArgList>::type t0; |
77 | | - typedef typename forward<t0>::type f0; |
78 | | - typedef typename mpl::at<1,ArgList>::type t1; |
79 | | - typedef typename forward<t1>::type f1; |
80 | | - typedef typename mpl::at<2,ArgList>::type t2; |
81 | | - typedef typename forward<t2>::type f2; |
82 | | - |
83 | | - static void execute( |
84 | | - PyObject* p, t0 a0, t1 a1, t2 a2) |
85 | | - { |
86 | | - (new Holder(p, f0(a0), f1(a1), f2(a2)))->install(p); |
87 | | - } |
88 | | - }; |
89 | | -}; |
90 | | - |
91 | | -template <> |
92 | | -struct make_holder<4> |
93 | | -{ |
94 | | - template <class Holder, class ArgList> |
95 | | - struct apply |
96 | | - { |
97 | | - typedef typename mpl::at<0,ArgList>::type t0; |
98 | | - typedef typename forward<t0>::type f0; |
99 | | - typedef typename mpl::at<1,ArgList>::type t1; |
100 | | - typedef typename forward<t1>::type f1; |
101 | | - typedef typename mpl::at<2,ArgList>::type t2; |
102 | | - typedef typename forward<t2>::type f2; |
103 | | - typedef typename mpl::at<3,ArgList>::type t3; |
104 | | - typedef typename forward<t3>::type f3; |
105 | | - |
106 | | - static void execute( |
107 | | - PyObject* p, t0 a0, t1 a1, t2 a2, t3 a3) |
108 | | - { |
109 | | - (new Holder(p, f0(a0), f1(a1), f2(a2), f3(a3)))->install(p); |
110 | | - } |
111 | | - }; |
112 | | -}; |
113 | | - |
114 | | -template <> |
115 | | -struct make_holder<5> |
116 | | -{ |
117 | | - template <class Holder, class ArgList> |
118 | | - struct apply |
119 | | - { |
120 | | - typedef typename mpl::at<0,ArgList>::type t0; |
121 | | - typedef typename forward<t0>::type f0; |
122 | | - typedef typename mpl::at<1,ArgList>::type t1; |
123 | | - typedef typename forward<t1>::type f1; |
124 | | - typedef typename mpl::at<2,ArgList>::type t2; |
125 | | - typedef typename forward<t2>::type f2; |
126 | | - typedef typename mpl::at<3,ArgList>::type t3; |
127 | | - typedef typename forward<t3>::type f3; |
128 | | - typedef typename mpl::at<4,ArgList>::type t4; |
129 | | - typedef typename forward<t4>::type f4; |
130 | | - |
131 | | - static void execute( |
132 | | - PyObject* p, t0 a0, t1 a1, t2 a2, t3 a3, t4 a4) |
133 | | - { |
134 | | - (new Holder(p, f0(a0), f1(a1), f2(a2), f3(a3), f4(a4)))->install(p); |
135 | | - } |
136 | | - }; |
137 | | -}; |
138 | | - |
139 | | -template <> |
140 | | -struct make_holder<6> |
141 | | -{ |
142 | | - template <class Holder, class ArgList> |
143 | | - struct apply |
144 | | - { |
145 | | - typedef typename mpl::at<0,ArgList>::type t0; |
146 | | - typedef typename forward<t0>::type f0; |
147 | | - typedef typename mpl::at<1,ArgList>::type t1; |
148 | | - typedef typename forward<t1>::type f1; |
149 | | - typedef typename mpl::at<2,ArgList>::type t2; |
150 | | - typedef typename forward<t2>::type f2; |
151 | | - typedef typename mpl::at<3,ArgList>::type t3; |
152 | | - typedef typename forward<t3>::type f3; |
153 | | - typedef typename mpl::at<4,ArgList>::type t4; |
154 | | - typedef typename forward<t4>::type f4; |
155 | | - typedef typename mpl::at<5,ArgList>::type t5; |
156 | | - typedef typename forward<t5>::type f5; |
157 | | - |
158 | | - static void execute( |
159 | | - PyObject* p, t0 a0, t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) |
160 | | - { |
161 | | - (new Holder(p, f0(a0), f1(a1), f2(a2), f3(a3), f4(a4), f5(a5)))->install(p); |
162 | | - } |
163 | | - }; |
164 | | -}; |
| 54 | +BOOST_PYTHON_REPEAT_ARITY_2ND(BOOST_PYTHON_MAKE_HOLDER,nil) |
165 | 55 |
|
166 | 56 | }}} // namespace boost::python::objects |
167 | 57 |
|
|
0 commit comments