GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
callable_traits.hpp
Go to the documentation of this file.
1// This file is distributed under the BSD License.
2// See "license.txt" for details.
3// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com)
4// Copyright 2009-2017, Jason Turner (jason@emptycrate.com)
5// http://www.chaiscript.com
6
7#ifndef CHAISCRIPT_CALLABLE_TRAITS_HPP_
8#define CHAISCRIPT_CALLABLE_TRAITS_HPP_
9
10#include <memory>
11
12namespace chaiscript {
13 namespace dispatch {
14 namespace detail {
15
16 template<typename Class, typename ... Param>
18 {
19 template<typename ... Inner>
20 std::shared_ptr<Class> operator()(Inner&& ... inner) const {
21 return std::make_shared<Class>(std::forward<Inner>(inner)...);
22 }
23 };
24
25 template<typename Ret, typename Class, typename ... Param>
27 {
28 explicit Const_Caller(Ret (Class::*t_func)(Param...) const) : m_func(t_func) {}
29
30 template<typename ... Inner>
31 Ret operator()(const Class &o, Inner&& ... inner) const {
32 return (o.*m_func)(std::forward<Inner>(inner)...);
33 }
34
35 Ret (Class::*m_func)(Param...) const;
36 };
37
38 template<typename Ret, typename ... Param>
40 {
41 explicit Fun_Caller(Ret( * t_func)(Param...) ) : m_func(t_func) {}
42
43 template<typename ... Inner>
44 Ret operator()(Inner&& ... inner) const {
45 return (m_func)(std::forward<Inner>(inner)...);
46 }
47
48 Ret(*m_func)(Param...);
49 };
50
51 template<typename Ret, typename Class, typename ... Param>
52 struct Caller
53 {
54 explicit Caller(Ret (Class::*t_func)(Param...)) : m_func(t_func) {}
55
56 template<typename ... Inner>
57 Ret operator()(Class &o, Inner&& ... inner) const {
58 return (o.*m_func)(std::forward<Inner>(inner)...);
59 }
60
61 Ret (Class::*m_func)(Param...);
62 };
63
64 template<typename T>
65 struct Arity
66 {
67 };
68
69 template<typename Ret, typename ... Params>
70 struct Arity<Ret (Params...)>
71 {
72 static const size_t arity = sizeof...(Params);
73 };
74
75
76 template<typename T>
78 {
79 };
80
81 template<typename Ret, typename ... Params>
82 struct Function_Signature<Ret (Params...)>
83 {
85 typedef Ret (Signature)(Params...);
86 };
87
88 template<typename Ret, typename T, typename ... Params>
89 struct Function_Signature<Ret (T::*)(Params...) const>
90 {
92 typedef Ret (Signature)(Params...);
93 };
94
95
96 template<typename T>
98 {
99 typedef typename Function_Signature<decltype(&T::operator())>::Signature Signature;
100 typedef typename Function_Signature<decltype(&T::operator())>::Return_Type Return_Type;
101 };
102 }
103 }
104}
105
106#endif
107
Definition callable_traits.hpp:14
Boxed_Value dispatch(const Funcs &funcs, const std::vector< Boxed_Value > &plist, const Type_Conversions_State &t_conversions)
Definition proxy_functions.hpp:936
Namespace chaiscript contains every API call that the average user will be concerned with.
Definition parser.cc:9
Definition GameApi_bm.cc:4579
Definition GameApi.h:42
static const size_t arity
Definition callable_traits.hpp:72
Definition callable_traits.hpp:66
Definition callable_traits.hpp:98
Function_Signature< decltype(&T::operator())>::Signature Signature
Definition callable_traits.hpp:99
Function_Signature< decltype(&T::operator())>::Return_Type Return_Type
Definition callable_traits.hpp:100
Ret operator()(Class &o, Inner &&... inner) const
Definition callable_traits.hpp:57
Caller(Ret(Class::*t_func)(Param...))
Definition callable_traits.hpp:54
Ret(Class::* m_func)(Param...)
Definition callable_traits.hpp:61
Ret(Class::* m_func)(Param...) const
Definition callable_traits.hpp:35
Const_Caller(Ret(Class::*t_func)(Param...) const)
Definition callable_traits.hpp:28
Ret operator()(const Class &o, Inner &&... inner) const
Definition callable_traits.hpp:31
Definition callable_traits.hpp:18
std::shared_ptr< Class > operator()(Inner &&... inner) const
Definition callable_traits.hpp:20
Fun_Caller(Ret(*t_func)(Param...))
Definition callable_traits.hpp:41
Ret(* m_func)(Param...)
Definition callable_traits.hpp:48
Ret operator()(Inner &&... inner) const
Definition callable_traits.hpp:44
Ret Signature(Params...)
Definition callable_traits.hpp:85
Definition callable_traits.hpp:78