diff --git a/extclass.h b/extclass.h index 9b5ff64b..87151940 100644 --- a/extclass.h +++ b/extclass.h @@ -151,6 +151,21 @@ class PyExtensionClassConverters { return py::Type(); } #endif + friend inline PyExtensionClassConverters const & converter(py::Type) + { + static PyExtensionClassConverters conv; + return conv; + } + + PyObject* to_python(const T& x) const + { + py::PyPtr result(create_instance(false)); + result->add_implementation( + std::auto_ptr( + new py::InstanceValueHolder(result.get(), x))); + return result.release(); + } + PyExtensionClassConverters() {} // Convert to T* @@ -267,6 +282,8 @@ py_copy_to_new_value_holder(py::ExtensionInstance* p, const T& x, py::Type) return new py::InstanceValueHolder(p, x); } +#if 0 + template PyObject* to_python(const T& x) { @@ -277,6 +294,14 @@ PyObject* to_python(const T& x) py_copy_to_new_value_holder(result.get(), x, py_holder_type(x)))); return result.release(); } +#endif /* #if 0 */ + + +template +PyObject* to_python(const T& x) +{ + return converter(py::Type()).to_python(x); +} #endif #ifdef PY_NO_INLINE_FRIENDS_IN_NAMESPACE // back from global namespace for this GCC bug