Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // Copyright David Abrahams and Nikolay Mladenov 2003.
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 RETURN_ARG_DWA2003719_HPP
0006 # define RETURN_ARG_DWA2003719_HPP
0007 # include <boost/python/default_call_policies.hpp>
0008 # include <boost/python/detail/none.hpp>
0009 # include <boost/python/detail/value_arg.hpp>
0010 
0011 #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
0012 # include <boost/python/converter/pytype_function.hpp>
0013 #endif
0014 
0015 # include <boost/python/detail/type_traits.hpp>
0016 
0017 # include <boost/mpl/int.hpp>
0018 # include <boost/mpl/at.hpp>
0019 
0020 # include <boost/static_assert.hpp>
0021 # include <boost/python/refcount.hpp>
0022 
0023 # include <cstddef>
0024 
0025 namespace boost { namespace python { 
0026 
0027 namespace detail
0028 {
0029   template <std::size_t>
0030   struct return_arg_pos_argument_must_be_positive
0031 # if defined(__GNUC__) || defined(__EDG__)
0032   {}
0033 # endif
0034   ;
0035 
0036   struct return_none
0037   {
0038       template <class T> struct apply
0039       {
0040           struct type
0041           {
0042               static bool convertible()
0043               {
0044                   return true;
0045               }
0046               
0047               PyObject *operator()( typename value_arg<T>::type ) const
0048               {
0049                   return none();
0050               }
0051 #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
0052               PyTypeObject const *get_pytype() const { return converter::expected_pytype_for_arg<T>::get_pytype() ; }
0053 #endif
0054           };
0055       };
0056   };
0057 }
0058     
0059 template <
0060     std::size_t arg_pos=1
0061   , class Base = default_call_policies
0062 > 
0063 struct return_arg : Base
0064 {
0065  private:
0066     BOOST_STATIC_CONSTANT(bool, legal = arg_pos > 0);
0067 
0068  public:
0069     typedef typename mpl::if_c<
0070         legal
0071         , detail::return_none
0072         , detail::return_arg_pos_argument_must_be_positive<arg_pos>
0073         // we could default to the base result_converter in case or
0074         // arg_pos==0 since return arg 0 means return result, but I
0075         // think it is better to issue an error instead, cause it can
0076         // lead to confusions
0077     >::type result_converter;
0078 
0079     template <class ArgumentPackage>
0080     static PyObject* postcall(ArgumentPackage const& args, PyObject* result)
0081     {
0082         // In case of arg_pos == 0 we could simply return Base::postcall,
0083         // but this is redundant
0084         BOOST_STATIC_ASSERT(arg_pos > 0);
0085 
0086         result = Base::postcall(args,result);
0087         if (!result)
0088             return 0;
0089         Py_DECREF(result);
0090         return incref( detail::get(mpl::int_<arg_pos-1>(),args) );
0091     }
0092 
0093     template <class Sig> 
0094     struct extract_return_type : mpl::at_c<Sig, arg_pos>
0095     {
0096     };
0097 
0098 };
0099 
0100 template <
0101     class Base = default_call_policies
0102     >
0103 struct return_self 
0104   : return_arg<1,Base>
0105 {};
0106 
0107 }} // namespace boost::python
0108 
0109 #endif // RETURN_ARG_DWA2003719_HPP