123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 |
- #if !defined(BOOST_PP_IS_ITERATING)
- #ifndef DEFAULTS_DEF_JDG20020811_HPP
- #define DEFAULTS_DEF_JDG20020811_HPP
- #include <boost/python/detail/defaults_gen.hpp>
- #include <boost/python/detail/type_traits.hpp>
- #include <boost/mpl/front.hpp>
- #include <boost/mpl/size.hpp>
- #include <boost/static_assert.hpp>
- #include <boost/preprocessor/iterate.hpp>
- #include <boost/python/class_fwd.hpp>
- #include <boost/python/scope.hpp>
- #include <boost/preprocessor/debug/line.hpp>
- #include <boost/python/detail/scope.hpp>
- #include <boost/python/detail/make_keyword_range_fn.hpp>
- #include <boost/python/object/add_to_namespace.hpp>
- namespace boost { namespace python {
- struct module;
- namespace objects
- {
- struct class_base;
- }
- namespace detail
- {
-
-
-
-
-
-
-
- template <class Func, class CallPolicies, class NameSpaceT>
- static void name_space_def(
- NameSpaceT& name_space
- , char const* name
- , Func f
- , keyword_range const& kw
- , CallPolicies const& policies
- , char const* doc
- , objects::class_base*
- )
- {
- typedef typename NameSpaceT::wrapped_type wrapped_type;
-
- objects::add_to_namespace(
- name_space, name,
- detail::make_keyword_range_function(
- f, policies, kw, get_signature(f, (wrapped_type*)0))
- , doc
- );
- }
- template <class Func, class CallPolicies>
- static void name_space_def(
- object& name_space
- , char const* name
- , Func f
- , keyword_range const& kw
- , CallPolicies const& policies
- , char const* doc
- , ...
- )
- {
- scope within(name_space);
- detail::scope_setattr_doc(
- name
- , detail::make_keyword_range_function(f, policies, kw)
- , doc);
- }
-
- template <class Func, class CallPolicies, class NameSpaceT>
- static void name_space_def(
- NameSpaceT& name_space
- , char const* name
- , Func f
- , keyword_range const& kw
- , CallPolicies const& policies
- , char const* doc
- , module*
- )
- {
- name_space.def(name, f, policies, doc);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- template <int N>
- struct define_stub_function {};
- #define BOOST_PP_ITERATION_PARAMS_1 \
- (3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/detail/defaults_def.hpp>))
- #include BOOST_PP_ITERATE()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- template <int N>
- struct define_with_defaults_helper {
- template <class StubsT, class CallPolicies, class NameSpaceT>
- static void
- def(
- char const* name,
- StubsT stubs,
- keyword_range kw,
- CallPolicies const& policies,
- NameSpaceT& name_space,
- char const* doc)
- {
-
- define_stub_function<N>::define(name, stubs, kw, policies, name_space, doc);
- if (kw.second > kw.first)
- --kw.second;
-
- define_with_defaults_helper<N-1>::def(name, stubs, kw, policies, name_space, doc);
- }
- };
- template <>
- struct define_with_defaults_helper<0> {
- template <class StubsT, class CallPolicies, class NameSpaceT>
- static void
- def(
- char const* name,
- StubsT stubs,
- keyword_range const& kw,
- CallPolicies const& policies,
- NameSpaceT& name_space,
- char const* doc)
- {
-
- define_stub_function<0>::define(name, stubs, kw, policies, name_space, doc);
-
- }
- };
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- template <class OverloadsT, class NameSpaceT, class SigT>
- inline void
- define_with_defaults(
- char const* name,
- OverloadsT const& overloads,
- NameSpaceT& name_space,
- SigT const&)
- {
- typedef typename mpl::front<SigT>::type return_type;
- typedef typename OverloadsT::void_return_type void_return_type;
- typedef typename OverloadsT::non_void_return_type non_void_return_type;
- typedef typename mpl::if_c<
- is_same<void, return_type>::value
- , void_return_type
- , non_void_return_type
- >::type stubs_type;
- BOOST_STATIC_ASSERT(
- (stubs_type::max_args) <= mpl::size<SigT>::value);
- typedef typename stubs_type::template gen<SigT> gen_type;
- define_with_defaults_helper<stubs_type::n_funcs-1>::def(
- name
- , gen_type()
- , overloads.keywords()
- , overloads.call_policies()
- , name_space
- , overloads.doc_string());
- }
- }
- }}
- #endif
- #else
- template <>
- struct define_stub_function<BOOST_PP_ITERATION()> {
- template <class StubsT, class CallPolicies, class NameSpaceT>
- static void define(
- char const* name
- , StubsT const&
- , keyword_range const& kw
- , CallPolicies const& policies
- , NameSpaceT& name_space
- , char const* doc)
- {
- detail::name_space_def(
- name_space
- , name
- , &StubsT::BOOST_PP_CAT(func_, BOOST_PP_ITERATION())
- , kw
- , policies
- , doc
- , &name_space);
- }
- };
- #endif
|