]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/python/test/test_builtin_converters.cpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / python / test / test_builtin_converters.cpp
CommitLineData
7c673cae
FG
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>
7#include <complex>
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>
12
13template <class T>
14struct by_value
15{
16 static T rewrap(T x)
17 {
18 return x;
19 }
20 static int size(void)
21 {
22 return sizeof(T);
23 }
24};
25
26template <class T>
27struct by_const_reference
28{
29 static T rewrap(T const& x)
30 {
31 return x;
32 }
33};
34
35template <class T>
36struct by_reference
37{
38 static T rewrap(T& x)
39 {
40 return x;
41 }
42};
43
44using boost::python::def;
45using boost::python::handle;
46using boost::python::object;
47using boost::python::borrowed;
48
49// Used to test that arbitrary handle<>s can be returned
50handle<PyTypeObject> get_type(handle<> x)
51{
52 return handle<PyTypeObject>(borrowed(x->ob_type));
53}
54
55handle<> return_null_handle()
56{
57 return handle<>();
58}
59
60char const* rewrap_value_mutable_cstring(char* x) { return x; }
61
62object identity_(object x) { return x; }
63
64BOOST_PYTHON_MODULE(builtin_converters_ext)
65{
66 def("get_type", get_type);
67 def("return_null_handle", return_null_handle);
68
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);
75#ifdef HAVE_LONG_LONG
76 def("long_long_size", by_value<BOOST_PYTHON_LONG_LONG>::size);
77#endif
78
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.
91#ifdef HAVE_LONG_LONG
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);
94# endif
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)
103 identity_
104# else
105 by_value<std::wstring>::rewrap
106# endif
107 );
108 def("rewrap_value_string",
109# if defined(BOOST_NO_STD_WSTRING) || !defined(Py_USING_UNICODE)
110 identity_
111# else
112 by_value<std::wstring>::rewrap
113# endif
114 );
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);
119
120 // Expose this to illustrate our failings ;-). See test_builtin_converters.py
121 def("rewrap_value_mutable_cstring", rewrap_value_mutable_cstring);
122
123
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);
139# endif
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);
151}
152