/usr/include/boost/python/converter
Edit: /usr/include/boost/python/converter/return_from_python.hpp (4270B)
// Copyright David Abrahams 2002.
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef RETURN_FROM_PYTHON_DWA200265_HPP
# define RETURN_FROM_PYTHON_DWA200265_HPP
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
namespace boost { namespace python { namespace converter {
template struct is_object_manager;
namespace detail
{
template
struct return_pointer_from_python
{
typedef T result_type;
T operator()(PyObject*) const;
};
template
struct return_reference_from_python
{
typedef T result_type;
T operator()(PyObject*) const;
};
template
struct return_rvalue_from_python
{
typedef T result_type;
return_rvalue_from_python();
result_type operator()(PyObject*);
private:
rvalue_from_python_data m_data;
};
template
struct return_object_manager_from_python
{
typedef T result_type;
result_type operator()(PyObject*) const;
};
template
struct select_return_from_python
{
BOOST_STATIC_CONSTANT(
bool, obj_mgr = is_object_manager::value);
BOOST_STATIC_CONSTANT(
bool, ptr = is_pointer::value);
BOOST_STATIC_CONSTANT(
bool, ref = is_reference::value);
typedef typename mpl::if_c<
obj_mgr
, return_object_manager_from_python
, typename mpl::if_c<
ptr
, return_pointer_from_python
, typename mpl::if_c<
ref
, return_reference_from_python
, return_rvalue_from_python
>::type
>::type
>::type type;
};
}
template
struct return_from_python
: detail::select_return_from_python::type
{
};
// Specialization as a convenience for call and call_method
template <>
struct return_from_python
{
typedef python::detail::returnable::type result_type;
result_type operator()(PyObject* x) const
{
(void_result_from_python)(x);
# ifdef BOOST_NO_VOID_RETURNS
return result_type();
# endif
}
};
//
// Implementations
//
namespace detail
{
template
inline return_rvalue_from_python::return_rvalue_from_python()
: m_data(
const_cast(®istered::converters)
)
{
}
template
inline typename return_rvalue_from_python::result_type
return_rvalue_from_python::operator()(PyObject* obj)
{
// Take possession of the source object here. If the result is in
// fact going to be a copy of an lvalue embedded in the object,
// and we take possession inside rvalue_result_from_python, it
// will be destroyed too early.
handle<> holder(obj);
return *(T*)
(rvalue_result_from_python)(obj, m_data.stage1);
}
template
inline T return_reference_from_python::operator()(PyObject* obj) const
{
return python::detail::void_ptr_to_reference(
(reference_result_from_python)(obj, registered::converters)
, (T(*)())0);
}
template
inline T return_pointer_from_python::operator()(PyObject* obj) const
{
return T(
(pointer_result_from_python)(obj, registered_pointee::converters)
);
}
template
inline T return_object_manager_from_python::operator()(PyObject* obj) const
{
return T(
object_manager_traits::adopt(expect_non_null(obj))
);
}
}
}}} // namespace boost::python::converter
#endif // RETURN_FROM_PYTHON_DWA200265_HPP