From eb6994e6b46aebbf31c425ca5292c6e92fce2fa2 Mon Sep 17 00:00:00 2001 From: Joel de Guzman Date: Mon, 30 Sep 2002 07:18:46 +0000 Subject: [PATCH] Removing BPL V1 Artifacts [SVN r15569] --- include/boost/python/args.hpp | 122 +- include/boost/python/callback.hpp | 829 ----------- include/boost/python/caller.hpp | 1279 ----------------- include/boost/python/class.hpp | 164 ++- include/boost/python/class_builder.hpp | 182 --- include/boost/python/class_fwd.hpp | 7 - include/boost/python/classes.hpp | 677 --------- include/boost/python/conversions.hpp | 415 ------ .../python/converter/return_from_python.hpp | 3 +- include/boost/python/cross_module.hpp | 329 ----- include/boost/python/def.hpp | 64 +- include/boost/python/detail/base_object.hpp | 60 - include/boost/python/detail/cast.hpp | 81 -- include/boost/python/detail/config.hpp | 9 - include/boost/python/detail/def_helper.hpp | 192 ++- include/boost/python/detail/defaults_def.hpp | 225 +-- include/boost/python/detail/defaults_gen.hpp | 308 ++-- .../boost/python/detail/extension_class.hpp | 1002 ------------- include/boost/python/detail/functions.hpp | 311 ---- .../boost/python/detail/indirect_traits.hpp | 9 +- include/boost/python/detail/init_function.hpp | 562 -------- include/boost/python/detail/msvc_typeinfo.hpp | 2 +- include/boost/python/detail/signatures.hpp | 251 ---- include/boost/python/detail/singleton.hpp | 68 - include/boost/python/detail/void_adaptor.hpp | 39 - include/boost/python/dict.hpp | 2 +- include/boost/python/init.hpp | 203 ++- include/boost/python/list.hpp | 2 +- include/boost/python/long.hpp | 2 +- include/boost/python/make_function.hpp | 15 + include/boost/python/module.hpp | 7 +- include/boost/python/object/function.hpp | 16 +- .../boost/python/object/function_object.hpp | 33 +- include/boost/python/object_core.hpp | 14 +- include/boost/python/signature.hpp | 12 +- include/boost/python/str.hpp | 2 +- include/boost/python/tuple.hpp | 2 +- include/boost/python/type_id.hpp | 2 +- 38 files changed, 899 insertions(+), 6603 deletions(-) delete mode 100644 include/boost/python/callback.hpp delete mode 100644 include/boost/python/caller.hpp delete mode 100644 include/boost/python/class_builder.hpp delete mode 100644 include/boost/python/classes.hpp delete mode 100644 include/boost/python/conversions.hpp delete mode 100644 include/boost/python/cross_module.hpp delete mode 100644 include/boost/python/detail/base_object.hpp delete mode 100644 include/boost/python/detail/cast.hpp delete mode 100644 include/boost/python/detail/extension_class.hpp delete mode 100644 include/boost/python/detail/functions.hpp delete mode 100644 include/boost/python/detail/init_function.hpp delete mode 100644 include/boost/python/detail/signatures.hpp delete mode 100644 include/boost/python/detail/singleton.hpp delete mode 100644 include/boost/python/detail/void_adaptor.hpp diff --git a/include/boost/python/args.hpp b/include/boost/python/args.hpp index e488f3d8..4e2e922b 100644 --- a/include/boost/python/args.hpp +++ b/include/boost/python/args.hpp @@ -3,33 +3,117 @@ // copyright notice appears in all copies. This software is provided // "as is" without express or implied warranty, and with no claim as // to its suitability for any purpose. -#ifndef ARGS_DWA2002323_HPP -# define ARGS_DWA2002323_HPP -# include -# include -# include -# include +#ifndef KEYWORDS_DWA2002323_HPP +# define KEYWORDS_DWA2002323_HPP + +# include +# include +# include +# include +# include + +# include +# include +# include + +# include +# include +# include +# include + +# include +# include + +# include +# include + namespace boost { namespace python { -enum no_init_t { no_init }; - namespace detail { - template - struct args_base {}; + struct keyword + { + char const* name; + handle<> default_value; + }; + + template + struct keywords + { + BOOST_STATIC_CONSTANT(std::size_t, size = nkeywords); + + keyword_range range() const + { + return keyword_range(elements, elements + nkeywords); + } + + keyword elements[nkeywords]; + }; + +# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + template + struct is_keywords + { + BOOST_STATIC_CONSTANT(bool, value = false); + }; + + template + struct is_keywords > + { + BOOST_STATIC_CONSTANT(bool, value = true); + }; + template + struct is_reference_to_keywords + { + BOOST_STATIC_CONSTANT(bool, is_ref = is_reference::value); + typedef typename remove_reference::type deref; + typedef typename remove_cv::type key_t; + BOOST_STATIC_CONSTANT(bool, is_key = is_keywords::value); + BOOST_STATIC_CONSTANT(bool, value = (is_ref & is_key)); + + typedef mpl::bool_c type; + BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_keywords,(T)) + }; +# else + typedef char (&yes_keywords_t)[1]; + typedef char (&no_keywords_t)[2]; + + no_keywords_t is_keywords_test(...); + + template + yes_keywords_t is_keywords_test(void (*)(keywords&)); + + template + yes_keywords_t is_keywords_test(void (*)(keywords const&)); + + template + class is_reference_to_keywords + { + public: + BOOST_STATIC_CONSTANT( + bool, value = ( + sizeof(detail::is_keywords_test( (void (*)(T))0 )) + == sizeof(detail::yes_keywords_t))); + + typedef mpl::bool_c type; + BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_keywords,(T)) + }; +# endif } -}} -namespace boost { namespace python { - -// A type list for specifying arguments -template < BOOST_PYTHON_ENUM_WITH_DEFAULT(BOOST_PYTHON_MAX_ARITY, typename A, mpl::void_) > -struct args : detail::args_base > - , detail::type_list< BOOST_PP_ENUM_PARAMS_Z(1, BOOST_PYTHON_MAX_ARITY, A) >::type -{}; +# define BOOST_PYTHON_ASSIGN_NAME(z, n, _) result.elements[n].name = name##n; +# define BOOST_PP_LOCAL_MACRO(n) \ +inline detail::keywords args(BOOST_PP_ENUM_PARAMS_Z(1, n, char const* name)) \ +{ \ + detail::keywords result; \ + BOOST_PP_REPEAT_1(n, BOOST_PYTHON_ASSIGN_NAME, _) \ + return result; \ +} +# define BOOST_PP_LOCAL_LIMITS (1, BOOST_PYTHON_MAX_ARITY) +# include BOOST_PP_LOCAL_ITERATE() }} // namespace boost::python -# endif // ARGS_DWA2002323_HPP +# endif // KEYWORDS_DWA2002323_HPP diff --git a/include/boost/python/callback.hpp b/include/boost/python/callback.hpp deleted file mode 100644 index 7240b5b7..00000000 --- a/include/boost/python/callback.hpp +++ /dev/null @@ -1,829 +0,0 @@ -// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and -// distribute this software is granted provided this copyright notice appears -// in all copies. This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// The author gratefully acknowleges the support of Dragon Systems, Inc., in -// producing this work. -// -// This file was generated for 10-argument python callbacks by gen_callback.python - -#ifndef CALLBACK_DWA_052100_H_ -# define CALLBACK_DWA_052100_H_ - -# include -# include - -namespace boost { namespace python { - -namespace detail { - template - inline void callback_adjust_refcount(PyObject*, type) {} - - inline void callback_adjust_refcount(PyObject* p, type) - { Py_INCREF(p); } -} - -// Calling Python from C++ -template -struct callback -{ - static R call_method(PyObject* self, const char* name) - { - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("()"))); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - static R call(PyObject* self) - { - ref result(PyEval_CallFunction(self, const_cast("()"))); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call_method(PyObject* self, const char* name, const A1& a1) - { - ref p1(to_python(a1)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(O)"), - p1.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call(PyObject* self, const A1& a1) - { - ref p1(to_python(a1)); - ref result(PyEval_CallFunction(self, const_cast("(O)"), - p1.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call_method(PyObject* self, const char* name, const A1& a1, const A2& a2) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(OO)"), - p1.get(), - p2.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call(PyObject* self, const A1& a1, const A2& a2) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref result(PyEval_CallFunction(self, const_cast("(OO)"), - p1.get(), - p2.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(OOO)"), - p1.get(), - p2.get(), - p3.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call(PyObject* self, const A1& a1, const A2& a2, const A3& a3) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref result(PyEval_CallFunction(self, const_cast("(OOO)"), - p1.get(), - p2.get(), - p3.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(OOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref result(PyEval_CallFunction(self, const_cast("(OOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(OOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref result(PyEval_CallFunction(self, const_cast("(OOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(OOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref result(PyEval_CallFunction(self, const_cast("(OOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref p7(to_python(a7)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(OOOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get(), - p7.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref p7(to_python(a7)); - ref result(PyEval_CallFunction(self, const_cast("(OOOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get(), - p7.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref p7(to_python(a7)); - ref p8(to_python(a8)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(OOOOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get(), - p7.get(), - p8.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref p7(to_python(a7)); - ref p8(to_python(a8)); - ref result(PyEval_CallFunction(self, const_cast("(OOOOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get(), - p7.get(), - p8.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref p7(to_python(a7)); - ref p8(to_python(a8)); - ref p9(to_python(a9)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(OOOOOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get(), - p7.get(), - p8.get(), - p9.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref p7(to_python(a7)); - ref p8(to_python(a8)); - ref p9(to_python(a9)); - ref result(PyEval_CallFunction(self, const_cast("(OOOOOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get(), - p7.get(), - p8.get(), - p9.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, const A10& a10) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref p7(to_python(a7)); - ref p8(to_python(a8)); - ref p9(to_python(a9)); - ref p10(to_python(a10)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(OOOOOOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get(), - p7.get(), - p8.get(), - p9.get(), - p10.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, const A10& a10) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref p7(to_python(a7)); - ref p8(to_python(a8)); - ref p9(to_python(a9)); - ref p10(to_python(a10)); - ref result(PyEval_CallFunction(self, const_cast("(OOOOOOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get(), - p7.get(), - p8.get(), - p9.get(), - p10.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } -}; - -// This specialization wouldn't be needed, but MSVC6 doesn't correctly allow the following: -// void g(); -// void f() { return g(); } -template <> -struct callback -{ - - static void call_method(PyObject* self, const char* name) - { - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("()"))); - } - - static void call(PyObject* self) - { - ref result(PyEval_CallFunction(self, const_cast("()"))); - } - - template - static void call_method(PyObject* self, const char* name, const A1& a1) - { - ref p1(to_python(a1)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(O)"), - p1.get())); - } - - template - static void call(PyObject* self, const A1& a1) - { - ref p1(to_python(a1)); - ref result(PyEval_CallFunction(self, const_cast("(O)"), - p1.get())); - } - - template - static void call_method(PyObject* self, const char* name, const A1& a1, const A2& a2) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(OO)"), - p1.get(), - p2.get())); - } - - template - static void call(PyObject* self, const A1& a1, const A2& a2) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref result(PyEval_CallFunction(self, const_cast("(OO)"), - p1.get(), - p2.get())); - } - - template - static void call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(OOO)"), - p1.get(), - p2.get(), - p3.get())); - } - - template - static void call(PyObject* self, const A1& a1, const A2& a2, const A3& a3) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref result(PyEval_CallFunction(self, const_cast("(OOO)"), - p1.get(), - p2.get(), - p3.get())); - } - - template - static void call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(OOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get())); - } - - template - static void call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref result(PyEval_CallFunction(self, const_cast("(OOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get())); - } - - template - static void call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(OOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get())); - } - - template - static void call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref result(PyEval_CallFunction(self, const_cast("(OOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get())); - } - - template - static void call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(OOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get())); - } - - template - static void call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref result(PyEval_CallFunction(self, const_cast("(OOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get())); - } - - template - static void call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref p7(to_python(a7)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(OOOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get(), - p7.get())); - } - - template - static void call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref p7(to_python(a7)); - ref result(PyEval_CallFunction(self, const_cast("(OOOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get(), - p7.get())); - } - - template - static void call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref p7(to_python(a7)); - ref p8(to_python(a8)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(OOOOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get(), - p7.get(), - p8.get())); - } - - template - static void call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref p7(to_python(a7)); - ref p8(to_python(a8)); - ref result(PyEval_CallFunction(self, const_cast("(OOOOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get(), - p7.get(), - p8.get())); - } - - template - static void call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref p7(to_python(a7)); - ref p8(to_python(a8)); - ref p9(to_python(a9)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(OOOOOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get(), - p7.get(), - p8.get(), - p9.get())); - } - - template - static void call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref p7(to_python(a7)); - ref p8(to_python(a8)); - ref p9(to_python(a9)); - ref result(PyEval_CallFunction(self, const_cast("(OOOOOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get(), - p7.get(), - p8.get(), - p9.get())); - } - - template - static void call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, const A10& a10) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref p7(to_python(a7)); - ref p8(to_python(a8)); - ref p9(to_python(a9)); - ref p10(to_python(a10)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(OOOOOOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get(), - p7.get(), - p8.get(), - p9.get(), - p10.get())); - } - - template - static void call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, const A10& a10) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref p7(to_python(a7)); - ref p8(to_python(a8)); - ref p9(to_python(a9)); - ref p10(to_python(a10)); - ref result(PyEval_CallFunction(self, const_cast("(OOOOOOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get(), - p7.get(), - p8.get(), - p9.get(), - p10.get())); - } -}; - -// Make it a compile-time error to try to return a const char* from a virtual -// function. The standard conversion -// -// from_python(PyObject* string, boost::python::type) -// -// returns a pointer to the character array which is internal to string. The -// problem with trying to do this in a standard callback function is that the -// Python string would likely be destroyed upon return from the calling function -// (boost::python::callback::call[_method]) when its reference count is -// decremented. If you absolutely need to do this and you're sure it's safe (it -// usually isn't), you can use -// -// boost::python::string result(boost::python::callback::call[_method](...args...)); -// ...result.c_str()... // access the char* array -template <> -struct callback -{ - // Try hard to generate a readable error message - typedef struct unsafe_since_python_string_may_be_destroyed {} call, call_method; -}; - -}} // namespace boost::python - -#endif // CALLBACK_DWA_052100_H_ diff --git a/include/boost/python/caller.hpp b/include/boost/python/caller.hpp deleted file mode 100644 index 35b2d618..00000000 --- a/include/boost/python/caller.hpp +++ /dev/null @@ -1,1279 +0,0 @@ -// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and -// distribute this software is granted provided this copyright notice appears -// in all copies. This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// The author gratefully acknowleges the support of Dragon Systems, Inc., in -// producing this work. -// -// This file generated for 10-argument member functions and 11-argument free -// functions by gen_caller.python - -#ifndef CALLER_DWA05090_H_ -# define CALLER_DWA05090_H_ - -# include -# include -# include -# include -# include - -namespace boost { namespace python { - -// Calling C++ from Python -template -struct caller -{ - template - static PyObject* call(R (T::*pmf)(), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - if (!PyArg_ParseTuple(args, const_cast("O"), &self)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)()); - } - - template - static PyObject* call(R (T::*pmf)(A1), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - if (!PyArg_ParseTuple(args, const_cast("OO"), &self, &a1)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()))); - } - - template - static PyObject* call(R (T::*pmf)(A1, A2), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - if (!PyArg_ParseTuple(args, const_cast("OOO"), &self, &a1, &a2)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()), - from_python(a2, type()))); - } - - template - static PyObject* call(R (T::*pmf)(A1, A2, A3), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - if (!PyArg_ParseTuple(args, const_cast("OOOO"), &self, &a1, &a2, &a3)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()))); - } - - template - static PyObject* call(R (T::*pmf)(A1, A2, A3, A4), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - if (!PyArg_ParseTuple(args, const_cast("OOOOO"), &self, &a1, &a2, &a3, &a4)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()))); - } - - template - static PyObject* call(R (T::*pmf)(A1, A2, A3, A4, A5), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - if (!PyArg_ParseTuple(args, const_cast("OOOOOO"), &self, &a1, &a2, &a3, &a4, &a5)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()))); - } - - template - static PyObject* call(R (T::*pmf)(A1, A2, A3, A4, A5, A6), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()))); - } - - template - static PyObject* call(R (T::*pmf)(A1, A2, A3, A4, A5, A6, A7), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6, &a7)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()))); - } - - template - static PyObject* call(R (T::*pmf)(A1, A2, A3, A4, A5, A6, A7, A8), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type()))); - } - - template - static PyObject* call(R (T::*pmf)(A1, A2, A3, A4, A5, A6, A7, A8, A9), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - PyObject* a9; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type()), - from_python(a9, type()))); - } - - template - static PyObject* call(R (T::*pmf)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - PyObject* a9; - PyObject* a10; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9, &a10)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type()), - from_python(a9, type()), - from_python(a10, type()))); - } - - - template - static PyObject* call(R (T::*pmf)() const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - if (!PyArg_ParseTuple(args, const_cast("O"), &self)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)()); - } - - template - static PyObject* call(R (T::*pmf)(A1) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - if (!PyArg_ParseTuple(args, const_cast("OO"), &self, &a1)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()))); - } - - template - static PyObject* call(R (T::*pmf)(A1, A2) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - if (!PyArg_ParseTuple(args, const_cast("OOO"), &self, &a1, &a2)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()), - from_python(a2, type()))); - } - - template - static PyObject* call(R (T::*pmf)(A1, A2, A3) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - if (!PyArg_ParseTuple(args, const_cast("OOOO"), &self, &a1, &a2, &a3)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()))); - } - - template - static PyObject* call(R (T::*pmf)(A1, A2, A3, A4) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - if (!PyArg_ParseTuple(args, const_cast("OOOOO"), &self, &a1, &a2, &a3, &a4)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()))); - } - - template - static PyObject* call(R (T::*pmf)(A1, A2, A3, A4, A5) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - if (!PyArg_ParseTuple(args, const_cast("OOOOOO"), &self, &a1, &a2, &a3, &a4, &a5)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()))); - } - - template - static PyObject* call(R (T::*pmf)(A1, A2, A3, A4, A5, A6) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()))); - } - - template - static PyObject* call(R (T::*pmf)(A1, A2, A3, A4, A5, A6, A7) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6, &a7)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()))); - } - - template - static PyObject* call(R (T::*pmf)(A1, A2, A3, A4, A5, A6, A7, A8) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type()))); - } - - template - static PyObject* call(R (T::*pmf)(A1, A2, A3, A4, A5, A6, A7, A8, A9) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - PyObject* a9; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type()), - from_python(a9, type()))); - } - - template - static PyObject* call(R (T::*pmf)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - PyObject* a9; - PyObject* a10; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9, &a10)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type()), - from_python(a9, type()), - from_python(a10, type()))); - } - - // Free functions - static PyObject* call(R (*f)(), PyObject* args, PyObject* /* keywords */ ) { - if (!PyArg_ParseTuple(args, const_cast(""))) - return 0; - return to_python(f()); - } - - template - static PyObject* call(R (*f)(A1), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - if (!PyArg_ParseTuple(args, const_cast("O"), &a1)) - return 0; - return to_python(f(from_python(a1, type()))); - } - - template - static PyObject* call(R (*f)(A1, A2), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - if (!PyArg_ParseTuple(args, const_cast("OO"), &a1, &a2)) - return 0; - return to_python(f(from_python(a1, type()), - from_python(a2, type()))); - } - - template - static PyObject* call(R (*f)(A1, A2, A3), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - PyObject* a3; - if (!PyArg_ParseTuple(args, const_cast("OOO"), &a1, &a2, &a3)) - return 0; - return to_python(f(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()))); - } - - template - static PyObject* call(R (*f)(A1, A2, A3, A4), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - if (!PyArg_ParseTuple(args, const_cast("OOOO"), &a1, &a2, &a3, &a4)) - return 0; - return to_python(f(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()))); - } - - template - static PyObject* call(R (*f)(A1, A2, A3, A4, A5), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - if (!PyArg_ParseTuple(args, const_cast("OOOOO"), &a1, &a2, &a3, &a4, &a5)) - return 0; - return to_python(f(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()))); - } - - template - static PyObject* call(R (*f)(A1, A2, A3, A4, A5, A6), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - if (!PyArg_ParseTuple(args, const_cast("OOOOOO"), &a1, &a2, &a3, &a4, &a5, &a6)) - return 0; - return to_python(f(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()))); - } - - template - static PyObject* call(R (*f)(A1, A2, A3, A4, A5, A6, A7), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOO"), &a1, &a2, &a3, &a4, &a5, &a6, &a7)) - return 0; - return to_python(f(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()))); - } - - template - static PyObject* call(R (*f)(A1, A2, A3, A4, A5, A6, A7, A8), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOO"), &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8)) - return 0; - return to_python(f(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type()))); - } - - template - static PyObject* call(R (*f)(A1, A2, A3, A4, A5, A6, A7, A8, A9), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - PyObject* a9; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOO"), &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9)) - return 0; - return to_python(f(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type()), - from_python(a9, type()))); - } - - template - static PyObject* call(R (*f)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - PyObject* a9; - PyObject* a10; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOOO"), &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9, &a10)) - return 0; - return to_python(f(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type()), - from_python(a9, type()), - from_python(a10, type()))); - } - - template - static PyObject* call(R (*f)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - PyObject* a9; - PyObject* a10; - PyObject* a11; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOOOO"), &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9, &a10, &a11)) - return 0; - return to_python(f(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type()), - from_python(a9, type()), - from_python(a10, type()), - from_python(a11, type()))); - } - -}; - -template <> -struct caller -{ - template - static PyObject* call(void (T::*pmf)(), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - if (!PyArg_ParseTuple(args, const_cast("O"), &self)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - if (!PyArg_ParseTuple(args, const_cast("OO"), &self, &a1)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type())); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1, A2), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - if (!PyArg_ParseTuple(args, const_cast("OOO"), &self, &a1, &a2)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type()), - from_python(a2, type())); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1, A2, A3), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - if (!PyArg_ParseTuple(args, const_cast("OOOO"), &self, &a1, &a2, &a3)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type())); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1, A2, A3, A4), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - if (!PyArg_ParseTuple(args, const_cast("OOOOO"), &self, &a1, &a2, &a3, &a4)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type())); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1, A2, A3, A4, A5), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - if (!PyArg_ParseTuple(args, const_cast("OOOOOO"), &self, &a1, &a2, &a3, &a4, &a5)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type())); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1, A2, A3, A4, A5, A6), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type())); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1, A2, A3, A4, A5, A6, A7), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6, &a7)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type())); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1, A2, A3, A4, A5, A6, A7, A8), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type())); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1, A2, A3, A4, A5, A6, A7, A8, A9), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - PyObject* a9; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type()), - from_python(a9, type())); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - PyObject* a9; - PyObject* a10; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9, &a10)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type()), - from_python(a9, type()), - from_python(a10, type())); - return detail::none(); - } - - - template - static PyObject* call(void (T::*pmf)() const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - if (!PyArg_ParseTuple(args, const_cast("O"), &self)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - if (!PyArg_ParseTuple(args, const_cast("OO"), &self, &a1)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type())); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1, A2) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - if (!PyArg_ParseTuple(args, const_cast("OOO"), &self, &a1, &a2)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type()), - from_python(a2, type())); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1, A2, A3) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - if (!PyArg_ParseTuple(args, const_cast("OOOO"), &self, &a1, &a2, &a3)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type())); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1, A2, A3, A4) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - if (!PyArg_ParseTuple(args, const_cast("OOOOO"), &self, &a1, &a2, &a3, &a4)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type())); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1, A2, A3, A4, A5) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - if (!PyArg_ParseTuple(args, const_cast("OOOOOO"), &self, &a1, &a2, &a3, &a4, &a5)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type())); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1, A2, A3, A4, A5, A6) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type())); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1, A2, A3, A4, A5, A6, A7) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6, &a7)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type())); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1, A2, A3, A4, A5, A6, A7, A8) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type())); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1, A2, A3, A4, A5, A6, A7, A8, A9) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - PyObject* a9; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type()), - from_python(a9, type())); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - PyObject* a9; - PyObject* a10; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9, &a10)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type()), - from_python(a9, type()), - from_python(a10, type())); - return detail::none(); - } - - - // Free functions - static PyObject* call(void (*f)(), PyObject* args, PyObject* /* keywords */ ) { - if (!PyArg_ParseTuple(args, const_cast(""))) - return 0; - f(); - return detail::none(); - } - - template - static PyObject* call(void (*f)(A1), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - if (!PyArg_ParseTuple(args, const_cast("O"), &a1)) - return 0; - f(from_python(a1, type())); - return detail::none(); - } - - template - static PyObject* call(void (*f)(A1, A2), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - if (!PyArg_ParseTuple(args, const_cast("OO"), &a1, &a2)) - return 0; - f(from_python(a1, type()), - from_python(a2, type())); - return detail::none(); - } - - template - static PyObject* call(void (*f)(A1, A2, A3), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - PyObject* a3; - if (!PyArg_ParseTuple(args, const_cast("OOO"), &a1, &a2, &a3)) - return 0; - f(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type())); - return detail::none(); - } - - template - static PyObject* call(void (*f)(A1, A2, A3, A4), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - if (!PyArg_ParseTuple(args, const_cast("OOOO"), &a1, &a2, &a3, &a4)) - return 0; - f(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type())); - return detail::none(); - } - - template - static PyObject* call(void (*f)(A1, A2, A3, A4, A5), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - if (!PyArg_ParseTuple(args, const_cast("OOOOO"), &a1, &a2, &a3, &a4, &a5)) - return 0; - f(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type())); - return detail::none(); - } - - template - static PyObject* call(void (*f)(A1, A2, A3, A4, A5, A6), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - if (!PyArg_ParseTuple(args, const_cast("OOOOOO"), &a1, &a2, &a3, &a4, &a5, &a6)) - return 0; - f(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type())); - return detail::none(); - } - - template - static PyObject* call(void (*f)(A1, A2, A3, A4, A5, A6, A7), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOO"), &a1, &a2, &a3, &a4, &a5, &a6, &a7)) - return 0; - f(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type())); - return detail::none(); - } - - template - static PyObject* call(void (*f)(A1, A2, A3, A4, A5, A6, A7, A8), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOO"), &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8)) - return 0; - f(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type())); - return detail::none(); - } - - template - static PyObject* call(void (*f)(A1, A2, A3, A4, A5, A6, A7, A8, A9), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - PyObject* a9; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOO"), &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9)) - return 0; - f(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type()), - from_python(a9, type())); - return detail::none(); - } - - template - static PyObject* call(void (*f)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - PyObject* a9; - PyObject* a10; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOOO"), &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9, &a10)) - return 0; - f(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type()), - from_python(a9, type()), - from_python(a10, type())); - return detail::none(); - } - - template - static PyObject* call(void (*f)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - PyObject* a9; - PyObject* a10; - PyObject* a11; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOOOO"), &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9, &a10, &a11)) - return 0; - f(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type()), - from_python(a9, type()), - from_python(a10, type()), - from_python(a11, type())); - return detail::none(); - } - -}; - -}} // namespace boost::python - -#endif diff --git a/include/boost/python/class.hpp b/include/boost/python/class.hpp index 76646b41..2e0840b3 100644 --- a/include/boost/python/class.hpp +++ b/include/boost/python/class.hpp @@ -9,7 +9,6 @@ # include # include # include -# include # include @@ -35,9 +34,12 @@ # include # include # include +# include namespace boost { namespace python { +enum no_init_t { no_init }; + namespace detail { // This function object is used with mpl::for_each to write the id @@ -85,7 +87,23 @@ namespace detail SelectHolder::register_(); } - template int assert_default_constructible(T const&); + // A helpful compile-time assertion which gives a reasonable error + // message if T can't be default-constructed. + template + class assert_default_constructible + { + template + static int specify_init_arguments_or_no_init_for_class_(U const&); + public: + assert_default_constructible() + { + force_instantiate( + sizeof( + specify_init_arguments_or_no_init_for_class_(T()) + )); + + } + }; } // @@ -102,9 +120,10 @@ template < > class class_ : public objects::class_base { - private: // types - typedef objects::class_base base; - + public: // types + typedef objects::class_base base; + typedef T wrapped_type; + typedef class_ self; BOOST_STATIC_CONSTANT(bool, is_copyable = (!detail::has_noncopyable::value)); @@ -116,12 +135,15 @@ class class_ : public objects::class_base typedef objects::select_holder holder_selector; + private: + typedef typename detail::select_bases::type >::type >::type bases; + // A helper class which will contain an array of id objects to be // passed to the base class constructor struct id_vector @@ -181,7 +203,7 @@ class class_ : public objects::class_base template self& def(char const* name, F f) { - this->def_impl(name, f, default_call_policies(), 0, &f); + this->def_impl(name, f, detail::keywords<>(), default_call_policies(), 0, &f); return *this; } @@ -199,7 +221,7 @@ class class_ : public objects::class_base // def(name, function) // def(name, function, policy) // def(name, function, doc_string) - // def(name, signature, stubs) + // def(name, signature, overloads) dispatch_def(&arg2, name, arg1, arg2); return *this; @@ -216,6 +238,13 @@ class class_ : public objects::class_base return *this; } + template + self& def(char const* name, Arg1T arg1, Arg2T const& arg2, Arg3T const& arg3, Arg4T const& arg4) + { + dispatch_def(&arg2, name, arg1, arg2, arg3, arg4); + return *this; + } + template self& def(detail::operator_ const& op) { @@ -223,42 +252,6 @@ class class_ : public objects::class_base return this->def(op.name(), &op_t::template apply::execute); } - // Define the constructor with the given Args, which should be an - // MPL sequence of types. - template - self& def_init(Args const&) - { - return this->def("__init__", - python::make_constructor( - // Using runtime type selection works around a CWPro7 bug. - holder_selector::execute((held_type*)0).get() - ) - ); - } - - template - self& def_init(Args const&, CallPolicyOrDoc const& policy_or_doc, char const* doc = 0) - { - typedef detail::def_helper helper; - - return this->def( - "__init__", - python::make_constructor( - helper::get_policy(policy_or_doc) - // Using runtime type selection works around a CWPro7 bug. - , holder_selector::execute((held_type*)0).get() - ) - , helper::get_doc(policy_or_doc, doc) - ); - } - - // Define the default constructor. - self& def_init() - { - this->def_init(mpl::list0<>::type()); - return *this; - } - // // Data member access // @@ -313,68 +306,105 @@ class class_ : public objects::class_base private: // helper functions - template - inline void def_impl(char const* name, Fn fn, Policies const& policies - , char const* doc, ...) + template + inline void def_impl( + char const* name + , Fn fn + , Keywords const& keywords + , Policies const& policies + , char const* doc + , ...) { objects::add_to_namespace( *this, name, make_function( - // This bit of nastiness casts F to a member function of T if possible. + // This bit of nastiness casts F to a member function of T if possible. detail::member_function_cast::stage1(fn).stage2((T*)0).stage3(fn) - , policies) + , policies, keywords) , doc); } template - inline void def_impl(char const* name, F f, default_call_policies const& - , char const* doc, object const*) + inline void def_impl( + char const* name + , F f + , detail::keywords<> const& + , default_call_policies const& + , char const* doc + , object const*) { objects::add_to_namespace(*this, name, f, doc); } inline void register_() const; - template + template void dispatch_def( detail::overloads_base const*, char const* name, SigT sig, - StubsT const& stubs) + OverloadsT const& overloads) { // convert sig to a type_list (see detail::get_signature in signature.hpp) // before calling detail::define_with_defaults. detail::define_with_defaults( - name, stubs, *this, detail::get_signature(sig)); + name, overloads, *this, detail::get_signature(sig)); } - template + template void dispatch_def( void const*, char const* name, Fn fn, - CallPolicyOrDoc const& policy_or_doc) + A1 const& a1) { - typedef detail::def_helper helper; + detail::def_helper helper(a1); + this->def_impl( - name, fn, helper::get_policy(policy_or_doc), - helper::get_doc(policy_or_doc, 0), &fn); + name, fn + , helper.keywords() + , helper.policies() + , helper.doc() + , &fn); } - template + template void dispatch_def( void const*, char const* name, Fn fn, - CallPolicyOrDoc1 const& policy_or_doc1, - CallPolicyOrDoc2 const& policy_or_doc2) + A1 const& a1, + A2 const& a2) { - typedef detail::def_helper helper; - + detail::def_helper helper(a1,a2); + this->def_impl( - name, fn, helper::get_policy(policy_or_doc1, policy_or_doc2), - helper::get_doc(policy_or_doc1, policy_or_doc2), &fn); + name, fn + , helper.keywords() + , helper.policies() + , helper.doc() + , &fn); + } + + template + void dispatch_def( + void const*, + char const* name, + Fn fn, + A1 const& a1, + A2 const& a2, + A3 const& a3 + ) + { + detail::def_helper helper(a1,a2,a3); + + this->def_impl( + name, fn + , helper.keywords() + , helper.policies() + , helper.doc() + , &fn); } }; @@ -399,8 +429,8 @@ inline class_::class_(char const* name, char const* doc) : base(name, id_vector::size, id_vector().ids, doc) { this->register_(); - detail::force_instantiate(sizeof(detail::assert_default_constructible(T()))); - this->def_init(); + detail::assert_default_constructible(); + this->def(init<>()); this->set_instance_size(holder_selector::additional_size()); } diff --git a/include/boost/python/class_builder.hpp b/include/boost/python/class_builder.hpp deleted file mode 100644 index fe2a7b74..00000000 --- a/include/boost/python/class_builder.hpp +++ /dev/null @@ -1,182 +0,0 @@ -// Revision History: -// Mar 03 01 added: pickle safety measures (Ralf W. Grosse-Kunstleve) - -#ifndef CLASS_WRAPPER_DWA101000_H_ -# define CLASS_WRAPPER_DWA101000_H_ - -#include -#include -#include -#include -#include -#include - -namespace boost { namespace python { - -// Syntactic sugar to make wrapping classes more convenient -template > -class class_builder - : python_extension_class_converters // Works around MSVC6.x/GCC2.95.2 bug described below -{ - public: - class_builder(module_builder& module, const char* name) - : m_class(new detail::extension_class(name)) - { - module.add(ref(as_object(m_class.get()), ref::increment_count), name); - } - - template - class_builder(class_builder& cls, const char* name) - : m_class(new detail::extension_class(name)) - { - cls.add(ref(as_object(m_class.get()), ref::increment_count), name); - } - - template - class_builder(detail::extension_class* cls, - const char* name) - : m_class(new detail::extension_class(name)) - { - cls->set_attribute(name, - ref(as_object(m_class.get()), ref::increment_count)); - } - - ~class_builder() - {} - - inline void dict_defines_state() { - add(ref(BOOST_PYTHON_CONVERSION::to_python(1)), "__dict_defines_state__"); - } - inline void getstate_manages_dict() { - add(ref(BOOST_PYTHON_CONVERSION::to_python(1)), "__getstate_manages_dict__"); - } - - // define constructors - template - void def(const signature& s) - { m_class->def(s); } - - // export heterogeneous reverse-argument operators - // (type of lhs: 'left', of rhs: 'right') - // usage: foo_class.def(boost::python::operators<(boost::python::op_add | boost::python::op_sub), Foo>(), - // boost::python::left_operand()); - template - void def(operators o1, left_operand o2) - { m_class->def(o1, o2); } - - // export heterogeneous operators (type of lhs: 'left', of rhs: 'right') - // usage: foo_class.def(boost::python::operators<(boost::python::op_add | boost::python::op_sub), Foo>(), - // boost::python::right_operand()); - template - void def(operators o1, right_operand o2) - { m_class->def(o1, o2); } - - // define a function that passes Python arguments and keywords - // to C++ verbatim (as a 'tuple const &' and 'dictionary const &' - // respectively). This is useful for manual argument passing. - // It's also the only possibility to pass keyword arguments to C++. - // Fn must have a signatur that is compatible to - // PyObject * (*)(PyObject * aTuple, PyObject * aDictionary) - template - void def_raw(Fn fn, const char* name) - { m_class->def_raw(fn, name); } - - // define member functions. In fact this works for free functions, too - - // they act like static member functions, or if they start with the - // appropriate self argument (as a pointer or reference), they can be used - // just like ordinary member functions -- just like Python! - template - void def(Fn fn, const char* name) - { m_class->def(fn, name); } - - // Define a virtual member function with a default implementation. - // default_fn should be a function which provides the default implementation. - // Be careful that default_fn does not in fact call fn virtually! - template - void def(Fn fn, const char* name, DefaultFn default_fn) - { m_class->def(fn, name, default_fn); } - - // Provide a function which implements x., reading from the given - // member (pm) of the T obj - template - void def_getter(MemberType T::*pm, const char* name) - { m_class->def_getter(pm, name); } - - // Provide a function which implements assignment to x., writing to - // the given member (pm) of the T obj - template - void def_setter(MemberType T::*pm, const char* name) - { m_class->def_getter(pm, name); } - - // Expose the given member (pm) of the T obj as a read-only attribute - template - void def_readonly(MemberType T::*pm, const char* name) - { m_class->def_readonly(pm, name); } - - // Expose the given member (pm) of the T obj as a read/write attribute - template - void def_read_write(MemberType T::*pm, const char* name) - { m_class->def_read_write(pm, name); } - - // define the standard coercion needed for operator overloading - void def_standard_coerce() - { m_class->def_standard_coerce(); } - - // declare the given class a base class of this one and register - // conversion functions - template - void declare_base(class_builder const & base) - { - m_class->declare_base(base.get_extension_class()); - } - - // declare the given class a base class of this one and register - // upcast conversion function - template - void declare_base(class_builder const & base, without_downcast_t) - { - m_class->declare_base(base.get_extension_class(), without_downcast); - } - - // get the embedded ExtensioClass object - detail::extension_class * get_extension_class() const - { - return m_class.get(); - } - - // set an arbitrary attribute. Useful for non-function class data members, - // e.g. enums - void add(PyObject* x, const char* name) - { m_class->set_attribute(name, x); } - void add(ref x, const char* name) - { m_class->set_attribute(name, x); } - private: - // declare the given class a base class of this one and register - // conversion functions - template - void declare_base(detail::extension_class * base) - { - m_class->declare_base(base); - } - - // declare the given class a base class of this one and register - // upcast conversion function - template - void declare_base(detail::extension_class * base, without_downcast_t) - { - m_class->declare_base(base, without_downcast); - } - - reference > m_class; -}; - -// The bug mentioned at the top of this file is that on certain compilers static -// global functions declared within the body of a class template will only be -// generated when the class template is constructed, and when (for some reason) -// the construction does not occur via a new-expression. Otherwise, we could -// rely on the initialization of the m_class data member to cause all of the -// to_/from_python functions to come into being. - -}} // namespace boost::python - -#endif // CLASS_WRAPPER_DWA101000_H_ diff --git a/include/boost/python/class_fwd.hpp b/include/boost/python/class_fwd.hpp index 87f3ba32..8aaec6a6 100644 --- a/include/boost/python/class_fwd.hpp +++ b/include/boost/python/class_fwd.hpp @@ -6,16 +6,9 @@ #ifndef CLASS_FWD_DWA200222_HPP # define CLASS_FWD_DWA200222_HPP # include -# include -# include namespace boost { namespace python { -namespace detail -{ - struct empty_list; -} - template < class T // class being wrapped // arbitrarily-ordered optional arguments. Full qualification needed for MSVC6 diff --git a/include/boost/python/classes.hpp b/include/boost/python/classes.hpp deleted file mode 100644 index 22fcb3d2..00000000 --- a/include/boost/python/classes.hpp +++ /dev/null @@ -1,677 +0,0 @@ -// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and -// distribute this software is granted provided this copyright notice appears -// in all copies. This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// The author gratefully acknowleges the support of Dragon Systems, Inc., in -// producing this work. - -#ifndef SUBCLASS_DWA051500_H_ -# define SUBCLASS_DWA051500_H_ - -# include -# include -# include -# include -# include -# include -# include - -namespace boost { namespace python { - -// A simple type which acts something like a built-in Python class obj. -class BOOST_PYTHON_DECL instance - : public boost::python::detail::python_object -{ - public: - instance(PyTypeObject* class_); - ~instance(); - - // Standard Python functions. - PyObject* repr(); - int compare(PyObject*); - PyObject* str(); - long hash(); - PyObject* call(PyObject* args, PyObject* keywords); - PyObject* getattr(const char* name, bool use_special_function = true); - int setattr(const char* name, PyObject* value); - - // Mapping methods - int length(); - PyObject* get_subscript(PyObject* key); - void set_subscript(PyObject* key, PyObject* value); - - // Sequence methods - PyObject* get_slice(int start, int finish); - void set_slice(int start, int finish, PyObject* value); - - // Number methods - PyObject* add(PyObject* other); - PyObject* subtract(PyObject* other); - PyObject* multiply(PyObject* other); - PyObject* divide(PyObject* other); - PyObject* remainder(PyObject* other); - PyObject* divmod(PyObject* other); - PyObject* power(PyObject*, PyObject*); - PyObject* negative(); - PyObject* positive(); - PyObject* absolute(); - int nonzero(); - PyObject* invert(); - PyObject* lshift(PyObject* other); - PyObject* rshift(PyObject* other); - PyObject* do_and(PyObject* other); - PyObject* do_xor(PyObject* other); - PyObject* do_or(PyObject* other); - int coerce(PyObject**, PyObject**); - PyObject* as_int(); - PyObject* as_long(); - PyObject* as_float(); - PyObject* oct(); - PyObject* hex(); - - // Rich comparisons - PyObject* lt(PyObject* other); - PyObject* le(PyObject* other); - PyObject* eq(PyObject* other); - PyObject* ne(PyObject* other); - PyObject* gt(PyObject* other); - PyObject* ge(PyObject* other); - - // Inplace operations. - PyObject* inplace_add(PyObject* other); - PyObject* inplace_subtract(PyObject* other); - PyObject* inplace_multiply(PyObject* other); - PyObject* inplace_divide(PyObject* other); - PyObject* inplace_remainder(PyObject* other); - PyObject* inplace_power(PyObject* exponent, PyObject* modulus); - PyObject* inplace_lshift(PyObject* other); - PyObject* inplace_rshift(PyObject* other); - PyObject* inplace_and(PyObject* other); - PyObject* inplace_or(PyObject* other); - PyObject* inplace_xor(PyObject* other); - - private: // noncopyable, without the size bloat - instance(const instance&); - void operator=(const instance&); - - private: // helper functions - int setattr_dict(PyObject* value); - - private: - dictionary m_name_space; -}; - -template class meta_class; - -namespace detail { - class BOOST_PYTHON_DECL class_base : public type_object_base - { - public: - class_base(PyTypeObject* meta_class_obj, string name, tuple bases, const dictionary& name_space); - tuple bases() const; - string name() const; - dictionary& dict(); - - // Standard Python functions. - PyObject* getattr(const char* name); - int setattr(const char* name, PyObject* value); - PyObject* repr() const; - void add_base(ref base); - - protected: - bool initialize_instance(instance* obj, PyObject* args, PyObject* keywords); - - private: // virtual functions - // Subclasses should override this to delete the particular obj type - virtual void delete_instance(PyObject*) const = 0; - - private: // boost::python::type_object_base required interface implementation - void instance_dealloc(PyObject*) const; // subclasses should not override this - - private: // noncopyable, without the size bloat - class_base(const class_base&); - void operator=(const class_base&); - - private: - string m_name; - tuple m_bases; - dictionary m_name_space; - }; - - void enable_named_method(class_base* type_obj, const char* name); -} - -// A type which acts a lot like a built-in Python class. T is the obj type, -// so class_t is a very simple "class-alike". -template -class class_t : public boost::python::detail::class_base -{ - public: - class_t(meta_class* meta_class_obj, string name, tuple bases, const dictionary& name_space); - ~class_t(); - - // Standard Python functions. - PyObject* call(PyObject* args, PyObject* keywords); - - private: // Implement mapping methods on instances - PyObject* instance_repr(PyObject*) const; - int instance_compare(PyObject*, PyObject* other) const; - PyObject* instance_str(PyObject*) const; - long instance_hash(PyObject*) const; - int instance_mapping_length(PyObject*) const; - PyObject* instance_mapping_subscript(PyObject*, PyObject*) const; - int instance_mapping_ass_subscript(PyObject*, PyObject*, PyObject*) const; - - private: // Implement sequence methods on instances - int instance_sequence_length(PyObject*) const; - PyObject* instance_sequence_item(PyObject* obj, int n) const; - int instance_sequence_ass_item(PyObject* obj, int n, PyObject* value) const; - PyObject* instance_sequence_slice(PyObject*, int start, int finish) const; - int instance_sequence_ass_slice(PyObject*, int start, int finish, PyObject* value) const; - - private: // Implement number methods on instances - PyObject* instance_number_add(PyObject*, PyObject*) const; - PyObject* instance_number_subtract(PyObject*, PyObject*) const; - PyObject* instance_number_multiply(PyObject*, PyObject*) const; - PyObject* instance_number_divide(PyObject*, PyObject*) const; - PyObject* instance_number_remainder(PyObject*, PyObject*) const; - PyObject* instance_number_divmod(PyObject*, PyObject*) const; - PyObject* instance_number_power(PyObject*, PyObject*, PyObject*) const; - PyObject* instance_number_negative(PyObject*) const; - PyObject* instance_number_positive(PyObject*) const; - PyObject* instance_number_absolute(PyObject*) const; - int instance_number_nonzero(PyObject*) const; - PyObject* instance_number_invert(PyObject*) const; - PyObject* instance_number_lshift(PyObject*, PyObject*) const; - PyObject* instance_number_rshift(PyObject*, PyObject*) const; - PyObject* instance_number_and(PyObject*, PyObject*) const; - PyObject* instance_number_xor(PyObject*, PyObject*) const; - PyObject* instance_number_or(PyObject*, PyObject*) const; - int instance_number_coerce(PyObject*, PyObject**, PyObject**) const; - PyObject* instance_number_int(PyObject*) const; - PyObject* instance_number_long(PyObject*) const; - PyObject* instance_number_float(PyObject*) const; - PyObject* instance_number_oct(PyObject*) const; - PyObject* instance_number_hex(PyObject*) const; - - PyObject* instance_number_inplace_add(PyObject*, PyObject*) const; - PyObject* instance_number_inplace_subtract(PyObject*, PyObject*) const; - PyObject* instance_number_inplace_multiply(PyObject*, PyObject*) const; - PyObject* instance_number_inplace_divide(PyObject*, PyObject*) const; - PyObject* instance_number_inplace_remainder(PyObject*, PyObject*) const; - PyObject* instance_number_inplace_power(PyObject*, PyObject*, PyObject*) const; - PyObject* instance_number_inplace_lshift(PyObject*, PyObject*) const; - PyObject* instance_number_inplace_rshift(PyObject*, PyObject*) const; - PyObject* instance_number_inplace_and(PyObject*, PyObject*) const; - PyObject* instance_number_inplace_or(PyObject*, PyObject*) const; - PyObject* instance_number_inplace_xor(PyObject*, PyObject*) const; - - private: // Implement rich comparisons - PyObject* instance_lt(PyObject*, PyObject*) const; - PyObject* instance_le(PyObject*, PyObject*) const; - PyObject* instance_eq(PyObject*, PyObject*) const; - PyObject* instance_ne(PyObject*, PyObject*) const; - PyObject* instance_gt(PyObject*, PyObject*) const; - PyObject* instance_ge(PyObject*, PyObject*) const; - - private: // Miscellaneous "special" methods - PyObject* instance_call(PyObject* obj, PyObject* args, PyObject* keywords) const; - PyObject* instance_getattr(PyObject* obj, const char* name) const; - int instance_setattr(PyObject* obj, const char* name, PyObject* value) const; - - private: // Implementation of boost::python::detail::class_base required interface - void delete_instance(PyObject*) const; -}; - -// The type of a class_t object. -template -class meta_class - : public boost::python::detail::reprable< - boost::python::detail::callable< - boost::python::detail::getattrable< - boost::python::detail::setattrable< - boost::python::detail::type_object > > > > >, - private boost::noncopyable -{ - public: - meta_class(); - - // Standard Python functions. - PyObject* call(PyObject* args, PyObject* keywords); - - struct type_object - : boost::python::detail::singleton > > - { - type_object() : singleton_base(&PyType_Type) {} - }; -}; - -// -// Member function implementations. -// -template -meta_class::meta_class() - : properties(type_object::instance()) -{ -} - -template -class_t::class_t(meta_class* meta_class_obj, string name, tuple bases, const dictionary& name_space) - : boost::python::detail::class_base(meta_class_obj, name, bases, name_space) -{ -} - -template -class_t::~class_t() -{ -} - -template -void class_t::delete_instance(PyObject* obj) const -{ - delete downcast(obj); -} - -template -PyObject* class_t::call(PyObject* args, PyObject* keywords) -{ - reference result(new T(this)); - if (!this->initialize_instance(result.get(), args, keywords)) - return 0; - else - return result.release(); -} - -template -PyObject* class_t::instance_repr(PyObject* obj) const -{ - return downcast(obj)->repr(); -} - -template -int class_t::instance_compare(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->compare(other); -} - -template -PyObject* class_t::instance_str(PyObject* obj) const -{ - return downcast(obj)->str(); -} - -template -long class_t::instance_hash(PyObject* obj) const -{ - return downcast(obj)->hash(); -} - -template -int class_t::instance_mapping_length(PyObject* obj) const -{ - return downcast(obj)->length(); -} - -template -int class_t::instance_sequence_length(PyObject* obj) const -{ - return downcast(obj)->length(); -} - -template -PyObject* class_t::instance_mapping_subscript(PyObject* obj, PyObject* key) const -{ - return downcast(obj)->get_subscript(key); -} - -template -PyObject* class_t::instance_sequence_item(PyObject* obj, int n) const -{ - ref key(to_python(n)); - return downcast(obj)->get_subscript(key.get()); -} - -template -int class_t::instance_sequence_ass_item(PyObject* obj, int n, PyObject* value) const -{ - ref key(to_python(n)); - downcast(obj)->set_subscript(key.get(), value); - return 0; -} - -template -int class_t::instance_mapping_ass_subscript(PyObject* obj, PyObject* key, PyObject* value) const -{ - downcast(obj)->set_subscript(key, value); - return 0; -} - -bool BOOST_PYTHON_DECL adjust_slice_indices(PyObject* obj, int& start, int& finish); - -template -PyObject* class_t::instance_sequence_slice(PyObject* obj, int start, int finish) const -{ - if (!adjust_slice_indices(obj, start, finish)) - return 0; - return downcast(obj)->get_slice(start, finish); -} - -template -int class_t::instance_sequence_ass_slice(PyObject* obj, int start, int finish, PyObject* value) const -{ - if (!adjust_slice_indices(obj, start, finish)) - return -1; - downcast(obj)->set_slice(start, finish, value); - return 0; -} - -template -PyObject* class_t::instance_call(PyObject* obj, PyObject* args, PyObject* keywords) const -{ - return downcast(obj)->call(args, keywords); -} - -template -PyObject* class_t::instance_getattr(PyObject* obj, const char* name) const -{ - return downcast(obj)->getattr(name); -} - - -template -int class_t::instance_setattr(PyObject* obj, const char* name, PyObject* value) const -{ - return downcast(obj)->setattr(name, value); -} - -template -PyObject* class_t::instance_number_add(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->add(other); -} - -template -PyObject* class_t::instance_number_subtract(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->subtract(other); -} - -template -PyObject* class_t::instance_number_multiply(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->multiply(other); -} - -template -PyObject* class_t::instance_number_divide(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->divide(other); -} - -template -PyObject* class_t::instance_number_remainder(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->remainder(other); -} - -template -PyObject* class_t::instance_number_divmod(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->divmod(other); -} - -template -PyObject* class_t::instance_number_power(PyObject* obj, PyObject* exponent, PyObject* modulus) const -{ - return downcast(obj)->power(exponent, modulus); -} - -template -PyObject* class_t::instance_number_negative(PyObject* obj) const -{ - return downcast(obj)->negative(); -} - -template -PyObject* class_t::instance_number_positive(PyObject* obj) const -{ - return downcast(obj)->positive(); -} - -template -PyObject* class_t::instance_number_absolute(PyObject* obj) const -{ - return downcast(obj)->absolute(); -} - -template -int class_t::instance_number_nonzero(PyObject* obj) const -{ - return downcast(obj)->nonzero(); -} - -template -PyObject* class_t::instance_number_invert(PyObject* obj) const -{ - return downcast(obj)->invert(); -} - -template -PyObject* class_t::instance_number_lshift(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->lshift(other); -} - -template -PyObject* class_t::instance_number_rshift(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->rshift(other); -} - -template -PyObject* class_t::instance_number_and(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->do_and(other); -} - -template -PyObject* class_t::instance_number_xor(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->do_xor(other); -} - -template -PyObject* class_t::instance_number_or(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->do_or(other); -} - -template -int class_t::instance_number_coerce(PyObject* obj, PyObject** x, PyObject** y) const -{ - return downcast(obj)->coerce(x, y); -} - -template -PyObject* class_t::instance_number_int(PyObject* obj) const -{ - return downcast(obj)->as_int(); -} - -template -PyObject* class_t::instance_number_long(PyObject* obj) const -{ - return downcast(obj)->as_long(); -} - -template -PyObject* class_t::instance_number_float(PyObject* obj) const -{ - return downcast(obj)->as_float(); -} - -template -PyObject* class_t::instance_number_oct(PyObject* obj) const -{ - return downcast(obj)->oct(); -} - -template -PyObject* class_t::instance_number_hex(PyObject* obj) const -{ - return downcast(obj)->hex(); -} - -template -PyObject* class_t::instance_number_inplace_add(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->inplace_add(other); -} - -template -PyObject* class_t::instance_number_inplace_subtract(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->inplace_subtract(other); -} - -template -PyObject* class_t::instance_number_inplace_multiply(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->inplace_multiply(other); -} - -template -PyObject* class_t::instance_number_inplace_divide(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->inplace_divide(other); -} - -template -PyObject* class_t::instance_number_inplace_remainder(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->inplace_remainder(other); -} - -template -PyObject* class_t::instance_number_inplace_power(PyObject* obj, PyObject* exponent, PyObject* modulus) const -{ - return downcast(obj)->inplace_power(exponent, modulus); -} - -template -PyObject* class_t::instance_number_inplace_lshift(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->inplace_lshift(other); -} - -template -PyObject* class_t::instance_number_inplace_rshift(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->inplace_rshift(other); -} - -template -PyObject* class_t::instance_number_inplace_and(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->inplace_and(other); -} - -template -PyObject* class_t::instance_number_inplace_or(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->inplace_or(other); -} - -template -PyObject* class_t::instance_number_inplace_xor(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->inplace_xor(other); -} - -template -PyObject* class_t::instance_lt(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->lt(other); -} - -template -PyObject* class_t::instance_le(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->le(other); -} - -template -PyObject* class_t::instance_eq(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->eq(other); -} - -template -PyObject* class_t::instance_ne(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->ne(other); -} - -template -PyObject* class_t::instance_gt(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->gt(other); -} - -template -PyObject* class_t::instance_ge(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->ge(other); -} - -namespace detail { - inline dictionary& class_base::dict() - { - return m_name_space; - } - - inline tuple class_base::bases() const - { - return m_bases; - } -} - -template -PyObject* meta_class::call(PyObject* args, PyObject* /*keywords*/) -{ - PyObject* name; - PyObject* bases; - PyObject* name_space; - - if (!PyArg_ParseTuple(args, const_cast("O!O!O!"), - &PyString_Type, &name, - &PyTuple_Type, &bases, - &PyDict_Type, &name_space)) - { - return 0; - } - - return as_object( - new class_t(this, string(ref(name, ref::increment_count)), - tuple(ref(bases, ref::increment_count)), - dictionary(ref(name_space, ref::increment_count))) - ); -} - -namespace detail { - const string& setattr_string(); - const string& getattr_string(); - const string& delattr_string(); - - inline string class_base::name() const - { - return m_name; - } -} - - -}} // namespace boost::python -#endif diff --git a/include/boost/python/conversions.hpp b/include/boost/python/conversions.hpp deleted file mode 100644 index 83823494..00000000 --- a/include/boost/python/conversions.hpp +++ /dev/null @@ -1,415 +0,0 @@ -// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and -// distribute this software is granted provided this copyright notice appears -// in all copies. This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// The author gratefully acknowleges the support of Dragon Systems, Inc., in -// producing this work. -// -// Revision History: -// 31 Jul 01 convert int/double to complex (Peter Bienstman) -// 04 Mar 01 Fixed std::complex<> stuff to work with MSVC (David Abrahams) -// 03 Mar 01 added: converters for [plain] char and std::complex -// (Ralf W. Grosse-Kunstleve) - -#ifndef METHOD_DWA122899_H_ -# define METHOD_DWA122899_H_ - -# include -# include -# include -# include -# include -# include -# include - -# ifdef BOOST_MSVC6_OR_EARLIER -# pragma warning(push) -# pragma warning(disable:4275) // disable a bogus warning caused by -# endif - -# include - -# ifdef BOOST_MSVC6_OR_EARLIER -# pragma warning(pop) -# endif - -BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE // this is a gcc 2.95.2 bug workaround - -// This can be instantiated on an enum to provide the to_python/from_python -// conversions, provided the values can fit in a long. -template -class py_enum_as_int_converters -{ - friend EnumType from_python(PyObject* x, boost::python::type) - { - return static_cast( - from_python(x, boost::python::type())); - } - - friend EnumType from_python(PyObject* x, boost::python::type) - { - return static_cast( - from_python(x, boost::python::type())); - } - - friend PyObject* to_python(EnumType x) - { - return to_python(static_cast(x)); - } -}; -BOOST_PYTHON_END_CONVERSION_NAMESPACE - -namespace boost { namespace python { -template class enum_as_int_converters - : public BOOST_PYTHON_CONVERSION::py_enum_as_int_converters {}; - -template class wrapped_pointer; - -//#pragma warn_possunwant off -inline void decref_impl(PyObject* p) { Py_DECREF(p); } -inline void xdecref_impl(PyObject* p) { Py_XDECREF(p); } -//#pragma warn_possunwant reset - -template -inline void decref(T* p) -{ - char* const raw_p = reinterpret_cast(p); - char* const p_base = raw_p - offsetof(PyObject, ob_refcnt); - decref_impl(reinterpret_cast(p_base)); -} - -template -inline void xdecref(T* p) -{ - char* const raw_p = reinterpret_cast(p); - char* const p_base = raw_p - offsetof(PyObject, ob_refcnt); - xdecref_impl(reinterpret_cast(p_base)); -} - -namespace detail { - - void expect_complex(PyObject*); - - template - std::complex complex_from_python(PyObject* p, boost::python::type) - { - if (PyInt_Check(p)) return std::complex(PyInt_AS_LONG(p)); - if (PyLong_Check(p)) return std::complex(PyLong_AsDouble(p)); - if (PyFloat_Check(p)) return std::complex(PyFloat_AS_DOUBLE(p)); - - expect_complex(p); - - return std::complex( - static_cast(PyComplex_RealAsDouble(p)), - static_cast(PyComplex_ImagAsDouble(p))); - } - - template - PyObject* complex_to_python(const std::complex& sc) { - Py_complex pcc; - pcc.real = sc.real(); - pcc.imag = sc.imag(); - return PyComplex_FromCComplex(pcc); - } - -} - -}} // namespace boost::python - -BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE -// -// Converters -// -PyObject* to_python(long); -BOOST_PYTHON_DECL long from_python(PyObject* p, boost::python::type); -long from_python(PyObject* p, boost::python::type); - -BOOST_PYTHON_DECL PyObject* to_python(unsigned long); -BOOST_PYTHON_DECL unsigned long from_python(PyObject* p, boost::python::type); -unsigned long from_python(PyObject* p, boost::python::type); - -PyObject* to_python(int); -BOOST_PYTHON_DECL int from_python(PyObject*, boost::python::type); -int from_python(PyObject*, boost::python::type); - -BOOST_PYTHON_DECL PyObject* to_python(unsigned int); -BOOST_PYTHON_DECL unsigned int from_python(PyObject*, boost::python::type); -unsigned int from_python(PyObject*, boost::python::type); - -PyObject* to_python(short); -BOOST_PYTHON_DECL short from_python(PyObject*, boost::python::type); -short from_python(PyObject*, boost::python::type); - -BOOST_PYTHON_DECL PyObject* to_python(unsigned short); -BOOST_PYTHON_DECL unsigned short from_python(PyObject*, boost::python::type); -unsigned short from_python(PyObject*, boost::python::type); - -BOOST_PYTHON_DECL PyObject* to_python(char); -BOOST_PYTHON_DECL char from_python(PyObject*, boost::python::type); -char from_python(PyObject*, boost::python::type); - -BOOST_PYTHON_DECL PyObject* to_python(signed char); -BOOST_PYTHON_DECL signed char from_python(PyObject*, boost::python::type); -signed char from_python(PyObject*, boost::python::type); - -BOOST_PYTHON_DECL PyObject* to_python(unsigned char); -BOOST_PYTHON_DECL unsigned char from_python(PyObject*, boost::python::type); -unsigned char from_python(PyObject*, boost::python::type); - -BOOST_PYTHON_DECL float from_python(PyObject*, boost::python::type); -BOOST_PYTHON_DECL double from_python(PyObject*, boost::python::type); - -# if !defined(BOOST_MSVC) || BOOST_MSVC > 1300 -PyObject* to_python(float); -PyObject* to_python(double); -# else -BOOST_PYTHON_DECL PyObject* to_python(float); -BOOST_PYTHON_DECL PyObject* to_python(double); -# endif -float from_python(PyObject*, boost::python::type); - -double from_python(PyObject*, boost::python::type); - -PyObject* to_python(bool); -BOOST_PYTHON_DECL bool from_python(PyObject*, boost::python::type); -bool from_python(PyObject*, boost::python::type); - -BOOST_PYTHON_DECL PyObject* to_python(void); -BOOST_PYTHON_DECL void from_python(PyObject*, boost::python::type); - -PyObject* to_python(const char* s); -BOOST_PYTHON_DECL const char* from_python(PyObject*, boost::python::type); - -BOOST_PYTHON_DECL PyObject* to_python(const std::string& s); -BOOST_PYTHON_DECL std::string from_python(PyObject*, boost::python::type); -std::string from_python(PyObject*, boost::python::type); - -inline PyObject* to_python(const std::complex& x) -{ - return boost::python::detail::complex_to_python(x); -} - -inline PyObject* to_python(const std::complex& x) -{ - return boost::python::detail::complex_to_python(x); -} - -inline std::complex from_python(PyObject* p, - boost::python::type >) { - return boost::python::detail::complex_from_python(p, boost::python::type()); -} - -inline std::complex from_python(PyObject* p, - boost::python::type&>) { - return boost::python::detail::complex_from_python(p, boost::python::type()); -} - -inline std::complex from_python(PyObject* p, - boost::python::type >) { - return boost::python::detail::complex_from_python(p, boost::python::type()); -} - -inline std::complex from_python(PyObject* p, - boost::python::type&>) { - return boost::python::detail::complex_from_python(p, boost::python::type()); -} - -// For when your C++ function really wants to pass/return a PyObject* -PyObject* to_python(PyObject*); -PyObject* from_python(PyObject*, boost::python::type); - -// Some standard conversions to/from smart pointer types. You can add your own -// from these examples. These are not generated using the friend technique from -// wrapped_pointer because: -// -// 1. We want to be able to extend conversion to/from WrappedPointers using -// arbitrary smart pointer types. -// -// 2. It helps with compilation independence. This way, code which creates -// wrappers for functions accepting and returning smart_ptr does not -// have to have already seen the invocation of wrapped_type. -// - -// Unfortunately, MSVC6 is so incredibly lame that we have to rely on the friend -// technique to auto_generate standard pointer conversions for wrapped -// types. This means that you need to write a non-templated function for each -// specific smart_ptr which you want to convert from_python. For example, -// -// namespace boost { namespace python { -// #ifdef MUST_SUPPORT_MSVC -// -// MyPtr from_python(PyObject*p, type >) -// { return smart_ptr_from_python(p, type >(), type());} -// } -// -// MyPtr from_python(PyObject*p, type >) -// { return smart_ptr_from_python(p, type >(), type());} -// -// ... // definitions for MyPtr, MyPtr, etc. -// -// #else -// -// // Just once for all MyPtr -// template -// MyPtr from_python(PyObject*p, type >) -// { -// return smart_ptr_from_python(p, type >(), type()); -// } -// -// #endif -// }} // namespace boost::python - -#if !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING) -template -boost::shared_ptr from_python(PyObject*p, boost::python::type >) -{ - return smart_ptr_from_python(p, boost::python::type >(), boost::python::type()); -} -#endif - -#if 0 -template -PyObject* to_python(std::auto_ptr p) -{ - return new boost::python::wrapped_pointer, T>(p); -} - -template -PyObject* to_python(boost::shared_ptr p) -{ - return new boost::python::wrapped_pointer, T>(p); -} -#endif - -// -// inline implementations -// - -#if !defined(BOOST_MSVC) || BOOST_MSVC > 1300 -inline PyObject* to_python(double d) -{ - return PyFloat_FromDouble(d); -} - -inline PyObject* to_python(float f) -{ - return PyFloat_FromDouble(f); -} -#endif - -inline PyObject* to_python(long l) -{ - return PyInt_FromLong(l); -} - -inline PyObject* to_python(int x) -{ - return PyInt_FromLong(x); -} - -inline PyObject* to_python(short x) -{ - return PyInt_FromLong(x); -} - -inline PyObject* to_python(bool b) -{ - return PyInt_FromLong(b); -} - -inline PyObject* to_python(void) -{ - return boost::python::detail::none(); -} - -inline PyObject* to_python(const char* s) -{ - return PyString_FromString(s); -} - -inline std::string from_python(PyObject* p, boost::python::type) -{ - return from_python(p, boost::python::type()); -} - -inline PyObject* to_python(PyObject* p) -{ - Py_INCREF(p); - return p; -} - -inline PyObject* from_python(PyObject* p, boost::python::type) -{ - return p; -} - -inline const char* from_python(PyObject* p, boost::python::type) -{ - return from_python(p, boost::python::type()); -} - -inline double from_python(PyObject* p, boost::python::type) -{ - return from_python(p, boost::python::type()); -} - -inline float from_python(PyObject* p, boost::python::type) -{ - return from_python(p, boost::python::type()); -} - -inline int from_python(PyObject* p, boost::python::type) -{ - return from_python(p, boost::python::type()); -} - -inline short from_python(PyObject* p, boost::python::type) -{ - return from_python(p, boost::python::type()); -} - -inline long from_python(PyObject* p, boost::python::type) -{ - return from_python(p, boost::python::type()); -} - -inline bool from_python(PyObject* p, boost::python::type) -{ - return from_python(p, boost::python::type()); -} - -inline unsigned int from_python(PyObject* p, boost::python::type) -{ - return from_python(p, boost::python::type()); -} - -inline unsigned short from_python(PyObject* p, boost::python::type) -{ - return from_python(p, boost::python::type()); -} - -inline char from_python(PyObject* p, boost::python::type) -{ - return from_python(p, boost::python::type()); -} - -inline signed char from_python(PyObject* p, boost::python::type) -{ - return from_python(p, boost::python::type()); -} - -inline unsigned char from_python(PyObject* p, boost::python::type) -{ - return from_python(p, boost::python::type()); -} - -inline unsigned long from_python(PyObject* p, boost::python::type) -{ - return from_python(p, boost::python::type()); -} - - -BOOST_PYTHON_END_CONVERSION_NAMESPACE - -#endif // METHOD_DWA122899_H_ diff --git a/include/boost/python/converter/return_from_python.hpp b/include/boost/python/converter/return_from_python.hpp index 58d182f0..c487aa22 100755 --- a/include/boost/python/converter/return_from_python.hpp +++ b/include/boost/python/converter/return_from_python.hpp @@ -13,6 +13,7 @@ # include # include # include +# include namespace boost { namespace python { namespace converter { @@ -141,7 +142,7 @@ namespace detail inline T return_object_manager_from_python::operator()(PyObject* obj) const { return T( - object_manager_traits::adopt(obj) + object_manager_traits::adopt(expect_non_null(obj)) ); } } diff --git a/include/boost/python/cross_module.hpp b/include/boost/python/cross_module.hpp deleted file mode 100644 index c6ac8c22..00000000 --- a/include/boost/python/cross_module.hpp +++ /dev/null @@ -1,329 +0,0 @@ -/* (C) Copyright Ralf W. Grosse-Kunstleve 2001. Permission to copy, use, - modify, sell and distribute this software is granted provided this - copyright notice appears in all copies. This software is provided - "as is" without express or implied warranty, and with no claim as to - its suitability for any purpose. - - Revision History: - 17 Apr 01 merged into boost CVS trunk (Ralf W. Grosse-Kunstleve) -*/ - -/* Implementation of Boost.Python cross-module support. - See root/libs/python/doc/cross_module.html for details. -*/ - -#ifndef CROSS_MODULE_HPP -# define CROSS_MODULE_HPP - -# include - -namespace boost { namespace python { - -struct BOOST_PYTHON_DECL import_error: error_already_set {}; -struct BOOST_PYTHON_DECL export_error : error_already_set {}; - -void BOOST_PYTHON_DECL throw_import_error(); -void BOOST_PYTHON_DECL throw_export_error(); - -namespace detail -{ - -// Concept: throw exception if api_major is changed -// show warning on stderr if api_minor is changed - const int export_converters_api_major = 4; - const int export_converters_api_minor = 1; - extern BOOST_PYTHON_DECL const char* converters_attribute_name; - BOOST_PYTHON_DECL void* import_converter_object(const std::string& module_name, - const std::string& py_class_name, - const std::string& attribute_name); - BOOST_PYTHON_DECL void check_export_converters_api(const int importing_major, - const int importing_minor, - const int imported_major, - const int imported_minor); - -} - -}} // namespace boost::python - -// forward declaration -namespace boost { namespace python { namespace detail { -template class import_extension_class; -}}} - -BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE - -/* This class template is instantiated by import_converters. - This class is a look-alike of class python_extension_class_converters. - The converters in this class are wrappers that call converters - imported from another module. - To ensure that the dynamic loader resolves all symbols in the - intended way, the signature of all friend functions is changed with - respect to the original functions in class - python_extension_class_converters by adding an arbitrary additional - parameter with a default value, in this case "bool sig = false". - See also: comments for class export_converter_object_base below. - */ -template -class python_import_extension_class_converters -{ - public: - - friend python_import_extension_class_converters py_extension_class_converters(boost::python::type, bool sig = false) { - return python_import_extension_class_converters(); - } - - PyObject* to_python(const T& x) const { - return boost::python::detail::import_extension_class::get_converters()->to_python(x); - } - - friend T* from_python(PyObject* p, boost::python::type t, bool sig = false) { - return boost::python::detail::import_extension_class::get_converters()->from_python_Ts(p, t); - } - friend const T* from_python(PyObject* p, boost::python::type t, bool sig = false) { - return boost::python::detail::import_extension_class::get_converters()->from_python_cTs(p, t); - } - friend const T* from_python(PyObject* p, boost::python::type t, bool sig = false) { - return boost::python::detail::import_extension_class::get_converters()->from_python_cTscr(p, t); - } - friend T* from_python(PyObject* p, boost::python::type t, bool sig = false) { - return boost::python::detail::import_extension_class::get_converters()->from_python_Tscr(p, t); - } - friend T& from_python(PyObject* p, boost::python::type t, bool sig = false) { - return boost::python::detail::import_extension_class::get_converters()->from_python_Tr(p, t); - } - friend const T& from_python(PyObject* p, boost::python::type t, bool sig = false) { - return boost::python::detail::import_extension_class::get_converters()->from_python_cTr(p, t); - } - friend const T& from_python(PyObject* p, boost::python::type t, bool sig = false) { - return boost::python::detail::import_extension_class::get_converters()->from_python_T(p, t); - } - - friend std::auto_ptr& from_python(PyObject* p, boost::python::type&> t, bool sig = false) { - return boost::python::detail::import_extension_class::get_converters()->from_python_aTr(p, t); - } - friend std::auto_ptr from_python(PyObject* p, boost::python::type > t, bool sig = false) { - return boost::python::detail::import_extension_class::get_converters()->from_python_aT(p, t); - } - friend const std::auto_ptr& from_python(PyObject* p, boost::python::type&> t, bool sig = false) { - return boost::python::detail::import_extension_class::get_converters()->from_python_caTr(p, t); - } - friend PyObject* to_python(std::auto_ptr x, bool sig = false) { - return boost::python::detail::import_extension_class::get_converters()->to_python(x); - } - - friend boost::shared_ptr& from_python(PyObject* p, boost::python::type&> t, bool sig = false) { - return boost::python::detail::import_extension_class::get_converters()->from_python_sTr(p, t); - } - friend const boost::shared_ptr& from_python(PyObject* p, boost::python::type > t, bool sig = false) { - return boost::python::detail::import_extension_class::get_converters()->from_python_sT(p, t); - } - friend const boost::shared_ptr& from_python(PyObject* p, boost::python::type&> t, bool sig = false) { - return boost::python::detail::import_extension_class::get_converters()->from_python_csTr(p, t); - } - friend PyObject* to_python(boost::shared_ptr x, bool sig = false) { - return boost::python::detail::import_extension_class::get_converters()->to_python(x); - } -}; - -BOOST_PYTHON_END_CONVERSION_NAMESPACE - -namespace boost { namespace python { - -BOOST_PYTHON_IMPORT_CONVERSION(python_import_extension_class_converters); - -/* This class template is instantiated by export_converters(). - A pointer to this class is exported/imported via the Python API. - Using the Python API ensures maximum portability. - All member functions are virtual. This is, what we export/import - is essentially just a pointer to a vtbl. - To work around a deficiency of Visual C++ 6.0, the name of each - from_python() member functions is made unique by appending a few - characters (derived in a ad-hoc manner from the corresponding type). - */ -template -struct export_converter_object_base -{ - virtual int get_api_major() const { return detail::export_converters_api_major; } - virtual int get_api_minor() const { return detail::export_converters_api_minor; } - - virtual PyObject* to_python(const T& x) = 0; - - virtual T* from_python_Ts(PyObject* p, boost::python::type t) = 0; - virtual const T* from_python_cTs(PyObject* p, boost::python::type t) = 0; - virtual const T* from_python_cTscr(PyObject* p, boost::python::type t) = 0; - virtual T* from_python_Tscr(PyObject* p, boost::python::type t) = 0; - virtual T& from_python_Tr(PyObject* p, boost::python::type t) = 0; - virtual const T& from_python_cTr(PyObject* p, boost::python::type t) = 0; - virtual const T& from_python_T(PyObject* p, boost::python::type t) = 0; - - virtual std::auto_ptr& from_python_aTr(PyObject* p, boost::python::type&> t) = 0; - virtual std::auto_ptr from_python_aT(PyObject* p, boost::python::type > t) = 0; - virtual const std::auto_ptr& from_python_caTr(PyObject* p, boost::python::type&> t) = 0; - virtual PyObject* to_python(std::auto_ptr x) = 0; - - virtual boost::shared_ptr& from_python_sTr(PyObject* p, boost::python::type&> t) = 0; - virtual const boost::shared_ptr& from_python_sT(PyObject* p, boost::python::type > t) = 0; - virtual const boost::shared_ptr& from_python_csTr(PyObject* p, boost::python::type&> t) = 0; - virtual PyObject* to_python(boost::shared_ptr x) = 0; -}; - -// Converters to be used if T is not copyable. -template -struct export_converter_object_noncopyable : export_converter_object_base -{ - virtual PyObject* to_python(const T& x) { - PyErr_SetString(PyExc_RuntimeError, - "to_python(const T&) converter not exported"); - throw_import_error(); - return 0; - } - - virtual T* from_python_Ts(PyObject* p, boost::python::type t) { - return BOOST_PYTHON_CONVERSION::from_python(p, t); - } - virtual const T* from_python_cTs(PyObject* p, boost::python::type t) { - return BOOST_PYTHON_CONVERSION::from_python(p, t); - } - virtual const T* from_python_cTscr(PyObject* p, boost::python::type t) { - return BOOST_PYTHON_CONVERSION::from_python(p, t); - } - virtual T* from_python_Tscr(PyObject* p, boost::python::type t) { - return BOOST_PYTHON_CONVERSION::from_python(p, t); - } - virtual T& from_python_Tr(PyObject* p, boost::python::type t) { - return BOOST_PYTHON_CONVERSION::from_python(p, t); - } - virtual const T& from_python_cTr(PyObject* p, boost::python::type t) { - return BOOST_PYTHON_CONVERSION::from_python(p, t); - } - virtual const T& from_python_T(PyObject* p, boost::python::type t) { - return BOOST_PYTHON_CONVERSION::from_python(p, t); - } - - virtual std::auto_ptr& from_python_aTr(PyObject* p, boost::python::type&> t) { - return BOOST_PYTHON_CONVERSION::from_python(p, t); - } - virtual std::auto_ptr from_python_aT(PyObject* p, boost::python::type > t) { - return BOOST_PYTHON_CONVERSION::from_python(p, t); - } - virtual const std::auto_ptr& from_python_caTr(PyObject* p, boost::python::type&> t) { - return BOOST_PYTHON_CONVERSION::from_python(p, t); - } - virtual PyObject* to_python(std::auto_ptr x) { - return BOOST_PYTHON_CONVERSION::to_python(x); - } - - virtual boost::shared_ptr& from_python_sTr(PyObject* p, boost::python::type&> t) { - return BOOST_PYTHON_CONVERSION::from_python(p, t); - } - virtual const boost::shared_ptr& from_python_sT(PyObject* p, boost::python::type > t) { - return BOOST_PYTHON_CONVERSION::from_python(p, t); - } - virtual const boost::shared_ptr& from_python_csTr(PyObject* p, boost::python::type&> t) { - return BOOST_PYTHON_CONVERSION::from_python(p, t); - } - virtual PyObject* to_python(boost::shared_ptr x) { - return BOOST_PYTHON_CONVERSION::to_python(x); - } -}; - -// The addditional to_python() converter that can be used if T is copyable. -template -struct export_converter_object : export_converter_object_noncopyable -{ - virtual PyObject* to_python(const T& x) { - return BOOST_PYTHON_CONVERSION::py_extension_class_converters(boost::python::type()).to_python(x); - } -}; - -namespace detail -{ - -/* This class template is instantiated by import_converters. - Its purpose is to import the converter_object via the Python API. - The actual import is only done once. The pointer to the - imported converter object is kept in the static data member - imported_converters. -*/ - template - class import_extension_class - : public python_import_extension_class_converters - { - public: - inline import_extension_class(const char* module, const char* py_class) { - m_module = module; - m_py_class = py_class; - } - - static boost::python::export_converter_object_base* get_converters(); - - private: - static std::string m_module; - static std::string m_py_class; - static boost::python::export_converter_object_base* imported_converters; - }; - - template std::string import_extension_class::m_module; - template std::string import_extension_class::m_py_class; - template - boost::python::export_converter_object_base* - import_extension_class::imported_converters = 0; - - template - boost::python::export_converter_object_base* - import_extension_class::get_converters() { - if (imported_converters == 0) { - void* cobject - = import_converter_object(m_module, m_py_class, - converters_attribute_name); - imported_converters - = static_cast*>(cobject); - check_export_converters_api( - export_converters_api_major, - export_converters_api_minor, - imported_converters->get_api_major(), - imported_converters->get_api_minor()); - } - return imported_converters; - } -}}} // namespace boost::python::detail - -namespace boost { namespace python { - -// Implementation of export_converters(). -template -void export_converters(class_builder& cb) -{ - static export_converter_object export_cvts; - cb.add( - ref(PyCObject_FromVoidPtr(reinterpret_cast(&export_cvts), NULL)), - detail::converters_attribute_name); -} - -// Implementation of export_converters_noncopyable(). -template -void export_converters_noncopyable(class_builder& cb) -{ - static export_converter_object_noncopyable export_cvts; - cb.add( - ref(PyCObject_FromVoidPtr(reinterpret_cast(&export_cvts), NULL)), - detail::converters_attribute_name); -} - -// Implementation of import_converters. -template -class import_converters - : python_import_extension_class_converters // Works around MSVC6.x/GCC2.95.2 bug described - // at the bottom of class_builder.hpp. -{ - public: - import_converters(const char* module, const char* py_class) - : m_class(new detail::import_extension_class(module, py_class)) - { } - private: - boost::shared_ptr > m_class; -}; - -}} // namespace boost::python - -#endif // CROSS_MODULE_HPP diff --git a/include/boost/python/def.hpp b/include/boost/python/def.hpp index 1ade4fd1..f6218886 100644 --- a/include/boost/python/def.hpp +++ b/include/boost/python/def.hpp @@ -12,43 +12,49 @@ # include # include # include +# include namespace boost { namespace python { namespace detail { - void BOOST_PYTHON_DECL scope_setattr_doc(char const* name, object const& obj, char const* doc); - - template + template void dispatch_def( void const*, char const* name, Fn fn, - CallPolicyOrDoc const& policy_or_doc) + A1 const& a1) { - typedef detail::def_helper helper; - + def_helper helper(a1); + detail::scope_setattr_doc( - name, boost::python::make_function(fn, helper::get_policy(policy_or_doc)), - helper::get_doc(policy_or_doc, 0)); + name, boost::python::make_function( + fn + , helper.policies() + , helper.keywords()) + , helper.doc() + ); } - template + template void dispatch_def( void const*, char const* name, Fn fn, - CallPolicyOrDoc1 const& policy_or_doc1, - CallPolicyOrDoc2 const& policy_or_doc2) + A1 const& a1, + A2 const& a2) { - typedef detail::def_helper helper; + def_helper helper(a1,a2); detail::scope_setattr_doc( - name, boost::python::make_function( - fn, helper::get_policy(policy_or_doc1, policy_or_doc2)), - helper::get_doc(policy_or_doc1, policy_or_doc2)); - } + name, python::make_function( + fn + , helper.policies() + , helper.keywords()) + , helper.doc() + ); + } template void dispatch_def( @@ -87,22 +93,22 @@ void def(char const* name, Arg1T arg1, Arg2T const& arg2) template void def(char const* name, Arg1T arg1, Arg2T const& arg2, Arg3T const& arg3) { - // The arguments are definitely: - // def(name, function, policy, doc_string) // TODO: exchange policy, doc_string position - detail::dispatch_def(&arg2, name, arg1, arg2, arg3); } -//template -//void def(char const* name, Arg1T arg1, Arg2T const& arg2, Arg3T const& arg3, char const* doc) -//{ -// // The arguments are definitely: -// // arg1: signature -// // arg2: stubs -// // arg3: policy -// -// detail::dispatch_def(&arg2, name, arg1, arg2, arg3, doc); -//} +template +void def(char const* name, F f, A1 const& a1, A2 const& a2, A3 const& a3) +{ + detail::def_helper helper(a1,a2,a3); + + detail::scope_setattr_doc( + name, python::make_function( + f + , helper.policies() + , helper.keywords()) + , helper.doc() + ); +} }} // namespace boost::python diff --git a/include/boost/python/detail/base_object.hpp b/include/boost/python/detail/base_object.hpp deleted file mode 100644 index d92b3972..00000000 --- a/include/boost/python/detail/base_object.hpp +++ /dev/null @@ -1,60 +0,0 @@ -// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and -// distribute this software is granted provided this copyright notice appears -// in all copies. This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// The author gratefully acknowleges the support of Dragon Systems, Inc., in -// producing this work. -// -// Revision History: -// Mar 01 01 Use PyObject_INIT() instead of trying to hand-initialize (David Abrahams) - -#ifndef BASE_OBJECT_DWA051600_H_ -# define BASE_OBJECT_DWA051600_H_ - -# include -# include -# include - -namespace boost { namespace python { namespace detail { - -// base_object - adds a constructor and non-virtual destructor to a -// base Python type (e.g. PyObject, PyTypeObject). -template -struct base_object : PythonType -{ - typedef PythonType base_python_type; - - // Initializes type and reference count. All other fields of base_python_type are 0 - base_object(PyTypeObject* type_obj); - - // Decrements reference count on the type - ~base_object(); -}; - -// Easy typedefs for common usage -typedef base_object python_object; -typedef base_object python_type; - - -// -// base_object member function implementations -// -template -base_object::base_object(PyTypeObject* type_obj) -{ - base_python_type* bp = this; - BOOST_CSTD_::memset(bp, 0, sizeof(base_python_type)); - Py_INCREF(type_obj); - PyObject_INIT(bp, type_obj); -} - -template -inline base_object::~base_object() -{ - Py_DECREF(ob_type); -} - -}}} // namespace boost::python::detail - -#endif // BASE_OBJECT_DWA051600_H_ diff --git a/include/boost/python/detail/cast.hpp b/include/boost/python/detail/cast.hpp deleted file mode 100644 index 367f1f14..00000000 --- a/include/boost/python/detail/cast.hpp +++ /dev/null @@ -1,81 +0,0 @@ -// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and -// distribute this software is granted provided this copyright notice appears -// in all copies. This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// The author gratefully acknowleges the support of Dragon Systems, Inc., in -// producing this work. - -#ifndef CAST_DWA052500_H_ -# define CAST_DWA052500_H_ - -# ifndef BOOST_PYTHON_V2 -# include -# include - -namespace boost { namespace python { - -namespace detail { - inline PyTypeObject* as_base_object(const PyTypeObject*, PyObject* p) - { - return reinterpret_cast(p); - } - - inline PyObject* as_base_object(const PyObject*, PyObject* p) - { - return p; - } - - inline const PyTypeObject* as_base_object(const PyTypeObject*, const PyObject* p) - { - return reinterpret_cast(p); - } - - inline const PyObject* as_base_object(const PyObject*, const PyObject* p) - { - return p; - } -} // namespace detail - -// Convert a pointer to any type derived from PyObject or PyTypeObject to a PyObject* -inline PyObject* as_object(PyObject* p) { return p; } -inline PyObject* as_object(PyTypeObject* p) { return reinterpret_cast(p); } - -// If I didn't have to support stupid MSVC6 we could just use a simple template function: -// template T* downcast(PyObject*). -template -struct downcast -{ - downcast(PyObject* p) - : m_p(static_cast(detail::as_base_object((T*)0, p))) - {} - - downcast(const PyObject* p) - : m_p(static_cast(detail::as_base_object((const T*)0, p))) - {} - - downcast(PyTypeObject* p) - : m_p(static_cast(p)) - {} - - downcast(const PyTypeObject* p) - : m_p(static_cast(p)) - {} - - operator T*() const { return m_p; } - - // MSVC doesn't like boost::dereferencable unless T has a default - // constructor, so operator-> must be defined by hand :( - T* operator->() const { return &**this; } - - T* get() const { return m_p; } - T& operator*() const { return *m_p; } - private: - T* m_p; -}; - -}} // namespace boost::python - -# endif // BOOST_PYTHON_V2 - -#endif // CAST_DWA052500_H_ diff --git a/include/boost/python/detail/config.hpp b/include/boost/python/detail/config.hpp index c3750902..16948010 100644 --- a/include/boost/python/detail/config.hpp +++ b/include/boost/python/detail/config.hpp @@ -97,15 +97,6 @@ # define BOOST_PYTHON_EXPORT_CLASS_TEMPLATE(instantiation) struct ThIsTyPeNeVeRuSeD #endif -#if defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730 -// Work around a compiler bug. -// boost::python::detail::function has to be seen by the compiler before the -// boost::function class template. -namespace boost { namespace python { namespace detail { -class function; -}}} -#endif - #if (defined(__DECCXX_VER) && __DECCXX_VER <= 60590014) // Replace broken Tru64/cxx offsetof macro # define BOOST_PYTHON_OFFSETOF(s_name, s_member) \ diff --git a/include/boost/python/detail/def_helper.hpp b/include/boost/python/detail/def_helper.hpp index b9931cfe..4135af55 100644 --- a/include/boost/python/detail/def_helper.hpp +++ b/include/boost/python/detail/def_helper.hpp @@ -6,72 +6,146 @@ #ifndef DEF_HELPER_DWA200287_HPP # define DEF_HELPER_DWA200287_HPP +# include # include # include -# include +# include +# include +# include +# include +# include +# include +# include +# include -namespace boost { namespace python { namespace detail { +namespace boost { namespace python { -// -// def_helper -- -// -// A helper for def() functions which determines how to interpret -// an argument of type T which could be either CallPolicies or a -// string literal representing a docstring. -// -// Generates two static functions: -// -// get_policy(x), where x is of type T, returns a policies -// object: either a reference to x or default_call_policies() -// if x is a string literal. -// -// get_doc(x, s), where s convertible to char const*, returns x -// if x is a string literal, s otherwise. +struct default_call_policies; -template -struct def_helper_impl +namespace detail { - template - static P const& - get_policy(P const& x) { return x; } - - template - static P1 const& - get_policy(P1 const& x, P2 const&) { return x; } // select left - - template - static char const* - get_doc(P const&, char const* doc) { return doc; } // select right -}; - -template <> -struct def_helper_impl -{ - static python::default_call_policies - get_policy(char const*) - { return default_call_policies(); } - - template - static P2 const& - get_policy(P1 const&, P2 const& y) { return y; } // select right - - template - static char const* - get_doc(char const* doc, P const&) // select left - { return doc; } -}; + template + struct tuple_extract; -template -struct def_helper - : def_helper_impl< - type_traits::ice_or< - is_string_literal::value - , is_same::value - , is_same::value ->::value -> -{}; + template + struct tuple_extract_impl + { + template + struct apply + { + typedef typename Tuple::head_type result_type; + + static typename Tuple::head_type extract(Tuple const& x) + { + return x.get_head(); + } + }; + }; + + template <> + struct tuple_extract_impl + { + template + struct apply + : tuple_extract + { + // All of this forwarding would be unneeded if tuples were + // derived from their tails. + typedef tuple_extract base; + typedef typename base::result_type result_type; + static result_type extract(Tuple const& x) + { + return base::extract(x.get_tail()); + } + }; + }; -}}} // namespace boost::python::detail + template + struct tuple_extract_base_select + { + typedef typename Tuple::head_type head_type; + typedef typename mpl::apply1::type match_t; + BOOST_STATIC_CONSTANT(bool, match = match_t::value); + typedef typename tuple_extract_impl::template apply type; + }; + + template + struct tuple_extract + : tuple_extract_base_select< + Tuple + , typename mpl::lambda::type + >::type + { + }; + + template + struct doc_extract + : tuple_extract< + Tuple, + mpl::logical_not< + is_reference_to_class< + add_reference + > + > > + { + }; + + template + struct keyword_extract + : tuple_extract > > + { + }; + + template + struct policy_extract + : tuple_extract< + Tuple, + mpl::logical_and< + is_reference_to_class > + , mpl::logical_not > > + > + > + { + }; + +# define BOOST_PYTHON_DEF_HELPER_TAIL default_call_policies, keywords<0>, char const* + template + struct def_helper + { + typedef typename mpl::if_< + is_same + , boost::tuples::tuple + , typename mpl::if_< + is_same + , boost::tuples::tuple + , boost::tuples::tuple + >::type + >::type all_t; + + def_helper(T1 const& a1) : m_all(a1) {} + def_helper(T1 const& a1, T2 const& a2) : m_all(a1,a2) {} + def_helper(T1 const& a1, T2 const& a2, T3 const& a3) : m_all(a1,a2,a3) {} + + char const* doc() const + { + return doc_extract::extract(m_all); + } + + typename keyword_extract::result_type keywords() const + { + return keyword_extract::extract(m_all); + } + + typename policy_extract::result_type policies() const + { + return policy_extract::extract(m_all); + } + + all_t m_all; + }; +# undef BOOST_PYTHON_DEF_HELPER_TAIL +} + +}} // namespace boost::python::detail #endif // DEF_HELPER_DWA200287_HPP diff --git a/include/boost/python/detail/defaults_def.hpp b/include/boost/python/detail/defaults_def.hpp index 721fc37f..6321247e 100644 --- a/include/boost/python/detail/defaults_def.hpp +++ b/include/boost/python/detail/defaults_def.hpp @@ -1,10 +1,10 @@ /////////////////////////////////////////////////////////////////////////////// // -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. +// Copyright David Abrahams 2002, Joel de Guzman, 2002. Permission to copy, +// use, modify, sell and distribute this software is granted provided this +// copyright notice appears in all copies. This software is provided "as is" +// without express or implied warranty, and with no claim as to its +// suitability for any purpose. // /////////////////////////////////////////////////////////////////////////////// #if !defined(BOOST_PP_IS_ITERATING) @@ -19,9 +19,11 @@ #include #include #include -#include #include #include +#include +#include +#include /////////////////////////////////////////////////////////////////////////////// namespace boost { namespace python { @@ -33,78 +35,92 @@ namespace objects struct class_base; } -namespace detail { - -template -static void name_space_def( - NameSpaceT& name_space, - char const* name, - Func f, - CallPolicies const& policies, - char const* doc, - objects::class_base* - ) +namespace detail { - name_space.def( - name, f, policies, doc); -} + template struct member_function_cast; -template -static void name_space_def( - object& name_space, - char const* name, - Func f, - CallPolicies const& policies, - char const* doc, - ... - ) -{ - scope within(name_space); + template + 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; - def(name, f, policies, doc); -} + objects::add_to_namespace( + name_space, name, + make_keyword_range_function( + // This bit of nastiness casts F to a member function of T if possible. + member_function_cast::stage1(f).stage2((wrapped_type*)0).stage3(f) + , policies, kw) + , doc); + } -// For backward compatibility -template -static void name_space_def( - NameSpaceT& name_space, - char const* name, - Func f, - CallPolicies const& policies, - char const* doc, - module* - ) -{ - name_space.def( - name, f, policies, doc); -} + template + 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); -/////////////////////////////////////////////////////////////////////////////// -// -// This Boost PP code generates expansions for -// -// template -// inline void -// define_stub_function( -// char const* name, StubsT s, NameSpaceT& name_space, mpl::int_c) -// { -// name_space.def(name, &StubsT::func_N); -// } -// -// where N runs from 0 to BOOST_PYTHON_MAX_ARITY -// -// The set of overloaded functions (define_stub_function) expects: -// -// 1. char const* name: function name that will be visible to python -// 2. StubsT: a function stubs struct (see defaults_gen.hpp) -// 3. NameSpaceT& name_space: a python::class_ or python::module instance -// 4. int_t: the Nth overloaded function (StubsT::func_N) -// (see defaults_gen.hpp) -// 5. char const* name: doc string -// -/////////////////////////////////////////////////////////////////////////////// -template -struct define_stub_function {}; + detail::scope_setattr_doc( + name + , detail::make_keyword_range_function(f, policies, kw) + , doc); + } + + // For backward compatibility + template + static void name_space_def( + NameSpaceT& name_space + , char const* name + , Func f + , keyword_range const& kw // ignored + , CallPolicies const& policies + , char const* doc + , module* + ) + { + name_space.def(name, f, policies, doc); + } + + /////////////////////////////////////////////////////////////////////////////// + // + // This Boost PP code generates expansions for + // + // template + // inline void + // define_stub_function( + // char const* name, OverloadsT s, NameSpaceT& name_space, mpl::int_c) + // { + // name_space.def(name, &OverloadsT::func_N); + // } + // + // where N runs from 0 to BOOST_PYTHON_MAX_ARITY + // + // The set of overloaded functions (define_stub_function) expects: + // + // 1. char const* name: function name that will be visible to python + // 2. OverloadsT: a function overloads struct (see defaults_gen.hpp) + // 3. NameSpaceT& name_space: a python::class_ or python::module instance + // 4. int_t: the Nth overloaded function (OverloadsT::func_N) + // (see defaults_gen.hpp) + // 5. char const* name: doc string + // + /////////////////////////////////////////////////////////////////////////////// + template + struct define_stub_function {}; #define BOOST_PP_ITERATION_PARAMS_1 \ (3, (0, BOOST_PYTHON_MAX_ARITY, )) @@ -120,10 +136,10 @@ struct define_stub_function {}; // terminal case define_with_defaults_helper<0>. The struct and its // specialization has a sole static member function def that expects: // -// 1. char const* name: function name that will be visible to python -// 2. StubsT: a function stubs struct (see defaults_gen.hpp) -// 3. NameSpaceT& name_space: a python::class_ or python::module instance -// 4. char const* name: doc string +// 1. char const* name: function name that will be visible to python +// 2. OverloadsT: a function overloads struct (see defaults_gen.hpp) +// 3. NameSpaceT& name_space: a python::class_ or python::module instance +// 4. char const* name: doc string // // The def static member function calls a corresponding // define_stub_function. The general case recursively calls @@ -139,14 +155,19 @@ struct define_stub_function {}; def( char const* name, StubsT stubs, + keyword_range kw, CallPolicies const& policies, NameSpaceT& name_space, char const* doc) { // define the NTH stub function of stubs - define_stub_function::define(name, stubs, policies, name_space, doc); + define_stub_function::define(name, stubs, kw, policies, name_space, doc); + + if (kw.second > kw.first) + --kw.second; + // call the next define_with_defaults_helper - define_with_defaults_helper::def(name, stubs, policies, name_space, doc); + define_with_defaults_helper::def(name, stubs, kw, policies, name_space, doc); } }; @@ -159,12 +180,13 @@ struct define_stub_function {}; def( char const* name, StubsT stubs, + keyword_range const& kw, CallPolicies const& policies, NameSpaceT& name_space, char const* doc) { // define the Oth stub function of stubs - define_stub_function<0>::define(name, stubs, policies, name_space, doc); + define_stub_function<0>::define(name, stubs, kw, policies, name_space, doc); // return } }; @@ -174,7 +196,7 @@ struct define_stub_function {}; // define_with_defaults // // 1. char const* name: function name that will be visible to python -// 2. StubsT: a function stubs struct (see defaults_gen.hpp) +// 2. OverloadsT: a function overloads struct (see defaults_gen.hpp) // 3. CallPolicies& policies: Call policies // 4. NameSpaceT& name_space: a python::class_ or python::module instance // 5. SigT sig: Function signature typelist (see defaults_gen.hpp) @@ -191,17 +213,17 @@ struct define_stub_function {}; // void C::foo(int) mpl::list // /////////////////////////////////////////////////////////////////////////////// - template + template inline void define_with_defaults( char const* name, - StubsT const& stubs, + OverloadsT const& overloads, NameSpaceT& name_space, SigT sig) { typedef typename mpl::front::type return_type; - typedef typename StubsT::void_return_type void_return_type; - typedef typename StubsT::non_void_return_type non_void_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< boost::is_same::value @@ -213,8 +235,13 @@ struct define_stub_function {}; (stubs_type::max_args) <= mpl::size::value); typedef typename stubs_type::template gen gen_type; - define_with_defaults_helper::def - (name, gen_type(), stubs.call_policies(), name_space, stubs.doc_string()); + define_with_defaults_helper::def( + name + , gen_type() + , overloads.keywords() + , overloads.call_policies() + , name_space + , overloads.doc_string()); } } // namespace detail @@ -232,17 +259,21 @@ template <> struct define_stub_function { template static void define( - char const* name, - StubsT, - CallPolicies const& policies, - NameSpaceT& name_space, - char const* doc) + 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()), - policies, - doc, &name_space); + detail::name_space_def( + name_space + , name + , &StubsT::BOOST_PP_CAT(func_, BOOST_PP_ITERATION()) + , kw + , policies + , doc + , &name_space); } }; diff --git a/include/boost/python/detail/defaults_gen.hpp b/include/boost/python/detail/defaults_gen.hpp index d8b96d53..2e560488 100644 --- a/include/boost/python/detail/defaults_gen.hpp +++ b/include/boost/python/detail/defaults_gen.hpp @@ -1,10 +1,10 @@ /////////////////////////////////////////////////////////////////////////////// // -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. +// Copyright David Abrahams 2002, Joel de Guzman, 2002. Permission to copy, +// use, modify, sell and distribute this software is granted provided this +// copyright notice appears in all copies. This software is provided "as is" +// without express or implied warranty, and with no claim as to its +// suitability for any purpose. // /////////////////////////////////////////////////////////////////////////////// #ifndef DEFAULTS_GEN_JDG20020807_HPP @@ -29,74 +29,96 @@ namespace boost { namespace python { -// overloads_base is used as a base class for all function -// stubs. This class holds the doc_string of the stubs. - namespace detail { + // overloads_base is used as a base class for all function + // stubs. This class holds the doc_string of the stubs. struct overloads_base { overloads_base(char const* doc_) - : doc(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 doc; } + { + return m_doc; + } - char const* doc; + detail::keyword_range const& keywords() const + { + return m_keywords; + } + + private: + char const* m_doc; + detail::keyword_range m_keywords; }; -} -// overloads_proxy is generated by the overloads_common operator[] (see -// below). This class holds a user defined call policies of the stubs. + // overloads_proxy is generated by the overloads_common operator[] (see + // below). This class holds a user defined call policies of the stubs. + template + 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; -template -struct overloads_proxy - : public detail::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_) + {} - overloads_proxy(CallPoliciesT const& policies_, char const* doc) - : detail::overloads_base(doc), policies(policies_) {} + CallPoliciesT + call_policies() const + { + return policies; + } - CallPoliciesT - call_policies() const - { return policies; } + CallPoliciesT policies; + }; - CallPoliciesT policies; -}; + // overloads_common is our default function stubs base class. This + // class returns the default_call_policies in its call_policies() + // member function. It can generate a overloads_proxy however through + // its operator[] + template + struct overloads_common + : public overloads_base + { + overloads_common(char const* doc) + : overloads_base(doc) {} -// overloads_common is our default function stubs base class. This class -// returns the default_call_policies in its call_policies() member function. -// It can generate a overloads_proxy however through its operator[] + overloads_common(char const* doc, keyword_range const& kw) + : overloads_base(doc, kw) {} -template -struct overloads_common -: public detail::overloads_base { + default_call_policies + call_policies() const + { + return default_call_policies(); + } - overloads_common(char const* doc) - : detail::overloads_base(doc) {} + template + overloads_proxy + operator[](CallPoliciesT const& policies) const + { + return overloads_proxy( + policies, this->doc_string(), this->keywords()); + } + }; - default_call_policies - call_policies() const - { return default_call_policies(); } +}}} // namespace boost::python::detail - template - ::boost::python::overloads_proxy - operator[](CallPoliciesT const& policies) const - { - return overloads_proxy - (policies, doc); - } -}; -}} // namespace boost::python - -/////////////////////////////////////////////////////////////////////////////// #define BOOST_PYTHON_TYPEDEF_GEN(z, index, data) \ typedef typename BOOST_PP_CAT(iter, index)::next \ BOOST_PP_CAT(iter, BOOST_PP_INC(index)); \ - typedef typename BOOST_PP_CAT(iter, index)::type BOOST_PP_CAT(T, index); \ + typedef typename 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_, \ @@ -112,14 +134,14 @@ struct overloads_common } #define BOOST_PYTHON_GEN_FUNCTION(fname, fstubs_name, n_args, n_dflts, ret) \ - struct fstubs_name { \ - \ + struct fstubs_name \ + { \ BOOST_STATIC_CONSTANT(int, n_funcs = BOOST_PP_INC(n_dflts)); \ BOOST_STATIC_CONSTANT(int, max_args = n_funcs); \ \ template \ - struct gen { \ - \ + struct gen \ + { \ typedef typename ::boost::mpl::begin::type rt_iter; \ typedef typename rt_iter::type RT; \ typedef typename rt_iter::next iter0; \ @@ -151,14 +173,14 @@ struct overloads_common } #define BOOST_PYTHON_GEN_MEM_FUNCTION(fname, fstubs_name, n_args, n_dflts, ret) \ - struct fstubs_name { \ - \ + struct fstubs_name \ + { \ BOOST_STATIC_CONSTANT(int, n_funcs = BOOST_PP_INC(n_dflts)); \ BOOST_STATIC_CONSTANT(int, max_args = n_funcs + 1); \ \ template \ - struct gen { \ - \ + struct gen \ + { \ typedef typename ::boost::mpl::begin::type rt_iter; \ typedef typename rt_iter::type RT; \ \ @@ -179,75 +201,82 @@ struct overloads_common }; \ }; -/////////////////////////////////////////////////////////////////////////////// -#if defined(BOOST_NO_VOID_RETURNS) - -#define BOOST_PYTHON_GEN_FUNCTION_STUB(fname, fstubs_name, n_args, n_dflts) \ - BOOST_PYTHON_GEN_FUNCTION \ - (fname, BOOST_PP_CAT(fstubs_name, _NV), n_args, n_dflts, return) \ - BOOST_PYTHON_GEN_FUNCTION \ - (fname, BOOST_PP_CAT(fstubs_name, _V), n_args, n_dflts, ;) \ - struct fstubs_name \ - : public boost::python::overloads_common \ - { \ - typedef BOOST_PP_CAT(fstubs_name, _NV) non_void_return_type; \ - typedef BOOST_PP_CAT(fstubs_name, _V) void_return_type; \ - \ - fstubs_name(char const* doc = 0) \ - : boost::python:: \ - overloads_common(doc) {} \ - }; \ - -/////////////////////////////////////////////////////////////////////////////// -#define BOOST_PYTHON_GEN_MEM_FUNCTION_STUB(fname, fstubs_name, n_args, n_dflts) \ - BOOST_PYTHON_GEN_MEM_FUNCTION \ - (fname, BOOST_PP_CAT(fstubs_name, _NV), n_args, n_dflts, return) \ - BOOST_PYTHON_GEN_MEM_FUNCTION \ - (fname, BOOST_PP_CAT(fstubs_name, _V), n_args, n_dflts, ;) \ - struct fstubs_name \ - : public boost::python::overloads_common \ +#define BOOST_PYTHON_OVERLOAD_CONSTRUCTORS(fstubs_name, n_args, n_dflts) \ + fstubs_name(char const* doc = 0) \ + : ::boost::python::detail::overloads_common(doc) {} \ + template \ + fstubs_name(char const* doc, Keywords const& keywords) \ + : ::boost::python::detail::overloads_common( \ + doc, keywords.range()) \ { \ - typedef BOOST_PP_CAT(fstubs_name, _NV) non_void_return_type; \ - typedef BOOST_PP_CAT(fstubs_name, _V) void_return_type; \ - \ - fstubs_name(char const* doc = 0) \ - : boost::python:: \ - overloads_common(doc) {} \ - }; \ - -#else - -/////////////////////////////////////////////////////////////////////////////// -#define BOOST_PYTHON_GEN_FUNCTION_STUB(fname, fstubs_name, n_args, n_dflts) \ - BOOST_PYTHON_GEN_FUNCTION \ - (fname, BOOST_PP_CAT(fstubs_name, _NV), n_args, n_dflts, return) \ - struct fstubs_name \ - : public boost::python::overloads_common \ + typedef typename ::boost::python::detail:: \ + error::more_keywords_than_function_arguments< \ + Keywords::size,(n_args+n_dflts)>::too_many_keywords assertion; \ + } \ + template \ + fstubs_name(Keywords const& keywords, char const* doc = 0) \ + : ::boost::python::detail::overloads_common( \ + doc, keywords.range()) \ { \ - typedef BOOST_PP_CAT(fstubs_name, _NV) non_void_return_type; \ - typedef BOOST_PP_CAT(fstubs_name, _NV) void_return_type; \ - \ - fstubs_name(char const* doc = 0) \ - : boost::python:: \ - overloads_common(doc) {} \ - }; \ + typedef typename ::boost::python::detail:: \ + error::more_keywords_than_function_arguments< \ + Keywords::size,(n_args+n_dflts)>::too_many_keywords assertion; \ + } -/////////////////////////////////////////////////////////////////////////////// -#define BOOST_PYTHON_GEN_MEM_FUNCTION_STUB(fname, fstubs_name, n_args, n_dflts) \ - BOOST_PYTHON_GEN_MEM_FUNCTION \ - (fname, BOOST_PP_CAT(fstubs_name, _NV), n_args, n_dflts, return) \ +# if defined(BOOST_NO_VOID_RETURNS) + +# define BOOST_PYTHON_GEN_FUNCTION_STUB(fname, fstubs_name, n_args, n_dflts) \ + BOOST_PYTHON_GEN_FUNCTION( \ + fname, BOOST_PP_CAT(fstubs_name, NonVoid), n_args, n_dflts, return) \ + BOOST_PYTHON_GEN_FUNCTION( \ + fname, BOOST_PP_CAT(fstubs_name, Void), n_args, n_dflts, ;) \ struct fstubs_name \ - : public boost::python::overloads_common \ + : public ::boost::python::detail::overloads_common \ { \ - typedef BOOST_PP_CAT(fstubs_name, _NV) non_void_return_type; \ - typedef BOOST_PP_CAT(fstubs_name, _NV) void_return_type; \ - \ - fstubs_name(char const* doc = 0) \ - : boost::python:: \ - overloads_common(doc) {} \ - }; \ + typedef BOOST_PP_CAT(fstubs_name, NonVoid) non_void_return_type; \ + typedef BOOST_PP_CAT(fstubs_name, Void) void_return_type; \ + BOOST_PYTHON_OVERLOAD_CONSTRUCTORS(fstubs_name, n_args, n_dflts) \ + }; -#endif // defined(BOOST_MSVC) +# define BOOST_PYTHON_GEN_MEM_FUNCTION_STUB(fname, fstubs_name, n_args, n_dflts) \ + BOOST_PYTHON_GEN_MEM_FUNCTION( \ + fname, BOOST_PP_CAT(fstubs_name, NonVoid), n_args, n_dflts, return) \ + BOOST_PYTHON_GEN_MEM_FUNCTION( \ + fname, BOOST_PP_CAT(fstubs_name, Void), n_args, n_dflts, ;) \ + struct fstubs_name \ + : public ::boost::python::detail::overloads_common \ + { \ + typedef BOOST_PP_CAT(fstubs_name, NonVoid) non_void_return_type; \ + typedef BOOST_PP_CAT(fstubs_name, Void) void_return_type; \ + BOOST_PYTHON_OVERLOAD_CONSTRUCTORS(fstubs_name, n_args, n_dflts) \ + }; + +# else // !defined(BOOST_NO_VOID_RETURNS) + +# define BOOST_PYTHON_GEN_FUNCTION_STUB(fname, fstubs_name, n_args, n_dflts) \ + BOOST_PYTHON_GEN_FUNCTION( \ + fname, BOOST_PP_CAT(fstubs_name, NonVoid), n_args, n_dflts, return) \ + struct fstubs_name \ + : public ::boost::python::detail::overloads_common \ + { \ + typedef BOOST_PP_CAT(fstubs_name, NonVoid) non_void_return_type; \ + typedef BOOST_PP_CAT(fstubs_name, NonVoid) 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) \ + BOOST_PYTHON_GEN_MEM_FUNCTION( \ + fname, BOOST_PP_CAT(fstubs_name, NonVoid), n_args, n_dflts, return) \ + struct fstubs_name \ + : public ::boost::python::detail::overloads_common \ + { \ + typedef BOOST_PP_CAT(fstubs_name, NonVoid) non_void_return_type; \ + typedef BOOST_PP_CAT(fstubs_name, NonVoid) void_return_type; \ + BOOST_PYTHON_OVERLOAD_CONSTRUCTORS(fstubs_name, n_args, n_dflts) \ + }; + +# endif // !defined(BOOST_NO_VOID_RETURNS) /////////////////////////////////////////////////////////////////////////////// // @@ -278,14 +307,14 @@ struct overloads_common // // Generates this code: // -// struct foo_stubs_NV { -// +// struct foo_stubsNonVoid +// { // static const int n_funcs = 4; // static const int max_args = n_funcs; // // template -// struct gen { -// +// struct gen +// { // typedef typename ::boost::mpl::begin::type rt_iter; // typedef typename rt_iter::type RT; // typedef typename rt_iter::next iter0; @@ -312,28 +341,27 @@ struct overloads_common // }; // }; // -// struct foo_stubs -// : public boost::python::overloads_common +// struct foo_overloads +// : public boost::python::detail::overloads_common +// { +// typedef foo_overloadsNonVoid non_void_return_type; +// typedef foo_overloadsNonVoid void_return_type; // -// typedef foo_stubs_NV non_void_return_type; -// typedef foo_stubs_NV void_return_type; -// -// fstubs_name(char const* doc = 0) -// : boost::python:: -// overloads_common(doc) {} +// foo_overloads(char const* doc = 0) +// : boost::python::detail::overloads_common(doc) {} // }; // // The typedefs non_void_return_type and void_return_type are // used to handle compilers that do not support void returns. The // example above typedefs non_void_return_type and -// void_return_type to foo_stubs_NV. On compilers that do not -// support void returns, there are two versions: foo_stubs_NV and -// foo_stubs_V. The "V" version is almost identical to the "NV" -// version except for the return type (void) and the lack of the -// return keyword. +// void_return_type to foo_overloadsNonVoid. On compilers that do +// not support void returns, there are two versions: +// foo_overloadsNonVoid and foo_overloadsVoid. The "Void" +// version is almost identical to the "NonVoid" version except +// for the return type (void) and the lack of the return keyword. // -// See the overloads_common above for a description of the foo_stubs' -// base class. +// See the overloads_common above for a description of the +// foo_overloads' base class. // /////////////////////////////////////////////////////////////////////////////// #define BOOST_PYTHON_FUNCTION_OVERLOADS(generator_name, fname, min_args, max_args) \ diff --git a/include/boost/python/detail/extension_class.hpp b/include/boost/python/detail/extension_class.hpp deleted file mode 100644 index f92bb83b..00000000 --- a/include/boost/python/detail/extension_class.hpp +++ /dev/null @@ -1,1002 +0,0 @@ -// (C) Copyright David Abrahams 2001. Permission to copy, use, modify, sell and -// distribute this software is granted provided this copyright notice appears -// in all copies. This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// The author gratefully acknowleges the support of Dragon Systems, Inc., in -// producing this work. -// -// This file automatically generated for 10-argument constructors by -// gen_extclass.python - -// Revision History: -// 17 Apr 01 Comment added with reference to cross_module.hpp (R.W. Grosse-Kunstleve) -// 05 Mar 01 Fixed a bug which prevented auto_ptr values from being converted -// to_python (Dave Abrahams) - -#ifndef EXTENSION_CLASS_DWA052000_H_ -# define EXTENSION_CLASS_DWA052000_H_ - -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include - -namespace boost { namespace python { - -// forward declarations -template struct operators; -template struct left_operand; -template struct right_operand; - -enum without_downcast_t { without_downcast }; - -namespace detail -{ - -// forward declarations - class extension_instance; - class extension_class_base; - template class instance_holder; - template class instance_value_holder; - template class instance_ptr_holder; - template struct operand_select; - template struct choose_op; - template struct choose_rop; - template struct choose_unary_op; - template struct define_operator; - - class BOOST_PYTHON_DECL extension_instance : public instance - { - public: - extension_instance(PyTypeObject* class_); - ~extension_instance(); - - void add_implementation(std::auto_ptr holder); - - typedef std::vector held_objects; - const held_objects& wrapped_objects() const - { return m_wrapped_objects; } - private: - held_objects m_wrapped_objects; - }; - -} // namespace detail - -BOOST_PYTHON_EXPORT_CLASS_TEMPLATE(class_t); -BOOST_PYTHON_EXPORT_CLASS_TEMPLATE(meta_class); - -namespace detail { - -BOOST_PYTHON_DECL meta_class* extension_meta_class(); -BOOST_PYTHON_DECL extension_instance* get_extension_instance(PyObject* p); -BOOST_PYTHON_DECL void report_missing_instance_data(extension_instance*, class_t*, const std::type_info&); -BOOST_PYTHON_DECL void report_missing_ptr_data(extension_instance*, class_t*, const std::type_info&); -BOOST_PYTHON_DECL void report_missing_class_object(const std::type_info&); -BOOST_PYTHON_DECL void report_released_smart_pointer(const std::type_info&); - -template -T* check_non_null(T* p) -{ - if (p == 0) - report_released_smart_pointer(typeid(T)); - return p; -} - -template class held_instance; - -typedef void* (*conversion_function_ptr)(void*); - -struct BOOST_PYTHON_DECL base_class_info -{ - base_class_info(extension_class_base* t, conversion_function_ptr f) - :class_object(t), convert(f) - {} - - extension_class_base* class_object; - conversion_function_ptr convert; -}; - -typedef base_class_info derived_class_info; - -struct add_operator_base; - -class BOOST_PYTHON_DECL extension_class_base : public class_t -{ - public: - extension_class_base(const char* name); - - public: - // the purpose of try_class_conversions() and its related functions - // is explained in extclass.cpp - void* try_class_conversions(instance_holder_base*) const; - void* try_base_class_conversions(instance_holder_base*) const; - void* try_derived_class_conversions(instance_holder_base*) const; - - void set_attribute(const char* name, PyObject* x); - void set_attribute(const char* name, ref x); - - private: - virtual void* extract_object_from_holder(instance_holder_base* v) const = 0; - virtual std::vector const& base_classes() const = 0; - virtual std::vector const& derived_classes() const = 0; - - protected: - friend struct add_operator_base; - void add_method(reference method, const char* name); - void add_method(function* method, const char* name); - - void add_constructor_object(function*); - void add_setter_method(function*, const char* name); - void add_getter_method(function*, const char* name); -}; - -template -class class_registry -{ - public: - static extension_class_base* class_object() - { return static_class_object; } - - // Register/unregister the Python class object corresponding to T - static void register_class(extension_class_base*); - static void unregister_class(extension_class_base*); - - // Establish C++ inheritance relationships - static void register_base_class(base_class_info const&); - static void register_derived_class(derived_class_info const&); - - // Query the C++ inheritance relationships - static std::vector const& base_classes(); - static std::vector const& derived_classes(); - private: - static extension_class_base* static_class_object; - static std::vector static_base_class_info; - static std::vector static_derived_class_info; -}; - -template -struct is_null_helper -{ - template - static bool test(Ptr x) { return x == 0; } -}; - -template <> -struct is_null_helper -{ - template - static bool test(const Ptr& x) { return x.get() == 0; } -}; - -template -bool is_null(const Ptr& x) -{ - return is_null_helper<(is_pointer::value)>::test(x); -} - -}}} // namespace boost::python::detail - -BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE - -// This class' only job is to define from_python and to_python converters for T -// and U. T is the class the user really intends to wrap. U is a class derived -// from T with some virtual function overriding boilerplate, or if there are no -// virtual functions, U = held_instance. -// -// A look-alike of this class in root/boost/python/cross_module.hpp -// is used for the implementation of the cross-module support -// (export_converters and import_converters). If from_python -// and to_python converters are added or removed from the class -// below, the class python_import_extension_class_converters has -// to be modified accordingly. -// -template > -class python_extension_class_converters -{ - public: - // Get an object which can be used to convert T to/from python. This is used - // as a kind of concept check by the global template - // - // PyObject* to_python(const T& x) - // - // below this class, to prevent the confusing messages that would otherwise - // pop up. Now, if T hasn't been wrapped as an extension class, the user - // will see an error message about the lack of an eligible - // py_extension_class_converters() function. - friend python_extension_class_converters py_extension_class_converters(boost::python::type) - { - return python_extension_class_converters(); - } - - // This is a member function because in a conforming implementation, friend - // funcitons defined inline in the class body are all instantiated as soon - // as the enclosing class is instantiated. If T is not copyable, that causes - // a compiler error. Instead, we access this function through the global - // template - // - // PyObject* to_python(const T& x) - // - // defined below this class. Since template functions are instantiated only - // on demand, errors will be avoided unless T is noncopyable and the user - // writes code which causes us to try to copy a T. - PyObject* to_python(const T& x) const - { - boost::python::reference result(create_instance()); - result->add_implementation( - std::auto_ptr( - new boost::python::detail::instance_value_holder(result.get(), x))); - return result.release(); - } - - friend - T* non_null_from_python(PyObject* obj, boost::python::type) - { - // downcast to an extension_instance, then find the actual T - boost::python::detail::extension_instance* self = boost::python::detail::get_extension_instance(obj); - typedef std::vector::const_iterator iterator; - for (iterator p = self->wrapped_objects().begin(); - p != self->wrapped_objects().end(); ++p) - { - boost::python::detail::instance_holder* held = dynamic_cast*>(*p); - if (held != 0) - return held->target(); - - // see extclass.cpp for an explanation of try_class_conversions() - void* target = boost::python::detail::class_registry::class_object()->try_class_conversions(*p); - if(target) - return static_cast(target); - } - boost::python::detail::report_missing_instance_data(self, boost::python::detail::class_registry::class_object(), typeid(T)); - boost::python::throw_argument_error(); - return 0; - } - - // Convert to T* - friend T* from_python(PyObject* obj, boost::python::type) - { - if (obj == Py_None) - return 0; - else - return non_null_from_python(obj, boost::python::type()); - } - - // Extract from obj a mutable reference to the PtrType object which is holding a T. - template - static PtrType& smart_ptr_reference(PyObject* obj, boost::python::type) - { - // downcast to an extension_instance, then find the actual T - boost::python::detail::extension_instance* self = boost::python::detail::get_extension_instance(obj); - typedef std::vector::const_iterator iterator; - for (iterator p = self->wrapped_objects().begin(); - p != self->wrapped_objects().end(); ++p) - { - boost::python::detail::instance_ptr_holder* held = - dynamic_cast*>(*p); - if (held != 0) - return held->ptr(); - } - boost::python::detail::report_missing_ptr_data(self, boost::python::detail::class_registry::class_object(), typeid(T)); - boost::python::throw_argument_error(); - - return *(PtrType*)obj; - } - - // Extract from obj a reference to the PtrType object which is holding a - // T. If it weren't for auto_ptr, it would be a constant reference. Do not - // modify the referent except by copying an auto_ptr! If obj is None, the - // reference denotes a default-constructed PtrType - template - static PtrType& smart_ptr_value(PyObject* obj, boost::python::type) - { - if (obj == Py_None) - { - static PtrType null_ptr; - return null_ptr; - } - return smart_ptr_reference(obj, boost::python::type()); - } - - template - static PyObject* smart_ptr_to_python(PtrType x) - { - if (boost::python::detail::is_null(x)) - { - return boost::python::detail::none(); - } - - boost::python::reference result(create_instance()); - result->add_implementation( - std::auto_ptr( - new boost::python::detail::instance_ptr_holder(x))); - return result.release(); - } - - static boost::python::reference create_instance() - { - PyTypeObject* class_object = boost::python::detail::class_registry::class_object(); - if (class_object == 0) - boost::python::detail::report_missing_class_object(typeid(T)); - - return boost::python::reference( - new boost::python::detail::extension_instance(class_object)); - } - - // Convert to const T* - friend const T* from_python(PyObject* p, boost::python::type) - { return from_python(p, boost::python::type()); } - - // Convert to const T* const& - friend const T* from_python(PyObject* p, boost::python::type) - { return from_python(p, boost::python::type()); } - - // Convert to T* const& - friend T* from_python(PyObject* p, boost::python::type) - { return from_python(p, boost::python::type()); } - - // Convert to T& - friend T& from_python(PyObject* p, boost::python::type) - { return *boost::python::detail::check_non_null(non_null_from_python(p, boost::python::type())); } - - // Convert to const T& - friend const T& from_python(PyObject* p, boost::python::type) - { return from_python(p, boost::python::type()); } - - // Convert to T - friend const T& from_python(PyObject* p, boost::python::type) - { return from_python(p, boost::python::type()); } - - friend std::auto_ptr& from_python(PyObject* p, boost::python::type&>) - { return smart_ptr_reference(p, boost::python::type >()); } - - friend std::auto_ptr from_python(PyObject* p, boost::python::type >) - { return smart_ptr_value(p, boost::python::type >()); } - - friend const std::auto_ptr& from_python(PyObject* p, boost::python::type&>) - { return smart_ptr_value(p, boost::python::type >()); } - - friend PyObject* to_python(std::auto_ptr x) - { return smart_ptr_to_python(x); } - - friend boost::shared_ptr& from_python(PyObject* p, boost::python::type&>) - { return smart_ptr_reference(p, boost::python::type >()); } - - friend const boost::shared_ptr& from_python(PyObject* p, boost::python::type >) - { return smart_ptr_value(p, boost::python::type >()); } - - friend const boost::shared_ptr& from_python(PyObject* p, boost::python::type&>) - { return smart_ptr_value(p, boost::python::type >()); } - - friend PyObject* to_python(boost::shared_ptr x) - { return smart_ptr_to_python(x); } -}; - -// Convert T to_python, instantiated on demand and only if there isn't a -// non-template overload for this function. This version is the one invoked when -// T is a wrapped class. See the first 2 functions declared in -// python_extension_class_converters above for more info. -template -PyObject* to_python(const T& x) -{ - return py_extension_class_converters(boost::python::type()).to_python(x); -} - -BOOST_PYTHON_END_CONVERSION_NAMESPACE - -namespace boost { namespace python { - -BOOST_PYTHON_IMPORT_CONVERSION(python_extension_class_converters); - -namespace detail { - -template class instance_holder; - -class BOOST_PYTHON_DECL read_only_setattr_function : public function -{ - public: - read_only_setattr_function(const char* name); - PyObject* do_call(PyObject* args, PyObject* keywords) const; - const char* description() const; - private: - string m_name; -}; - - template - struct define_conversion - { - static void* upcast_ptr(void* v) - { - return static_cast(static_cast(v)); - } - - static void* downcast_ptr(void* v) - { - return dynamic_cast(static_cast(v)); - } - }; - -// An easy way to make an extension base class which wraps T. Note that Python -// subclasses of this class will simply be class_t objects. -// -// U should be a class derived from T which overrides virtual functions with -// boilerplate code to call back into Python. See extclass_demo.h for examples. -// -// U is optional, but you won't be able to override any member functions in -// Python which are called from C++ if you don't supply it. If you just want to -// be able to use T in python without overriding member functions, you can omit -// U. -template > -class extension_class - : public python_extension_class_converters, // This generates the to_python/from_python functions - public extension_class_base -{ - public: - typedef T wrapped_type; - typedef U callback_type; - - // Construct with a name that comes from typeid(T).name(). The name only - // affects the objects of this class are represented through repr() - extension_class(); - - // Construct with the given name. The name only affects the objects of this - // class are represented through repr() - extension_class(const char* name); - - ~extension_class(); - - // define constructors - template - inline void def(constructor) - // The following incantation builds a signature1, signature2,... object. It - // should _all_ get optimized away. - { add_constructor( - prepend(type::id(), - prepend(type::id(), - prepend(type::id(), - prepend(type::id(), - prepend(type::id(), - prepend(type::id(), - prepend(type::id(), - prepend(type::id(), - prepend(type::id(), - prepend(type::id(), - signature0()))))))))))); - } - - - // export homogeneous operators (type of both lhs and rhs is 'operator') - // usage: foo_class.def(boost::python::operators<(boost::python::op_add | boost::python::op_sub), Foo>()); - - // export homogeneous operators (type of both lhs and rhs is 'T const&') - // usage: foo_class.def(boost::python::operators<(boost::python::op_add | boost::python::op_sub)>()); - template - inline void def(operators) - { - typedef typename operand_select::template wrapped::type true_operand; - def_operators(operators()); - } - - // export heterogeneous operators (type of lhs: 'left', of rhs: 'right') - // usage: foo_class.def(boost::python::operators<(boost::python::op_add | boost::python::op_sub), Foo>(), - // boost::python::right_operand()); - - // export heterogeneous operators (type of lhs: 'T const&', of rhs: 'right') - // usage: foo_class.def(boost::python::operators<(boost::python::op_add | boost::python::op_sub)>(), - // boost::python::right_operand()); - template - inline void def(operators, right_operand r) - { - typedef typename operand_select::template wrapped::type true_left; - def_operators(operators(), r); - } - - // export heterogeneous reverse-argument operators - // (type of lhs: 'left', of rhs: 'right') - // usage: foo_class.def(boost::python::operators<(boost::python::op_add | boost::python::op_sub), Foo>(), - // boost::python::left_operand()); - - // export heterogeneous reverse-argument operators - // (type of lhs: 'left', of rhs: 'T const&') - // usage: foo_class.def(boost::python::operators<(boost::python::op_add | boost::python::op_sub)>(), - // boost::python::left_operand()); - template - inline void def(operators, left_operand l) - { - typedef typename operand_select::template wrapped::type true_right; - def_operators(operators(), l); - } - - // define a function that passes Python arguments and keywords - // to C++ verbatim (as a 'tuple const&' and 'dictionary const&' - // respectively). This is useful for manual argument passing. - // It's also the only possibility to pass keyword arguments to C++. - // Fn must have a signatur that is compatible to - // PyObject* (*)(PyObject* aTuple, PyObject* aDictionary) - template - inline void def_raw(Fn fn, const char* name) - { - this->add_method(new_raw_arguments_function(fn), name); - } - - // define member functions. In fact this works for free functions, too - - // they act like static member functions, or if they start with the - // appropriate self argument (as a pointer), they can be used just like - // ordinary member functions -- just like Python! - template - inline void def(Fn fn, const char* name) - { - this->add_method(new_wrapped_function(fn), name); - } - - // Define a virtual member function with a default implementation. - // default_fn should be a function which provides the default implementation. - // Be careful that default_fn does not in fact call fn virtually! - template - inline void def(Fn fn, const char* name, DefaultFn default_fn) - { - this->add_method(new_virtual_function(type(), fn, default_fn), name); - } - - // Provide a function which implements x., reading from the given - // member (pm) of the T obj - template - inline void def_getter(MemberType T::*pm, const char* name) - { - this->add_getter_method(new getter_function(pm), name); - } - - // Provide a function which implements assignment to x., writing to - // the given member (pm) of the T obj - template - inline void def_setter(MemberType T::*pm, const char* name) - { - this->add_setter_method(new setter_function(pm), name); - } - - // Expose the given member (pm) of the T obj as a read-only attribute - template - inline void def_readonly(MemberType T::*pm, const char* name) - { - this->add_setter_method(new read_only_setattr_function(name), name); - this->def_getter(pm, name); - } - - // Expose the given member (pm) of the T obj as a read/write attribute - template - inline void def_read_write(MemberType T::*pm, const char* name) - { - this->def_getter(pm, name); - this->def_setter(pm, name); - } - - // define the standard coercion needed for operator overloading - void def_standard_coerce(); - - // declare the given class a base class of this one and register - // up and down conversion functions - template - void declare_base(extension_class* base) - { - // see extclass.cpp for an explanation of why we need to register - // conversion functions - base_class_info baseInfo(base, - &define_conversion::downcast_ptr); - class_registry::register_base_class(baseInfo); - add_base(ref(as_object(base), ref::increment_count)); - - derived_class_info derivedInfo(this, - &define_conversion::upcast_ptr); - class_registry::register_derived_class(derivedInfo); - } - - // declare the given class a base class of this one and register - // only up conversion function - template - void declare_base(extension_class* base, without_downcast_t) - { - // see extclass.cpp for an explanation of why we need to register - // conversion functions - base_class_info baseInfo(base, 0); - class_registry::register_base_class(baseInfo); - add_base(ref(as_object(base), ref::increment_count)); - - derived_class_info derivedInfo(this, - &define_conversion::upcast_ptr); - class_registry::register_derived_class(derivedInfo); - } - - private: // types - typedef instance_value_holder holder; - - private: // extension_class_base virtual function implementations - std::vector const& base_classes() const; - std::vector const& derived_classes() const; - void* extract_object_from_holder(instance_holder_base* v) const; - - private: // Utility functions - template - inline void def_operators(operators) - { - def_standard_coerce(); - - // for some strange reason, this prevents MSVC from having an - // "unrecoverable block scoping error"! - typedef choose_op<(which & op_add)> choose_add; - - choose_op<(which & op_add)>::template args::add(this); - choose_op<(which & op_sub)>::template args::add(this); - choose_op<(which & op_mul)>::template args::add(this); - choose_op<(which & op_div)>::template args::add(this); - choose_op<(which & op_mod)>::template args::add(this); - choose_op<(which & op_divmod)>::template args::add(this); - choose_op<(which & op_pow)>::template args::add(this); - choose_op<(which & op_lshift)>::template args::add(this); - choose_op<(which & op_rshift)>::template args::add(this); - choose_op<(which & op_and)>::template args::add(this); - choose_op<(which & op_xor)>::template args::add(this); - choose_op<(which & op_or)>::template args::add(this); - choose_op<(which & op_gt)>::template args::add(this); - choose_op<(which & op_ge)>::template args::add(this); - choose_op<(which & op_lt)>::template args::add(this); - choose_op<(which & op_le)>::template args::add(this); - choose_op<(which & op_eq)>::template args::add(this); - choose_op<(which & op_ne)>::template args::add(this); - choose_unary_op<(which & op_neg)>::template args::add(this); - choose_unary_op<(which & op_pos)>::template args::add(this); - choose_unary_op<(which & op_abs)>::template args::add(this); - choose_unary_op<(which & op_invert)>::template args::add(this); - choose_unary_op<(which & op_int)>::template args::add(this); - choose_unary_op<(which & op_long)>::template args::add(this); - choose_unary_op<(which & op_float)>::template args::add(this); - choose_op<(which & op_cmp)>::template args::add(this); - choose_unary_op<(which & op_str)>::template args::add(this); - } - - template - inline void def_operators(operators, right_operand) - { - def_standard_coerce(); - - choose_op<(which & op_add)>::template args::add(this); - choose_op<(which & op_sub)>::template args::add(this); - choose_op<(which & op_mul)>::template args::add(this); - choose_op<(which & op_div)>::template args::add(this); - choose_op<(which & op_mod)>::template args::add(this); - choose_op<(which & op_divmod)>::template args::add(this); - choose_op<(which & op_pow)>::template args::add(this); - choose_op<(which & op_lshift)>::template args::add(this); - choose_op<(which & op_rshift)>::template args::add(this); - choose_op<(which & op_and)>::template args::add(this); - choose_op<(which & op_xor)>::template args::add(this); - choose_op<(which & op_or)>::template args::add(this); - choose_op<(which & op_cmp)>::template args::add(this); - choose_op<(which & op_gt)>::template args::add(this); - choose_op<(which & op_ge)>::template args::add(this); - choose_op<(which & op_lt)>::template args::add(this); - choose_op<(which & op_le)>::template args::add(this); - choose_op<(which & op_eq)>::template args::add(this); - choose_op<(which & op_ne)>::template args::add(this); - } - - template - inline void def_operators(operators, left_operand) - { - def_standard_coerce(); - - choose_rop<(which & op_add)>::template args::add(this); - choose_rop<(which & op_sub)>::template args::add(this); - choose_rop<(which & op_mul)>::template args::add(this); - choose_rop<(which & op_div)>::template args::add(this); - choose_rop<(which & op_mod)>::template args::add(this); - choose_rop<(which & op_divmod)>::template args::add(this); - choose_rop<(which & op_pow)>::template args::add(this); - choose_rop<(which & op_lshift)>::template args::add(this); - choose_rop<(which & op_rshift)>::template args::add(this); - choose_rop<(which & op_and)>::template args::add(this); - choose_rop<(which & op_xor)>::template args::add(this); - choose_rop<(which & op_or)>::template args::add(this); - choose_rop<(which & op_cmp)>::template args::add(this); - } - - template - void add_constructor(signature sig) - { - this->add_constructor_object(init_function::create(sig)); - } -}; - -// A simple wrapper over a T which allows us to use extension_class with a -// single template parameter only. See extension_class, above. -template -class held_instance : public Held -{ - // There are no member functions: we want to avoid inadvertently overriding - // any virtual functions in Held. -public: - held_instance(PyObject*) : Held() {} - template - held_instance(PyObject*, A1 a1) : Held( - typename unwrap_parameter::type(a1)) {} - template - held_instance(PyObject*, A1 a1, A2 a2) : Held( - typename unwrap_parameter::type(a1) - , typename unwrap_parameter::type(a2)) {} - template - held_instance(PyObject*, A1 a1, A2 a2, A3 a3) : Held( - typename unwrap_parameter::type(a1) - , typename unwrap_parameter::type(a2) - , typename unwrap_parameter::type(a3)) {} - template - held_instance(PyObject*, A1 a1, A2 a2, A3 a3, A4 a4) : Held( - typename unwrap_parameter::type(a1) - , typename unwrap_parameter::type(a2) - , typename unwrap_parameter::type(a3) - , typename unwrap_parameter::type(a4)) {} - template - held_instance(PyObject*, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) : Held( - typename unwrap_parameter::type(a1) - , typename unwrap_parameter::type(a2) - , typename unwrap_parameter::type(a3) - , typename unwrap_parameter::type(a4) - , typename unwrap_parameter::type(a5)) {} - template - held_instance(PyObject*, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) : Held( - typename unwrap_parameter::type(a1) - , typename unwrap_parameter::type(a2) - , typename unwrap_parameter::type(a3) - , typename unwrap_parameter::type(a4) - , typename unwrap_parameter::type(a5) - , typename unwrap_parameter::type(a6)) {} - template - held_instance(PyObject*, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) : Held( - typename unwrap_parameter::type(a1) - , typename unwrap_parameter::type(a2) - , typename unwrap_parameter::type(a3) - , typename unwrap_parameter::type(a4) - , typename unwrap_parameter::type(a5) - , typename unwrap_parameter::type(a6) - , typename unwrap_parameter::type(a7)) {} - template - held_instance(PyObject*, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) : Held( - typename unwrap_parameter::type(a1) - , typename unwrap_parameter::type(a2) - , typename unwrap_parameter::type(a3) - , typename unwrap_parameter::type(a4) - , typename unwrap_parameter::type(a5) - , typename unwrap_parameter::type(a6) - , typename unwrap_parameter::type(a7) - , typename unwrap_parameter::type(a8)) {} - template - held_instance(PyObject*, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) : Held( - typename unwrap_parameter::type(a1) - , typename unwrap_parameter::type(a2) - , typename unwrap_parameter::type(a3) - , typename unwrap_parameter::type(a4) - , typename unwrap_parameter::type(a5) - , typename unwrap_parameter::type(a6) - , typename unwrap_parameter::type(a7) - , typename unwrap_parameter::type(a8) - , typename unwrap_parameter::type(a9)) {} - template - held_instance(PyObject*, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) : Held( - typename unwrap_parameter::type(a1) - , typename unwrap_parameter::type(a2) - , typename unwrap_parameter::type(a3) - , typename unwrap_parameter::type(a4) - , typename unwrap_parameter::type(a5) - , typename unwrap_parameter::type(a6) - , typename unwrap_parameter::type(a7) - , typename unwrap_parameter::type(a8) - , typename unwrap_parameter::type(a9) - , typename unwrap_parameter::type(a10)) {} -}; - -// Abstract base class for all obj holders. Base for template class -// instance_holder<>, below. -class BOOST_PYTHON_DECL instance_holder_base -{ -public: - virtual ~instance_holder_base() {} - virtual bool held_by_value() = 0; -}; - -// Abstract base class which holds a Held, somehow. Provides a uniform way to -// get a pointer to the held object -template -class instance_holder : public instance_holder_base -{ -public: - virtual Held*target() = 0; -}; - -// Concrete class which holds a Held by way of a wrapper class Wrapper. If Held -// can be constructed with arguments (A1...An), Wrapper must have a -// corresponding constructor for arguments (PyObject*, A1...An). Wrapper is -// neccessary to implement virtual function callbacks (there must be a -// back-pointer to the actual Python object so that we can call any -// overrides). held_instance (above) is used as a default Wrapper class when -// there are no virtual functions. -template -class instance_value_holder : public instance_holder -{ -public: - Held* target() { return &m_held; } - Wrapper* value_target() { return &m_held; } - - instance_value_holder(extension_instance* p) : - m_held(p) {} - template - instance_value_holder(extension_instance* p, A1 a1) : - m_held(p, a1) {} - template - instance_value_holder(extension_instance* p, A1 a1, A2 a2) : - m_held(p, a1, a2) {} - template - instance_value_holder(extension_instance* p, A1 a1, A2 a2, A3 a3) : - m_held(p, a1, a2, a3) {} - template - instance_value_holder(extension_instance* p, A1 a1, A2 a2, A3 a3, A4 a4) : - m_held(p, a1, a2, a3, a4) {} - template - instance_value_holder(extension_instance* p, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) : - m_held(p, a1, a2, a3, a4, a5) {} - template - instance_value_holder(extension_instance* p, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) : - m_held(p, a1, a2, a3, a4, a5, a6) {} - template - instance_value_holder(extension_instance* p, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) : - m_held(p, a1, a2, a3, a4, a5, a6, a7) {} - template - instance_value_holder(extension_instance* p, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) : - m_held(p, a1, a2, a3, a4, a5, a6, a7, a8) {} - template - instance_value_holder(extension_instance* p, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) : - m_held(p, a1, a2, a3, a4, a5, a6, a7, a8, a9) {} - template - instance_value_holder(extension_instance* p, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) : - m_held(p, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {} - - public: // implementation of instance_holder_base required interface - bool held_by_value() { return true; } - - private: - Wrapper m_held; -}; - -// Concrete class which holds a HeldType by way of a (possibly smart) pointer -// PtrType. By default, these are only generated for PtrType == -// std::auto_ptr and PtrType == boost::shared_ptr. -template -class instance_ptr_holder : public instance_holder -{ - public: - HeldType* target() { return &*m_ptr; } - PtrType& ptr() { return m_ptr; } - - instance_ptr_holder(PtrType ptr) : m_ptr(ptr) {} - - public: // implementation of instance_holder_base required interface - bool held_by_value() { return false; } - private: - PtrType m_ptr; -}; - -// -// Template function implementations -// - -template -extension_class::extension_class() - : extension_class_base(typeid(T).name()) -{ - class_registry::register_class(this); -} - -template -extension_class::extension_class(const char* name) - : extension_class_base(name) -{ - class_registry::register_class(this); -} - -template -void extension_class::def_standard_coerce() -{ - ref coerce_fct = dict().get_item(string("__coerce__")); - - if(coerce_fct.get() == 0) // not yet defined - this->def(&standard_coerce, "__coerce__"); -} - -template -inline -std::vector const& -extension_class::base_classes() const -{ - return class_registry::base_classes(); -} - -template -inline -std::vector const& -extension_class::derived_classes() const -{ - return class_registry::derived_classes(); -} - -template -void* extension_class::extract_object_from_holder(instance_holder_base* v) const -{ - instance_holder* held = dynamic_cast*>(v); - if(held) - return held->target(); - return 0; -} - -template -extension_class::~extension_class() -{ - class_registry::unregister_class(this); -} - -template -inline void class_registry::register_class(extension_class_base* p) -{ - // You're not expected to create more than one of these! - assert(static_class_object == 0); - static_class_object = p; -} - -template -inline void class_registry::unregister_class(extension_class_base* p) -{ - // The user should be destroying the same object they created. - assert(static_class_object == p); - (void)p; // unused in shipping version - static_class_object = 0; -} - -template -void class_registry::register_base_class(base_class_info const& i) -{ - static_base_class_info.push_back(i); -} - -template -void class_registry::register_derived_class(derived_class_info const& i) -{ - static_derived_class_info.push_back(i); -} - -template -std::vector const& class_registry::base_classes() -{ - return static_base_class_info; -} - -template -std::vector const& class_registry::derived_classes() -{ - return static_derived_class_info; -} - -// -// Static data member declaration. -// -template -extension_class_base* class_registry::static_class_object; -template -std::vector class_registry::static_base_class_info; -template -std::vector class_registry::static_derived_class_info; - -}}} // namespace boost::python::detail - -#endif // EXTENSION_CLASS_DWA052000_H_ diff --git a/include/boost/python/detail/functions.hpp b/include/boost/python/detail/functions.hpp deleted file mode 100644 index 486d73f9..00000000 --- a/include/boost/python/detail/functions.hpp +++ /dev/null @@ -1,311 +0,0 @@ -// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and -// distribute this software is granted provided this copyright notice appears -// in all copies. This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// The author gratefully acknowleges the support of Dragon Systems, Inc., in -// producing this work. - -#ifndef FUNCTIONS_DWA051400_H_ -# define FUNCTIONS_DWA051400_H_ - -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include - -namespace boost { namespace python { namespace detail { - -// forward declaration -class extension_instance; - - -// function -- -// the common base class for all overloadable function and method objects -// supplied by the library. -class BOOST_PYTHON_DECL function : public python_object -{ - public: - function(); - // function objects are reasonably rare, so we guess we can afford a virtual table. - // This cuts down on the number of distinct type objects which need to be defined. - virtual ~function() {} - - PyObject* call(PyObject* args, PyObject* keywords) const; - static void add_to_namespace(reference f, const char* name, PyObject* dict); - - private: - virtual PyObject* do_call(PyObject* args, PyObject* keywords) const = 0; - virtual const char* description() const = 0; - private: - struct type_object; - private: - reference m_overloads; // A linked list of the function overloads -}; - -// wrapped_function_pointer<> -- -// A single function or member function pointer wrapped and presented to -// Python as a callable object. -// -// Template parameters: -// R - the return type of the function pointer -// F - the complete type of the wrapped function pointer -template -struct wrapped_function_pointer : function -{ - typedef F ptr_fun; // pointer-to--function or pointer-to-member-function - - wrapped_function_pointer(ptr_fun pf) - : m_pf(pf) {} - - private: - PyObject* do_call(PyObject* args, PyObject* keywords) const - { - // This is where the boundary between the uniform Python function - // interface and the statically-checked C++ function interface is - // crossed. - return caller::call(m_pf, args, keywords); - } - - const char* description() const - { return typeid(F).name(); } - - private: - const ptr_fun m_pf; -}; - -// raw_arguments_function -// A function that passes the Python argument tuple and keyword dictionary -// verbatim to C++ (useful for customized argument parsing and variable -// argument lists) -template -struct raw_arguments_function : function -{ - typedef Ret (*ptr_fun)(Args, Keywords); - - raw_arguments_function(ptr_fun pf) - : m_pf(pf) {} - - private: - PyObject* do_call(PyObject* args, PyObject* keywords) const - { - ref dict(keywords ? - ref(keywords, ref::increment_count) : - ref(PyDict_New())); - - return to_python( - (*m_pf)(from_python(args, boost::python::type()), - from_python(dict.get(), boost::python::type()))); - } - - const char* description() const - { return typeid(ptr_fun).name(); } - - private: - const ptr_fun m_pf; -}; - -// virtual_function<> -- -// A virtual function with a default implementation wrapped and presented -// to Python as a callable object. -// -// Template parameters: -// T - the type of the target class -// R - the return type of the function pointer -// V - the virtual function pointer being wrapped -// (should be of the form R(T::*)(), or R (*)(T, )) -// D - a function which takes a T&, const T&, T*, or const T* first -// parameter and calls T::f on it /non-virtually/, where V -// approximates &T::f. -template -class virtual_function : public function -{ - public: - virtual_function(V virtual_function_ptr, D default_implementation) - : m_virtual_function_ptr(virtual_function_ptr), - m_default_implementation(default_implementation) - {} - - private: - PyObject* do_call(PyObject* args, PyObject* keywords) const; - - const char* description() const - { return typeid(V).name(); } - - private: - const V m_virtual_function_ptr; - const D m_default_implementation; -}; - -// A helper function for new_member_function(), below. Implements the core -// functionality once the return type has already been deduced. R is expected to -// be type, where X is the actual return type of pmf. -template -function* new_wrapped_function_aux(R, F pmf) -{ - // We can't just use "typename R::Type" below because MSVC (incorrectly) pukes. - typedef typename R::type return_type; - return new wrapped_function_pointer(pmf); -} - -// Create and return a new member function object wrapping the given -// pointer-to-member function -template -inline function* new_wrapped_function(F pmf) -{ - // Deduce the return type and pass it off to the helper function above - return new_wrapped_function_aux(return_value(pmf), pmf); -} - -template -function* new_raw_arguments_function(R (*pmf)(Args, keywords)) -{ - return new raw_arguments_function(pmf); -} - - -// A helper function for new_virtual_function(), below. Implements the core -// functionality once the return type has already been deduced. R is expected to -// be type, where X is the actual return type of V. -template -inline function* new_virtual_function_aux( - type, R, V virtual_function_ptr, D default_implementation - ) -{ - // We can't just use "typename R::Type" below because MSVC (incorrectly) pukes. - typedef typename R::type return_type; - return new virtual_function( - virtual_function_ptr, default_implementation); -} - -// Create and return a new virtual_function object wrapping the given -// virtual_function_ptr and default_implementation -template -inline function* new_virtual_function( - type, V virtual_function_ptr, D default_implementation - ) -{ - // Deduce the return type and pass it off to the helper function above - return new_virtual_function_aux( - type(), return_value(virtual_function_ptr), - virtual_function_ptr, default_implementation); -} - -// A function with a bundled "bound target" object. This is what is produced by -// the expression a.b where a is an instance or extension_instance object and b -// is a callable object not found in the obj namespace but on its class or -// a base class. -class BOOST_PYTHON_DECL bound_function : public python_object -{ - public: - static bound_function* create(const ref& target, const ref& fn); - - bound_function(const ref& target, const ref& fn); - PyObject* call(PyObject*args, PyObject* keywords) const; - PyObject* getattr(const char* name) const; - - private: - struct type_object; - friend struct type_object; - - ref m_target; - ref m_unbound_function; - - private: // data members for allocation/deallocation optimization - bound_function* m_free_list_link; - - static bound_function* free_list; -}; - -// Special functions designed to access data members of a wrapped C++ object. -template -class getter_function : public function -{ - public: - typedef MemberType ClassType::* pointer_to_member; - - getter_function(pointer_to_member pm) - : m_pm(pm) {} - - private: - PyObject* do_call(PyObject* args, PyObject* keywords) const; - - const char* description() const - { return typeid(MemberType (*)(const ClassType&)).name(); } - private: - pointer_to_member m_pm; -}; - -template -class setter_function : public function -{ - public: - typedef MemberType ClassType::* pointer_to_member; - - setter_function(pointer_to_member pm) - : m_pm(pm) {} - - private: - PyObject* do_call(PyObject* args, PyObject* keywords) const; - - const char* description() const - { return typeid(void (*)(const ClassType&, const MemberType&)).name(); } - private: - pointer_to_member m_pm; -}; - -template -PyObject* getter_function::do_call( - PyObject* args, PyObject* /* keywords */) const -{ - PyObject* self; - if (!PyArg_ParseTuple(args, const_cast("O"), &self)) - return 0; - - return to_python( - from_python(self, type())->*m_pm); -} - -template -PyObject* setter_function::do_call( - PyObject* args, PyObject* /* keywords */) const -{ - PyObject* self; - PyObject* value; - if (!PyArg_ParseTuple(args, const_cast("OO"), &self, &value)) - return 0; - - typedef typename boost::call_traits::const_reference extract_type; - from_python(self, type())->*m_pm - = from_python(value, type()); - - return none(); -} - -template -PyObject* virtual_function::do_call(PyObject* args, PyObject* keywords) const -{ - // If the target object is held by pointer, we must call through the virtual - // function pointer to the most-derived override. - PyObject* target = PyTuple_GetItem(args, 0); - if (target != 0) - { - extension_instance* self = get_extension_instance(target); - if (self->wrapped_objects().size() == 1 - && !self->wrapped_objects()[0]->held_by_value()) - { - return caller::call(m_virtual_function_ptr, args, keywords); - } - } - return caller::call(m_default_implementation, args, keywords); -} - -}}} // namespace boost::python::detail - -#endif // FUNCTIONS_DWA051400_H_ diff --git a/include/boost/python/detail/indirect_traits.hpp b/include/boost/python/detail/indirect_traits.hpp index c6f8bcc7..5d1a2697 100644 --- a/include/boost/python/detail/indirect_traits.hpp +++ b/include/boost/python/detail/indirect_traits.hpp @@ -16,6 +16,8 @@ # include # include # include +# include +# include namespace boost { namespace python { namespace detail { @@ -163,6 +165,8 @@ struct is_reference_to_class >::value >::value) ); + typedef mpl::bool_c type; + BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_class,(T)) }; template @@ -343,7 +347,6 @@ struct is_reference_to_volatile { }; - template typename is_pointer_help::type reference_to_pointer_helper(V&); outer_no_type reference_to_pointer_helper(...); @@ -370,8 +373,10 @@ struct is_reference_to_class BOOST_STATIC_CONSTANT( bool, value = (is_reference::value - && sizeof(reference_to_class_helper(t)) == sizeof(inner_yes_type)) + & (sizeof(reference_to_class_helper(t)) == sizeof(inner_yes_type))) ); + typedef mpl::bool_c type; + BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_class,(T)) }; template diff --git a/include/boost/python/detail/init_function.hpp b/include/boost/python/detail/init_function.hpp deleted file mode 100644 index 928159c2..00000000 --- a/include/boost/python/detail/init_function.hpp +++ /dev/null @@ -1,562 +0,0 @@ -// (C) Copyright David Abrahams 2001. Permission to copy, use, modify, sell and -// distribute this software is granted provided this copyright notice appears -// in all copies. This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// The author gratefully acknowleges the support of Dragon Systems, Inc., in -// producing this work. -// -// This file was generated for %d-argument constructors by gen_init_function.python - -#ifndef INIT_FUNCTION_DWA052000_H_ -# define INIT_FUNCTION_DWA052000_H_ - -# include -# include -# include -# include - -namespace boost { namespace python { - -namespace detail { - - // parameter_traits - so far, this is a way to pass a const T& when we can be - // sure T is not a reference type, and a raw T otherwise. This should be - // rolled into boost::call_traits. Ordinarily, parameter_traits would be - // written: - // - // template struct parameter_traits - // { - // typedef const T& const_reference; - // }; - // - // template struct parameter_traits - // { - // typedef T& const_reference; - // }; - // - // template <> struct parameter_traits - // { - // typedef void const_reference; - // }; - // - // ...but since we can't partially specialize on reference types, we need this - // long-winded but equivalent incantation. - - // const_ref_selector -- an implementation detail of parameter_traits (below). This uses - // the usual "poor man's partial specialization" hack for MSVC. - template - struct const_ref_selector - { - template - struct const_ref - { - typedef const T& type; - }; - }; - - template <> - struct const_ref_selector - { - template - struct const_ref - { - typedef T type; - }; - }; - -# ifdef BOOST_MSVC -# pragma warning(push) -# pragma warning(disable: 4181) -# endif // BOOST_MSVC - template - struct parameter_traits - { - private: - enum { is_ref = boost::is_reference::value }; - typedef const_ref_selector selector; - public: - typedef typename selector::template const_ref::type const_reference; - }; -# ifdef BOOST_MSVC -# pragma warning(pop) -# endif // BOOST_MSVC - - // Full spcialization for void - template <> - struct parameter_traits - { - typedef void const_reference; - }; - - struct reference_parameter_base {}; - - template - class reference_parameter - : public reference_parameter_base - { - public: - typedef typename parameter_traits::const_reference const_reference; - reference_parameter(const_reference value) - : value(value) {} - operator const_reference() { return value; } - private: - const_reference value; - }; - -# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION - template - struct unwrap_parameter - { - typedef typename boost::add_reference::type type; - }; - - template - struct unwrap_parameter > - { - typedef typename reference_parameter::const_reference type; - }; -# else - template - struct unwrap_parameter_helper - { - template - struct apply - { - typedef typename T::const_reference type; - }; - }; - - template <> - struct unwrap_parameter_helper - { - template - struct apply - { - typedef typename add_reference::type type; - }; - }; - - template - struct unwrap_parameter - { - BOOST_STATIC_CONSTANT( - bool, is_wrapped = (is_base_and_derived::value)); - - typedef typename unwrap_parameter_helper< - is_wrapped - >::template apply::type type; - }; -# endif - -class extension_instance; -class instance_holder_base; - -class init; -template struct init0; -template struct init1; -template struct init2; -template struct init3; -template struct init4; -template struct init5; -template struct init6; -template struct init7; -template struct init8; -template struct init9; -template struct init10; - -template -struct init_function -{ -# ifdef BOOST_MSVC6_OR_EARLIER -# define typename -# endif - static init* create(signature0) { - return new init0; - } - - template - static init* create(signature1) { - return new init1::const_reference>; - } - - template - static init* create(signature2) { - return new init2::const_reference, - typename detail::parameter_traits::const_reference>; - } - - template - static init* create(signature3) { - return new init3::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference>; - } - - template - static init* create(signature4) { - return new init4::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference>; - } - - template - static init* create(signature5) { - return new init5::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference>; - } - - template - static init* create(signature6) { - return new init6::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference>; - } - - template - static init* create(signature7) { - return new init7::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference>; - } - - template - static init* create(signature8) { - return new init8::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference>; - } - - template - static init* create(signature9) { - return new init9::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference>; - } - - template - static init* create(signature10) { - return new init10::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference>; - } -#ifdef BOOST_MSVC6_OR_EARLIER -# undef typename -#endif -}; - -class BOOST_PYTHON_DECL init : public function -{ -private: // override function hook - PyObject* do_call(PyObject* args, PyObject* keywords) const; -private: - virtual instance_holder_base* create_holder(extension_instance* self, PyObject* tail_args, PyObject* keywords) const = 0; -}; - - -template -struct init0 : init -{ - virtual instance_holder_base* create_holder(extension_instance* self, PyObject* args, PyObject* /*keywords*/) const - { - if (!PyArg_ParseTuple(args, const_cast(""))) - throw_argument_error(); - return new T(self - ); - } - const char* description() const - { return typeid(void (*)(T&)).name(); } -}; - -template -struct init1 : init -{ - virtual instance_holder_base* create_holder(extension_instance* self, PyObject* args, PyObject* /*keywords*/) const - { - PyObject* a1; - if (!PyArg_ParseTuple(args, const_cast("O"), &a1)) - throw_argument_error(); - return new T(self, - boost::python::detail::reference_parameter(from_python(a1, type())) - ); - } - const char* description() const - { return typeid(void (*)(T&, A1)).name(); } -}; - -template -struct init2 : init -{ - virtual instance_holder_base* create_holder(extension_instance* self, PyObject* args, PyObject* /*keywords*/) const - { - PyObject* a1; - PyObject* a2; - if (!PyArg_ParseTuple(args, const_cast("OO"), &a1, &a2)) - throw_argument_error(); - return new T(self, - boost::python::detail::reference_parameter(from_python(a1, type())), - boost::python::detail::reference_parameter(from_python(a2, type())) - ); - } - const char* description() const - { return typeid(void (*)(T&, A1, A2)).name(); } -}; - -template -struct init3 : init -{ - virtual instance_holder_base* create_holder(extension_instance* self, PyObject* args, PyObject* /*keywords*/) const - { - PyObject* a1; - PyObject* a2; - PyObject* a3; - if (!PyArg_ParseTuple(args, const_cast("OOO"), &a1, &a2, &a3)) - throw_argument_error(); - return new T(self, - boost::python::detail::reference_parameter(from_python(a1, type())), - boost::python::detail::reference_parameter(from_python(a2, type())), - boost::python::detail::reference_parameter(from_python(a3, type())) - ); - } - const char* description() const - { return typeid(void (*)(T&, A1, A2, A3)).name(); } -}; - -template -struct init4 : init -{ - virtual instance_holder_base* create_holder(extension_instance* self, PyObject* args, PyObject* /*keywords*/) const - { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - if (!PyArg_ParseTuple(args, const_cast("OOOO"), &a1, &a2, &a3, &a4)) - throw_argument_error(); - return new T(self, - boost::python::detail::reference_parameter(from_python(a1, type())), - boost::python::detail::reference_parameter(from_python(a2, type())), - boost::python::detail::reference_parameter(from_python(a3, type())), - boost::python::detail::reference_parameter(from_python(a4, type())) - ); - } - const char* description() const - { return typeid(void (*)(T&, A1, A2, A3, A4)).name(); } -}; - -template -struct init5 : init -{ - virtual instance_holder_base* create_holder(extension_instance* self, PyObject* args, PyObject* /*keywords*/) const - { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - if (!PyArg_ParseTuple(args, const_cast("OOOOO"), &a1, &a2, &a3, &a4, &a5)) - throw_argument_error(); - return new T(self, - boost::python::detail::reference_parameter(from_python(a1, type())), - boost::python::detail::reference_parameter(from_python(a2, type())), - boost::python::detail::reference_parameter(from_python(a3, type())), - boost::python::detail::reference_parameter(from_python(a4, type())), - boost::python::detail::reference_parameter(from_python(a5, type())) - ); - } - const char* description() const - { return typeid(void (*)(T&, A1, A2, A3, A4, A5)).name(); } -}; - -template -struct init6 : init -{ - virtual instance_holder_base* create_holder(extension_instance* self, PyObject* args, PyObject* /*keywords*/) const - { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - if (!PyArg_ParseTuple(args, const_cast("OOOOOO"), &a1, &a2, &a3, &a4, &a5, &a6)) - throw_argument_error(); - return new T(self, - boost::python::detail::reference_parameter(from_python(a1, type())), - boost::python::detail::reference_parameter(from_python(a2, type())), - boost::python::detail::reference_parameter(from_python(a3, type())), - boost::python::detail::reference_parameter(from_python(a4, type())), - boost::python::detail::reference_parameter(from_python(a5, type())), - boost::python::detail::reference_parameter(from_python(a6, type())) - ); - } - const char* description() const - { return typeid(void (*)(T&, A1, A2, A3, A4, A5, A6)).name(); } -}; - -template -struct init7 : init -{ - virtual instance_holder_base* create_holder(extension_instance* self, PyObject* args, PyObject* /*keywords*/) const - { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOO"), &a1, &a2, &a3, &a4, &a5, &a6, &a7)) - throw_argument_error(); - return new T(self, - boost::python::detail::reference_parameter(from_python(a1, type())), - boost::python::detail::reference_parameter(from_python(a2, type())), - boost::python::detail::reference_parameter(from_python(a3, type())), - boost::python::detail::reference_parameter(from_python(a4, type())), - boost::python::detail::reference_parameter(from_python(a5, type())), - boost::python::detail::reference_parameter(from_python(a6, type())), - boost::python::detail::reference_parameter(from_python(a7, type())) - ); - } - const char* description() const - { return typeid(void (*)(T&, A1, A2, A3, A4, A5, A6, A7)).name(); } -}; - -template -struct init8 : init -{ - virtual instance_holder_base* create_holder(extension_instance* self, PyObject* args, PyObject* /*keywords*/) const - { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOO"), &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8)) - throw_argument_error(); - return new T(self, - boost::python::detail::reference_parameter(from_python(a1, type())), - boost::python::detail::reference_parameter(from_python(a2, type())), - boost::python::detail::reference_parameter(from_python(a3, type())), - boost::python::detail::reference_parameter(from_python(a4, type())), - boost::python::detail::reference_parameter(from_python(a5, type())), - boost::python::detail::reference_parameter(from_python(a6, type())), - boost::python::detail::reference_parameter(from_python(a7, type())), - boost::python::detail::reference_parameter(from_python(a8, type())) - ); - } - const char* description() const - { return typeid(void (*)(T&, A1, A2, A3, A4, A5, A6, A7, A8)).name(); } -}; - -template -struct init9 : init -{ - virtual instance_holder_base* create_holder(extension_instance* self, PyObject* args, PyObject* /*keywords*/) const - { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - PyObject* a9; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOO"), &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9)) - throw_argument_error(); - return new T(self, - boost::python::detail::reference_parameter(from_python(a1, type())), - boost::python::detail::reference_parameter(from_python(a2, type())), - boost::python::detail::reference_parameter(from_python(a3, type())), - boost::python::detail::reference_parameter(from_python(a4, type())), - boost::python::detail::reference_parameter(from_python(a5, type())), - boost::python::detail::reference_parameter(from_python(a6, type())), - boost::python::detail::reference_parameter(from_python(a7, type())), - boost::python::detail::reference_parameter(from_python(a8, type())), - boost::python::detail::reference_parameter(from_python(a9, type())) - ); - } - const char* description() const - { return typeid(void (*)(T&, A1, A2, A3, A4, A5, A6, A7, A8, A9)).name(); } -}; - -template -struct init10 : init -{ - virtual instance_holder_base* create_holder(extension_instance* self, PyObject* args, PyObject* /*keywords*/) const - { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - PyObject* a9; - PyObject* a10; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOOO"), &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9, &a10)) - throw_argument_error(); - return new T(self, - boost::python::detail::reference_parameter(from_python(a1, type())), - boost::python::detail::reference_parameter(from_python(a2, type())), - boost::python::detail::reference_parameter(from_python(a3, type())), - boost::python::detail::reference_parameter(from_python(a4, type())), - boost::python::detail::reference_parameter(from_python(a5, type())), - boost::python::detail::reference_parameter(from_python(a6, type())), - boost::python::detail::reference_parameter(from_python(a7, type())), - boost::python::detail::reference_parameter(from_python(a8, type())), - boost::python::detail::reference_parameter(from_python(a9, type())), - boost::python::detail::reference_parameter(from_python(a10, type())) - ); - } - const char* description() const - { return typeid(void (*)(T&, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)).name(); } -}; - -}}} // namespace boost::python::detail - -#endif // INIT_FUNCTION_DWA052000_H_ diff --git a/include/boost/python/detail/msvc_typeinfo.hpp b/include/boost/python/detail/msvc_typeinfo.hpp index b50922b7..92f0f56d 100644 --- a/include/boost/python/detail/msvc_typeinfo.hpp +++ b/include/boost/python/detail/msvc_typeinfo.hpp @@ -18,7 +18,7 @@ // could probably be done, but I haven't figured it out yet. // -# if defined(BOOST_MSVC) && BOOST_MSVC <= 1300 || defined(BOOST_INTEL_CXX_VERSION) && BOOST_INTEL_CXX_VERSION <= 600 +# if defined(BOOST_MSVC) && BOOST_MSVC <= 1300 || defined(BOOST_INTEL_CXX_VERSION) && BOOST_INTEL_CXX_VERSION <= 700 namespace boost { namespace python { namespace detail { diff --git a/include/boost/python/detail/signatures.hpp b/include/boost/python/detail/signatures.hpp deleted file mode 100644 index e216f688..00000000 --- a/include/boost/python/detail/signatures.hpp +++ /dev/null @@ -1,251 +0,0 @@ -// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and -// distribute this software is granted provided this copyright notice appears -// in all copies. This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// The author gratefully acknowleges the support of Dragon Systems, Inc., in -// producing this work. -// -// This file automatically generated by gen_signatures.python for 10 arguments. -#ifndef SIGNATURES_DWA050900_H_ -# define SIGNATURES_DWA050900_H_ - -# include - -namespace boost { namespace python { - -namespace detail { -// A stand-in for the built-in void. This one can be passed to functions and -// (under MSVC, which has a bug, be used as a default template type parameter). -struct BOOST_PYTHON_DECL void_t {}; -} - -// An envelope in which type information can be delivered for the purposes -// of selecting an overloaded from_python() function. This is needed to work -// around MSVC's lack of partial specialiation/ordering. Where normally we'd -// want to form a function call like void f(), We instead pass -// type as one of the function parameters to select a particular -// overload. -// -// The id typedef helps us deal with the lack of partial ordering by generating -// unique types for constructor signatures. In general, type::id is type, -// but type::id is just void_t. -template -struct type -{ - typedef type id; -}; - -template <> -struct type -{ - typedef boost::python::detail::void_t id; -}; - -namespace detail { -// These basically encapsulate a chain of types, , used to make the syntax of -// add(constructor()) work. We need to produce a unique type for each number -// of non-default parameters to constructor<>. Q: why not use a recursive -// formulation for infinite extensibility? A: MSVC6 seems to choke on constructs -// that involve recursive template nesting. -// -// signature chaining -template -struct signature10 {}; - -template -struct signature9 {}; - -template -inline signature10 prepend(type, signature9) - { return signature10(); } - -template -struct signature8 {}; - -template -inline signature9 prepend(type, signature8) - { return signature9(); } - -template -struct signature7 {}; - -template -inline signature8 prepend(type, signature7) - { return signature8(); } - -template -struct signature6 {}; - -template -inline signature7 prepend(type, signature6) - { return signature7(); } - -template -struct signature5 {}; - -template -inline signature6 prepend(type, signature5) - { return signature6(); } - -template -struct signature4 {}; - -template -inline signature5 prepend(type, signature4) - { return signature5(); } - -template -struct signature3 {}; - -template -inline signature4 prepend(type, signature3) - { return signature4(); } - -template -struct signature2 {}; - -template -inline signature3 prepend(type, signature2) - { return signature3(); } - -template -struct signature1 {}; - -template -inline signature2 prepend(type, signature1) - { return signature2(); } - -struct signature0 {}; - -template -inline signature1 prepend(type, signature0) - { return signature1(); } - - -// This one terminates the chain. Prepending void_t to the head of a void_t -// signature results in a void_t signature again. -inline signature0 prepend(void_t, signature0) { return signature0(); } - -} // namespace detail - -template -struct constructor -{ -}; - -namespace detail { -// Return value extraction: - -// This is just another little envelope for carrying a typedef (see type, -// above). I could have re-used type, but that has a very specific purpose. I -// thought this would be clearer. -template -struct return_value_select { typedef T type; }; - -// free functions -template -return_value_select return_value(R (*)()) { return return_value_select(); } - -template -return_value_select return_value(R (*)(A1)) { return return_value_select(); } - -template -return_value_select return_value(R (*)(A1, A2)) { return return_value_select(); } - -template -return_value_select return_value(R (*)(A1, A2, A3)) { return return_value_select(); } - -template -return_value_select return_value(R (*)(A1, A2, A3, A4)) { return return_value_select(); } - -template -return_value_select return_value(R (*)(A1, A2, A3, A4, A5)) { return return_value_select(); } - -template -return_value_select return_value(R (*)(A1, A2, A3, A4, A5, A6)) { return return_value_select(); } - -template -return_value_select return_value(R (*)(A1, A2, A3, A4, A5, A6, A7)) { return return_value_select(); } - -template -return_value_select return_value(R (*)(A1, A2, A3, A4, A5, A6, A7, A8)) { return return_value_select(); } - -template -return_value_select return_value(R (*)(A1, A2, A3, A4, A5, A6, A7, A8, A9)) { return return_value_select(); } - -template -return_value_select return_value(R (*)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)) { return return_value_select(); } - -// TODO(?): handle 'const void' - -// member functions -template -return_value_select return_value(R (T::*)()) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1)) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1, A2)) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1, A2, A3)) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1, A2, A3, A4)) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1, A2, A3, A4, A5)) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1, A2, A3, A4, A5, A6)) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1, A2, A3, A4, A5, A6, A7)) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1, A2, A3, A4, A5, A6, A7, A8)) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1, A2, A3, A4, A5, A6, A7, A8, A9)) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)() const) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1) const) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1, A2) const) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1, A2, A3) const) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1, A2, A3, A4) const) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1, A2, A3, A4, A5) const) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1, A2, A3, A4, A5, A6) const) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1, A2, A3, A4, A5, A6, A7) const) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1, A2, A3, A4, A5, A6, A7, A8) const) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1, A2, A3, A4, A5, A6, A7, A8, A9) const) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10) const) { return return_value_select(); } - -}}} // namespace boost::python::detail - -#endif diff --git a/include/boost/python/detail/singleton.hpp b/include/boost/python/detail/singleton.hpp deleted file mode 100644 index 3e7d91af..00000000 --- a/include/boost/python/detail/singleton.hpp +++ /dev/null @@ -1,68 +0,0 @@ -// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and -// distribute this software is granted provided this copyright notice appears -// in all copies. This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// The author gratefully acknowleges the support of Dragon Systems, Inc., in -// producing this work. - -#ifndef SINGLETON_DWA051900_H_ -# define SINGLETON_DWA051900_H_ - -# include - -namespace boost { namespace python { namespace detail { - -struct BOOST_PYTHON_DECL empty {}; -template -struct singleton : Base -{ - typedef singleton singleton_base; // Convenience type for derived class constructors - - static Derived* instance(); - - // Pass-through constructors - singleton() : Base() {} - - template - singleton(const A1& a1) : Base(a1) {} - - template - singleton(const A1& a1, const A2& a2) : Base(a1, a2) {} - - template - singleton(const A1& a1, const A2& a2, const A3& a3) : Base(a1, a2, a3) {} - - template - singleton(const A1& a1, const A2& a2, const A3& a3, const A4& a4) : Base(a1, a2, a3, a4) {} - - template - singleton(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5) : Base(a1, a2, a3, a4, a5) {} - - template - singleton(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6) : Base(a1, a2, a3, a4, a5, a6) {} - - template - singleton(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7) : Base(a1, a2, a3, a4, a5, a6, a7) {} - - template - singleton(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8) : Base(a1, a2, a3, a4, a5, a6, a7, a8) {} - - template - singleton(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9) : Base(a1, a2, a3, a4, a5, a6, a7, a8, a9) {} - - template - singleton(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, const A10& a10) : Base(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {} - -}; - -template -Derived* singleton::instance() -{ - static Derived x; - return &x; -} - -}}} // namespace boost::python::detail - -#endif diff --git a/include/boost/python/detail/void_adaptor.hpp b/include/boost/python/detail/void_adaptor.hpp deleted file mode 100644 index 3b4b2124..00000000 --- a/include/boost/python/detail/void_adaptor.hpp +++ /dev/null @@ -1,39 +0,0 @@ -// (C) Copyright David Abrahams 2001. Permission to copy, use, modify, sell and -// distribute this software is granted provided this copyright notice appears -// in all copies. This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. - -#ifndef VOID_ADAPTOR_DWA20011112_HPP -# define VOID_ADAPTOR_DWA20011112_HPP - -namespace boost { namespace python { namespace detail { - - extern BOOST_PYTHON_DECL PyObject arbitrary_object; - - template - struct void_adaptor - { - typedef PyObject* result_type; - - void_adaptor(T const& f) - : m_f(f) - {} - - PyObject* operator()() const - { - m_f(); - return &arbitrary_object; - } - private: - T m_f; - }; - - template - void_adaptor make_void_adaptor(T const& f) - { - return void_adaptor(f); - } -}}} // namespace boost::python::detail - -#endif // VOID_ADAPTOR_DWA20011112_HPP - diff --git a/include/boost/python/dict.hpp b/include/boost/python/dict.hpp index b593f902..d78ccaf8 100644 --- a/include/boost/python/dict.hpp +++ b/include/boost/python/dict.hpp @@ -105,7 +105,7 @@ class dict : public object BOOST_PYTHON_DECL list values() const; public: // implementation detail -- for internal use only - BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(dict) + BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(dict, object) private: static BOOST_PYTHON_DECL detail::new_reference call(object const&); diff --git a/include/boost/python/init.hpp b/include/boost/python/init.hpp index 75c5da84..1022706f 100644 --- a/include/boost/python/init.hpp +++ b/include/boost/python/init.hpp @@ -1,16 +1,17 @@ /////////////////////////////////////////////////////////////////////////////// // -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. +// Copyright David Abrahams 2002, Joel de Guzman, 2002. Permission to copy, +// use, modify, sell and distribute this software is granted provided this +// copyright notice appears in all copies. This software is provided "as is" +// without express or implied warranty, and with no claim as to its +// suitability for any purpose. // /////////////////////////////////////////////////////////////////////////////// #ifndef INIT_JDG20020820_HPP #define INIT_JDG20020820_HPP #include +#include #include #include #include @@ -25,6 +26,7 @@ #include #include #include +#include #include @@ -34,6 +36,8 @@ #include #include +#include + /////////////////////////////////////////////////////////////////////////////// #define BOOST_PYTHON_OVERLOAD_TYPES_WITH_DEFAULT \ BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT( \ @@ -55,13 +59,22 @@ namespace boost { namespace python { template -struct init; // forward declaration +class init; // forward declaration + -/////////////////////////////////////// template struct optional; // forward declaration -namespace detail { +namespace detail +{ + namespace error + { + template + struct more_keywords_than_init_arguments + { + typedef char too_many_keywords[init_args - keywords >= 0 ? 1 : -1]; + }; + } /////////////////////////////////////////////////////////////////////////// // @@ -89,7 +102,7 @@ namespace detail { sizeof(f(t())) == sizeof(::boost::type_traits::yes_type)); typedef mpl::bool_c type; - BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_optional,(T)) // needed for MSVC & Borland + BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_optional,(T)) }; /////////////////////////////////////// @@ -111,61 +124,114 @@ namespace detail { struct is_optional : is_optional_impl { typedef mpl::bool_c::value> type; - BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_optional,(T)) // needed for MSVC & Borland + BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_optional,(T)) }; #endif // defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) } // namespace detail template -struct init_base { +struct init_base +{ + init_base(char const* doc_, detail::keyword_range const& keywords_) + : m_doc(doc_), m_keywords(keywords_) + {} + + init_base(char const* doc_) + : m_doc(doc_) + {} DerivedT const& derived() const - { return *static_cast(this); } + { + return *static_cast(this); + } + + char const* doc_string() const + { + return m_doc; + } + + detail::keyword_range const& keywords() const + { + return m_keywords; + } + + static default_call_policies call_policies() + { + return default_call_policies(); + } + + private: // data members + char const* m_doc; + detail::keyword_range m_keywords; }; template -struct init_with_call_policies -: public init_base > +class init_with_call_policies + : public init_base > { + typedef init_base > base; + public: BOOST_STATIC_CONSTANT(int, n_arguments = InitT::n_arguments); BOOST_STATIC_CONSTANT(int, n_defaults = InitT::n_defaults); typedef typename InitT::reversed_args reversed_args; - init_with_call_policies(CallPoliciesT const& policies_, char const* doc_) - : policies(policies_), doc(doc_) {} + init_with_call_policies( + CallPoliciesT const& policies_ + , char const* doc_ + , detail::keyword_range const& keywords + ) + : base(doc_, keywords) + , m_policies(policies_) + {} - char const* doc_string() const - { return doc; } + CallPoliciesT const& call_policies() const + { + return this->m_policies; + } - CallPoliciesT - call_policies() const - { return policies; } - - CallPoliciesT policies; - char const* doc; + private: // data members + CallPoliciesT m_policies; }; template -struct init : public init_base > +class init : public init_base > { + typedef init_base > base; + public: typedef init self_t; init(char const* doc_ = 0) - : doc(doc_) {} + : base(doc_) + { + } - char const* doc_string() const - { return doc; } + template + init(char const* doc_, Keywords const& kw) + : base(doc_, std::make_pair(kw.base(), kw.base() + Keywords::size)) + { + typedef typename detail::error::more_keywords_than_init_arguments< + Keywords::size, n_arguments + >::too_many_keywords assertion; + } - default_call_policies - call_policies() const - { return default_call_policies(); } + template + init(Keywords const& kw, char const* doc_ = 0) + : base(doc_, kw.range()) + { + typedef typename detail::error::more_keywords_than_init_arguments< + Keywords::size, n_arguments + >::too_many_keywords assertion; + } template init_with_call_policies operator[](CallPoliciesT const& policies) const - { return init_with_call_policies(policies, doc); } + { + return init_with_call_policies( + policies, this->doc_string(), this->keywords()); + } typedef detail::type_list signature_; typedef typename mpl::end::type finish; @@ -213,37 +279,35 @@ struct init : public init_base > // Count the maximum number of arguments BOOST_STATIC_CONSTANT(int, n_arguments = mpl::size::value); - - char const* doc; }; +# if 1 template <> // specialization for zero args -struct init<> : public init_base > +class init<> : public init_base > { + typedef init_base > base; + public: typedef init<> self_t; init(char const* doc_ = 0) - : doc(doc_) {} - - char const* doc_string() const - { return doc; } - - default_call_policies - call_policies() const - { return default_call_policies(); } + : base(doc_) + { + } template init_with_call_policies operator[](CallPoliciesT const& policies) const - { return init_with_call_policies(policies, doc); } + { + return init_with_call_policies( + policies, this->doc_string(), this->keywords()); + } BOOST_STATIC_CONSTANT(int, n_defaults = 0); BOOST_STATIC_CONSTANT(int, n_arguments = 0); typedef detail::type_list<> reversed_args; - - char const* doc; }; +# endif /////////////////////////////////////////////////////////////////////////////// // @@ -261,7 +325,13 @@ struct optional namespace detail { template - void def_init_reversed(ClassT& cl, ReversedArgs const&, CallPoliciesT const& policies, char const* doc) + void def_init_reversed( + ClassT& cl + , ReversedArgs const& + , CallPoliciesT const& policies + , char const* doc + , detail::keyword_range const& keywords_ + ) { typedef typename mpl::fold< ReversedArgs @@ -269,7 +339,19 @@ namespace detail , mpl::push_front<> >::type args; - cl.def_init(args(), policies, doc); + typedef typename ClassT::holder_selector holder_selector_t; + typedef typename ClassT::held_type held_type_t; + + cl.def( + "__init__", + detail::make_keyword_range_constructor( + policies + , keywords_ + // Using runtime type selection works around a CWPro7 bug. + , holder_selector_t::execute((held_type_t*)0).get() + ) + , doc + ); } /////////////////////////////////////////////////////////////////////////////// @@ -288,12 +370,20 @@ namespace detail struct define_class_init_helper { template - static void apply(ClassT& cl, CallPoliciesT const& policies, ReversedArgs const& args, char const* doc) + static void apply( + ClassT& cl + , CallPoliciesT const& policies + , ReversedArgs const& args + , char const* doc + , detail::keyword_range keywords) { - def_init_reversed(cl, args, policies, doc); + def_init_reversed(cl, args, policies, doc, keywords); + + if (keywords.second > keywords.first) + --keywords.second; typename mpl::pop_front::type next; - define_class_init_helper::apply(cl, policies, next, doc); + define_class_init_helper::apply(cl, policies, next, doc, keywords); } }; @@ -311,9 +401,14 @@ namespace detail struct define_class_init_helper<0> { template - static void apply(ClassT& cl, CallPoliciesT const& policies, ReversedArgs const& args, char const* doc) + static void apply( + ClassT& cl + , CallPoliciesT const& policies + , ReversedArgs const& args + , char const* doc + , detail::keyword_range const& keywords) { - def_init_reversed(cl, args, policies, doc); + def_init_reversed(cl, args, policies, doc, keywords); } }; } @@ -345,7 +440,7 @@ define_init(ClassT& cl, InitT const& i) { typedef typename InitT::reversed_args reversed_args; detail::define_class_init_helper::apply( - cl, i.call_policies(), reversed_args(), i.doc_string()); + cl, i.call_policies(), reversed_args(), i.doc_string(), i.keywords()); } }} // namespace boost::python diff --git a/include/boost/python/list.hpp b/include/boost/python/list.hpp index 501eeed5..e6696878 100644 --- a/include/boost/python/list.hpp +++ b/include/boost/python/list.hpp @@ -94,7 +94,7 @@ class list : public object } public: // implementation detail -- for internal use only - BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(list) + BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(list, object) private: static BOOST_PYTHON_DECL detail::new_non_null_reference call(object const&); diff --git a/include/boost/python/long.hpp b/include/boost/python/long.hpp index 3ba4f434..b0cc6417 100644 --- a/include/boost/python/long.hpp +++ b/include/boost/python/long.hpp @@ -31,7 +31,7 @@ class long_ : public object { } public: // implementation detail -- for internal use only - BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(long_) + BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(long_, object) private: static BOOST_PYTHON_DECL detail::new_non_null_reference call(object const&); diff --git a/include/boost/python/make_function.hpp b/include/boost/python/make_function.hpp index decdf5b4..2277371f 100644 --- a/include/boost/python/make_function.hpp +++ b/include/boost/python/make_function.hpp @@ -7,6 +7,7 @@ # define MAKE_FUNCTION_DWA20011221_HPP # include +# include # include # include # include @@ -32,6 +33,20 @@ object make_function(F f, Policies const& policies) , detail::arg_tuple_size::value); } +template +object make_function(F f, Policies const& policies, Keywords const& keywords) +{ + enum { n_arguments = detail::arg_tuple_size::value }; + typedef typename detail::error::more_keywords_than_function_arguments< + Keywords::size, n_arguments + >::too_many_keywords assertion; + + return objects::function_object( + ::boost::bind(detail::caller(), f, _1, _2, policies) + , n_arguments + , keywords.range()); +} + template object make_constructor(HolderGenerator* = 0, ArgList* = 0) { diff --git a/include/boost/python/module.hpp b/include/boost/python/module.hpp index 2bf923c0..69e9001d 100644 --- a/include/boost/python/module.hpp +++ b/include/boost/python/module.hpp @@ -71,11 +71,12 @@ class module : public detail::module_base char const* doc, void const*) { - typedef detail::def_helper helper; + detail::def_helper helper(policy_or_doc, doc); this->setattr_doc( - name, boost::python::make_function(fn, helper::get_policy(policy_or_doc)), - helper::get_doc(policy_or_doc, doc)); + name + , boost::python::make_function(fn, helper.policies()) + , helper.doc()); } template diff --git a/include/boost/python/object/function.hpp b/include/boost/python/object/function.hpp index c14f57e3..1a3c3f5f 100644 --- a/include/boost/python/object/function.hpp +++ b/include/boost/python/object/function.hpp @@ -7,6 +7,7 @@ # define FUNCTION_DWA20011214_HPP # include +# include # include # include # include @@ -17,7 +18,13 @@ namespace boost { namespace python { namespace objects { struct BOOST_PYTHON_DECL function : PyObject { - function(py_function const&, unsigned min_args, unsigned max_args = 0); + function( + py_function const& + , unsigned min_arity + , unsigned max_arity + , python::detail::keyword const* names_and_defaults + , unsigned num_keywords); + ~function(); PyObject* call(PyObject*, PyObject*) const; @@ -42,11 +49,12 @@ struct BOOST_PYTHON_DECL function : PyObject private: // data members py_function m_fn; - unsigned m_min_args; - unsigned m_max_args; + unsigned m_min_arity; + unsigned m_max_arity; handle m_overloads; object m_name; object m_doc; + object m_arg_names; }; // @@ -66,7 +74,7 @@ inline object const& function::name() const { return this->m_name; } - + }}} // namespace boost::python::objects #endif // FUNCTION_DWA20011214_HPP diff --git a/include/boost/python/object/function_object.hpp b/include/boost/python/object/function_object.hpp index 03535ec3..d3661563 100644 --- a/include/boost/python/object/function_object.hpp +++ b/include/boost/python/object/function_object.hpp @@ -8,17 +8,36 @@ # include # include # include +# include +# include -namespace boost { namespace python { namespace objects { +namespace boost { namespace python { -BOOST_PYTHON_DECL api::object function_object_impl(boost::function2 const& f, unsigned min_args, unsigned max_args = 0); +namespace objects +{ + BOOST_PYTHON_DECL api::object function_object( + py_function const& f + , unsigned min_arity, unsigned max_arity + , python::detail::keyword_range const&); -template -inline object function_object(F const& f, unsigned min_args, unsigned max_args = 0) -{ - return objects::function_object_impl(boost::function2(f), min_args, max_args); + BOOST_PYTHON_DECL api::object function_object( + py_function const& f + , unsigned arity + , python::detail::keyword_range const&); + + BOOST_PYTHON_DECL api::object function_object(py_function const& f, unsigned arity); + + // Add an attribute to the name_space with the given name. If it is + // a Boost.Python function object + // (boost/python/object/function.hpp), and an existing function is + // already there, add it as an overload. + BOOST_PYTHON_DECL void add_to_namespace( + object const& name_space, char const* name, object const& attribute); + + BOOST_PYTHON_DECL void add_to_namespace( + object const& name_space, char const* name, object const& attribute, char const* doc); } -}}} // namespace boost::python::objects +}} // namespace boost::python::objects #endif // FUNCTION_OBJECT_DWA2002725_HPP diff --git a/include/boost/python/object_core.hpp b/include/boost/python/object_core.hpp index ebdfeac1..2ee532a8 100755 --- a/include/boost/python/object_core.hpp +++ b/include/boost/python/object_core.hpp @@ -234,13 +234,13 @@ namespace api // Macros for forwarding constructors in classes derived from // object. Derived classes will usually want these as an // implementation detail -# define BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS_(derived) \ +# define BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS_(derived, base) \ inline explicit derived(python::detail::borrowed_reference p) \ - : object(p) {} \ + : base(p) {} \ inline explicit derived(python::detail::new_reference p) \ - : object(p) {} \ + : base(p) {} \ inline explicit derived(python::detail::new_non_null_reference p) \ - : object(p) {} + : base(p) {} # if !defined(BOOST_MSVC) || BOOST_MSVC > 1200 # define BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS_ @@ -253,9 +253,9 @@ namespace api // runtime failure into an ambiguity error at compile-time due to // the lack of partial ordering, or at least a link-time error if no // generalized template constructor is declared. -# define BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(derived) \ - BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS_(derived) \ - template \ +# define BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(derived, base) \ + BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS_(derived, base) \ + template \ explicit derived(extract const&); # endif diff --git a/include/boost/python/signature.hpp b/include/boost/python/signature.hpp index be93ea4a..8afa7314 100644 --- a/include/boost/python/signature.hpp +++ b/include/boost/python/signature.hpp @@ -1,10 +1,10 @@ /////////////////////////////////////////////////////////////////////////////// // -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. +// Copyright David Abrahams 2002, Joel de Guzman, 2002. Permission to copy, +// use, modify, sell and distribute this software is granted provided this +// copyright notice appears in all copies. This software is provided "as is" +// without express or implied warranty, and with no claim as to its +// suitability for any purpose. // /////////////////////////////////////////////////////////////////////////////// #if !defined(BOOST_PP_IS_ITERATING) @@ -129,7 +129,7 @@ get_signature(RT(ClassT::*)(BOOST_PYTHON_SIGNATURE_TYPES) const) #endif // N < (BOOST_PYTHON_MAX_ARITY - 2) # undef BOOST_PYTHON_SIGNATURE_PARAMS -# undef BOOST_PYTHON_SIGNATURE_TYPES +# undef BOOST_PYTHON_SIGNATURE_TYPES # undef BOOST_PYTHON_TRAILING_SIGNATURE_TYPES #endif // !defined(BOOST_PP_IS_ITERATING) diff --git a/include/boost/python/str.hpp b/include/boost/python/str.hpp index fb8bfe58..ffb3c362 100644 --- a/include/boost/python/str.hpp +++ b/include/boost/python/str.hpp @@ -352,7 +352,7 @@ class str : public object BOOST_PYTHON_DECL str upper() const; public: // implementation detail -- for internal use only - BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(str) + BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(str, object) private: static BOOST_PYTHON_DECL detail::new_reference call(object const&); diff --git a/include/boost/python/tuple.hpp b/include/boost/python/tuple.hpp index 2ab4ad73..77c5e67c 100644 --- a/include/boost/python/tuple.hpp +++ b/include/boost/python/tuple.hpp @@ -24,7 +24,7 @@ class tuple : public object } public: // implementation detail -- for internal use only - BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(tuple) + BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(tuple, object) private: static BOOST_PYTHON_DECL detail::new_reference call(object const&); diff --git a/include/boost/python/type_id.hpp b/include/boost/python/type_id.hpp index cf818fe3..d44ce26a 100755 --- a/include/boost/python/type_id.hpp +++ b/include/boost/python/type_id.hpp @@ -54,7 +54,7 @@ template inline type_info type_id(boost::type* = 0) { return type_info( -# if (!defined(BOOST_MSVC) || BOOST_MSVC > 1300) && (!defined(BOOST_INTEL_CXX_VERSION) || BOOST_INTEL_CXX_VERSION > 600) +# if (!defined(BOOST_MSVC) || BOOST_MSVC > 1300) && (!defined(BOOST_INTEL_CXX_VERSION) || BOOST_INTEL_CXX_VERSION > 700) typeid(T) # else // strip the decoration which msvc and Intel mistakenly leave in python::detail::msvc_typeid()