Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/python/object/pointer_holder.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 #if !defined(BOOST_PP_IS_ITERATING)
0002 
0003 // Copyright David Abrahams 2001.
0004 // Distributed under the Boost Software License, Version 1.0. (See
0005 // accompanying file LICENSE_1_0.txt or copy at
0006 // http://www.boost.org/LICENSE_1_0.txt)
0007 
0008 # ifndef POINTER_HOLDER_DWA20011215_HPP
0009 #  define POINTER_HOLDER_DWA20011215_HPP 
0010 
0011 # include <boost/get_pointer.hpp>
0012 #  include <boost/type.hpp>
0013 
0014 #  include <boost/python/instance_holder.hpp>
0015 #  include <boost/python/object/inheritance_query.hpp>
0016 #  include <boost/python/object/forward.hpp>
0017 
0018 #  include <boost/python/pointee.hpp>
0019 #  include <boost/python/type_id.hpp>
0020 
0021 #  include <boost/python/detail/wrapper_base.hpp>
0022 #  include <boost/python/detail/force_instantiate.hpp>
0023 #  include <boost/python/detail/preprocessor.hpp>
0024 # include <boost/python/detail/type_traits.hpp>
0025 
0026 
0027 #  include <boost/mpl/if.hpp>
0028 #  include <boost/mpl/apply.hpp>
0029 
0030 #  include <boost/preprocessor/comma_if.hpp>
0031 #  include <boost/preprocessor/iterate.hpp>
0032 #  include <boost/preprocessor/repeat.hpp>
0033 #  include <boost/preprocessor/debug/line.hpp>
0034 #  include <boost/preprocessor/enum_params.hpp>
0035 #  include <boost/preprocessor/repetition/enum_binary_params.hpp>
0036 
0037 #  include <boost/detail/workaround.hpp>
0038 
0039 namespace boost { namespace python {
0040 
0041 template <class T> class wrapper;
0042 
0043 }}
0044 
0045 
0046 namespace boost { namespace python { namespace objects {
0047 
0048 #define BOOST_PYTHON_UNFORWARD_LOCAL(z, n, _) BOOST_PP_COMMA_IF(n) objects::do_unforward(a##n,0)
0049 
0050 template <class Pointer, class Value>
0051 struct pointer_holder : instance_holder
0052 {
0053     typedef Value value_type;
0054     
0055     pointer_holder(Pointer);
0056 
0057     // Forward construction to the held object
0058 
0059 #  define BOOST_PP_ITERATION_PARAMS_1 (4, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/object/pointer_holder.hpp>, 1))
0060 #  include BOOST_PP_ITERATE()
0061 
0062  private: // types
0063     
0064  private: // required holder implementation
0065     void* holds(type_info, bool null_ptr_only);
0066     
0067     template <class T>
0068     inline void* holds_wrapped(type_info dst_t, wrapper<T>*,T* p)
0069     {
0070         return python::type_id<T>() == dst_t ? p : 0;
0071     }
0072     
0073     inline void* holds_wrapped(type_info, ...)
0074     {
0075         return 0;
0076     }
0077 
0078  private: // data members
0079     Pointer m_p;
0080 };
0081 
0082 template <class Pointer, class Value>
0083 struct pointer_holder_back_reference : instance_holder
0084 {
0085  private:
0086     typedef typename python::pointee<Pointer>::type held_type;
0087  public:
0088     typedef Value value_type;
0089 
0090     // Not sure about this one -- can it work? The source object
0091     // undoubtedly does not carry the correct back reference pointer.
0092     pointer_holder_back_reference(Pointer);
0093 
0094     // Forward construction to the held object
0095 #  define BOOST_PP_ITERATION_PARAMS_1 (4, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/object/pointer_holder.hpp>, 2))
0096 #  include BOOST_PP_ITERATE()
0097 
0098  private: // required holder implementation
0099     void* holds(type_info, bool null_ptr_only);
0100 
0101  private: // data members
0102     Pointer m_p;
0103 };
0104 
0105 #  undef BOOST_PYTHON_UNFORWARD_LOCAL
0106 
0107 template <class Pointer, class Value>
0108 inline pointer_holder<Pointer,Value>::pointer_holder(Pointer p)
0109 #if defined(BOOST_NO_CXX11_SMART_PTR)
0110     : m_p(p)
0111 #else
0112     : m_p(std::move(p))
0113 #endif
0114 {
0115 }
0116 
0117 template <class Pointer, class Value>
0118 inline pointer_holder_back_reference<Pointer,Value>::pointer_holder_back_reference(Pointer p)
0119 #if defined(BOOST_NO_CXX11_SMART_PTR)
0120     : m_p(p)
0121 #else
0122     : m_p(std::move(p))
0123 #endif
0124 {
0125 }
0126 
0127 template <class Pointer, class Value>
0128 void* pointer_holder<Pointer, Value>::holds(type_info dst_t, bool null_ptr_only)
0129 {
0130     typedef typename boost::python::detail::remove_const< Value >::type non_const_value;
0131 
0132     if (dst_t == python::type_id<Pointer>()
0133         && !(null_ptr_only && get_pointer(this->m_p))
0134     )
0135         return &this->m_p;
0136 
0137     Value* p0
0138 #  if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x590))
0139         = static_cast<Value*>( get_pointer(this->m_p) )
0140 #  else 
0141         = get_pointer(this->m_p)
0142 #  endif
0143         ;
0144     non_const_value* p = const_cast<non_const_value*>( p0 );
0145 
0146     if (p == 0)
0147         return 0;
0148     
0149     if (void* wrapped = holds_wrapped(dst_t, p, p))
0150         return wrapped;
0151     
0152     type_info src_t = python::type_id<non_const_value>();
0153     return src_t == dst_t ? p : find_dynamic_type(p, src_t, dst_t);
0154 }
0155 
0156 template <class Pointer, class Value>
0157 void* pointer_holder_back_reference<Pointer, Value>::holds(type_info dst_t, bool null_ptr_only)
0158 {
0159     if (dst_t == python::type_id<Pointer>()
0160         && !(null_ptr_only && get_pointer(this->m_p))
0161     )
0162         return &this->m_p;
0163 
0164     if (!get_pointer(this->m_p))
0165         return 0;
0166     
0167     Value* p = get_pointer(m_p);
0168     
0169     if (dst_t == python::type_id<held_type>())
0170         return p;
0171 
0172     type_info src_t = python::type_id<Value>();
0173     return src_t == dst_t ? p : find_dynamic_type(p, src_t, dst_t);
0174 }
0175 
0176 }}} // namespace boost::python::objects
0177 
0178 # endif // POINTER_HOLDER_DWA20011215_HPP
0179 
0180 /* --------------- pointer_holder --------------- */
0181 // For gcc 4.4 compatability, we must include the
0182 // BOOST_PP_ITERATION_DEPTH test inside an #else clause.
0183 #else // BOOST_PP_IS_ITERATING
0184 #if BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == 1
0185 # if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100)                      \
0186         && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201)))
0187 #  line BOOST_PP_LINE(__LINE__, pointer_holder.hpp)
0188 # endif
0189 
0190 # define N BOOST_PP_ITERATION()
0191 
0192 # if (N != 0)
0193     template< BOOST_PP_ENUM_PARAMS_Z(1, N, class A) >
0194 # endif
0195     pointer_holder(PyObject* self BOOST_PP_COMMA_IF(N) BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, A, a))
0196         : m_p(new Value(
0197                 BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_UNFORWARD_LOCAL, nil)
0198             ))
0199     {
0200         python::detail::initialize_wrapper(self, get_pointer(this->m_p));
0201     }
0202 
0203 # undef N
0204 
0205 /* --------------- pointer_holder_back_reference --------------- */
0206 #elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == 2
0207 # if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100)                      \
0208         && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201)))
0209 #  line BOOST_PP_LINE(__LINE__, pointer_holder.hpp(pointer_holder_back_reference))
0210 # endif 
0211 
0212 # define N BOOST_PP_ITERATION()
0213 
0214 # if (N != 0)
0215     template < BOOST_PP_ENUM_PARAMS_Z(1, N, class A) >
0216 # endif
0217     pointer_holder_back_reference(
0218         PyObject* p BOOST_PP_COMMA_IF(N) BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, A, a))
0219         : m_p(new held_type(
0220                     p BOOST_PP_COMMA_IF(N) BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_UNFORWARD_LOCAL, nil)
0221             ))
0222     {}
0223 
0224 # undef N
0225 
0226 #endif // BOOST_PP_ITERATION_DEPTH()
0227 #endif