Chris@16: // Copyright David Abrahams 2002. Chris@16: // Distributed under the Boost Software License, Version 1.0. (See Chris@16: // accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: #ifndef TO_PYTHON_CONVERTER_DWA200221_HPP Chris@16: # define TO_PYTHON_CONVERTER_DWA200221_HPP Chris@16: Chris@16: # include Chris@16: Chris@16: # include Chris@16: # include Chris@16: #ifndef BOOST_PYTHON_NO_PY_SIGNATURES Chris@16: # include Chris@16: #endif Chris@16: # include Chris@16: Chris@16: namespace boost { namespace python { Chris@16: Chris@16: #if 0 //get_pytype member detection Chris@16: namespace detail Chris@16: { Chris@16: typedef char yes_type; Chris@16: typedef struct {char a[2]; } no_type; Chris@16: template struct test_get_pytype1 { }; Chris@16: template struct test_get_pytype2 { }; Chris@16: Chris@16: template yes_type tester(test_get_pytype1<&T::get_pytype>*); Chris@16: Chris@16: template yes_type tester(test_get_pytype2<&T::get_pytype>*); Chris@16: Chris@16: template no_type tester(...); Chris@16: Chris@16: template Chris@16: struct test_get_pytype_base Chris@16: { Chris@16: BOOST_STATIC_CONSTANT(bool, value= (sizeof(detail::tester(0)) == sizeof(yes_type))); Chris@16: }; Chris@16: Chris@16: template Chris@16: struct test_get_pytype : boost::mpl::bool_::value> Chris@16: { Chris@16: }; Chris@16: Chris@16: } Chris@16: #endif Chris@16: Chris@16: template < class T, class Conversion, bool has_get_pytype=false > Chris@16: struct to_python_converter Chris@16: { Chris@16: #ifndef BOOST_PYTHON_NO_PY_SIGNATURES Chris@16: #if 0 //defined _MSC_VER && _MSC_VER >=1310 Chris@16: //probably other compilers could come here as well Chris@16: typedef typename detail::test_get_pytype HasGetPytype; Chris@16: #else Chris@16: typedef boost::mpl::bool_ HasGetPytype; Chris@16: #endif Chris@16: Chris@16: static PyTypeObject const* get_pytype_1(boost::mpl::true_ *) Chris@16: { Chris@16: return Conversion::get_pytype(); Chris@16: } Chris@16: Chris@16: static PyTypeObject const* get_pytype_1(boost::mpl::false_ *) Chris@16: { Chris@16: return 0; Chris@16: } Chris@16: static PyTypeObject const* get_pytype_impl() Chris@16: { Chris@16: return get_pytype_1((HasGetPytype*)0); Chris@16: } Chris@16: #endif Chris@16: Chris@16: to_python_converter(); Chris@16: }; Chris@16: Chris@16: // Chris@16: // implementation Chris@16: // Chris@16: Chris@16: template Chris@16: to_python_converter::to_python_converter() Chris@16: { Chris@16: typedef converter::as_to_python_function< Chris@16: T, Conversion Chris@16: > normalized; Chris@16: Chris@16: converter::registry::insert( Chris@16: &normalized::convert Chris@16: , type_id() Chris@16: #ifndef BOOST_PYTHON_NO_PY_SIGNATURES Chris@16: , &get_pytype_impl Chris@16: #endif Chris@16: ); Chris@16: } Chris@16: Chris@16: }} // namespace boost::python Chris@16: Chris@16: #endif // TO_PYTHON_CONVERTER_DWA200221_HPP Chris@16: