function_handle.hpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright David Abrahams 2002.
  2. // Distributed under the Boost Software License, Version 1.0. (See
  3. // accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef FUNCTION_HANDLE_DWA2002725_HPP
  6. # define FUNCTION_HANDLE_DWA2002725_HPP
  7. # include <boost/python/handle.hpp>
  8. # include <boost/python/detail/caller.hpp>
  9. # include <boost/python/default_call_policies.hpp>
  10. # include <boost/python/object/py_function.hpp>
  11. # include <boost/python/signature.hpp>
  12. namespace boost { namespace python { namespace objects {
  13. BOOST_PYTHON_DECL handle<> function_handle_impl(py_function const& f);
  14. // Just like function_object, but returns a handle<> instead. Using
  15. // this for arg_to_python<> allows us to break a circular dependency
  16. // between object and arg_to_python.
  17. template <class F, class Signature>
  18. inline handle<> function_handle(F const& f, Signature)
  19. {
  20. enum { n_arguments = mpl::size<Signature>::value - 1 };
  21. return objects::function_handle_impl(
  22. python::detail::caller<
  23. F,default_call_policies,Signature
  24. >(
  25. f, default_call_policies()
  26. )
  27. );
  28. }
  29. // Just like make_function, but returns a handle<> intead. Same
  30. // reasoning as above.
  31. template <class F>
  32. handle<> make_function_handle(F f)
  33. {
  34. return objects::function_handle(f, python::detail::get_signature(f));
  35. }
  36. }}} // namespace boost::python::objects
  37. #endif // FUNCTION_HANDLE_DWA2002725_HPP