1 // Copyright David Abrahams 2002.
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 #include <boost/python/module.hpp>
6 #include <boost/python/def.hpp>
8 #include <boost/python/handle.hpp>
9 #include <boost/python/cast.hpp>
10 #include <boost/python/object.hpp>
11 #include <boost/python/detail/wrap_python.hpp>
27 struct by_const_reference
29 static T
rewrap(T
const& x
)
44 using boost::python::def
;
45 using boost::python::handle
;
46 using boost::python::object
;
47 using boost::python::borrowed
;
49 // Used to test that arbitrary handle<>s can be returned
50 handle
<PyTypeObject
> get_type(handle
<> x
)
52 return handle
<PyTypeObject
>(borrowed(x
->ob_type
));
55 handle
<> return_null_handle()
60 char const* rewrap_value_mutable_cstring(char* x
) { return x
; }
62 object
identity_(object x
) { return x
; }
64 BOOST_PYTHON_MODULE(builtin_converters_ext
)
66 def("get_type", get_type
);
67 def("return_null_handle", return_null_handle
);
69 // These methods are used solely for getting some C++ type sizes
70 def("bool_size", by_value
<bool>::size
);
71 def("char_size", by_value
<char>::size
);
72 def("int_size", by_value
<int>::size
);
73 def("short_size", by_value
<short>::size
);
74 def("long_size", by_value
<long>::size
);
76 def("long_long_size", by_value
<BOOST_PYTHON_LONG_LONG
>::size
);
79 def("rewrap_value_bool", by_value
<bool>::rewrap
);
80 def("rewrap_value_char", by_value
<char>::rewrap
);
81 def("rewrap_value_signed_char", by_value
<signed char>::rewrap
);
82 def("rewrap_value_unsigned_char", by_value
<unsigned char>::rewrap
);
83 def("rewrap_value_int", by_value
<int>::rewrap
);
84 def("rewrap_value_unsigned_int", by_value
<unsigned int>::rewrap
);
85 def("rewrap_value_short", by_value
<short>::rewrap
);
86 def("rewrap_value_unsigned_short", by_value
<unsigned short>::rewrap
);
87 def("rewrap_value_long", by_value
<long>::rewrap
);
88 def("rewrap_value_unsigned_long", by_value
<unsigned long>::rewrap
);
89 // using Python's macro instead of Boost's - we don't seem to get the
90 // config right all the time.
92 def("rewrap_value_long_long", by_value
<BOOST_PYTHON_LONG_LONG
>::rewrap
);
93 def("rewrap_value_unsigned_long_long", by_value
<unsigned BOOST_PYTHON_LONG_LONG
>::rewrap
);
95 def("rewrap_value_float", by_value
<float>::rewrap
);
96 def("rewrap_value_double", by_value
<double>::rewrap
);
97 def("rewrap_value_long_double", by_value
<long double>::rewrap
);
98 def("rewrap_value_complex_float", by_value
<std::complex<float> >::rewrap
);
99 def("rewrap_value_complex_double", by_value
<std::complex<double> >::rewrap
);
100 def("rewrap_value_complex_long_double", by_value
<std::complex<long double> >::rewrap
);
101 def("rewrap_value_wstring",
102 # if defined(BOOST_NO_STD_WSTRING) || !defined(Py_USING_UNICODE)
105 by_value
<std::wstring
>::rewrap
108 def("rewrap_value_string",
109 # if defined(BOOST_NO_STD_WSTRING) || !defined(Py_USING_UNICODE)
112 by_value
<std::wstring
>::rewrap
115 def("rewrap_value_string", by_value
<std::string
>::rewrap
);
116 def("rewrap_value_cstring", by_value
<char const*>::rewrap
);
117 def("rewrap_value_handle", by_value
<handle
<> >::rewrap
);
118 def("rewrap_value_object", by_value
<object
>::rewrap
);
120 // Expose this to illustrate our failings ;-). See test_builtin_converters.py
121 def("rewrap_value_mutable_cstring", rewrap_value_mutable_cstring
);
124 def("rewrap_const_reference_bool", by_const_reference
<bool>::rewrap
);
125 def("rewrap_const_reference_char", by_const_reference
<char>::rewrap
);
126 def("rewrap_const_reference_signed_char", by_const_reference
<signed char>::rewrap
);
127 def("rewrap_const_reference_unsigned_char", by_const_reference
<unsigned char>::rewrap
);
128 def("rewrap_const_reference_int", by_const_reference
<int>::rewrap
);
129 def("rewrap_const_reference_unsigned_int", by_const_reference
<unsigned int>::rewrap
);
130 def("rewrap_const_reference_short", by_const_reference
<short>::rewrap
);
131 def("rewrap_const_reference_unsigned_short", by_const_reference
<unsigned short>::rewrap
);
132 def("rewrap_const_reference_long", by_const_reference
<long>::rewrap
);
133 def("rewrap_const_reference_unsigned_long", by_const_reference
<unsigned long>::rewrap
);
134 // using Python's macro instead of Boost's - we don't seem to get the
135 // config right all the time.
136 # ifdef HAVE_LONG_LONG
137 def("rewrap_const_reference_long_long", by_const_reference
<BOOST_PYTHON_LONG_LONG
>::rewrap
);
138 def("rewrap_const_reference_unsigned_long_long", by_const_reference
<unsigned BOOST_PYTHON_LONG_LONG
>::rewrap
);
140 def("rewrap_const_reference_float", by_const_reference
<float>::rewrap
);
141 def("rewrap_const_reference_double", by_const_reference
<double>::rewrap
);
142 def("rewrap_const_reference_long_double", by_const_reference
<long double>::rewrap
);
143 def("rewrap_const_reference_complex_float", by_const_reference
<std::complex<float> >::rewrap
);
144 def("rewrap_const_reference_complex_double", by_const_reference
<std::complex<double> >::rewrap
);
145 def("rewrap_const_reference_complex_long_double", by_const_reference
<std::complex<long double> >::rewrap
);
146 def("rewrap_const_reference_string", by_const_reference
<std::string
>::rewrap
);
147 def("rewrap_const_reference_cstring", by_const_reference
<char const*>::rewrap
);
148 def("rewrap_const_reference_handle", by_const_reference
<handle
<> >::rewrap
);
149 def("rewrap_const_reference_object", by_const_reference
<object
>::rewrap
);
150 def("rewrap_reference_object", by_reference
<object
>::rewrap
);