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 TO_PYTHON_INDIRECT_DWA200221_HPP
6 # define TO_PYTHON_INDIRECT_DWA200221_HPP
8 # include <boost/python/detail/prefix.hpp>
10 # include <boost/python/object/pointer_holder.hpp>
11 # include <boost/python/object/make_ptr_instance.hpp>
13 # include <boost/python/detail/none.hpp>
15 #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
16 # include <boost/python/converter/pytype_function.hpp>
19 # include <boost/python/refcount.hpp>
21 # include <boost/type_traits/is_pointer.hpp>
22 # include <boost/type_traits/is_polymorphic.hpp>
24 # include <boost/mpl/bool.hpp>
26 # if defined(__ICL) && __ICL < 600
27 # include <boost/shared_ptr.hpp>
32 namespace boost
{ namespace python
{
34 template <class T
, class MakeHolder
>
35 struct to_python_indirect
39 operator()(U
const& ref
) const
41 return this->execute(const_cast<U
&>(ref
), is_pointer
<U
>());
43 #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
44 inline PyTypeObject
const*
47 return converter::registered_pytype
<T
>::get_pytype();
52 inline PyObject
* execute(U
* ptr
, mpl::true_
) const
54 // No special NULL treatment for references
56 return python::detail::none();
58 return this->execute(*ptr
, mpl::false_());
62 inline PyObject
* execute(U
const& x
, mpl::false_
) const
64 U
* const p
= &const_cast<U
&>(x
);
65 if (is_polymorphic
<U
>::value
)
67 if (PyObject
* o
= detail::wrapper_base_::owner(p
))
70 return MakeHolder::execute(p
);
79 struct make_owning_holder
82 static PyObject
* execute(T
* p
)
84 // can't use auto_ptr with Intel 5 and VC6 Dinkum library
85 // for some reason. We get link errors against the auto_ptr
87 # if defined(__ICL) && __ICL < 600
88 typedef boost::shared_ptr
<T
> smart_pointer
;
90 typedef std::auto_ptr
<T
> smart_pointer
;
92 typedef objects::pointer_holder
<smart_pointer
, T
> holder_t
;
94 smart_pointer
ptr(const_cast<T
*>(p
));
95 return objects::make_ptr_instance
<T
, holder_t
>::execute(ptr
);
99 struct make_reference_holder
102 static PyObject
* execute(T
* p
)
104 typedef objects::pointer_holder
<T
*, T
> holder_t
;
105 T
* q
= const_cast<T
*>(p
);
106 return objects::make_ptr_instance
<T
, holder_t
>::execute(q
);
111 }} // namespace boost::python
113 #endif // TO_PYTHON_INDIRECT_DWA200221_HPP