Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:50:41

0001 // Copyright David Abrahams 2001.
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 MAKE_FUNCTION_DWA20011221_HPP
0006 # define MAKE_FUNCTION_DWA20011221_HPP
0007 
0008 # include <boost/python/detail/prefix.hpp>
0009 
0010 # include <boost/python/default_call_policies.hpp>
0011 # include <boost/python/args.hpp>
0012 # include <boost/python/detail/caller.hpp>
0013 
0014 # include <boost/python/object/function_object.hpp>
0015 
0016 # include <boost/mpl/size.hpp>
0017 # include <boost/mpl/int.hpp>
0018 
0019 namespace boost { namespace python {
0020 
0021 namespace detail
0022 {
0023   // make_function_aux --
0024   //
0025   // These helper functions for make_function (below) do the raw work
0026   // of constructing a Python object from some invokable entity. See
0027   // <boost/python/detail/caller.hpp> for more information about how
0028   // the Sig arguments is used.
0029   template <class F, class CallPolicies, class Sig>
0030   object make_function_aux(
0031       F f                               // An object that can be invoked by detail::invoke()
0032       , CallPolicies const& p           // CallPolicies to use in the invocation
0033       , Sig const&                      // An MPL sequence of argument types expected by F
0034       )
0035   {
0036       return objects::function_object(
0037           detail::caller<F,CallPolicies,Sig>(f, p)
0038       );
0039   }
0040 
0041   // As above, except that it accepts argument keywords. NumKeywords
0042   // is used only for a compile-time assertion to make sure the user
0043   // doesn't pass more keywords than the function can accept. To
0044   // disable all checking, pass mpl::int_<0> for NumKeywords.
0045   template <class F, class CallPolicies, class Sig, class NumKeywords>
0046   object make_function_aux(
0047       F f
0048       , CallPolicies const& p
0049       , Sig const&
0050       , detail::keyword_range const& kw // a [begin,end) pair of iterators over keyword names
0051       , NumKeywords                     // An MPL integral type wrapper: the size of kw
0052       )
0053   {
0054       enum { arity = mpl::size<Sig>::value - 1 };
0055       
0056       typedef typename detail::error::more_keywords_than_function_arguments<
0057           NumKeywords::value, arity
0058           >::too_many_keywords assertion BOOST_ATTRIBUTE_UNUSED;
0059     
0060       return objects::function_object(
0061           detail::caller<F,CallPolicies,Sig>(f, p)
0062         , kw);
0063   }
0064 
0065   //   Helpers for make_function when called with 3 arguments.  These
0066   //   dispatch functions are used to discriminate between the cases
0067   //   when the 3rd argument is keywords or when it is a signature.
0068   //
0069   // @group {
0070   template <class F, class CallPolicies, class Keywords>
0071   object make_function_dispatch(F f, CallPolicies const& policies, Keywords const& kw, mpl::true_)
0072   {
0073       return detail::make_function_aux(
0074           f
0075         , policies
0076         , detail::get_signature(f)
0077         , kw.range()
0078         , mpl::int_<Keywords::size>()
0079       );
0080   }
0081 
0082   template <class F, class CallPolicies, class Signature>
0083   object make_function_dispatch(F f, CallPolicies const& policies, Signature const& sig, mpl::false_)
0084   {
0085       return detail::make_function_aux(
0086           f
0087         , policies
0088         , sig
0089       );
0090   }
0091   // }
0092   
0093  }
0094 
0095 //   These overloaded functions wrap a function or member function
0096 //   pointer as a Python object, using optional CallPolicies,
0097 //   Keywords, and/or Signature.
0098 //
0099 //   @group {
0100 template <class F>
0101 object make_function(F f)
0102 {
0103     return detail::make_function_aux(
0104         f,default_call_policies(), detail::get_signature(f));
0105 }
0106 
0107 template <class F, class CallPolicies>
0108 object make_function(F f, CallPolicies const& policies)
0109 {
0110     return detail::make_function_aux(
0111         f, policies, detail::get_signature(f));
0112 }
0113 
0114 template <class F, class CallPolicies, class KeywordsOrSignature>
0115 object make_function(
0116     F f
0117   , CallPolicies const& policies
0118   , KeywordsOrSignature const& keywords_or_signature)
0119 {
0120     typedef typename
0121         detail::is_reference_to_keywords<KeywordsOrSignature&>::type
0122         is_kw;
0123     
0124     return detail::make_function_dispatch(
0125         f
0126       , policies
0127       , keywords_or_signature
0128       , is_kw()
0129     );
0130 }
0131 
0132 template <class F, class CallPolicies, class Keywords, class Signature>
0133 object make_function(
0134     F f
0135   , CallPolicies const& policies
0136   , Keywords const& kw
0137   , Signature const& sig
0138  )
0139 {
0140     return detail::make_function_aux(
0141           f
0142         , policies
0143         , sig
0144         , kw.range()
0145         , mpl::int_<Keywords::size>()
0146       );
0147 }
0148 // }
0149 
0150 }} 
0151 
0152 
0153 #endif // MAKE_FUNCTION_DWA20011221_HPP