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 ARG_FROM_PYTHON_DWA2002128_HPP 6 # define ARG_FROM_PYTHON_DWA2002128_HPP 7 8 # include <boost/python/detail/prefix.hpp> 9 # include <boost/python/converter/arg_from_python.hpp> 10 # if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1400)) \ 11 || BOOST_WORKAROUND(BOOST_INTEL_WIN, BOOST_TESTED_AT(800)) 12 # include <boost/python/detail/type_traits.hpp> 13 #endif 14 15 namespace boost { namespace python { 16 17 template <class T> 18 struct arg_from_python 19 : converter::select_arg_from_python< 20 # if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1400)) \ 21 || BOOST_WORKAROUND(BOOST_INTEL_WIN, BOOST_TESTED_AT(800)) 22 typename detail::remove_cv<T>::type 23 # else 24 T 25 # endif 26 >::type 27 { 28 typedef typename converter::select_arg_from_python< 29 # if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1400)) \ 30 || BOOST_WORKAROUND(BOOST_INTEL_WIN, BOOST_TESTED_AT(800)) 31 typename detail::remove_cv<T>::type 32 # else 33 T 34 # endif 35 >::type base; 36 37 arg_from_python(PyObject*); 38 }; 39 40 // specialization for PyObject* 41 template <> 42 struct arg_from_python<PyObject*> 43 { 44 typedef PyObject* result_type; 45 arg_from_pythonboost::python::arg_from_python46 arg_from_python(PyObject* p) : m_source(p) {} convertibleboost::python::arg_from_python47 bool convertible() const { return true; } operator ()boost::python::arg_from_python48 PyObject* operator()() const { return m_source; } 49 private: 50 PyObject* m_source; 51 }; 52 53 template <> 54 struct arg_from_python<PyObject* const&> 55 { 56 typedef PyObject* const& result_type; 57 arg_from_pythonboost::python::arg_from_python58 arg_from_python(PyObject* p) : m_source(p) {} convertibleboost::python::arg_from_python59 bool convertible() const { return true; } operator ()boost::python::arg_from_python60 PyObject*const& operator()() const { return m_source; } 61 private: 62 PyObject* m_source; 63 }; 64 65 // 66 // implementations 67 // 68 template <class T> arg_from_python(PyObject * source)69inline arg_from_python<T>::arg_from_python(PyObject* source) 70 : base(source) 71 { 72 } 73 74 }} // namespace boost::python 75 76 #endif // ARG_FROM_PYTHON_DWA2002128_HPP 77