File indexing completed on 2025-01-18 09:50:38
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef DEFAULTS_GEN_JDG20020807_HPP
0010 #define DEFAULTS_GEN_JDG20020807_HPP
0011
0012 #include <boost/python/detail/preprocessor.hpp>
0013 #include <boost/preprocessor/repeat.hpp>
0014 #include <boost/preprocessor/repeat_from_to.hpp>
0015 #include <boost/preprocessor/enum.hpp>
0016 #include <boost/preprocessor/enum_params.hpp>
0017 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
0018 #include <boost/preprocessor/tuple.hpp>
0019 #include <boost/preprocessor/cat.hpp>
0020 #include <boost/preprocessor/arithmetic/sub.hpp>
0021 #include <boost/preprocessor/stringize.hpp>
0022 #include <boost/preprocessor/inc.hpp>
0023 #include <boost/preprocessor/empty.hpp>
0024 #include <boost/preprocessor/comma_if.hpp>
0025 #include <boost/config.hpp>
0026 #include <boost/mpl/begin_end.hpp>
0027 #include <boost/mpl/next.hpp>
0028 #include <boost/mpl/deref.hpp>
0029 #include <cstddef>
0030
0031 namespace boost { namespace python {
0032
0033 namespace detail
0034 {
0035
0036
0037 struct overloads_base
0038 {
0039 overloads_base(char const* doc_)
0040 : m_doc(doc_) {}
0041
0042 overloads_base(char const* doc_, detail::keyword_range const& kw)
0043 : m_doc(doc_), m_keywords(kw) {}
0044
0045 char const* doc_string() const
0046 {
0047 return m_doc;
0048 }
0049
0050 detail::keyword_range const& keywords() const
0051 {
0052 return m_keywords;
0053 }
0054
0055 private:
0056 char const* m_doc;
0057 detail::keyword_range m_keywords;
0058 };
0059
0060
0061
0062 template <class CallPoliciesT, class OverloadsT>
0063 struct overloads_proxy
0064 : public overloads_base
0065 {
0066 typedef typename OverloadsT::non_void_return_type non_void_return_type;
0067 typedef typename OverloadsT::void_return_type void_return_type;
0068
0069 overloads_proxy(
0070 CallPoliciesT const& policies_
0071 , char const* doc
0072 , keyword_range const& kw
0073 )
0074 : overloads_base(doc, kw)
0075 , policies(policies_)
0076 {}
0077
0078 CallPoliciesT
0079 call_policies() const
0080 {
0081 return policies;
0082 }
0083
0084 CallPoliciesT policies;
0085 };
0086
0087
0088
0089
0090
0091 template <class DerivedT>
0092 struct overloads_common
0093 : public overloads_base
0094 {
0095 overloads_common(char const* doc)
0096 : overloads_base(doc) {}
0097
0098 overloads_common(char const* doc, keyword_range const& kw)
0099 : overloads_base(doc, kw) {}
0100
0101 default_call_policies
0102 call_policies() const
0103 {
0104 return default_call_policies();
0105 }
0106
0107 template <class CallPoliciesT>
0108 overloads_proxy<CallPoliciesT, DerivedT>
0109 operator[](CallPoliciesT const& policies) const
0110 {
0111 return overloads_proxy<CallPoliciesT, DerivedT>(
0112 policies, this->doc_string(), this->keywords());
0113 }
0114 };
0115
0116 }}}
0117
0118
0119 #define BOOST_PYTHON_TYPEDEF_GEN(z, index, data) \
0120 typedef typename ::boost::mpl::next<BOOST_PP_CAT(iter, index)>::type \
0121 BOOST_PP_CAT(iter, BOOST_PP_INC(index)); \
0122 typedef typename ::boost::mpl::deref<BOOST_PP_CAT(iter, index)>::type \
0123 BOOST_PP_CAT(T, index);
0124
0125 #define BOOST_PYTHON_FUNC_WRAPPER_GEN(z, index, data) \
0126 static RT BOOST_PP_CAT(func_, \
0127 BOOST_PP_SUB_D(1, index, BOOST_PP_TUPLE_ELEM(3, 1, data))) ( \
0128 BOOST_PP_ENUM_BINARY_PARAMS_Z( \
0129 1, index, T, arg)) \
0130 { \
0131 BOOST_PP_TUPLE_ELEM(3, 2, data) \
0132 BOOST_PP_TUPLE_ELEM(3, 0, data)( \
0133 BOOST_PP_ENUM_PARAMS( \
0134 index, \
0135 arg)); \
0136 }
0137
0138 #define BOOST_PYTHON_GEN_FUNCTION(fname, fstubs_name, n_args, n_dflts, ret) \
0139 struct fstubs_name \
0140 { \
0141 BOOST_STATIC_CONSTANT(int, n_funcs = BOOST_PP_INC(n_dflts)); \
0142 BOOST_STATIC_CONSTANT(int, max_args = n_funcs); \
0143 \
0144 template <typename SigT> \
0145 struct gen \
0146 { \
0147 typedef typename ::boost::mpl::begin<SigT>::type rt_iter; \
0148 typedef typename ::boost::mpl::deref<rt_iter>::type RT; \
0149 typedef typename ::boost::mpl::next<rt_iter>::type iter0; \
0150 \
0151 BOOST_PP_REPEAT_2ND( \
0152 n_args, \
0153 BOOST_PYTHON_TYPEDEF_GEN, \
0154 0) \
0155 \
0156 BOOST_PP_REPEAT_FROM_TO_2( \
0157 BOOST_PP_SUB_D(1, n_args, n_dflts), \
0158 BOOST_PP_INC(n_args), \
0159 BOOST_PYTHON_FUNC_WRAPPER_GEN, \
0160 (fname, BOOST_PP_SUB_D(1, n_args, n_dflts), ret)) \
0161 }; \
0162 }; \
0163
0164
0165 #define BOOST_PYTHON_MEM_FUNC_WRAPPER_GEN(z, index, data) \
0166 static RT BOOST_PP_CAT(func_, \
0167 BOOST_PP_SUB_D(1, index, BOOST_PP_TUPLE_ELEM(3, 1, data))) ( \
0168 ClassT obj BOOST_PP_COMMA_IF(index) \
0169 BOOST_PP_ENUM_BINARY_PARAMS_Z(1, index, T, arg) \
0170 ) \
0171 { \
0172 BOOST_PP_TUPLE_ELEM(3, 2, data) obj.BOOST_PP_TUPLE_ELEM(3, 0, data)( \
0173 BOOST_PP_ENUM_PARAMS(index, arg) \
0174 ); \
0175 }
0176
0177 #define BOOST_PYTHON_GEN_MEM_FUNCTION(fname, fstubs_name, n_args, n_dflts, ret) \
0178 struct fstubs_name \
0179 { \
0180 BOOST_STATIC_CONSTANT(int, n_funcs = BOOST_PP_INC(n_dflts)); \
0181 BOOST_STATIC_CONSTANT(int, max_args = n_funcs + 1); \
0182 \
0183 template <typename SigT> \
0184 struct gen \
0185 { \
0186 typedef typename ::boost::mpl::begin<SigT>::type rt_iter; \
0187 typedef typename ::boost::mpl::deref<rt_iter>::type RT; \
0188 \
0189 typedef typename ::boost::mpl::next<rt_iter>::type class_iter; \
0190 typedef typename ::boost::mpl::deref<class_iter>::type ClassT; \
0191 typedef typename ::boost::mpl::next<class_iter>::type iter0; \
0192 \
0193 BOOST_PP_REPEAT_2ND( \
0194 n_args, \
0195 BOOST_PYTHON_TYPEDEF_GEN, \
0196 0) \
0197 \
0198 BOOST_PP_REPEAT_FROM_TO_2( \
0199 BOOST_PP_SUB_D(1, n_args, n_dflts), \
0200 BOOST_PP_INC(n_args), \
0201 BOOST_PYTHON_MEM_FUNC_WRAPPER_GEN, \
0202 (fname, BOOST_PP_SUB_D(1, n_args, n_dflts), ret)) \
0203 }; \
0204 };
0205
0206 #define BOOST_PYTHON_OVERLOAD_CONSTRUCTORS(fstubs_name, n_args, n_dflts) \
0207 fstubs_name(char const* doc = 0) \
0208 : ::boost::python::detail::overloads_common<fstubs_name>(doc) {} \
0209 template <std::size_t N> \
0210 fstubs_name(char const* doc, ::boost::python::detail::keywords<N> const& keywords) \
0211 : ::boost::python::detail::overloads_common<fstubs_name>( \
0212 doc, keywords.range()) \
0213 { \
0214 typedef typename ::boost::python::detail:: \
0215 error::more_keywords_than_function_arguments< \
0216 N,n_args>::too_many_keywords assertion BOOST_ATTRIBUTE_UNUSED; \
0217 } \
0218 template <std::size_t N> \
0219 fstubs_name(::boost::python::detail::keywords<N> const& keywords, char const* doc = 0) \
0220 : ::boost::python::detail::overloads_common<fstubs_name>( \
0221 doc, keywords.range()) \
0222 { \
0223 typedef typename ::boost::python::detail:: \
0224 error::more_keywords_than_function_arguments< \
0225 N,n_args>::too_many_keywords assertion BOOST_ATTRIBUTE_UNUSED; \
0226 }
0227
0228 # if defined(BOOST_NO_VOID_RETURNS)
0229
0230 # define BOOST_PYTHON_GEN_FUNCTION_STUB(fname, fstubs_name, n_args, n_dflts) \
0231 struct fstubs_name \
0232 : public ::boost::python::detail::overloads_common<fstubs_name> \
0233 { \
0234 BOOST_PYTHON_GEN_FUNCTION( \
0235 fname, non_void_return_type, n_args, n_dflts, return) \
0236 BOOST_PYTHON_GEN_FUNCTION( \
0237 fname, void_return_type, n_args, n_dflts, ;) \
0238 \
0239 BOOST_PYTHON_OVERLOAD_CONSTRUCTORS(fstubs_name, n_args, n_dflts) \
0240 };
0241
0242 # define BOOST_PYTHON_GEN_MEM_FUNCTION_STUB(fname, fstubs_name, n_args, n_dflts) \
0243 struct fstubs_name \
0244 : public ::boost::python::detail::overloads_common<fstubs_name> \
0245 { \
0246 BOOST_PYTHON_GEN_MEM_FUNCTION( \
0247 fname, non_void_return_type, n_args, n_dflts, return) \
0248 BOOST_PYTHON_GEN_MEM_FUNCTION( \
0249 fname, void_return_type, n_args, n_dflts, ;) \
0250 \
0251 BOOST_PYTHON_OVERLOAD_CONSTRUCTORS(fstubs_name, n_args + 1, n_dflts) \
0252 };
0253
0254 # else
0255
0256 # define BOOST_PYTHON_GEN_FUNCTION_STUB(fname, fstubs_name, n_args, n_dflts) \
0257 struct fstubs_name \
0258 : public ::boost::python::detail::overloads_common<fstubs_name> \
0259 { \
0260 BOOST_PYTHON_GEN_FUNCTION( \
0261 fname, non_void_return_type, n_args, n_dflts, return) \
0262 \
0263 typedef non_void_return_type void_return_type; \
0264 BOOST_PYTHON_OVERLOAD_CONSTRUCTORS(fstubs_name, n_args, n_dflts) \
0265 };
0266
0267
0268 # define BOOST_PYTHON_GEN_MEM_FUNCTION_STUB(fname, fstubs_name, n_args, n_dflts) \
0269 struct fstubs_name \
0270 : public ::boost::python::detail::overloads_common<fstubs_name> \
0271 { \
0272 BOOST_PYTHON_GEN_MEM_FUNCTION( \
0273 fname, non_void_return_type, n_args, n_dflts, return) \
0274 \
0275 typedef non_void_return_type void_return_type; \
0276 BOOST_PYTHON_OVERLOAD_CONSTRUCTORS(fstubs_name, n_args + 1, n_dflts) \
0277 };
0278
0279 # endif
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319
0320
0321
0322
0323
0324
0325
0326
0327
0328
0329
0330
0331
0332
0333
0334
0335
0336
0337
0338
0339
0340
0341
0342
0343
0344
0345
0346
0347
0348
0349
0350
0351
0352
0353
0354
0355
0356
0357
0358
0359
0360
0361
0362
0363
0364
0365
0366
0367 #define BOOST_PYTHON_FUNCTION_OVERLOADS(generator_name, fname, min_args, max_args) \
0368 BOOST_PYTHON_GEN_FUNCTION_STUB( \
0369 fname, \
0370 generator_name, \
0371 max_args, \
0372 BOOST_PP_SUB_D(1, max_args, min_args))
0373
0374 #define BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(generator_name, fname, min_args, max_args) \
0375 BOOST_PYTHON_GEN_MEM_FUNCTION_STUB( \
0376 fname, \
0377 generator_name, \
0378 max_args, \
0379 BOOST_PP_SUB_D(1, max_args, min_args))
0380
0381
0382 #define BOOST_PYTHON_FUNCTION_GENERATOR BOOST_PYTHON_FUNCTION_OVERLOADS
0383 #define BOOST_PYTHON_MEM_FUN_GENERATOR BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS
0384
0385
0386 #endif
0387
0388