123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388 |
- #ifndef DEFAULTS_GEN_JDG20020807_HPP
- #define DEFAULTS_GEN_JDG20020807_HPP
- #include <boost/python/detail/preprocessor.hpp>
- #include <boost/preprocessor/repeat.hpp>
- #include <boost/preprocessor/repeat_from_to.hpp>
- #include <boost/preprocessor/enum.hpp>
- #include <boost/preprocessor/enum_params.hpp>
- #include <boost/preprocessor/repetition/enum_binary_params.hpp>
- #include <boost/preprocessor/tuple.hpp>
- #include <boost/preprocessor/cat.hpp>
- #include <boost/preprocessor/arithmetic/sub.hpp>
- #include <boost/preprocessor/stringize.hpp>
- #include <boost/preprocessor/inc.hpp>
- #include <boost/preprocessor/empty.hpp>
- #include <boost/preprocessor/comma_if.hpp>
- #include <boost/config.hpp>
- #include <boost/mpl/begin_end.hpp>
- #include <boost/mpl/next.hpp>
- #include <boost/mpl/deref.hpp>
- #include <cstddef>
- namespace boost { namespace python {
- namespace detail
- {
-
-
- struct overloads_base
- {
- overloads_base(char const* doc_)
- : m_doc(doc_) {}
- overloads_base(char const* doc_, detail::keyword_range const& kw)
- : m_doc(doc_), m_keywords(kw) {}
- char const* doc_string() const
- {
- return m_doc;
- }
- detail::keyword_range const& keywords() const
- {
- return m_keywords;
- }
- private:
- char const* m_doc;
- detail::keyword_range m_keywords;
- };
-
-
- template <class CallPoliciesT, class OverloadsT>
- struct overloads_proxy
- : public overloads_base
- {
- typedef typename OverloadsT::non_void_return_type non_void_return_type;
- typedef typename OverloadsT::void_return_type void_return_type;
- overloads_proxy(
- CallPoliciesT const& policies_
- , char const* doc
- , keyword_range const& kw
- )
- : overloads_base(doc, kw)
- , policies(policies_)
- {}
- CallPoliciesT
- call_policies() const
- {
- return policies;
- }
- CallPoliciesT policies;
- };
-
-
-
-
- template <class DerivedT>
- struct overloads_common
- : public overloads_base
- {
- overloads_common(char const* doc)
- : overloads_base(doc) {}
- overloads_common(char const* doc, keyword_range const& kw)
- : overloads_base(doc, kw) {}
- default_call_policies
- call_policies() const
- {
- return default_call_policies();
- }
- template <class CallPoliciesT>
- overloads_proxy<CallPoliciesT, DerivedT>
- operator[](CallPoliciesT const& policies) const
- {
- return overloads_proxy<CallPoliciesT, DerivedT>(
- policies, this->doc_string(), this->keywords());
- }
- };
- }}}
- #define BOOST_PYTHON_TYPEDEF_GEN(z, index, data) \
- typedef typename ::boost::mpl::next<BOOST_PP_CAT(iter, index)>::type \
- BOOST_PP_CAT(iter, BOOST_PP_INC(index)); \
- typedef typename ::boost::mpl::deref<BOOST_PP_CAT(iter, index)>::type \
- BOOST_PP_CAT(T, index);
- #define BOOST_PYTHON_FUNC_WRAPPER_GEN(z, index, data) \
- static RT BOOST_PP_CAT(func_, \
- BOOST_PP_SUB_D(1, index, BOOST_PP_TUPLE_ELEM(3, 1, data))) ( \
- BOOST_PP_ENUM_BINARY_PARAMS_Z( \
- 1, index, T, arg)) \
- { \
- BOOST_PP_TUPLE_ELEM(3, 2, data) \
- BOOST_PP_TUPLE_ELEM(3, 0, data)( \
- BOOST_PP_ENUM_PARAMS( \
- index, \
- arg)); \
- }
- #define BOOST_PYTHON_GEN_FUNCTION(fname, fstubs_name, n_args, n_dflts, ret) \
- struct fstubs_name \
- { \
- BOOST_STATIC_CONSTANT(int, n_funcs = BOOST_PP_INC(n_dflts)); \
- BOOST_STATIC_CONSTANT(int, max_args = n_funcs); \
- \
- template <typename SigT> \
- struct gen \
- { \
- typedef typename ::boost::mpl::begin<SigT>::type rt_iter; \
- typedef typename ::boost::mpl::deref<rt_iter>::type RT; \
- typedef typename ::boost::mpl::next<rt_iter>::type iter0; \
- \
- BOOST_PP_REPEAT_2ND( \
- n_args, \
- BOOST_PYTHON_TYPEDEF_GEN, \
- 0) \
- \
- BOOST_PP_REPEAT_FROM_TO_2( \
- BOOST_PP_SUB_D(1, n_args, n_dflts), \
- BOOST_PP_INC(n_args), \
- BOOST_PYTHON_FUNC_WRAPPER_GEN, \
- (fname, BOOST_PP_SUB_D(1, n_args, n_dflts), ret)) \
- }; \
- }; \
- #define BOOST_PYTHON_MEM_FUNC_WRAPPER_GEN(z, index, data) \
- static RT BOOST_PP_CAT(func_, \
- BOOST_PP_SUB_D(1, index, BOOST_PP_TUPLE_ELEM(3, 1, data))) ( \
- ClassT obj BOOST_PP_COMMA_IF(index) \
- BOOST_PP_ENUM_BINARY_PARAMS_Z(1, index, T, arg) \
- ) \
- { \
- BOOST_PP_TUPLE_ELEM(3, 2, data) obj.BOOST_PP_TUPLE_ELEM(3, 0, data)( \
- BOOST_PP_ENUM_PARAMS(index, arg) \
- ); \
- }
- #define BOOST_PYTHON_GEN_MEM_FUNCTION(fname, fstubs_name, n_args, n_dflts, ret) \
- struct fstubs_name \
- { \
- BOOST_STATIC_CONSTANT(int, n_funcs = BOOST_PP_INC(n_dflts)); \
- BOOST_STATIC_CONSTANT(int, max_args = n_funcs + 1); \
- \
- template <typename SigT> \
- struct gen \
- { \
- typedef typename ::boost::mpl::begin<SigT>::type rt_iter; \
- typedef typename ::boost::mpl::deref<rt_iter>::type RT; \
- \
- typedef typename ::boost::mpl::next<rt_iter>::type class_iter; \
- typedef typename ::boost::mpl::deref<class_iter>::type ClassT; \
- typedef typename ::boost::mpl::next<class_iter>::type iter0; \
- \
- BOOST_PP_REPEAT_2ND( \
- n_args, \
- BOOST_PYTHON_TYPEDEF_GEN, \
- 0) \
- \
- BOOST_PP_REPEAT_FROM_TO_2( \
- BOOST_PP_SUB_D(1, n_args, n_dflts), \
- BOOST_PP_INC(n_args), \
- BOOST_PYTHON_MEM_FUNC_WRAPPER_GEN, \
- (fname, BOOST_PP_SUB_D(1, n_args, n_dflts), ret)) \
- }; \
- };
- #define BOOST_PYTHON_OVERLOAD_CONSTRUCTORS(fstubs_name, n_args, n_dflts) \
- fstubs_name(char const* doc = 0) \
- : ::boost::python::detail::overloads_common<fstubs_name>(doc) {} \
- template <std::size_t N> \
- fstubs_name(char const* doc, ::boost::python::detail::keywords<N> const& keywords) \
- : ::boost::python::detail::overloads_common<fstubs_name>( \
- doc, keywords.range()) \
- { \
- typedef typename ::boost::python::detail:: \
- error::more_keywords_than_function_arguments< \
- N,n_args>::too_many_keywords assertion BOOST_ATTRIBUTE_UNUSED; \
- } \
- template <std::size_t N> \
- fstubs_name(::boost::python::detail::keywords<N> const& keywords, char const* doc = 0) \
- : ::boost::python::detail::overloads_common<fstubs_name>( \
- doc, keywords.range()) \
- { \
- typedef typename ::boost::python::detail:: \
- error::more_keywords_than_function_arguments< \
- N,n_args>::too_many_keywords assertion BOOST_ATTRIBUTE_UNUSED; \
- }
- # if defined(BOOST_NO_VOID_RETURNS)
- # define BOOST_PYTHON_GEN_FUNCTION_STUB(fname, fstubs_name, n_args, n_dflts) \
- struct fstubs_name \
- : public ::boost::python::detail::overloads_common<fstubs_name> \
- { \
- BOOST_PYTHON_GEN_FUNCTION( \
- fname, non_void_return_type, n_args, n_dflts, return) \
- BOOST_PYTHON_GEN_FUNCTION( \
- fname, void_return_type, n_args, n_dflts, ;) \
- \
- BOOST_PYTHON_OVERLOAD_CONSTRUCTORS(fstubs_name, n_args, n_dflts) \
- };
- # define BOOST_PYTHON_GEN_MEM_FUNCTION_STUB(fname, fstubs_name, n_args, n_dflts) \
- struct fstubs_name \
- : public ::boost::python::detail::overloads_common<fstubs_name> \
- { \
- BOOST_PYTHON_GEN_MEM_FUNCTION( \
- fname, non_void_return_type, n_args, n_dflts, return) \
- BOOST_PYTHON_GEN_MEM_FUNCTION( \
- fname, void_return_type, n_args, n_dflts, ;) \
- \
- BOOST_PYTHON_OVERLOAD_CONSTRUCTORS(fstubs_name, n_args + 1, n_dflts) \
- };
- # else
- # define BOOST_PYTHON_GEN_FUNCTION_STUB(fname, fstubs_name, n_args, n_dflts) \
- struct fstubs_name \
- : public ::boost::python::detail::overloads_common<fstubs_name> \
- { \
- BOOST_PYTHON_GEN_FUNCTION( \
- fname, non_void_return_type, n_args, n_dflts, return) \
- \
- typedef non_void_return_type void_return_type; \
- BOOST_PYTHON_OVERLOAD_CONSTRUCTORS(fstubs_name, n_args, n_dflts) \
- };
- # define BOOST_PYTHON_GEN_MEM_FUNCTION_STUB(fname, fstubs_name, n_args, n_dflts) \
- struct fstubs_name \
- : public ::boost::python::detail::overloads_common<fstubs_name> \
- { \
- BOOST_PYTHON_GEN_MEM_FUNCTION( \
- fname, non_void_return_type, n_args, n_dflts, return) \
- \
- typedef non_void_return_type void_return_type; \
- BOOST_PYTHON_OVERLOAD_CONSTRUCTORS(fstubs_name, n_args + 1, n_dflts) \
- };
- # endif
- #define BOOST_PYTHON_FUNCTION_OVERLOADS(generator_name, fname, min_args, max_args) \
- BOOST_PYTHON_GEN_FUNCTION_STUB( \
- fname, \
- generator_name, \
- max_args, \
- BOOST_PP_SUB_D(1, max_args, min_args))
- #define BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(generator_name, fname, min_args, max_args) \
- BOOST_PYTHON_GEN_MEM_FUNCTION_STUB( \
- fname, \
- generator_name, \
- max_args, \
- BOOST_PP_SUB_D(1, max_args, min_args))
- #define BOOST_PYTHON_FUNCTION_GENERATOR BOOST_PYTHON_FUNCTION_OVERLOADS
- #define BOOST_PYTHON_MEM_FUN_GENERATOR BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS
- #endif
|