annotate DEPENDENCIES/generic/include/boost/python/to_python_converter.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 // Copyright David Abrahams 2002.
Chris@16 2 // Distributed under the Boost Software License, Version 1.0. (See
Chris@16 3 // accompanying file LICENSE_1_0.txt or copy at
Chris@16 4 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 5 #ifndef TO_PYTHON_CONVERTER_DWA200221_HPP
Chris@16 6 # define TO_PYTHON_CONVERTER_DWA200221_HPP
Chris@16 7
Chris@16 8 # include <boost/python/detail/prefix.hpp>
Chris@16 9
Chris@16 10 # include <boost/python/converter/registry.hpp>
Chris@16 11 # include <boost/python/converter/as_to_python_function.hpp>
Chris@16 12 #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
Chris@16 13 # include <boost/python/converter/pytype_function.hpp>
Chris@16 14 #endif
Chris@16 15 # include <boost/python/type_id.hpp>
Chris@16 16
Chris@16 17 namespace boost { namespace python {
Chris@16 18
Chris@16 19 #if 0 //get_pytype member detection
Chris@16 20 namespace detail
Chris@16 21 {
Chris@16 22 typedef char yes_type;
Chris@16 23 typedef struct {char a[2]; } no_type;
Chris@16 24 template<PyTypeObject const * (*f)()> struct test_get_pytype1 { };
Chris@16 25 template<PyTypeObject * (*f)()> struct test_get_pytype2 { };
Chris@16 26
Chris@16 27 template<class T> yes_type tester(test_get_pytype1<&T::get_pytype>*);
Chris@16 28
Chris@16 29 template<class T> yes_type tester(test_get_pytype2<&T::get_pytype>*);
Chris@16 30
Chris@16 31 template<class T> no_type tester(...);
Chris@16 32
Chris@16 33 template<class T>
Chris@16 34 struct test_get_pytype_base
Chris@16 35 {
Chris@16 36 BOOST_STATIC_CONSTANT(bool, value= (sizeof(detail::tester<T>(0)) == sizeof(yes_type)));
Chris@16 37 };
Chris@16 38
Chris@16 39 template<class T>
Chris@16 40 struct test_get_pytype : boost::mpl::bool_<test_get_pytype_base<T>::value>
Chris@16 41 {
Chris@16 42 };
Chris@16 43
Chris@16 44 }
Chris@16 45 #endif
Chris@16 46
Chris@16 47 template < class T, class Conversion, bool has_get_pytype=false >
Chris@16 48 struct to_python_converter
Chris@16 49 {
Chris@16 50 #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
Chris@16 51 #if 0 //defined _MSC_VER && _MSC_VER >=1310
Chris@16 52 //probably other compilers could come here as well
Chris@16 53 typedef typename detail::test_get_pytype<Conversion> HasGetPytype;
Chris@16 54 #else
Chris@16 55 typedef boost::mpl::bool_<has_get_pytype> HasGetPytype;
Chris@16 56 #endif
Chris@16 57
Chris@16 58 static PyTypeObject const* get_pytype_1(boost::mpl::true_ *)
Chris@16 59 {
Chris@16 60 return Conversion::get_pytype();
Chris@16 61 }
Chris@16 62
Chris@16 63 static PyTypeObject const* get_pytype_1(boost::mpl::false_ *)
Chris@16 64 {
Chris@16 65 return 0;
Chris@16 66 }
Chris@16 67 static PyTypeObject const* get_pytype_impl()
Chris@16 68 {
Chris@16 69 return get_pytype_1((HasGetPytype*)0);
Chris@16 70 }
Chris@16 71 #endif
Chris@16 72
Chris@16 73 to_python_converter();
Chris@16 74 };
Chris@16 75
Chris@16 76 //
Chris@16 77 // implementation
Chris@16 78 //
Chris@16 79
Chris@16 80 template <class T, class Conversion ,bool has_get_pytype>
Chris@16 81 to_python_converter<T,Conversion, has_get_pytype>::to_python_converter()
Chris@16 82 {
Chris@16 83 typedef converter::as_to_python_function<
Chris@16 84 T, Conversion
Chris@16 85 > normalized;
Chris@16 86
Chris@16 87 converter::registry::insert(
Chris@16 88 &normalized::convert
Chris@16 89 , type_id<T>()
Chris@16 90 #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
Chris@16 91 , &get_pytype_impl
Chris@16 92 #endif
Chris@16 93 );
Chris@16 94 }
Chris@16 95
Chris@16 96 }} // namespace boost::python
Chris@16 97
Chris@16 98 #endif // TO_PYTHON_CONVERTER_DWA200221_HPP
Chris@16 99