File indexing completed on 2025-01-18 09:50:37
0001
0002
0003
0004
0005
0006
0007
0008
0009 #if !defined(BOOST_PP_IS_ITERATING)
0010
0011 #ifndef DEFAULTS_DEF_JDG20020811_HPP
0012 #define DEFAULTS_DEF_JDG20020811_HPP
0013
0014 #include <boost/python/detail/defaults_gen.hpp>
0015 #include <boost/python/detail/type_traits.hpp>
0016 #include <boost/mpl/front.hpp>
0017 #include <boost/mpl/size.hpp>
0018 #include <boost/static_assert.hpp>
0019 #include <boost/preprocessor/iterate.hpp>
0020 #include <boost/python/class_fwd.hpp>
0021 #include <boost/python/scope.hpp>
0022 #include <boost/preprocessor/debug/line.hpp>
0023 #include <boost/python/detail/scope.hpp>
0024 #include <boost/python/detail/make_keyword_range_fn.hpp>
0025 #include <boost/python/object/add_to_namespace.hpp>
0026
0027
0028 namespace boost { namespace python {
0029
0030 struct module;
0031
0032 namespace objects
0033 {
0034 struct class_base;
0035 }
0036
0037 namespace detail
0038 {
0039
0040
0041
0042
0043
0044
0045
0046 template <class Func, class CallPolicies, class NameSpaceT>
0047 static void name_space_def(
0048 NameSpaceT& name_space
0049 , char const* name
0050 , Func f
0051 , keyword_range const& kw
0052 , CallPolicies const& policies
0053 , char const* doc
0054 , objects::class_base*
0055 )
0056 {
0057 typedef typename NameSpaceT::wrapped_type wrapped_type;
0058
0059 objects::add_to_namespace(
0060 name_space, name,
0061 detail::make_keyword_range_function(
0062 f, policies, kw, get_signature(f, (wrapped_type*)0))
0063 , doc
0064 );
0065 }
0066
0067 template <class Func, class CallPolicies>
0068 static void name_space_def(
0069 object& name_space
0070 , char const* name
0071 , Func f
0072 , keyword_range const& kw
0073 , CallPolicies const& policies
0074 , char const* doc
0075 , ...
0076 )
0077 {
0078 scope within(name_space);
0079
0080 detail::scope_setattr_doc(
0081 name
0082 , detail::make_keyword_range_function(f, policies, kw)
0083 , doc);
0084 }
0085
0086
0087 template <class Func, class CallPolicies, class NameSpaceT>
0088 static void name_space_def(
0089 NameSpaceT& name_space
0090 , char const* name
0091 , Func f
0092 , keyword_range const& kw
0093 , CallPolicies const& policies
0094 , char const* doc
0095 , module*
0096 )
0097 {
0098 name_space.def(name, f, policies, doc);
0099 }
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125 template <int N>
0126 struct define_stub_function {};
0127
0128 #define BOOST_PP_ITERATION_PARAMS_1 \
0129 (3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/detail/defaults_def.hpp>))
0130
0131 #include BOOST_PP_ITERATE()
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157 template <int N>
0158 struct define_with_defaults_helper {
0159
0160 template <class StubsT, class CallPolicies, class NameSpaceT>
0161 static void
0162 def(
0163 char const* name,
0164 StubsT stubs,
0165 keyword_range kw,
0166 CallPolicies const& policies,
0167 NameSpaceT& name_space,
0168 char const* doc)
0169 {
0170
0171 define_stub_function<N>::define(name, stubs, kw, policies, name_space, doc);
0172
0173 if (kw.second > kw.first)
0174 --kw.second;
0175
0176
0177 define_with_defaults_helper<N-1>::def(name, stubs, kw, policies, name_space, doc);
0178 }
0179 };
0180
0181 template <>
0182 struct define_with_defaults_helper<0> {
0183
0184 template <class StubsT, class CallPolicies, class NameSpaceT>
0185 static void
0186 def(
0187 char const* name,
0188 StubsT stubs,
0189 keyword_range const& kw,
0190 CallPolicies const& policies,
0191 NameSpaceT& name_space,
0192 char const* doc)
0193 {
0194
0195 define_stub_function<0>::define(name, stubs, kw, policies, name_space, doc);
0196
0197 }
0198 };
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228 template <class OverloadsT, class NameSpaceT, class SigT>
0229 inline void
0230 define_with_defaults(
0231 char const* name,
0232 OverloadsT const& overloads,
0233 NameSpaceT& name_space,
0234 SigT const&)
0235 {
0236 typedef typename mpl::front<SigT>::type return_type;
0237 typedef typename OverloadsT::void_return_type void_return_type;
0238 typedef typename OverloadsT::non_void_return_type non_void_return_type;
0239
0240 typedef typename mpl::if_c<
0241 is_same<void, return_type>::value
0242 , void_return_type
0243 , non_void_return_type
0244 >::type stubs_type;
0245
0246 BOOST_STATIC_ASSERT(
0247 (stubs_type::max_args) <= mpl::size<SigT>::value);
0248
0249 typedef typename stubs_type::template gen<SigT> gen_type;
0250 define_with_defaults_helper<stubs_type::n_funcs-1>::def(
0251 name
0252 , gen_type()
0253 , overloads.keywords()
0254 , overloads.call_policies()
0255 , name_space
0256 , overloads.doc_string());
0257 }
0258
0259 }
0260
0261 }}
0262
0263 #endif
0264
0265 #else
0266
0267
0268
0269 template <>
0270 struct define_stub_function<BOOST_PP_ITERATION()> {
0271 template <class StubsT, class CallPolicies, class NameSpaceT>
0272 static void define(
0273 char const* name
0274 , StubsT const&
0275 , keyword_range const& kw
0276 , CallPolicies const& policies
0277 , NameSpaceT& name_space
0278 , char const* doc)
0279 {
0280 detail::name_space_def(
0281 name_space
0282 , name
0283 , &StubsT::BOOST_PP_CAT(func_, BOOST_PP_ITERATION())
0284 , kw
0285 , policies
0286 , doc
0287 , &name_space);
0288 }
0289 };
0290
0291 #endif