From 176beb3b47867b05497abb6cd34d6d616121ffca Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Tue, 10 Apr 2001 23:04:02 +0000 Subject: [PATCH] uniform python_import_extension_class_converters [SVN r9755] --- include/boost/python/cross_module.hpp | 217 ++++++++++++++------------ 1 file changed, 113 insertions(+), 104 deletions(-) diff --git a/include/boost/python/cross_module.hpp b/include/boost/python/cross_module.hpp index 538f43dd..56e2e951 100644 --- a/include/boost/python/cross_module.hpp +++ b/include/boost/python/cross_module.hpp @@ -12,7 +12,7 @@ namespace boost { namespace python { 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 = 3; +const int export_converters_api_major = 4; const int export_converters_api_minor = 1; extern const char* converters_attribute_name; void* import_converter_object(const std::string& module_name, @@ -40,74 +40,58 @@ class python_import_extension_class_converters { public: - friend python_import_extension_class_converters py_extension_class_converters(boost::python::type, bool sig = false) - { + 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 - { + 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, bool sig = false) - { - return boost::python::detail::import_extension_class::get_converters()->T_pointer_from_python(p); + 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); } - // Convert to const T* - friend const T* from_python(PyObject* p, boost::python::type, bool sig = false) - { return from_python(p, boost::python::type()); } - - // Convert to const T* const& - friend const T* from_python(PyObject* p, boost::python::type, bool sig = false) - { return from_python(p, boost::python::type()); } - - // Convert to T* const& - friend T* from_python(PyObject* p, boost::python::type, bool sig = false) - { return from_python(p, boost::python::type()); } - - // Convert to T& - friend T& from_python(PyObject* p, boost::python::type, bool sig = false) { - return boost::python::detail::import_extension_class::get_converters()->T_reference_from_python(p); + 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); } - - // Convert to const T& - friend const T& from_python(PyObject* p, boost::python::type, bool sig = false) - { return from_python(p, boost::python::type()); } - - // Convert to T - friend const T& from_python(PyObject* p, boost::python::type, bool sig = false) - { return from_python(p, boost::python::type()); } - - friend std::auto_ptr& from_python(PyObject* p, boost::python::type&>, bool sig = false) { - return boost::python::detail::import_extension_class::get_converters()->auto_ptr_reference_from_python(p); + 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 std::auto_ptr from_python(PyObject* p, boost::python::type >, bool sig = false) { - return boost::python::detail::import_extension_class::get_converters()->auto_ptr_from_python(p); + 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 const std::auto_ptr& from_python(PyObject* p, boost::python::type&>, bool sig = false) { - return boost::python::detail::import_extension_class::get_converters()->const_auto_ptr_reference_from_python(p); - } - 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&>, bool sig = false) { - return boost::python::detail::import_extension_class::get_converters()->shared_ptr_reference_from_python(p); + 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 >, bool sig = false) { - return boost::python::detail::import_extension_class::get_converters()->shared_ptr_from_python(p); + 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&>, bool sig = false) { - return boost::python::detail::import_extension_class::get_converters()->const_shared_ptr_reference_from_python(p); + 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); } @@ -125,71 +109,96 @@ BOOST_PYTHON_IMPORT_CONVERSION(python_import_extension_class_converters); 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 PyObject* to_python(std::auto_ptr x) = 0; - virtual PyObject* to_python(boost::shared_ptr x) = 0; - virtual T* T_pointer_from_python(PyObject* obj) = 0; - virtual T& T_reference_from_python(PyObject* obj) = 0; - virtual std::auto_ptr& auto_ptr_reference_from_python(PyObject* obj) = 0; - virtual std::auto_ptr auto_ptr_from_python(PyObject* obj) = 0; - virtual const std::auto_ptr& const_auto_ptr_reference_from_python(PyObject* obj) = 0; - virtual boost::shared_ptr& shared_ptr_reference_from_python(PyObject* obj) = 0; - virtual const boost::shared_ptr& shared_ptr_from_python(PyObject* obj) = 0; - virtual const boost::shared_ptr& const_shared_ptr_reference_from_python(PyObject* obj) = 0; + 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(); - } - virtual PyObject* to_python(std::auto_ptr x) { - return BOOST_PYTHON_CONVERSION::to_python(x); - } - virtual PyObject* to_python(boost::shared_ptr x) { - return BOOST_PYTHON_CONVERSION::to_python(x); - } - virtual T* T_pointer_from_python(PyObject* obj) { - return BOOST_PYTHON_CONVERSION::from_python(obj, boost::python::type()); - } - virtual T& T_reference_from_python(PyObject* obj) { - return BOOST_PYTHON_CONVERSION::from_python(obj, boost::python::type()); - } - virtual std::auto_ptr& auto_ptr_reference_from_python(PyObject* obj) { - return BOOST_PYTHON_CONVERSION::from_python(obj, boost::python::type&>()); - } - virtual std::auto_ptr auto_ptr_from_python(PyObject* obj) { - return BOOST_PYTHON_CONVERSION::from_python(obj, boost::python::type >()); - } - virtual const std::auto_ptr& const_auto_ptr_reference_from_python(PyObject* obj) { - return BOOST_PYTHON_CONVERSION::from_python(obj, boost::python::type&>()); - } - virtual boost::shared_ptr& shared_ptr_reference_from_python(PyObject* obj) { - return BOOST_PYTHON_CONVERSION::from_python(obj, boost::python::type&>()); - } - virtual const boost::shared_ptr& shared_ptr_from_python(PyObject* obj) { - return BOOST_PYTHON_CONVERSION::from_python(obj, boost::python::type >()); - } - virtual const boost::shared_ptr& const_shared_ptr_reference_from_python(PyObject* obj) { - return BOOST_PYTHON_CONVERSION::from_python(obj, boost::python::type&>()); - } + virtual PyObject* to_python(const T& x) { + PyErr_SetString(PyExc_RuntimeError, + "to_python(const T&) converter not exported"); + throw import_error(); + } + + 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); - } + virtual PyObject* to_python(const T& x) { + return BOOST_PYTHON_CONVERSION::py_extension_class_converters(boost::python::type()).to_python(x); + } }; namespace detail {