Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/python/object/value_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 VALUE_HOLDER_DWA20011215_HPP
0009 #  define VALUE_HOLDER_DWA20011215_HPP 
0010 
0011 #  include <boost/python/object/value_holder_fwd.hpp>
0012 
0013 #  include <boost/python/instance_holder.hpp>
0014 #  include <boost/python/type_id.hpp>
0015 #  include <boost/python/wrapper.hpp>
0016 
0017 #  include <boost/python/object/inheritance_query.hpp>
0018 #  include <boost/python/object/forward.hpp>
0019 
0020 #  include <boost/python/detail/force_instantiate.hpp>
0021 #  include <boost/python/detail/preprocessor.hpp>
0022 
0023 #  include <boost/preprocessor/comma_if.hpp>
0024 #  include <boost/preprocessor/enum_params.hpp>
0025 #  include <boost/preprocessor/iterate.hpp>
0026 #  include <boost/preprocessor/repeat.hpp>
0027 #  include <boost/preprocessor/debug/line.hpp>
0028 
0029 #  include <boost/preprocessor/repetition/enum_params.hpp>
0030 #  include <boost/preprocessor/repetition/enum_binary_params.hpp>
0031 
0032 #  include <boost/utility/addressof.hpp>
0033 
0034 namespace boost { namespace python { namespace objects { 
0035 
0036 #define BOOST_PYTHON_UNFORWARD_LOCAL(z, n, _) BOOST_PP_COMMA_IF(n) objects::do_unforward(a##n,0)
0037 
0038 template <class Value>
0039 struct value_holder : instance_holder
0040 {
0041     typedef Value held_type;
0042     typedef Value value_type;
0043 
0044     // Forward construction to the held object
0045 #  define BOOST_PP_ITERATION_PARAMS_1 (4, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/object/value_holder.hpp>, 1))
0046 #  include BOOST_PP_ITERATE()
0047 
0048  private: // required holder implementation
0049     void* holds(type_info, bool null_ptr_only);
0050     
0051     template <class T>
0052     inline void* holds_wrapped(type_info dst_t, wrapper<T>*,T* p)
0053     {
0054         return python::type_id<T>() == dst_t ? p : 0;
0055     }
0056     
0057     inline void* holds_wrapped(type_info, ...)
0058     {
0059         return 0;
0060     }
0061  private: // data members
0062     Value m_held;
0063 };
0064 
0065 template <class Value, class Held>
0066 struct value_holder_back_reference : instance_holder
0067 {
0068     typedef Held held_type;
0069     typedef Value value_type;
0070     
0071     // Forward construction to the held object
0072 #  define BOOST_PP_ITERATION_PARAMS_1 (4, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/object/value_holder.hpp>, 2))
0073 #  include BOOST_PP_ITERATE()
0074 
0075 private: // required holder implementation
0076     void* holds(type_info, bool null_ptr_only);
0077 
0078  private: // data members
0079     Held m_held;
0080 };
0081 
0082 #  undef BOOST_PYTHON_UNFORWARD_LOCAL
0083 
0084 template <class Value>
0085 void* value_holder<Value>::holds(type_info dst_t, bool /*null_ptr_only*/)
0086 {
0087     if (void* wrapped = holds_wrapped(dst_t, boost::addressof(m_held), boost::addressof(m_held)))
0088         return wrapped;
0089     
0090     type_info src_t = python::type_id<Value>();
0091     return src_t == dst_t ? boost::addressof(m_held)
0092         : find_static_type(boost::addressof(m_held), src_t, dst_t);
0093 }
0094 
0095 template <class Value, class Held>
0096 void* value_holder_back_reference<Value,Held>::holds(
0097     type_info dst_t, bool /*null_ptr_only*/)
0098 {
0099     type_info src_t = python::type_id<Value>();
0100     Value* x = &m_held;
0101     
0102     if (dst_t == src_t)
0103         return x;
0104     else if (dst_t == python::type_id<Held>())
0105         return &m_held;
0106     else
0107         return find_static_type(x, src_t, dst_t);
0108 }
0109 
0110 }}} // namespace boost::python::objects
0111 
0112 # endif // VALUE_HOLDER_DWA20011215_HPP
0113 
0114 // --------------- value_holder ---------------
0115 
0116 // For gcc 4.4 compatability, we must include the
0117 // BOOST_PP_ITERATION_DEPTH test inside an #else clause.
0118 #else // BOOST_PP_IS_ITERATING
0119 #if BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == 1
0120 # if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100)                      \
0121         && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201)))
0122 #  line BOOST_PP_LINE(__LINE__, value_holder.hpp(value_holder))
0123 # endif
0124 
0125 # define N BOOST_PP_ITERATION()
0126 
0127 # if (N != 0)
0128     template <BOOST_PP_ENUM_PARAMS_Z(1, N, class A)>
0129 # endif
0130     value_holder(
0131       PyObject* self BOOST_PP_COMMA_IF(N) BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, A, a))
0132         : m_held(
0133             BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_UNFORWARD_LOCAL, nil)
0134             )
0135     {
0136         python::detail::initialize_wrapper(self, boost::addressof(this->m_held));
0137     }
0138 
0139 # undef N
0140 
0141 // --------------- value_holder_back_reference ---------------
0142 
0143 #elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == 2
0144 # if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100)                      \
0145         && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201)))
0146 #  line BOOST_PP_LINE(__LINE__, value_holder.hpp(value_holder_back_reference))
0147 # endif
0148 
0149 # define N BOOST_PP_ITERATION()
0150 
0151 # if (N != 0)
0152     template <BOOST_PP_ENUM_PARAMS_Z(1, N, class A)>
0153 # endif
0154     value_holder_back_reference(
0155         PyObject* p BOOST_PP_COMMA_IF(N) BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, A, a))
0156         : m_held(
0157             p BOOST_PP_COMMA_IF(N)
0158             BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_UNFORWARD_LOCAL, nil)
0159             )
0160     {
0161     }
0162 
0163 # undef N
0164 
0165 #endif // BOOST_PP_ITERATION_DEPTH()
0166 #endif