2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-22 17:32:55 +00:00
Files
python/test/test_builtin_converters.cpp
Dave Abrahams ac2746f680 * Generalized use of force_instantiate()
* Proper handling for numeric conversion overflows
* Moved internal converter names out of the way to prepare for user conversions
* Added comments
* Fixed a bug where None could be converted to the NULL target of a member function call, causing a crash.
* Wiped out and restarted todo.txt
* long long support
* Added more regression tests and checks for current limitations


[SVN r14094]
2002-06-06 20:24:39 +00:00

87 lines
4.1 KiB
C++

// Copyright David Abrahams 2002. Permission to copy, use,
// modify, sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
#include <string>
#include <boost/python/module.hpp>
#include <complex>
template <class T>
struct by_value
{
static T rewrap(T x)
{
return x;
}
};
template <class T>
struct by_const_reference
{
static T rewrap(T const& x)
{
return x;
}
};
char const* rewrap_value_mutable_cstring(char* x) { return x; }
BOOST_PYTHON_MODULE_INIT(builtin_converters)
{
boost::python::module("builtin_converters")
.def("rewrap_value_bool", by_value<bool>::rewrap)
.def("rewrap_value_char", by_value<char>::rewrap)
.def("rewrap_value_signed_char", by_value<signed char>::rewrap)
.def("rewrap_value_unsigned_char", by_value<unsigned char>::rewrap)
.def("rewrap_value_int", by_value<int>::rewrap)
.def("rewrap_value_unsigned_int", by_value<unsigned int>::rewrap)
.def("rewrap_value_short", by_value<short>::rewrap)
.def("rewrap_value_unsigned_short", by_value<unsigned short>::rewrap)
.def("rewrap_value_long", by_value<long>::rewrap)
.def("rewrap_value_unsigned_long", by_value<unsigned long>::rewrap)
#ifdef BOOST_HAS_LONG_LONG
.def("rewrap_value_long_long", by_value<long long>::rewrap)
.def("rewrap_value_unsigned_long_long", by_value<unsigned long long>::rewrap)
#endif
.def("rewrap_value_float", by_value<float>::rewrap)
.def("rewrap_value_double", by_value<double>::rewrap)
.def("rewrap_value_long_double", by_value<long double>::rewrap)
.def("rewrap_value_complex_float", by_value<std::complex<float> >::rewrap)
.def("rewrap_value_complex_double", by_value<std::complex<double> >::rewrap)
.def("rewrap_value_complex_long_double", by_value<std::complex<long double> >::rewrap)
.def("rewrap_value_string", by_value<std::string>::rewrap)
.def("rewrap_value_cstring", by_value<char const*>::rewrap)
// Expose this to illustrate our failings ;-). See test_builtin_converters.py
.def("rewrap_value_mutable_cstring", rewrap_value_mutable_cstring)
.def("rewrap_const_reference_bool", by_const_reference<bool>::rewrap)
.def("rewrap_const_reference_char", by_const_reference<char>::rewrap)
.def("rewrap_const_reference_signed_char", by_const_reference<signed char>::rewrap)
.def("rewrap_const_reference_unsigned_char", by_const_reference<unsigned char>::rewrap)
.def("rewrap_const_reference_int", by_const_reference<int>::rewrap)
.def("rewrap_const_reference_unsigned_int", by_const_reference<unsigned int>::rewrap)
.def("rewrap_const_reference_short", by_const_reference<short>::rewrap)
.def("rewrap_const_reference_unsigned_short", by_const_reference<unsigned short>::rewrap)
.def("rewrap_const_reference_long", by_const_reference<long>::rewrap)
.def("rewrap_const_reference_unsigned_long", by_const_reference<unsigned long>::rewrap)
#ifdef BOOST_HAS_LONG_LONG
.def("rewrap_const_reference_long_long", by_const_reference<long long>::rewrap)
.def("rewrap_const_reference_unsigned_long_long", by_const_reference<unsigned long long>::rewrap)
#endif
.def("rewrap_const_reference_float", by_const_reference<float>::rewrap)
.def("rewrap_const_reference_double", by_const_reference<double>::rewrap)
.def("rewrap_const_reference_long_double", by_const_reference<long double>::rewrap)
.def("rewrap_const_reference_complex_float", by_const_reference<std::complex<float> >::rewrap)
.def("rewrap_const_reference_complex_double", by_const_reference<std::complex<double> >::rewrap)
.def("rewrap_const_reference_complex_long_double", by_const_reference<std::complex<long double> >::rewrap)
.def("rewrap_const_reference_string", by_const_reference<std::string>::rewrap)
.def("rewrap_const_reference_cstring", by_const_reference<char const*>::rewrap)
;
}