16 #ifndef _SMING_CORE_DELEGATE_H_ 17 #define _SMING_CORE_DELEGATE_H_ 19 #include <user_config.h> 33 virtual ReturnType
invoke(ParamsList...) = 0;
54 uint32_t references = 1;
61 template <
class ClassType,
class ReturnType,
typename... ParamsList>
67 typedef ReturnType (ClassType::*MethodDeclaration)(ParamsList...);
74 MethodCaller(ClassType* c, MethodDeclaration m) : mClass(c), mMethod(m)
82 ReturnType
invoke(ParamsList... args)
override 84 return (mClass->*mMethod)(args...);
89 MethodDeclaration mMethod;
94 template <
class MethodDeclaration,
class ReturnType,
typename... ParamsList>
109 ReturnType
invoke(ParamsList... args)
override 111 return (mMethod)(args...);
115 MethodDeclaration mMethod;
122 template <
class ReturnType,
class... ParamsList>
class Delegate<ReturnType(ParamsList...)>
126 typedef ReturnType (*FunctionDeclaration)(ParamsList...);
128 template <
typename ClassType>
using MethodDeclaration = ReturnType (ClassType::*)(ParamsList...);
142 template <
class ClassType> __forceinline
Delegate(MethodDeclaration<ClassType> m, ClassType* c)
156 impl =
new FunctionCaller<FunctionDeclaration, ReturnType, ParamsList...>(m);
162 if(impl !=
nullptr) {
171 __forceinline ReturnType
operator()(ParamsList... params)
const 173 return impl->invoke(params...);
210 if(impl !=
nullptr) {
223 __forceinline
operator bool()
const 225 return impl !=
nullptr;
231 if(impl != other.impl) {
232 if(impl !=
nullptr) {
236 if(impl !=
nullptr) {
__forceinline Delegate(const Delegate &that)
Copy a delegate from another Delegate object.
Definition: Delegate.h:188
__forceinline Delegate()
Instantiate a delegate object.
Definition: Delegate.h:133
ReturnType invoke(ParamsList...args) override
Invoke the delegate function.
Definition: Delegate.h:109
MethodCaller(ClassType *c, MethodDeclaration m)
Instantiate a delegate method caller object.
Definition: Delegate.h:74
__forceinline Delegate(FunctionDeclaration m)
Delegate a function.
Definition: Delegate.h:153
__forceinline Delegate(Delegate &&that)
Move a delegate from another object.
Definition: Delegate.h:179
Definition: Delegate.h:57
__forceinline void decrease()
Decrease the quantity of delegate caller references by one.
Definition: Delegate.h:45
__forceinline Delegate(MethodDeclaration< ClassType > m, ClassType *c)
Delegate a class method.
Definition: Delegate.h:142
Delegate function caller class.
Definition: Delegate.h:95
ReturnType invoke(ParamsList...args) override
Invoke the delegate method.
Definition: Delegate.h:82
Definition: Delegate.h:118
__forceinline Delegate & operator=(const Delegate &that)
Copy a delegate from another Delegate object.
Definition: Delegate.h:197
__forceinline void increase()
Increase the quantity of delegate caller references by one.
Definition: Delegate.h:37
virtual ReturnType invoke(ParamsList...)=0
Invode the delegate.
__forceinline ReturnType operator()(ParamsList...params) const
Invoke a delegate.
Definition: Delegate.h:171
Delegate & operator=(Delegate &&that)
Move a delegate from another Delegate object.
Definition: Delegate.h:207
IDelegateCaller class.
Definition: Delegate.h:24
FunctionCaller(MethodDeclaration m)
Instantiate a delegate function caller object.
Definition: Delegate.h:101