sl@0
|
1 |
// Copyright David Abrahams 2001.
|
sl@0
|
2 |
// Distributed under the Boost Software License, Version 1.0. (See
|
sl@0
|
3 |
// accompanying file LICENSE_1_0.txt or copy at
|
sl@0
|
4 |
// http://www.boost.org/LICENSE_1_0.txt)
|
sl@0
|
5 |
#ifndef MAKE_FUNCTION_DWA20011221_HPP
|
sl@0
|
6 |
# define MAKE_FUNCTION_DWA20011221_HPP
|
sl@0
|
7 |
|
sl@0
|
8 |
# include <boost/python/detail/prefix.hpp>
|
sl@0
|
9 |
|
sl@0
|
10 |
# include <boost/python/default_call_policies.hpp>
|
sl@0
|
11 |
# include <boost/python/args.hpp>
|
sl@0
|
12 |
# include <boost/python/detail/caller.hpp>
|
sl@0
|
13 |
|
sl@0
|
14 |
# include <boost/python/object/function_object.hpp>
|
sl@0
|
15 |
|
sl@0
|
16 |
# include <boost/mpl/size.hpp>
|
sl@0
|
17 |
# include <boost/mpl/int.hpp>
|
sl@0
|
18 |
|
sl@0
|
19 |
namespace boost { namespace python {
|
sl@0
|
20 |
|
sl@0
|
21 |
namespace detail
|
sl@0
|
22 |
{
|
sl@0
|
23 |
// make_function_aux --
|
sl@0
|
24 |
//
|
sl@0
|
25 |
// These helper functions for make_function (below) do the raw work
|
sl@0
|
26 |
// of constructing a Python object from some invokable entity. See
|
sl@0
|
27 |
// <boost/python/detail/caller.hpp> for more information about how
|
sl@0
|
28 |
// the Sig arguments is used.
|
sl@0
|
29 |
template <class F, class CallPolicies, class Sig>
|
sl@0
|
30 |
object make_function_aux(
|
sl@0
|
31 |
F f // An object that can be invoked by detail::invoke()
|
sl@0
|
32 |
, CallPolicies const& p // CallPolicies to use in the invocation
|
sl@0
|
33 |
, Sig const& // An MPL sequence of argument types expected by F
|
sl@0
|
34 |
)
|
sl@0
|
35 |
{
|
sl@0
|
36 |
return objects::function_object(
|
sl@0
|
37 |
detail::caller<F,CallPolicies,Sig>(f, p)
|
sl@0
|
38 |
);
|
sl@0
|
39 |
}
|
sl@0
|
40 |
|
sl@0
|
41 |
// As above, except that it accepts argument keywords. NumKeywords
|
sl@0
|
42 |
// is used only for a compile-time assertion to make sure the user
|
sl@0
|
43 |
// doesn't pass more keywords than the function can accept. To
|
sl@0
|
44 |
// disable all checking, pass mpl::int_<0> for NumKeywords.
|
sl@0
|
45 |
template <class F, class CallPolicies, class Sig, class NumKeywords>
|
sl@0
|
46 |
object make_function_aux(
|
sl@0
|
47 |
F f
|
sl@0
|
48 |
, CallPolicies const& p
|
sl@0
|
49 |
, Sig const&
|
sl@0
|
50 |
, detail::keyword_range const& kw // a [begin,end) pair of iterators over keyword names
|
sl@0
|
51 |
, NumKeywords // An MPL integral type wrapper: the size of kw
|
sl@0
|
52 |
)
|
sl@0
|
53 |
{
|
sl@0
|
54 |
enum { arity = mpl::size<Sig>::value - 1 };
|
sl@0
|
55 |
|
sl@0
|
56 |
typedef typename detail::error::more_keywords_than_function_arguments<
|
sl@0
|
57 |
NumKeywords::value, arity
|
sl@0
|
58 |
>::too_many_keywords assertion;
|
sl@0
|
59 |
|
sl@0
|
60 |
return objects::function_object(
|
sl@0
|
61 |
detail::caller<F,CallPolicies,Sig>(f, p)
|
sl@0
|
62 |
, kw);
|
sl@0
|
63 |
}
|
sl@0
|
64 |
|
sl@0
|
65 |
// Helpers for make_function when called with 3 arguments. These
|
sl@0
|
66 |
// dispatch functions are used to discriminate between the cases
|
sl@0
|
67 |
// when the 3rd argument is keywords or when it is a signature.
|
sl@0
|
68 |
//
|
sl@0
|
69 |
// @group {
|
sl@0
|
70 |
template <class F, class CallPolicies, class Keywords>
|
sl@0
|
71 |
object make_function_dispatch(F f, CallPolicies const& policies, Keywords const& kw, mpl::true_)
|
sl@0
|
72 |
{
|
sl@0
|
73 |
return detail::make_function_aux(
|
sl@0
|
74 |
f
|
sl@0
|
75 |
, policies
|
sl@0
|
76 |
, detail::get_signature(f)
|
sl@0
|
77 |
, kw.range()
|
sl@0
|
78 |
, mpl::int_<Keywords::size>()
|
sl@0
|
79 |
);
|
sl@0
|
80 |
}
|
sl@0
|
81 |
|
sl@0
|
82 |
template <class F, class CallPolicies, class Signature>
|
sl@0
|
83 |
object make_function_dispatch(F f, CallPolicies const& policies, Signature const& sig, mpl::false_)
|
sl@0
|
84 |
{
|
sl@0
|
85 |
return detail::make_function_aux(
|
sl@0
|
86 |
f
|
sl@0
|
87 |
, policies
|
sl@0
|
88 |
, sig
|
sl@0
|
89 |
);
|
sl@0
|
90 |
}
|
sl@0
|
91 |
// }
|
sl@0
|
92 |
|
sl@0
|
93 |
}
|
sl@0
|
94 |
|
sl@0
|
95 |
// These overloaded functions wrap a function or member function
|
sl@0
|
96 |
// pointer as a Python object, using optional CallPolicies,
|
sl@0
|
97 |
// Keywords, and/or Signature.
|
sl@0
|
98 |
//
|
sl@0
|
99 |
// @group {
|
sl@0
|
100 |
template <class F>
|
sl@0
|
101 |
object make_function(F f)
|
sl@0
|
102 |
{
|
sl@0
|
103 |
return detail::make_function_aux(
|
sl@0
|
104 |
f,default_call_policies(), detail::get_signature(f));
|
sl@0
|
105 |
}
|
sl@0
|
106 |
|
sl@0
|
107 |
template <class F, class CallPolicies>
|
sl@0
|
108 |
object make_function(F f, CallPolicies const& policies)
|
sl@0
|
109 |
{
|
sl@0
|
110 |
return detail::make_function_aux(
|
sl@0
|
111 |
f, policies, detail::get_signature(f));
|
sl@0
|
112 |
}
|
sl@0
|
113 |
|
sl@0
|
114 |
template <class F, class CallPolicies, class KeywordsOrSignature>
|
sl@0
|
115 |
object make_function(
|
sl@0
|
116 |
F f
|
sl@0
|
117 |
, CallPolicies const& policies
|
sl@0
|
118 |
, KeywordsOrSignature const& keywords_or_signature)
|
sl@0
|
119 |
{
|
sl@0
|
120 |
typedef typename
|
sl@0
|
121 |
detail::is_reference_to_keywords<KeywordsOrSignature&>::type
|
sl@0
|
122 |
is_kw;
|
sl@0
|
123 |
|
sl@0
|
124 |
return detail::make_function_dispatch(
|
sl@0
|
125 |
f
|
sl@0
|
126 |
, policies
|
sl@0
|
127 |
, keywords_or_signature
|
sl@0
|
128 |
, is_kw()
|
sl@0
|
129 |
);
|
sl@0
|
130 |
}
|
sl@0
|
131 |
|
sl@0
|
132 |
template <class F, class CallPolicies, class Keywords, class Signature>
|
sl@0
|
133 |
object make_function(
|
sl@0
|
134 |
F f
|
sl@0
|
135 |
, CallPolicies const& policies
|
sl@0
|
136 |
, Keywords const& kw
|
sl@0
|
137 |
, Signature const& sig
|
sl@0
|
138 |
)
|
sl@0
|
139 |
{
|
sl@0
|
140 |
return detail::make_function_aux(
|
sl@0
|
141 |
f
|
sl@0
|
142 |
, policies
|
sl@0
|
143 |
, sig
|
sl@0
|
144 |
, kw.range()
|
sl@0
|
145 |
, mpl::int_<Keywords::size>()
|
sl@0
|
146 |
);
|
sl@0
|
147 |
}
|
sl@0
|
148 |
// }
|
sl@0
|
149 |
|
sl@0
|
150 |
}}
|
sl@0
|
151 |
|
sl@0
|
152 |
|
sl@0
|
153 |
#endif // MAKE_FUNCTION_DWA20011221_HPP
|