From 3447aaa8c67c3a648f2af72473bd2ac7c7f542df Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Sun, 10 Mar 2002 06:32:07 +0000 Subject: [PATCH] Pointer/reference from_python callback conversions [SVN r13158] --- include/boost/python/converter/callback.hpp | 26 +++++++++++++++++++ .../converter/callback_from_python_base.hpp | 5 ++++ 2 files changed, 31 insertions(+) diff --git a/include/boost/python/converter/callback.hpp b/include/boost/python/converter/callback.hpp index 756466e3..a8fceb53 100644 --- a/include/boost/python/converter/callback.hpp +++ b/include/boost/python/converter/callback.hpp @@ -164,6 +164,32 @@ namespace detail BOOST_PYTHON_DECL void throw_no_class_registered(); + template + inline reference_callback_from_python::reference_callback_from_python() + { + detail::throw_if_not_registered(lvalue_from_python_chain::value); + } + + template + inline T reference_callback_from_python::operator()(PyObject* obj) const + { + return python::detail::void_ptr_to_reference( + callback_convert_reference(obj, lvalue_from_python_chain::value) + , (T(*)())0); + } + + template + inline pointer_callback_from_python::pointer_callback_from_python() + { + detail::throw_if_not_registered(lvalue_from_python_chain::value); + } + + template + inline T pointer_callback_from_python::operator()(PyObject* obj) const + { + return T(callback_convert_pointer(obj, lvalue_from_python_chain::value)); + } + template inline value_callback_to_python::value_callback_to_python(T const& x) : callback_to_python_base(&x, to_python_function::value) diff --git a/include/boost/python/converter/callback_from_python_base.hpp b/include/boost/python/converter/callback_from_python_base.hpp index 0eeccb0e..117ba145 100644 --- a/include/boost/python/converter/callback_from_python_base.hpp +++ b/include/boost/python/converter/callback_from_python_base.hpp @@ -10,9 +10,14 @@ namespace boost { namespace python { namespace converter { namespace detail { + // Throw an exception BOOST_PYTHON_DECL void throw_if_not_registered(rvalue_stage1_data const&); BOOST_PYTHON_DECL void* convert_rvalue(PyObject*, rvalue_stage1_data& data, void* storage); + + BOOST_PYTHON_DECL void throw_if_not_registered(lvalue_from_python_registration*const&); + BOOST_PYTHON_DECL void* callback_convert_reference(PyObject*, lvalue_from_python_registration*const&); + BOOST_PYTHON_DECL void* callback_convert_pointer(PyObject*, lvalue_from_python_registration*const&); } }}} // namespace boost::python::converter