File indexing completed on 2025-12-16 10:07:40
0001
0002
0003
0004
0005 #ifndef OBJ_MGR_ARG_FROM_PYTHON_DWA2002628_HPP
0006 # define OBJ_MGR_ARG_FROM_PYTHON_DWA2002628_HPP
0007
0008 # include <boost/python/detail/prefix.hpp>
0009 # include <boost/python/detail/referent_storage.hpp>
0010 # include <boost/python/detail/destroy.hpp>
0011 # include <boost/python/detail/construct.hpp>
0012 # include <boost/python/converter/object_manager.hpp>
0013 # include <boost/python/detail/raw_pyobject.hpp>
0014 # include <boost/python/tag.hpp>
0015
0016
0017
0018
0019
0020 namespace boost { namespace python { namespace converter {
0021
0022 template <class T>
0023 struct object_manager_value_arg_from_python
0024 {
0025 typedef T result_type;
0026
0027 object_manager_value_arg_from_python(PyObject*);
0028 bool convertible() const;
0029 T operator()() const;
0030 private:
0031 PyObject* m_source;
0032 };
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043 template <class Ref>
0044 struct object_manager_ref_arg_from_python
0045 {
0046 typedef Ref result_type;
0047
0048 object_manager_ref_arg_from_python(PyObject*);
0049 bool convertible() const;
0050 Ref operator()() const;
0051 ~object_manager_ref_arg_from_python();
0052 private:
0053 typename python::detail::referent_storage<Ref>::type m_result;
0054 };
0055
0056
0057
0058
0059
0060 template <class T>
0061 inline object_manager_value_arg_from_python<T>::object_manager_value_arg_from_python(PyObject* x)
0062 : m_source(x)
0063 {
0064 }
0065
0066 template <class T>
0067 inline bool object_manager_value_arg_from_python<T>::convertible() const
0068 {
0069 return object_manager_traits<T>::check(m_source);
0070 }
0071
0072 template <class T>
0073 inline T object_manager_value_arg_from_python<T>::operator()() const
0074 {
0075 return T(python::detail::borrowed_reference(m_source));
0076 }
0077
0078 template <class Ref>
0079 inline object_manager_ref_arg_from_python<Ref>::object_manager_ref_arg_from_python(PyObject* x)
0080 {
0081 # if defined(__EDG_VERSION__) && __EDG_VERSION__ <= 243
0082
0083 python::detail::borrowed_reference x_ = python::detail::borrowed_reference(x);
0084 python::detail::construct_referent<Ref>(m_result.bytes, x_);
0085 # else
0086 python::detail::construct_referent<Ref>(m_result.bytes, (python::detail::borrowed_reference)x);
0087 # endif
0088 }
0089
0090 template <class Ref>
0091 inline object_manager_ref_arg_from_python<Ref>::~object_manager_ref_arg_from_python()
0092 {
0093 python::detail::destroy_referent<Ref>(this->m_result.bytes);
0094 }
0095
0096 namespace detail
0097 {
0098 template <class T>
0099 inline bool object_manager_ref_check(T const& x)
0100 {
0101 return object_manager_traits<T>::check(get_managed_object(x, tag));
0102 }
0103 }
0104
0105 template <class Ref>
0106 inline bool object_manager_ref_arg_from_python<Ref>::convertible() const
0107 {
0108 return detail::object_manager_ref_check(
0109 python::detail::void_ptr_to_reference(this->m_result.bytes, (Ref(*)())0));
0110 }
0111
0112 template <class Ref>
0113 inline Ref object_manager_ref_arg_from_python<Ref>::operator()() const
0114 {
0115 return python::detail::void_ptr_to_reference(
0116 this->m_result.bytes, (Ref(*)())0);
0117 }
0118
0119 }}}
0120
0121 #endif