Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/python/raw_function.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 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 RAW_FUNCTION_DWA200336_HPP
0006 # define RAW_FUNCTION_DWA200336_HPP
0007 
0008 # include <boost/python/detail/prefix.hpp>
0009 
0010 # include <boost/python/tuple.hpp>
0011 # include <boost/python/dict.hpp>
0012 # include <boost/python/object/py_function.hpp>
0013 # include <boost/mpl/vector/vector10.hpp>
0014 
0015 # include <boost/limits.hpp>
0016 # include <cstddef>
0017 
0018 namespace boost { namespace python { 
0019 
0020 namespace detail
0021 {
0022   template <class F>
0023   struct raw_dispatcher
0024   {
0025       raw_dispatcher(F f) : f(f) {}
0026       
0027       PyObject* operator()(PyObject* args, PyObject* keywords)
0028       {
0029           return incref(
0030               object(
0031                   f(
0032                       tuple(borrowed_reference(args))
0033                     , keywords ? dict(borrowed_reference(keywords)) : dict()
0034                   )
0035               ).ptr()
0036           );
0037       }
0038 
0039    private:
0040       F f;
0041   };
0042 
0043   object BOOST_PYTHON_DECL make_raw_function(objects::py_function);
0044 }
0045 
0046 template <class F>
0047 object raw_function(F f, std::size_t min_args = 0)
0048 {
0049     return detail::make_raw_function(
0050         objects::py_function(
0051             detail::raw_dispatcher<F>(f)
0052           , mpl::vector1<PyObject*>()
0053           , min_args
0054           , (std::numeric_limits<unsigned>::max)()
0055         )
0056     );
0057 }
0058     
0059 }} // namespace boost::python
0060 
0061 #endif // RAW_FUNCTION_DWA200336_HPP