2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-22 05:22:45 +00:00

uniform python_import_extension_class_converters

[SVN r9755]
This commit is contained in:
Ralf W. Grosse-Kunstleve
2001-04-10 23:04:02 +00:00
parent 77626967d6
commit 176beb3b47

View File

@@ -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<T>, bool sig = false)
{
friend python_import_extension_class_converters py_extension_class_converters(boost::python::type<T>, 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<T>::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<T>::get_converters()->T_pointer_from_python(p);
friend T* from_python(PyObject* p, boost::python::type<T*> t, bool sig = false) {
return boost::python::detail::import_extension_class<T>::get_converters()->from_python_Ts(p, t);
}
friend const T* from_python(PyObject* p, boost::python::type<const T*> t, bool sig = false) {
return boost::python::detail::import_extension_class<T>::get_converters()->from_python_cTs(p, t);
}
friend const T* from_python(PyObject* p, boost::python::type<const T*const&> t, bool sig = false) {
return boost::python::detail::import_extension_class<T>::get_converters()->from_python_cTscr(p, t);
}
friend T* from_python(PyObject* p, boost::python::type<T* const&> t, bool sig = false) {
return boost::python::detail::import_extension_class<T>::get_converters()->from_python_Tscr(p, t);
}
friend T& from_python(PyObject* p, boost::python::type<T&> t, bool sig = false) {
return boost::python::detail::import_extension_class<T>::get_converters()->from_python_Tr(p, t);
}
friend const T& from_python(PyObject* p, boost::python::type<const T&> t, bool sig = false) {
return boost::python::detail::import_extension_class<T>::get_converters()->from_python_cTr(p, t);
}
friend const T& from_python(PyObject* p, boost::python::type<T> t, bool sig = false) {
return boost::python::detail::import_extension_class<T>::get_converters()->from_python_T(p, t);
}
// Convert to const T*
friend const T* from_python(PyObject* p, boost::python::type<const T*>, bool sig = false)
{ return from_python(p, boost::python::type<T*>()); }
// Convert to const T* const&
friend const T* from_python(PyObject* p, boost::python::type<const T*const&>, bool sig = false)
{ return from_python(p, boost::python::type<const T*>()); }
// Convert to T* const&
friend T* from_python(PyObject* p, boost::python::type<T* const&>, bool sig = false)
{ return from_python(p, boost::python::type<T*>()); }
// Convert to T&
friend T& from_python(PyObject* p, boost::python::type<T&>, bool sig = false) {
return boost::python::detail::import_extension_class<T>::get_converters()->T_reference_from_python(p);
friend std::auto_ptr<T>& from_python(PyObject* p, boost::python::type<std::auto_ptr<T>&> t, bool sig = false) {
return boost::python::detail::import_extension_class<T>::get_converters()->from_python_aTr(p, t);
}
// Convert to const T&
friend const T& from_python(PyObject* p, boost::python::type<const T&>, bool sig = false)
{ return from_python(p, boost::python::type<T&>()); }
// Convert to T
friend const T& from_python(PyObject* p, boost::python::type<T>, bool sig = false)
{ return from_python(p, boost::python::type<T&>()); }
friend std::auto_ptr<T>& from_python(PyObject* p, boost::python::type<std::auto_ptr<T>&>, bool sig = false) {
return boost::python::detail::import_extension_class<T>::get_converters()->auto_ptr_reference_from_python(p);
friend std::auto_ptr<T> from_python(PyObject* p, boost::python::type<std::auto_ptr<T> > t, bool sig = false) {
return boost::python::detail::import_extension_class<T>::get_converters()->from_python_aT(p, t);
}
friend std::auto_ptr<T> from_python(PyObject* p, boost::python::type<std::auto_ptr<T> >, bool sig = false) {
return boost::python::detail::import_extension_class<T>::get_converters()->auto_ptr_from_python(p);
friend const std::auto_ptr<T>& from_python(PyObject* p, boost::python::type<const std::auto_ptr<T>&> t, bool sig = false) {
return boost::python::detail::import_extension_class<T>::get_converters()->from_python_caTr(p, t);
}
friend const std::auto_ptr<T>& from_python(PyObject* p, boost::python::type<const std::auto_ptr<T>&>, bool sig = false) {
return boost::python::detail::import_extension_class<T>::get_converters()->const_auto_ptr_reference_from_python(p);
}
friend PyObject* to_python(std::auto_ptr<T> x, bool sig = false) {
return boost::python::detail::import_extension_class<T>::get_converters()->to_python(x);
}
friend boost::shared_ptr<T>& from_python(PyObject* p, boost::python::type<boost::shared_ptr<T>&>, bool sig = false) {
return boost::python::detail::import_extension_class<T>::get_converters()->shared_ptr_reference_from_python(p);
friend boost::shared_ptr<T>& from_python(PyObject* p, boost::python::type<boost::shared_ptr<T>&> t, bool sig = false) {
return boost::python::detail::import_extension_class<T>::get_converters()->from_python_sTr(p, t);
}
friend const boost::shared_ptr<T>& from_python(PyObject* p, boost::python::type<boost::shared_ptr<T> >, bool sig = false) {
return boost::python::detail::import_extension_class<T>::get_converters()->shared_ptr_from_python(p);
friend const boost::shared_ptr<T>& from_python(PyObject* p, boost::python::type<boost::shared_ptr<T> > t, bool sig = false) {
return boost::python::detail::import_extension_class<T>::get_converters()->from_python_sT(p, t);
}
friend const boost::shared_ptr<T>& from_python(PyObject* p, boost::python::type<const boost::shared_ptr<T>&>, bool sig = false) {
return boost::python::detail::import_extension_class<T>::get_converters()->const_shared_ptr_reference_from_python(p);
friend const boost::shared_ptr<T>& from_python(PyObject* p, boost::python::type<const boost::shared_ptr<T>&> t, bool sig = false) {
return boost::python::detail::import_extension_class<T>::get_converters()->from_python_csTr(p, t);
}
friend PyObject* to_python(boost::shared_ptr<T> x, bool sig = false) {
return boost::python::detail::import_extension_class<T>::get_converters()->to_python(x);
}
@@ -125,71 +109,96 @@ BOOST_PYTHON_IMPORT_CONVERSION(python_import_extension_class_converters);
template <class T>
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<T> x) = 0;
virtual PyObject* to_python(boost::shared_ptr<T> x) = 0;
virtual T* T_pointer_from_python(PyObject* obj) = 0;
virtual T& T_reference_from_python(PyObject* obj) = 0;
virtual std::auto_ptr<T>& auto_ptr_reference_from_python(PyObject* obj) = 0;
virtual std::auto_ptr<T> auto_ptr_from_python(PyObject* obj) = 0;
virtual const std::auto_ptr<T>& const_auto_ptr_reference_from_python(PyObject* obj) = 0;
virtual boost::shared_ptr<T>& shared_ptr_reference_from_python(PyObject* obj) = 0;
virtual const boost::shared_ptr<T>& shared_ptr_from_python(PyObject* obj) = 0;
virtual const boost::shared_ptr<T>& 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*> t) = 0;
virtual const T* from_python_cTs(PyObject* p, boost::python::type<const T*> t) = 0;
virtual const T* from_python_cTscr(PyObject* p, boost::python::type<const T*const&> t) = 0;
virtual T* from_python_Tscr(PyObject* p, boost::python::type<T* const&> t) = 0;
virtual T& from_python_Tr(PyObject* p, boost::python::type<T&> t) = 0;
virtual const T& from_python_cTr(PyObject* p, boost::python::type<const T&> t) = 0;
virtual const T& from_python_T(PyObject* p, boost::python::type<T> t) = 0;
virtual std::auto_ptr<T>& from_python_aTr(PyObject* p, boost::python::type<std::auto_ptr<T>&> t) = 0;
virtual std::auto_ptr<T> from_python_aT(PyObject* p, boost::python::type<std::auto_ptr<T> > t) = 0;
virtual const std::auto_ptr<T>& from_python_caTr(PyObject* p, boost::python::type<const std::auto_ptr<T>&> t) = 0;
virtual PyObject* to_python(std::auto_ptr<T> x) = 0;
virtual boost::shared_ptr<T>& from_python_sTr(PyObject* p, boost::python::type<boost::shared_ptr<T>&> t) = 0;
virtual const boost::shared_ptr<T>& from_python_sT(PyObject* p, boost::python::type<boost::shared_ptr<T> > t) = 0;
virtual const boost::shared_ptr<T>& from_python_csTr(PyObject* p, boost::python::type<const boost::shared_ptr<T>&> t) = 0;
virtual PyObject* to_python(boost::shared_ptr<T> x) = 0;
};
// Converters to be used if T is not copyable.
template <class T>
struct export_converter_object_noncopyable : export_converter_object_base<T>
{
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<T> x) {
return BOOST_PYTHON_CONVERSION::to_python(x);
}
virtual PyObject* to_python(boost::shared_ptr<T> 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<T*>());
}
virtual T& T_reference_from_python(PyObject* obj) {
return BOOST_PYTHON_CONVERSION::from_python(obj, boost::python::type<T&>());
}
virtual std::auto_ptr<T>& auto_ptr_reference_from_python(PyObject* obj) {
return BOOST_PYTHON_CONVERSION::from_python(obj, boost::python::type<std::auto_ptr<T>&>());
}
virtual std::auto_ptr<T> auto_ptr_from_python(PyObject* obj) {
return BOOST_PYTHON_CONVERSION::from_python(obj, boost::python::type<std::auto_ptr<T> >());
}
virtual const std::auto_ptr<T>& const_auto_ptr_reference_from_python(PyObject* obj) {
return BOOST_PYTHON_CONVERSION::from_python(obj, boost::python::type<const std::auto_ptr<T>&>());
}
virtual boost::shared_ptr<T>& shared_ptr_reference_from_python(PyObject* obj) {
return BOOST_PYTHON_CONVERSION::from_python(obj, boost::python::type<boost::shared_ptr<T>&>());
}
virtual const boost::shared_ptr<T>& shared_ptr_from_python(PyObject* obj) {
return BOOST_PYTHON_CONVERSION::from_python(obj, boost::python::type<boost::shared_ptr<T> >());
}
virtual const boost::shared_ptr<T>& const_shared_ptr_reference_from_python(PyObject* obj) {
return BOOST_PYTHON_CONVERSION::from_python(obj, boost::python::type<const boost::shared_ptr<T>&>());
}
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*> t) {
return BOOST_PYTHON_CONVERSION::from_python(p, t);
}
virtual const T* from_python_cTs(PyObject* p, boost::python::type<const T*> t) {
return BOOST_PYTHON_CONVERSION::from_python(p, t);
}
virtual const T* from_python_cTscr(PyObject* p, boost::python::type<const T*const&> t) {
return BOOST_PYTHON_CONVERSION::from_python(p, t);
}
virtual T* from_python_Tscr(PyObject* p, boost::python::type<T* const&> t) {
return BOOST_PYTHON_CONVERSION::from_python(p, t);
}
virtual T& from_python_Tr(PyObject* p, boost::python::type<T&> t) {
return BOOST_PYTHON_CONVERSION::from_python(p, t);
}
virtual const T& from_python_cTr(PyObject* p, boost::python::type<const T&> t) {
return BOOST_PYTHON_CONVERSION::from_python(p, t);
}
virtual const T& from_python_T(PyObject* p, boost::python::type<T> t) {
return BOOST_PYTHON_CONVERSION::from_python(p, t);
}
virtual std::auto_ptr<T>& from_python_aTr(PyObject* p, boost::python::type<std::auto_ptr<T>&> t) {
return BOOST_PYTHON_CONVERSION::from_python(p, t);
}
virtual std::auto_ptr<T> from_python_aT(PyObject* p, boost::python::type<std::auto_ptr<T> > t) {
return BOOST_PYTHON_CONVERSION::from_python(p, t);
}
virtual const std::auto_ptr<T>& from_python_caTr(PyObject* p, boost::python::type<const std::auto_ptr<T>&> t) {
return BOOST_PYTHON_CONVERSION::from_python(p, t);
}
virtual PyObject* to_python(std::auto_ptr<T> x) {
return BOOST_PYTHON_CONVERSION::to_python(x);
}
virtual boost::shared_ptr<T>& from_python_sTr(PyObject* p, boost::python::type<boost::shared_ptr<T>&> t) {
return BOOST_PYTHON_CONVERSION::from_python(p, t);
}
virtual const boost::shared_ptr<T>& from_python_sT(PyObject* p, boost::python::type<boost::shared_ptr<T> > t) {
return BOOST_PYTHON_CONVERSION::from_python(p, t);
}
virtual const boost::shared_ptr<T>& from_python_csTr(PyObject* p, boost::python::type<const boost::shared_ptr<T>&> t) {
return BOOST_PYTHON_CONVERSION::from_python(p, t);
}
virtual PyObject* to_python(boost::shared_ptr<T> x) {
return BOOST_PYTHON_CONVERSION::to_python(x);
}
};
// The addditional to_python() converter that can be used if T is copyable.
template <class T>
struct export_converter_object : export_converter_object_noncopyable<T>
{
virtual PyObject* to_python(const T& x) {
return BOOST_PYTHON_CONVERSION::py_extension_class_converters(boost::python::type<T>()).to_python(x);
}
virtual PyObject* to_python(const T& x) {
return BOOST_PYTHON_CONVERSION::py_extension_class_converters(boost::python::type<T>()).to_python(x);
}
};
namespace detail {