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 #ifndef TO_PYTHON_CONVERTER_DWA200221_HPP
6 # define TO_PYTHON_CONVERTER_DWA200221_HPP
8 # include <boost/python/detail/prefix.hpp>
10 # include <boost/python/converter/registry.hpp>
11 # include <boost/python/converter/as_to_python_function.hpp>
12 #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
13 # include <boost/python/converter/pytype_function.hpp>
15 # include <boost/python/type_id.hpp>
17 namespace boost { namespace python {
19 #if 0 //get_pytype member detection
22 typedef char yes_type;
23 typedef struct {char a[2]; } no_type;
24 template<PyTypeObject const * (*f)()> struct test_get_pytype1 { };
25 template<PyTypeObject * (*f)()> struct test_get_pytype2 { };
27 template<class T> yes_type tester(test_get_pytype1<&T::get_pytype>*);
29 template<class T> yes_type tester(test_get_pytype2<&T::get_pytype>*);
31 template<class T> no_type tester(...);
34 struct test_get_pytype_base
36 BOOST_STATIC_CONSTANT(bool, value= (sizeof(detail::tester<T>(0)) == sizeof(yes_type)));
40 struct test_get_pytype : boost::mpl::bool_<test_get_pytype_base<T>::value>
47 template < class T, class Conversion, bool has_get_pytype=false >
48 struct to_python_converter
50 #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
51 typedef boost::mpl::bool_<has_get_pytype> HasGetPytype;
53 static PyTypeObject const* get_pytype_1(boost::mpl::true_ *)
55 return Conversion::get_pytype();
58 static PyTypeObject const* get_pytype_1(boost::mpl::false_ *)
62 static PyTypeObject const* get_pytype_impl()
64 return get_pytype_1((HasGetPytype*)0);
68 to_python_converter();
75 template <class T, class Conversion ,bool has_get_pytype>
76 to_python_converter<T,Conversion, has_get_pytype>::to_python_converter()
78 typedef converter::as_to_python_function<
82 converter::registry::insert(
85 #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
91 }} // namespace boost::python
93 #endif // TO_PYTHON_CONVERTER_DWA200221_HPP