Merge branch '0.8' to sync with v0.8 release.
[luabind.git] / luabind / detail / overload_rep.hpp
blob483b2fc5b0c9cd0b4904ea130ffb8388c4326d25
1 // Copyright (c) 2003 Daniel Wallin and Arvid Norberg
3 // Permission is hereby granted, free of charge, to any person obtaining a
4 // copy of this software and associated documentation files (the "Software"),
5 // to deal in the Software without restriction, including without limitation
6 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 // and/or sell copies of the Software, and to permit persons to whom the
8 // Software is furnished to do so, subject to the following conditions:
10 // The above copyright notice and this permission notice shall be included
11 // in all copies or substantial portions of the Software.
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
14 // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
15 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16 // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
17 // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
18 // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
21 // OR OTHER DEALINGS IN THE SOFTWARE.
24 #if !BOOST_PP_IS_ITERATING
26 #ifndef LUABIND_OVERLOAD_REP_HPP_INCLUDED
27 #define LUABIND_OVERLOAD_REP_HPP_INCLUDED
29 #include <luabind/config.hpp>
31 #include <boost/preprocessor/enum_params.hpp>
32 #include <boost/preprocessor/iteration/iterate.hpp>
33 #include <boost/preprocessor/repetition/enum_trailing_params.hpp>
34 #include <boost/preprocessor/repeat.hpp>
35 #include <vector>
37 #include <luabind/detail/overload_rep_base.hpp>
39 #include <luabind/detail/is_indirect_const.hpp>
41 #ifndef BOOST_MSVC
42 #include <luabind/detail/policy.hpp>
43 #endif
45 namespace luabind { namespace detail
47 struct dummy_ {};
49 // this class represents a specific overload of a member-function.
50 struct overload_rep: public overload_rep_base
52 #define BOOST_PP_ITERATION_PARAMS_1 (4 \
53 , (0, LUABIND_MAX_ARITY, <luabind/detail/overload_rep.hpp>, 1))
54 #include BOOST_PP_ITERATE()
56 bool operator==(const overload_rep& o)
58 if (o.m_const != m_const) return false;
59 if (o.m_arity != m_arity) return false;
60 if (o.m_params_.size() != m_params_.size()) return false;
61 for (int i = 0; i < (int)m_params_.size(); ++i)
63 if (!(LUABIND_TYPE_INFO_EQUAL(m_params_[i], o.m_params_[i])))
64 return false;
66 return true;
69 void set_fun(boost::function1<int, lua_State*> const& f)
70 { call_fun = f; }
72 void set_fun_static(boost::function1<int, lua_State*> const& f)
73 { call_fun_static = f; }
75 int call(lua_State* L, bool force_static_call) const;
77 bool has_static() const { return !call_fun_static.empty(); }
79 private:
81 // this is the normal function pointer that may be a virtual
82 boost::function1<int, lua_State*> call_fun;
84 // this is the optional function pointer that is only set if
85 // the first function pointer is virtual. This must always point
86 // to a static function.
87 boost::function1<int, lua_State*> call_fun_static;
89 // the types of the parameter it takes
90 std::vector<LUABIND_TYPE_INFO> m_params_;
91 // is true if the overload is const (this is a part of the signature)
92 bool m_const;
95 }} // namespace luabind::detail
97 #endif // LUABIND_OVERLOAD_REP_HPP_INCLUDED
99 #elif BOOST_PP_ITERATION_FLAGS() == 1
101 #define LUABIND_PARAM(z, n, _) m_params_.push_back(LUABIND_TYPEID(A##n));
102 #define LUABIND_POLICY_DECL(z,n,offset) typedef typename detail::find_conversion_policy<n + offset, Policies>::type BOOST_PP_CAT(p,n);
103 #define LUABIND_ARITY(z,n,text) + BOOST_PP_CAT(p,n)::has_arg
105 // overloaded template funtion that initializes the parameter list
106 // called m_params and the m_arity member.
107 template<class R, class T BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A), class Policies>
108 overload_rep(R(T::*)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), A)), Policies*)
109 : m_const(false)
111 m_params_.reserve(BOOST_PP_ITERATION());
112 BOOST_PP_REPEAT(BOOST_PP_ITERATION(), LUABIND_PARAM, _)
113 BOOST_PP_REPEAT(BOOST_PP_ITERATION(), LUABIND_POLICY_DECL, 2)
114 m_arity = 1 BOOST_PP_REPEAT(BOOST_PP_ITERATION(), LUABIND_ARITY, 0);
117 template<class R, class T BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A), class Policies>
118 overload_rep(R(T::*)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), A)) const, Policies*)
119 : m_const(true)
121 m_params_.reserve(BOOST_PP_ITERATION());
122 BOOST_PP_REPEAT(BOOST_PP_ITERATION(), LUABIND_PARAM, _)
123 BOOST_PP_REPEAT(BOOST_PP_ITERATION(), LUABIND_POLICY_DECL, 2)
124 m_arity = 1 BOOST_PP_REPEAT(BOOST_PP_ITERATION(), LUABIND_ARITY, 0);
127 template<class R BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(), class A), class Policies>
128 overload_rep(R(*)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), A)), Policies*)
129 : m_const(false/*is_indirect_const<T>::value*/)
131 m_params_.reserve(BOOST_PP_ITERATION());
132 BOOST_PP_REPEAT(BOOST_PP_ITERATION(), LUABIND_PARAM, _)
133 BOOST_PP_REPEAT(BOOST_PP_ITERATION(), LUABIND_POLICY_DECL, 1)
134 m_arity = 0 BOOST_PP_REPEAT(BOOST_PP_ITERATION(), LUABIND_ARITY, 0);
137 #undef LUABIND_ARITY
138 #undef LUABIND_POLICY_DECL
139 #undef LUABIND_PARAM
141 #endif