os/ossrv/ossrv_pub/boost_apis/boost/python/override.hpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/python/override.hpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,144 @@
     1.4 +#if !defined(BOOST_PP_IS_ITERATING)
     1.5 +
     1.6 +// Copyright David Abrahams 2004. Distributed under the Boost
     1.7 +// Software License, Version 1.0. (See accompanying
     1.8 +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
     1.9 +#ifndef OVERRIDE_DWA2004721_HPP
    1.10 +# define OVERRIDE_DWA2004721_HPP
    1.11 +
    1.12 +# include <boost/python/detail/prefix.hpp>
    1.13 +
    1.14 +# include <boost/python/converter/return_from_python.hpp>
    1.15 +
    1.16 +# include <boost/python/extract.hpp>
    1.17 +# include <boost/python/handle.hpp>
    1.18 +
    1.19 +#  include <boost/preprocessor/iterate.hpp>
    1.20 +#  include <boost/preprocessor/repeat.hpp>
    1.21 +#  include <boost/preprocessor/debug/line.hpp>
    1.22 +#  include <boost/preprocessor/repetition/enum_params.hpp>
    1.23 +#  include <boost/preprocessor/repetition/enum_binary_params.hpp>
    1.24 +
    1.25 +#  include <boost/type.hpp>
    1.26 +
    1.27 +namespace boost { namespace python {
    1.28 +
    1.29 +class override;
    1.30 +
    1.31 +namespace detail
    1.32 +{
    1.33 +  class wrapper_base;
    1.34 +  
    1.35 +  // The result of calling a method.
    1.36 +  class method_result
    1.37 +  {
    1.38 +   private:
    1.39 +      friend class boost::python::override;
    1.40 +      explicit method_result(PyObject* x)
    1.41 +        : m_obj(x)
    1.42 +      {}
    1.43 +
    1.44 +   public:
    1.45 +      template <class T>
    1.46 +      operator T()
    1.47 +      {
    1.48 +          converter::return_from_python<T> converter;
    1.49 +          return converter(m_obj.release());
    1.50 +      }
    1.51 +
    1.52 +#  if BOOST_WORKAROUND(_MSC_FULL_VER, BOOST_TESTED_AT(140050215))
    1.53 +      template <class T>
    1.54 +      operator T*()
    1.55 +      {
    1.56 +          converter::return_from_python<T*> converter;
    1.57 +          return converter(m_obj.release());
    1.58 +      }
    1.59 +#  endif 
    1.60 +      
    1.61 +#  if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1400)) || BOOST_WORKAROUND(BOOST_INTEL_WIN, >= 900)
    1.62 +      // No operator T&
    1.63 +#  else
    1.64 +      
    1.65 +      template <class T>
    1.66 +      operator T&() const
    1.67 +      {
    1.68 +          converter::return_from_python<T&> converter;
    1.69 +          return converter(const_cast<handle<>&>(m_obj).release());
    1.70 +      }
    1.71 +#  endif 
    1.72 +
    1.73 +      template <class T>
    1.74 +      T as(type<T>* = 0)
    1.75 +      {
    1.76 +          converter::return_from_python<T> converter;
    1.77 +          return converter(m_obj.release());
    1.78 +      }
    1.79 +
    1.80 +      template <class T>
    1.81 +      T unchecked(type<T>* = 0)
    1.82 +      {
    1.83 +          return extract<T>(m_obj)();
    1.84 +      }
    1.85 +   private:
    1.86 +      mutable handle<> m_obj;
    1.87 +  };
    1.88 +}
    1.89 +
    1.90 +class override : public object
    1.91 +{
    1.92 + private:
    1.93 +    friend class detail::wrapper_base;
    1.94 +    override(handle<> x)
    1.95 +      : object(x)
    1.96 +    {}
    1.97 +    
    1.98 + public:
    1.99 +    detail::method_result
   1.100 +    operator()() const
   1.101 +    {
   1.102 +        detail::method_result x(
   1.103 +            PyEval_CallFunction(
   1.104 +                this->ptr()
   1.105 +              , const_cast<char*>("()")
   1.106 +            ));
   1.107 +        return x;
   1.108 +    }
   1.109 +
   1.110 +# define BOOST_PYTHON_fast_arg_to_python_get(z, n, _)   \
   1.111 +    , converter::arg_to_python<A##n>(a##n).get()
   1.112 +
   1.113 +# define BOOST_PP_ITERATION_PARAMS_1 (3, (1, BOOST_PYTHON_MAX_ARITY, <boost/python/override.hpp>))
   1.114 +# include BOOST_PP_ITERATE()
   1.115 +
   1.116 +# undef BOOST_PYTHON_fast_arg_to_python_get
   1.117 +};
   1.118 +
   1.119 +}} // namespace boost::python
   1.120 +
   1.121 +#endif // OVERRIDE_DWA2004721_HPP
   1.122 +
   1.123 +#else
   1.124 +# if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100)                      \
   1.125 +        && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201)))
   1.126 +#  line BOOST_PP_LINE(__LINE__, override.hpp)
   1.127 +# endif 
   1.128 +
   1.129 +# define N BOOST_PP_ITERATION()
   1.130 +
   1.131 +template <
   1.132 +    BOOST_PP_ENUM_PARAMS_Z(1, N, class A)
   1.133 +    >
   1.134 +detail::method_result
   1.135 +operator()( BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, A, const& a) ) const
   1.136 +{
   1.137 +    detail::method_result x(
   1.138 +        PyEval_CallFunction(
   1.139 +            this->ptr()
   1.140 +          , const_cast<char*>("(" BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_FIXED, "O") ")")
   1.141 +            BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_fast_arg_to_python_get, nil)
   1.142 +        ));
   1.143 +    return x;
   1.144 +}
   1.145 +
   1.146 +# undef N
   1.147 +#endif