1 // Copyright David Abrahams 2002, Nikolay Mladenov 2007.
2 // Distributed under the Boost Software License, Version 1.0. (See
3 // accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5 #ifndef WRAP_PYTYPE_NM20070606_HPP
6 # define WRAP_PYTYPE_NM20070606_HPP
8 # include <boost/python/detail/prefix.hpp>
9 # include <boost/python/converter/registered.hpp>
10 # include <boost/python/detail/unwind_type.hpp>
11 # include <boost/python/detail/type_traits.hpp>
14 namespace boost { namespace python {
18 template <PyTypeObject const* python_type>
21 static PyTypeObject const* get_pytype()
27 typedef PyTypeObject const* (*pytype_function)();
29 #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
35 struct unwind_type_id_helper{
36 typedef python::type_info result_type;
38 static result_type execute(U* ){
39 return python::type_id<U>();
44 inline python::type_info unwind_type_id_(boost::type<T>* = 0, mpl::false_ * =0)
46 return boost::python::detail::unwind_type<unwind_type_id_helper, T> ();
49 inline python::type_info unwind_type_id_(boost::type<void>* = 0, mpl::true_* =0)
51 return type_id<void>();
55 inline python::type_info unwind_type_id(boost::type<T>* p= 0)
57 return unwind_type_id_(p, (mpl::bool_<boost::python::detail::is_void<T>::value >*)0 );
63 struct expected_pytype_for_arg
65 static PyTypeObject const *get_pytype()
67 const converter::registration *r=converter::registry::query(
68 detail::unwind_type_id_((boost::type<T>*)0, (mpl::bool_<boost::python::detail::is_void<T>::value >*)0 )
70 return r ? r->expected_from_python_type(): 0;
76 struct registered_pytype
78 static PyTypeObject const *get_pytype()
80 const converter::registration *r=converter::registry::query(
81 detail::unwind_type_id_((boost::type<T>*) 0, (mpl::bool_<boost::python::detail::is_void<T>::value >*)0 )
83 return r ? r->m_class_object: 0;
89 struct registered_pytype_direct
91 static PyTypeObject const* get_pytype()
93 return registered<T>::converters.m_class_object;
98 struct expected_from_python_type : expected_pytype_for_arg<T>{};
101 struct expected_from_python_type_direct
103 static PyTypeObject const* get_pytype()
105 return registered<T>::converters.expected_from_python_type();
110 struct to_python_target_type
112 static PyTypeObject const *get_pytype()
114 const converter::registration *r=converter::registry::query(
115 detail::unwind_type_id_((boost::type<T>*)0, (mpl::bool_<boost::python::detail::is_void<T>::value >*)0 )
117 return r ? r->to_python_target_type(): 0;
122 struct to_python_target_type_direct
124 static PyTypeObject const *get_pytype()
126 return registered<T>::converters.to_python_target_type();
131 }}} // namespace boost::python
133 #endif // WRAP_PYTYPE_NM20070606_HPP