sl@0: // Copyright David Abrahams 2001. sl@0: // Distributed under the Boost Software License, Version 1.0. (See sl@0: // accompanying file LICENSE_1_0.txt or copy at sl@0: // http://www.boost.org/LICENSE_1_0.txt) sl@0: #ifndef MAKE_FUNCTION_DWA20011221_HPP sl@0: # define MAKE_FUNCTION_DWA20011221_HPP sl@0: sl@0: # include sl@0: sl@0: # include sl@0: # include sl@0: # include sl@0: sl@0: # include sl@0: sl@0: # include sl@0: # include sl@0: sl@0: namespace boost { namespace python { sl@0: sl@0: namespace detail sl@0: { sl@0: // make_function_aux -- sl@0: // sl@0: // These helper functions for make_function (below) do the raw work sl@0: // of constructing a Python object from some invokable entity. See sl@0: // for more information about how sl@0: // the Sig arguments is used. sl@0: template sl@0: object make_function_aux( sl@0: F f // An object that can be invoked by detail::invoke() sl@0: , CallPolicies const& p // CallPolicies to use in the invocation sl@0: , Sig const& // An MPL sequence of argument types expected by F sl@0: ) sl@0: { sl@0: return objects::function_object( sl@0: detail::caller(f, p) sl@0: ); sl@0: } sl@0: sl@0: // As above, except that it accepts argument keywords. NumKeywords sl@0: // is used only for a compile-time assertion to make sure the user sl@0: // doesn't pass more keywords than the function can accept. To sl@0: // disable all checking, pass mpl::int_<0> for NumKeywords. sl@0: template sl@0: object make_function_aux( sl@0: F f sl@0: , CallPolicies const& p sl@0: , Sig const& sl@0: , detail::keyword_range const& kw // a [begin,end) pair of iterators over keyword names sl@0: , NumKeywords // An MPL integral type wrapper: the size of kw sl@0: ) sl@0: { sl@0: enum { arity = mpl::size::value - 1 }; sl@0: sl@0: typedef typename detail::error::more_keywords_than_function_arguments< sl@0: NumKeywords::value, arity sl@0: >::too_many_keywords assertion; sl@0: sl@0: return objects::function_object( sl@0: detail::caller(f, p) sl@0: , kw); sl@0: } sl@0: sl@0: // Helpers for make_function when called with 3 arguments. These sl@0: // dispatch functions are used to discriminate between the cases sl@0: // when the 3rd argument is keywords or when it is a signature. sl@0: // sl@0: // @group { sl@0: template sl@0: object make_function_dispatch(F f, CallPolicies const& policies, Keywords const& kw, mpl::true_) sl@0: { sl@0: return detail::make_function_aux( sl@0: f sl@0: , policies sl@0: , detail::get_signature(f) sl@0: , kw.range() sl@0: , mpl::int_() sl@0: ); sl@0: } sl@0: sl@0: template sl@0: object make_function_dispatch(F f, CallPolicies const& policies, Signature const& sig, mpl::false_) sl@0: { sl@0: return detail::make_function_aux( sl@0: f sl@0: , policies sl@0: , sig sl@0: ); sl@0: } sl@0: // } sl@0: sl@0: } sl@0: sl@0: // These overloaded functions wrap a function or member function sl@0: // pointer as a Python object, using optional CallPolicies, sl@0: // Keywords, and/or Signature. sl@0: // sl@0: // @group { sl@0: template sl@0: object make_function(F f) sl@0: { sl@0: return detail::make_function_aux( sl@0: f,default_call_policies(), detail::get_signature(f)); sl@0: } sl@0: sl@0: template sl@0: object make_function(F f, CallPolicies const& policies) sl@0: { sl@0: return detail::make_function_aux( sl@0: f, policies, detail::get_signature(f)); sl@0: } sl@0: sl@0: template sl@0: object make_function( sl@0: F f sl@0: , CallPolicies const& policies sl@0: , KeywordsOrSignature const& keywords_or_signature) sl@0: { sl@0: typedef typename sl@0: detail::is_reference_to_keywords::type sl@0: is_kw; sl@0: sl@0: return detail::make_function_dispatch( sl@0: f sl@0: , policies sl@0: , keywords_or_signature sl@0: , is_kw() sl@0: ); sl@0: } sl@0: sl@0: template sl@0: object make_function( sl@0: F f sl@0: , CallPolicies const& policies sl@0: , Keywords const& kw sl@0: , Signature const& sig sl@0: ) sl@0: { sl@0: return detail::make_function_aux( sl@0: f sl@0: , policies sl@0: , sig sl@0: , kw.range() sl@0: , mpl::int_() sl@0: ); sl@0: } sl@0: // } sl@0: sl@0: }} sl@0: sl@0: sl@0: #endif // MAKE_FUNCTION_DWA20011221_HPP