13 #ifndef SMINGCORE_DELEGATE_H_ 14 #define SMINGCORE_DELEGATE_H_ 16 #include <user_config.h> 21 template<
class ReturnType,
typename... ParamsList>
31 virtual ReturnType
invoke(ParamsList...) = 0;
50 uint32_t references = 1;
58 template<
class ClassType,
class ReturnType,
typename... ParamsList >
64 typedef ReturnType (ClassType::*MethodDeclaration)(ParamsList ...);
71 MethodCaller( ClassType* c, MethodDeclaration m ) : mClass( c ), mMethod( m ) {}
77 ReturnType
invoke(ParamsList... args)
79 return (mClass->*mMethod)( args... );
84 MethodDeclaration mMethod;
89 template<
class MethodDeclaration,
class ReturnType,
typename... ParamsList >
104 return (mMethod)( args... );
108 MethodDeclaration mMethod;
117 template<
class ReturnType,
class ... ParamsList>
122 typedef ReturnType (*FunctionDeclaration)(ParamsList...);
124 template<
typename ClassType>
using MethodDeclaration = ReturnType (ClassType::*)(ParamsList ...);
139 template <
class ClassType>
140 __forceinline
Delegate(MethodDeclaration<ClassType> m, ClassType* c)
155 impl =
new FunctionCaller< FunctionDeclaration, ReturnType, ParamsList... >(m);
170 __forceinline ReturnType
operator()(ParamsList... params)
const 172 return impl->invoke(params...);
222 __forceinline
operator bool()
const 224 return impl !=
nullptr;
230 if (impl != other.impl)
ReturnType invoke(ParamsList...args)
Invoke the delegate function.
Definition: Delegate.h:102
__forceinline Delegate(const Delegate &that)
Copy a delegate from another Delegate object.
Definition: Delegate.h:187
__forceinline Delegate()
Instantiate a delegate object.
Definition: Delegate.h:129
MethodCaller(ClassType *c, MethodDeclaration m)
Instantiate a delegate method caller object.
Definition: Delegate.h:71
__forceinline Delegate(FunctionDeclaration m)
Delegate a function.
Definition: Delegate.h:152
__forceinline Delegate(Delegate &&that)
Move a delegate from another object.
Definition: Delegate.h:178
Definition: Delegate.h:54
__forceinline void decrease()
Decrease the quantity of delegate caller references by one.
Definition: Delegate.h:43
__forceinline Delegate(MethodDeclaration< ClassType > m, ClassType *c)
Delegate a class method.
Definition: Delegate.h:140
Delegate function caller class.
Definition: Delegate.h:90
Definition: Delegate.h:112
__forceinline Delegate & operator=(const Delegate &that)
Copy a delegate from another Delegate object.
Definition: Delegate.h:196
ReturnType invoke(ParamsList...args)
Invoke the delegate method.
Definition: Delegate.h:77
__forceinline void increase()
Increase the quantity of delegate caller references by one.
Definition: Delegate.h:35
virtual ReturnType invoke(ParamsList...)=0
Invode the delegate.
__forceinline ReturnType operator()(ParamsList...params) const
Invoke a delegate.
Definition: Delegate.h:170
Delegate & operator=(Delegate &&that)
Move a delegate from another Delegate object.
Definition: Delegate.h:206
IDelegateCaller class.
Definition: Delegate.h:22
FunctionCaller(MethodDeclaration m)
Instantiate a delegate function caller object.
Definition: Delegate.h:96