Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:50:42

0001 // Copyright David Abrahams 2002.
0002 // Distributed under the Boost Software License, Version 1.0. (See
0003 // accompanying file LICENSE_1_0.txt or copy at
0004 // http://www.boost.org/LICENSE_1_0.txt)
0005 #ifndef TO_PYTHON_CONVERTER_DWA200221_HPP
0006 # define TO_PYTHON_CONVERTER_DWA200221_HPP
0007 
0008 # include <boost/python/detail/prefix.hpp>
0009 
0010 # include <boost/python/converter/registry.hpp>
0011 # include <boost/python/converter/as_to_python_function.hpp>
0012 #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
0013 # include <boost/python/converter/pytype_function.hpp>
0014 #endif
0015 # include <boost/python/type_id.hpp>
0016 
0017 namespace boost { namespace python { 
0018 
0019 #if 0 //get_pytype member detection
0020 namespace detail
0021 {
0022     typedef char yes_type;
0023     typedef struct {char a[2]; } no_type;
0024     template<PyTypeObject const * (*f)()> struct test_get_pytype1 { };
0025     template<PyTypeObject * (*f)()>          struct test_get_pytype2 { };
0026 
0027     template<class T> yes_type tester(test_get_pytype1<&T::get_pytype>*);
0028 
0029     template<class T> yes_type tester(test_get_pytype2<&T::get_pytype>*);
0030 
0031     template<class T> no_type tester(...);
0032 
0033     template<class T>
0034     struct test_get_pytype_base  
0035     {
0036         BOOST_STATIC_CONSTANT(bool, value= (sizeof(detail::tester<T>(0)) == sizeof(yes_type)));
0037     };
0038 
0039     template<class T>
0040     struct test_get_pytype : boost::mpl::bool_<test_get_pytype_base<T>::value> 
0041     {
0042     };
0043 
0044 }
0045 #endif
0046 
0047 template < class T, class Conversion, bool has_get_pytype=false >
0048 struct to_python_converter 
0049 {
0050 #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
0051     typedef boost::mpl::bool_<has_get_pytype> HasGetPytype;
0052 
0053     static PyTypeObject const* get_pytype_1(boost::mpl::true_ *)
0054     {
0055         return Conversion::get_pytype();
0056     }
0057 
0058     static PyTypeObject const* get_pytype_1(boost::mpl::false_ *)
0059     {
0060         return 0;
0061     }
0062     static PyTypeObject const* get_pytype_impl()
0063     {
0064         return get_pytype_1((HasGetPytype*)0);
0065     }
0066 #endif
0067     
0068     to_python_converter();
0069 };
0070 
0071 //
0072 // implementation
0073 //
0074 
0075 template <class T, class Conversion ,bool has_get_pytype>
0076 to_python_converter<T,Conversion, has_get_pytype>::to_python_converter()
0077 {
0078     typedef converter::as_to_python_function<
0079         T, Conversion
0080         > normalized;
0081             
0082     converter::registry::insert(
0083         &normalized::convert
0084         , type_id<T>()
0085 #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
0086         , &get_pytype_impl
0087 #endif
0088         );
0089 }
0090 
0091 }} // namespace boost::python
0092 
0093 #endif // TO_PYTHON_CONVERTER_DWA200221_HPP
0094