Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 10:07:14

0001 // Copyright David Abrahams 2002.
0002 // Distributed under the Boost Software License, Version 1.0. (See
0003 // accompanying file LICENSE_1_0.txt or copy at
0004 // http://www.boost.org/LICENSE_1_0.txt)
0005 #ifndef TO_PYTHON_INDIRECT_DWA200221_HPP
0006 # define TO_PYTHON_INDIRECT_DWA200221_HPP
0007 
0008 # include <boost/python/detail/prefix.hpp>
0009 
0010 # include <boost/python/object/pointer_holder.hpp>
0011 # include <boost/python/object/make_ptr_instance.hpp>
0012 
0013 # include <boost/python/detail/none.hpp>
0014 
0015 #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
0016 # include <boost/python/converter/pytype_function.hpp>
0017 #endif
0018 
0019 # include <boost/python/refcount.hpp>
0020 
0021 # include <boost/python/detail/type_traits.hpp>
0022 
0023 # if defined(__ICL) && __ICL < 600 
0024 #  include <boost/shared_ptr.hpp>
0025 # else 
0026 #  include <memory>
0027 # endif
0028 
0029 namespace boost { namespace python {
0030 
0031 template <class T, class MakeHolder>
0032 struct to_python_indirect
0033 {
0034     template <class U>
0035     inline PyObject*
0036     operator()(U const& ref) const
0037     {
0038         return this->execute(const_cast<U&>(ref), detail::is_pointer<U>());
0039     }
0040 #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
0041     inline PyTypeObject const*
0042     get_pytype()const
0043     {
0044         return converter::registered_pytype<T>::get_pytype();
0045     }
0046 #endif
0047  private:
0048     template <class U>
0049     inline PyObject* execute(U* ptr, detail::true_) const
0050     {
0051         // No special NULL treatment for references
0052         if (ptr == 0)
0053             return python::detail::none();
0054         else
0055             return this->execute(*ptr, detail::false_());
0056     }
0057     
0058     template <class U>
0059     inline PyObject* execute(U const& x, detail::false_) const
0060     {
0061         U* const p = &const_cast<U&>(x);
0062         if (detail::is_polymorphic<U>::value)
0063         {
0064             if (PyObject* o = detail::wrapper_base_::owner(p))
0065                 return incref(o);
0066         }
0067         return MakeHolder::execute(p);
0068     }
0069 };
0070 
0071 //
0072 // implementations
0073 //
0074 namespace detail
0075 {
0076   struct make_owning_holder
0077   {
0078       template <class T>
0079       static PyObject* execute(T* p)
0080       {
0081           // can't use auto_ptr with Intel 5 and VC6 Dinkum library
0082           // for some reason. We get link errors against the auto_ptr
0083           // copy constructor.
0084 # if defined(__ICL) && __ICL < 600 
0085           typedef boost::shared_ptr<T> smart_pointer;
0086 # elif defined(BOOST_NO_CXX11_SMART_PTR)
0087           typedef std::auto_ptr<T> smart_pointer;
0088 # else
0089           typedef std::unique_ptr<T> smart_pointer;
0090 # endif
0091           typedef objects::pointer_holder<smart_pointer, T> holder_t;
0092 
0093           smart_pointer ptr(const_cast<T*>(p));
0094           return objects::make_ptr_instance<T, holder_t>::execute(ptr);
0095       }
0096   };
0097 
0098   struct make_reference_holder
0099   {
0100       template <class T>
0101       static PyObject* execute(T* p)
0102       {
0103           typedef objects::pointer_holder<T*, T> holder_t;
0104           T* q = const_cast<T*>(p);
0105           return objects::make_ptr_instance<T, holder_t>::execute(q);
0106       }
0107   };
0108 }
0109 
0110 }} // namespace boost::python
0111 
0112 #endif // TO_PYTHON_INDIRECT_DWA200221_HPP