28 #ifndef __RTTR_METHOD_ACCESSOR__
29 #define __RTTR_METHOD_ACCESSOR__
39 template<
typename F,
typename IndexSequence,
typename B>
40 struct method_accessor_impl;
42 template<
typename F, std::size_t... ArgCount>
43 struct method_accessor_impl<F, index_sequence<ArgCount...>, std::true_type>
45 static std::vector<bool> get_is_reference()
47 return { std::is_reference<typename param_types<F, ArgCount>::type>::value... };
50 static std::vector<bool> get_is_const()
52 return { std::is_const<typename std::remove_reference<typename param_types<F, ArgCount>::type>::type>::value... };
55 static std::vector<type> get_parameter_types()
57 return { type::get<typename param_types<F, ArgCount>::type>()... };
61 template<
typename F, std::size_t... ArgCount>
62 struct method_accessor_impl<F, index_sequence<ArgCount...>, std::false_type>
64 static std::vector<bool> get_is_reference()
66 return std::vector<bool>();
69 static std::vector<bool> get_is_const()
71 return std::vector<bool>();
74 static std::vector<type> get_parameter_types()
76 return std::vector<type>();
80 template<
typename F,
typename Policy,
typename Method_Type,
typename IndexSequence,
typename ArgCountInRange>
81 struct method_accessor_invoker;
83 template<
typename F, std::size_t... ArgCount>
84 struct method_accessor_invoker<F, default_invoke, void_member_func, index_sequence<ArgCount...>, std::true_type>
86 template<
typename... TArgs>
87 RTTR_FORCE_INLINE static variant invoke(
const F& func_ptr,
const instance& obj,
const TArgs&...args)
89 typedef typename function_traits<F>::class_type C;
90 C* ptr = obj.try_convert<C>();
91 if (ptr && check_all_true(args.template is_type<
typename param_types<F, ArgCount>::type>()...))
93 (ptr->*func_ptr)(args.template get_value<
typename param_types<F, ArgCount>::type>()...);
101 template<
typename F, std::size_t... ArgCount>
102 struct method_accessor_invoker<F, default_invoke, void_func, index_sequence<ArgCount...>, std::true_type>
104 template<
typename... TArgs>
105 RTTR_FORCE_INLINE static variant invoke(
const F& func,
const instance& obj,
const TArgs&...args)
107 if (check_all_true(args.template is_type<
typename param_types<F, ArgCount>::type>()...))
109 func(args.template get_value<
typename param_types<F, ArgCount>::type>()...);
117 template<
typename F, std::size_t... ArgCount>
118 struct method_accessor_invoker<F, default_invoke, return_member_func, index_sequence<ArgCount...>, std::true_type>
120 template<
typename... TArgs>
121 RTTR_FORCE_INLINE static variant invoke(
const F& func_ptr,
const instance& obj,
const TArgs&...args)
123 typedef typename function_traits<F>::class_type C;
124 C* ptr = obj.try_convert<C>();
125 if (ptr && check_all_true(args.template is_type<
typename param_types<F, ArgCount>::type>()...))
126 return (ptr->*func_ptr)(args.template get_value<typename param_types<F, ArgCount>::type>()...);
132 template<
typename F, std::size_t... ArgCount>
133 struct method_accessor_invoker<F, default_invoke, return_func, index_sequence<ArgCount...>, std::true_type>
135 template<
typename... TArgs>
136 RTTR_FORCE_INLINE static variant invoke(
const F& func,
const instance& obj,
const TArgs&...args)
138 if (check_all_true(args.template is_type<
typename param_types<F, ArgCount>::type>()...))
139 return func(args.template get_value<
typename param_types<F, ArgCount>::type>()...);
145 template<
typename F, std::size_t... ArgCount>
146 struct method_accessor_invoker<F, discard_return, return_member_func, index_sequence<ArgCount...>, std::true_type>
148 template<
typename... TArgs>
149 RTTR_FORCE_INLINE static variant invoke(
const F& func_ptr,
const instance& obj,
const TArgs&...args)
151 typedef typename function_traits<F>::class_type C;
152 C* ptr = obj.try_convert<C>();
153 if (ptr && check_all_true(args.template is_type<
typename param_types<F, ArgCount>::type>()...))
155 (ptr->*func_ptr)(args.template get_value<
typename param_types<F, ArgCount>::type>()...);
163 template<
typename F, std::size_t... ArgCount>
164 struct method_accessor_invoker<F, discard_return, return_func, index_sequence<ArgCount...>, std::true_type>
166 template<
typename... TArgs>
167 RTTR_FORCE_INLINE static variant invoke(
const F& func,
const instance& obj,
const TArgs&...args)
169 if (check_all_true(args.template is_type<
typename param_types<F, ArgCount>::type>()...))
171 func(args.template get_value<
typename param_types<F, ArgCount>::type>()...);
179 template<
typename F, std::size_t... ArgCount>
180 struct method_accessor_invoker<F, return_as_ptr, return_member_func, index_sequence<ArgCount...>, std::true_type>
182 template<
typename... TArgs>
183 RTTR_FORCE_INLINE static variant invoke(
const F& func_ptr,
const instance& obj,
const TArgs&...args)
185 typedef typename function_traits<F>::class_type C;
186 C* ptr = obj.try_convert<C>();
187 if (ptr && check_all_true(args.template is_type<
typename param_types<F, ArgCount>::type>()...))
189 return &(ptr->*func_ptr)(args.template get_value<
typename param_types<F, ArgCount>::type>()...);
196 template<
typename F, std::size_t... ArgCount>
197 struct method_accessor_invoker<F, return_as_ptr, return_func, index_sequence<ArgCount...>, std::true_type>
199 template<
typename... TArgs>
200 RTTR_FORCE_INLINE static variant invoke(
const F& func,
const instance& obj,
const TArgs&...args)
202 if (check_all_true(args.template is_type<
typename param_types<F, ArgCount>::type>()...))
204 return &func(args.template get_value<
typename param_types<F, ArgCount>::type>()...);
211 template<
typename F,
typename Policy,
typename MethodType,
typename IndexSequence>
212 struct method_accessor_invoker<F, Policy, MethodType, IndexSequence, std::false_type>
214 template<
typename... TArgs>
215 RTTR_FORCE_INLINE static variant invoke(
const F& func_ptr,
const instance& obj,
const TArgs&...args)
221 template<
typename F,
typename Policy,
typename IndexSequence>
222 struct method_accessor_variadic;
224 template<
typename F,
typename Policy, std::size_t... ArgCount>
225 struct method_accessor_variadic<F, Policy, index_sequence<ArgCount...>>
227 static variant invoke(
const F& func_ptr,
const instance& obj, std::vector<argument>& arg_list)
229 using method_type =
typename detail::method_type<F>::type;
230 return method_accessor_invoker<F, Policy, method_type, index_sequence<ArgCount...>, std::true_type>::invoke(func_ptr, obj, arg_list[ArgCount]...);
234 template<
typename MethodType>
235 struct method_accessor_helper_is_static
237 static bool is_static() {
return true; }
241 struct method_accessor_helper_is_static<return_member_func>
243 static bool is_static() {
return false; }
247 struct method_accessor_helper_is_static<void_member_func>
249 static bool is_static() {
return false; }
252 template<
typename F,
typename Policy>
253 struct method_accessor_helper_return_type
255 static type get_return_type() {
return type::get<typename function_traits<F>::return_type>(); }
259 struct method_accessor_helper_return_type<F, return_as_ptr>
261 using return_type =
typename function_traits<F>::return_type;
262 static type get_return_type() {
return type::get<typename std::remove_reference<return_type>::type*>(); }
266 struct method_accessor_helper_return_type<F, discard_return>
268 static type get_return_type() {
return type::get<void>(); }
271 template<
typename F,
typename Policy>
272 struct method_accessor
274 static bool is_static()
276 using method_type =
typename detail::method_type<F>::type;
277 return method_accessor_helper_is_static<method_type>::is_static();
280 static type get_return_type()
282 return method_accessor_helper_return_type<F, Policy>::get_return_type();
285 static std::vector<bool> get_is_reference()
287 const std::size_t ArgCount = function_traits<F>::arg_count;
288 using has_arguments =
typename std::integral_constant<bool, ArgCount != 0>::type;
289 return method_accessor_impl<F, make_index_sequence<ArgCount>, has_arguments>::get_is_reference();
292 static std::vector<bool> get_is_const()
294 const std::size_t ArgCount = function_traits<F>::arg_count;
295 using has_arguments =
typename std::integral_constant<bool, ArgCount != 0>::type;
296 return method_accessor_impl<F, make_index_sequence<ArgCount>, has_arguments>::get_is_const();
299 static std::vector<type> get_parameter_types()
301 const std::size_t ArgCount = function_traits<F>::arg_count;
302 using has_arguments =
typename std::integral_constant<bool, ArgCount != 0>::type;
303 return method_accessor_impl<F, make_index_sequence<ArgCount>, has_arguments>::get_parameter_types();
306 template<
typename... TArgs>
307 RTTR_FORCE_INLINE static variant invoke(
const F& func_ptr,
const instance& obj,
const TArgs&...args)
309 const std::size_t ArgCount = function_traits<F>::arg_count;
310 using method_type =
typename detail::method_type<F>::type;
311 using arg_count_in_range =
typename std::integral_constant<bool, ArgCount ==
sizeof...(args)>::type;
312 return method_accessor_invoker<F, Policy, method_type, make_index_sequence<ArgCount>, arg_count_in_range>::invoke(func_ptr, obj, args...);
315 template<
typename... TArgs>
316 RTTR_FORCE_INLINE static variant invoke(
const F& func_ptr,
const instance& obj, std::vector<argument>& arg_list)
318 const std::size_t ArgCount = function_traits<F>::arg_count;
319 if (arg_list.size() == ArgCount)
320 return method_accessor_variadic<F, Policy, make_index_sequence<ArgCount>>::invoke(func_ptr, obj, arg_list);
329 #endif // __RTTR_METHOD_ACCESSOR__
#define RTTR_FORCE_INLINE
Definition: core_prerequisites.h:91