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>
13 namespace boost { namespace python {
17 template <PyTypeObject const* python_type>
20 static PyTypeObject const* get_pytype()
26 typedef PyTypeObject const* (*pytype_function)();
28 #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
34 struct unwind_type_id_helper{
35 typedef python::type_info result_type;
37 static result_type execute(U* ){
38 return python::type_id<U>();
43 inline python::type_info unwind_type_id_(boost::type<T>* = 0, mpl::false_ * =0)
45 return boost::python::detail::unwind_type<unwind_type_id_helper, T> ();
48 inline python::type_info unwind_type_id_(boost::type<void>* = 0, mpl::true_* =0)
50 return type_id<void>();
54 inline python::type_info unwind_type_id(boost::type<T>* p= 0)
56 return unwind_type_id_(p, (mpl::bool_<boost::is_void<T>::value >*)0 );
62 struct expected_pytype_for_arg
64 static PyTypeObject const *get_pytype()
66 const converter::registration *r=converter::registry::query(
67 detail::unwind_type_id_((boost::type<T>*)0, (mpl::bool_<boost::is_void<T>::value >*)0 )
69 return r ? r->expected_from_python_type(): 0;
75 struct registered_pytype
77 static PyTypeObject const *get_pytype()
79 const converter::registration *r=converter::registry::query(
80 detail::unwind_type_id_((boost::type<T>*) 0, (mpl::bool_<boost::is_void<T>::value >*)0 )
82 return r ? r->m_class_object: 0;
88 struct registered_pytype_direct
90 static PyTypeObject const* get_pytype()
92 return registered<T>::converters.m_class_object;
97 struct expected_from_python_type : expected_pytype_for_arg<T>{};
100 struct expected_from_python_type_direct
102 static PyTypeObject const* get_pytype()
104 return registered<T>::converters.expected_from_python_type();
109 struct to_python_target_type
111 static PyTypeObject const *get_pytype()
113 const converter::registration *r=converter::registry::query(
114 detail::unwind_type_id_((boost::type<T>*)0, (mpl::bool_<boost::is_void<T>::value >*)0 )
116 return r ? r->to_python_target_type(): 0;
121 struct to_python_target_type_direct
123 static PyTypeObject const *get_pytype()
125 return registered<T>::converters.to_python_target_type();
130 }}} // namespace boost::python
132 #endif // WRAP_PYTYPE_NM20070606_HPP