]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/python/converter/pytype_function.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / python / converter / pytype_function.hpp
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
7
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>
12
13
14 namespace boost { namespace python {
15
16 namespace converter
17 {
18 template <PyTypeObject const* python_type>
19 struct wrap_pytype
20 {
21 static PyTypeObject const* get_pytype()
22 {
23 return python_type;
24 }
25 };
26
27 typedef PyTypeObject const* (*pytype_function)();
28
29 #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
30
31
32
33 namespace detail
34 {
35 struct unwind_type_id_helper{
36 typedef python::type_info result_type;
37 template <class U>
38 static result_type execute(U* ){
39 return python::type_id<U>();
40 }
41 };
42
43 template <class T>
44 inline python::type_info unwind_type_id_(boost::type<T>* = 0, mpl::false_ * =0)
45 {
46 return boost::python::detail::unwind_type<unwind_type_id_helper, T> ();
47 }
48
49 inline python::type_info unwind_type_id_(boost::type<void>* = 0, mpl::true_* =0)
50 {
51 return type_id<void>();
52 }
53
54 template <class T>
55 inline python::type_info unwind_type_id(boost::type<T>* p= 0)
56 {
57 return unwind_type_id_(p, (mpl::bool_<boost::python::detail::is_void<T>::value >*)0 );
58 }
59 }
60
61
62 template <class T>
63 struct expected_pytype_for_arg
64 {
65 static PyTypeObject const *get_pytype()
66 {
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 )
69 );
70 return r ? r->expected_from_python_type(): 0;
71 }
72 };
73
74
75 template <class T>
76 struct registered_pytype
77 {
78 static PyTypeObject const *get_pytype()
79 {
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 )
82 );
83 return r ? r->m_class_object: 0;
84 }
85 };
86
87
88 template <class T>
89 struct registered_pytype_direct
90 {
91 static PyTypeObject const* get_pytype()
92 {
93 return registered<T>::converters.m_class_object;
94 }
95 };
96
97 template <class T>
98 struct expected_from_python_type : expected_pytype_for_arg<T>{};
99
100 template <class T>
101 struct expected_from_python_type_direct
102 {
103 static PyTypeObject const* get_pytype()
104 {
105 return registered<T>::converters.expected_from_python_type();
106 }
107 };
108
109 template <class T>
110 struct to_python_target_type
111 {
112 static PyTypeObject const *get_pytype()
113 {
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 )
116 );
117 return r ? r->to_python_target_type(): 0;
118 }
119 };
120
121 template <class T>
122 struct to_python_target_type_direct
123 {
124 static PyTypeObject const *get_pytype()
125 {
126 return registered<T>::converters.to_python_target_type();
127 }
128 };
129 #endif
130
131 }}} // namespace boost::python
132
133 #endif // WRAP_PYTYPE_NM20070606_HPP