|
| 1 | +// Copyright David Abrahams 2002. Permission to copy, use, |
| 2 | +// modify, sell and distribute this software is granted provided this |
| 3 | +// copyright notice appears in all copies. This software is provided |
| 4 | +// "as is" without express or implied warranty, and with no claim as |
| 5 | +// to its suitability for any purpose. |
| 6 | +#ifndef LONG_DWA2002627_HPP |
| 7 | +# define LONG_DWA2002627_HPP |
| 8 | + |
| 9 | +# include <boost/python/object.hpp> |
| 10 | +# include <boost/python/converter/pytype_arg_from_python.hpp> |
| 11 | + |
| 12 | +namespace boost { namespace python { |
| 13 | + |
| 14 | +class long_ : public object |
| 15 | +{ |
| 16 | + public: |
| 17 | + BOOST_PYTHON_DECL long_(); // new long_ |
| 18 | + explicit BOOST_PYTHON_DECL long_(object_cref rhs); |
| 19 | + |
| 20 | + template <class T> |
| 21 | + explicit long_(T const& rhs) |
| 22 | + : object(long_::call(object(rhs))) |
| 23 | + { |
| 24 | + } |
| 25 | + |
| 26 | + explicit BOOST_PYTHON_DECL long_(object_cref rhs, object_cref base); |
| 27 | + |
| 28 | + template <class T, class U> |
| 29 | + explicit long_(T const& rhs, U const& base) |
| 30 | + : object(long_::call(object(rhs), object(base))) |
| 31 | + { |
| 32 | + } |
| 33 | + public: // implementation detail -- for internal use only |
| 34 | + explicit long_(detail::borrowed_reference); |
| 35 | + explicit long_(detail::new_reference); |
| 36 | + |
| 37 | + private: |
| 38 | + static BOOST_PYTHON_DECL detail::new_reference call(object const&); |
| 39 | + static BOOST_PYTHON_DECL detail::new_reference call(object const&, object const&); |
| 40 | +}; |
| 41 | + |
| 42 | +// |
| 43 | +// Converter Specializations |
| 44 | +// |
| 45 | +template <class T> struct arg_from_python; |
| 46 | + |
| 47 | +template <> |
| 48 | +struct arg_from_python<long_> |
| 49 | + : converter::pytype_wrapper_value_arg_from_python<long_, &PyLong_Type> |
| 50 | +{ |
| 51 | + typedef converter::pytype_wrapper_value_arg_from_python<long_, &PyLong_Type> base; |
| 52 | + typedef long_ result_type; |
| 53 | + |
| 54 | + arg_from_python(PyObject* p) : base(p) {} |
| 55 | +}; |
| 56 | + |
| 57 | +template <> |
| 58 | +struct arg_from_python<long_ const&> |
| 59 | + : arg_from_python<long_> |
| 60 | +{ |
| 61 | + arg_from_python(PyObject* p) |
| 62 | + : arg_from_python<long_>(p) {} |
| 63 | +}; |
| 64 | + |
| 65 | +template <> |
| 66 | +struct arg_from_python<long_&> |
| 67 | + : converter::pytype_wrapper_ref_arg_from_python<long_, &PyLong_Type> |
| 68 | +{ |
| 69 | + typedef converter::pytype_wrapper_ref_arg_from_python<long_, &PyLong_Type> base; |
| 70 | + typedef long_ result_type; |
| 71 | + |
| 72 | + arg_from_python(PyObject* p) |
| 73 | + : base(p) {} |
| 74 | +}; |
| 75 | + |
| 76 | +namespace converter |
| 77 | +{ |
| 78 | + template <class T> struct is_object_manager; |
| 79 | + |
| 80 | + template <> |
| 81 | + struct is_object_manager<long_> |
| 82 | + { |
| 83 | + BOOST_STATIC_CONSTANT(bool, value = true); |
| 84 | + }; |
| 85 | + |
| 86 | + template <class T> struct return_from_python; |
| 87 | + template <> |
| 88 | + struct return_from_python<long_> |
| 89 | + { |
| 90 | + typedef long_ result_type; |
| 91 | + |
| 92 | + result_type operator()(PyObject* x) const |
| 93 | + { |
| 94 | + return long_(python::detail::new_reference(x)); |
| 95 | + } |
| 96 | + }; |
| 97 | +} |
| 98 | + |
| 99 | +// |
| 100 | +// long_ implementation |
| 101 | +// |
| 102 | +inline long_::long_(detail::borrowed_reference p) |
| 103 | + : object(p) |
| 104 | +{} |
| 105 | + |
| 106 | +inline long_::long_(detail::new_reference p) |
| 107 | + : object(p) |
| 108 | +{} |
| 109 | + |
| 110 | +}} // namespace boost::python |
| 111 | + |
| 112 | +#endif // LONG_DWA2002627_HPP |
0 commit comments