New inheritance graph code.
[luabind.git] / luabind / detail / compute_score.hpp
blob91f1d7ab6b02824178bed16ae6915fbd1a1b2624
1 // Copyright Daniel Wallin 2008. Use, modification and distribution is
2 // subject to the Boost Software License, Version 1.0. (See accompanying
3 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 #ifndef LUABIND_COMPUTE_RANK_081006_HPP
6 # define LUABIND_COMPUTE_RANK_081006_HPP
8 # include <luabind/config.hpp>
9 # include <luabind/detail/policy.hpp>
10 # include <boost/mpl/apply_wrap.hpp>
11 # include <boost/mpl/begin_end.hpp>
12 # include <boost/mpl/int.hpp>
13 # include <boost/mpl/next.hpp>
15 namespace luabind { namespace detail {
17 namespace mpl = boost::mpl;
19 template <class Idx, class Iter, class End, class Policies>
20 int compute_score_aux(
21 lua_State*L, int index, Idx, Iter, End end, Policies const& policies)
23 typedef typename Iter::type arg_type;
24 typedef typename find_conversion_policy<Idx::value, Policies>::type
25 conversion_policy;
26 typedef typename mpl::apply_wrap2<
27 conversion_policy, arg_type, lua_to_cpp>::type converter;
29 int score = converter::match(L, LUABIND_DECORATE_TYPE(arg_type), index);
31 if (score < 0)
32 return score;
34 if (conversion_policy::has_arg)
35 ++index;
37 int next = compute_score_aux(
39 , index
40 , typename mpl::next<Idx>::type()
41 , typename mpl::next<Iter>::type()
42 , end
43 , policies
46 if (next < 0)
47 return next;
49 return score + next;
52 template <class Idx, class End, class Policies>
53 int compute_score_aux(lua_State*, int, Idx, End, End, Policies const&)
55 return 0;
58 template <class Signature, class Policies>
59 int compute_score(lua_State* L, Signature, Policies const& policies)
61 return compute_score_aux(
63 , 1
64 , mpl::int_<1>()
65 , typename mpl::next<typename mpl::begin<Signature>::type>::type()
66 , typename mpl::end<Signature>::type()
67 , policies
71 template <class Iter, class End, class Idx, class Policies>
72 int compute_arity_aux(Iter, End end, Idx, Policies const& policies)
74 typedef typename find_conversion_policy<Idx::value, Policies>::type
75 conversion_policy;
77 int next = compute_arity_aux(
78 typename mpl::next<Iter>::type()
79 , end
80 , typename mpl::next<Idx>::type()
81 , policies
84 return (conversion_policy::has_arg ? 1 : 0) + next;
87 template <class End, class Idx, class Policies>
88 int compute_arity_aux(End, End, Idx, Policies const&)
90 return 0;
93 template <class Signature, class Policies>
94 int compute_arity(Signature, Policies const& policies)
96 return compute_arity_aux(
97 typename mpl::next<typename mpl::begin<Signature>::type>::type()
98 , typename mpl::end<Signature>::type()
99 , mpl::int_<1>()
100 , policies
104 }} // namespace luabind::detail
106 #endif // LUABIND_COMPUTE_RANK_081006_HPP