os/ossrv/ossrv_pub/boost_apis/boost/python/make_function.hpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/python/make_function.hpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,153 @@
     1.4 +// Copyright David Abrahams 2001.
     1.5 +// Distributed under the Boost Software License, Version 1.0. (See
     1.6 +// accompanying file LICENSE_1_0.txt or copy at
     1.7 +// http://www.boost.org/LICENSE_1_0.txt)
     1.8 +#ifndef MAKE_FUNCTION_DWA20011221_HPP
     1.9 +# define MAKE_FUNCTION_DWA20011221_HPP
    1.10 +
    1.11 +# include <boost/python/detail/prefix.hpp>
    1.12 +
    1.13 +# include <boost/python/default_call_policies.hpp>
    1.14 +# include <boost/python/args.hpp>
    1.15 +# include <boost/python/detail/caller.hpp>
    1.16 +
    1.17 +# include <boost/python/object/function_object.hpp>
    1.18 +
    1.19 +# include <boost/mpl/size.hpp>
    1.20 +# include <boost/mpl/int.hpp>
    1.21 +
    1.22 +namespace boost { namespace python {
    1.23 +
    1.24 +namespace detail
    1.25 +{
    1.26 +  // make_function_aux --
    1.27 +  //
    1.28 +  // These helper functions for make_function (below) do the raw work
    1.29 +  // of constructing a Python object from some invokable entity. See
    1.30 +  // <boost/python/detail/caller.hpp> for more information about how
    1.31 +  // the Sig arguments is used.
    1.32 +  template <class F, class CallPolicies, class Sig>
    1.33 +  object make_function_aux(
    1.34 +      F f                               // An object that can be invoked by detail::invoke()
    1.35 +      , CallPolicies const& p           // CallPolicies to use in the invocation
    1.36 +      , Sig const&                      // An MPL sequence of argument types expected by F
    1.37 +      )
    1.38 +  {
    1.39 +      return objects::function_object(
    1.40 +          detail::caller<F,CallPolicies,Sig>(f, p)
    1.41 +      );
    1.42 +  }
    1.43 +
    1.44 +  // As above, except that it accepts argument keywords. NumKeywords
    1.45 +  // is used only for a compile-time assertion to make sure the user
    1.46 +  // doesn't pass more keywords than the function can accept. To
    1.47 +  // disable all checking, pass mpl::int_<0> for NumKeywords.
    1.48 +  template <class F, class CallPolicies, class Sig, class NumKeywords>
    1.49 +  object make_function_aux(
    1.50 +      F f
    1.51 +      , CallPolicies const& p
    1.52 +      , Sig const&
    1.53 +      , detail::keyword_range const& kw // a [begin,end) pair of iterators over keyword names
    1.54 +      , NumKeywords                     // An MPL integral type wrapper: the size of kw
    1.55 +      )
    1.56 +  {
    1.57 +      enum { arity = mpl::size<Sig>::value - 1 };
    1.58 +      
    1.59 +      typedef typename detail::error::more_keywords_than_function_arguments<
    1.60 +          NumKeywords::value, arity
    1.61 +          >::too_many_keywords assertion;
    1.62 +    
    1.63 +      return objects::function_object(
    1.64 +          detail::caller<F,CallPolicies,Sig>(f, p)
    1.65 +        , kw);
    1.66 +  }
    1.67 +
    1.68 +  //   Helpers for make_function when called with 3 arguments.  These
    1.69 +  //   dispatch functions are used to discriminate between the cases
    1.70 +  //   when the 3rd argument is keywords or when it is a signature.
    1.71 +  //
    1.72 +  // @group {
    1.73 +  template <class F, class CallPolicies, class Keywords>
    1.74 +  object make_function_dispatch(F f, CallPolicies const& policies, Keywords const& kw, mpl::true_)
    1.75 +  {
    1.76 +      return detail::make_function_aux(
    1.77 +          f
    1.78 +        , policies
    1.79 +        , detail::get_signature(f)
    1.80 +        , kw.range()
    1.81 +        , mpl::int_<Keywords::size>()
    1.82 +      );
    1.83 +  }
    1.84 +
    1.85 +  template <class F, class CallPolicies, class Signature>
    1.86 +  object make_function_dispatch(F f, CallPolicies const& policies, Signature const& sig, mpl::false_)
    1.87 +  {
    1.88 +      return detail::make_function_aux(
    1.89 +          f
    1.90 +        , policies
    1.91 +        , sig
    1.92 +      );
    1.93 +  }
    1.94 +  // }
    1.95 +  
    1.96 + }
    1.97 +
    1.98 +//   These overloaded functions wrap a function or member function
    1.99 +//   pointer as a Python object, using optional CallPolicies,
   1.100 +//   Keywords, and/or Signature.
   1.101 +//
   1.102 +//   @group {
   1.103 +template <class F>
   1.104 +object make_function(F f)
   1.105 +{
   1.106 +    return detail::make_function_aux(
   1.107 +        f,default_call_policies(), detail::get_signature(f));
   1.108 +}
   1.109 +
   1.110 +template <class F, class CallPolicies>
   1.111 +object make_function(F f, CallPolicies const& policies)
   1.112 +{
   1.113 +    return detail::make_function_aux(
   1.114 +        f, policies, detail::get_signature(f));
   1.115 +}
   1.116 +
   1.117 +template <class F, class CallPolicies, class KeywordsOrSignature>
   1.118 +object make_function(
   1.119 +    F f
   1.120 +  , CallPolicies const& policies
   1.121 +  , KeywordsOrSignature const& keywords_or_signature)
   1.122 +{
   1.123 +    typedef typename
   1.124 +        detail::is_reference_to_keywords<KeywordsOrSignature&>::type
   1.125 +        is_kw;
   1.126 +    
   1.127 +    return detail::make_function_dispatch(
   1.128 +        f
   1.129 +      , policies
   1.130 +      , keywords_or_signature
   1.131 +      , is_kw()
   1.132 +    );
   1.133 +}
   1.134 +
   1.135 +template <class F, class CallPolicies, class Keywords, class Signature>
   1.136 +object make_function(
   1.137 +    F f
   1.138 +  , CallPolicies const& policies
   1.139 +  , Keywords const& kw
   1.140 +  , Signature const& sig
   1.141 + )
   1.142 +{
   1.143 +    return detail::make_function_aux(
   1.144 +          f
   1.145 +        , policies
   1.146 +        , sig
   1.147 +        , kw.range()
   1.148 +        , mpl::int_<Keywords::size>()
   1.149 +      );
   1.150 +}
   1.151 +// }
   1.152 +
   1.153 +}} 
   1.154 +
   1.155 +
   1.156 +#endif // MAKE_FUNCTION_DWA20011221_HPP