arg_from_python.hpp 2.0 KB

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