45template<
typename RETTYPE,
typename ... ARGTYPES>
56 template <
typename LAMBDA>
69 template <
typename LAMBDA>
76 template<
class CLASS, RETTYPE (CLASS::*METHOD)(ARGTYPES ...)>
static Delegate<RETTYPE(ARGTYPES ...)>
FromMethod(CLASS* objPtr);
80 template <
typename LAMBDA>
static Delegate<RETTYPE(ARGTYPES ...)>
FromLambda(
const LAMBDA & instance);
83 template<
class CLASS>
const CLASS*
GetObject()
const;
90 using StubType = RETTYPE(*)(
void*, ARGTYPES...);
93 template<
class CLASS, RETTYPE(CLASS::*METHOD)(ARGTYPES ...)>
static RETTYPE
MethodStub(
void* objPtr, ARGTYPES ... args);
95 template<RETTYPE(*FUNCTION)(ARGTYPES ... )>
static RETTYPE
FunctionStub(
void* dummyPtr, ARGTYPES ... args);
97 template <
typename LAMBDA>
static RETTYPE
LambdaStub(
void* objPtr, ARGTYPES... arg);
109template<
typename RETTYPE,
typename ... ARGTYPES>
110Delegate<RETTYPE(ARGTYPES ...)>::Delegate() :
120template<
typename RETTYPE,
typename ... ARGTYPES>
121Delegate<RETTYPE(ARGTYPES ...)>::Delegate(Delegate<RETTYPE(ARGTYPES...)>
const& rhs) :
131template<
typename RETTYPE,
typename ... ARGTYPES>
132Delegate<RETTYPE(ARGTYPES ...)>::Delegate(Delegate<RETTYPE(ARGTYPES...)>&& rhs) :
136 rhs.objPtr =
nullptr;
137 rhs.stubPtr =
nullptr;
143template<
typename RETTYPE,
typename ... ARGTYPES>
144template <
typename LAMBDA>
145Delegate<RETTYPE(ARGTYPES...)>::Delegate(LAMBDA
const& lambda)
147 static_assert(
sizeof(LAMBDA) == 1ULL,
"Util::Delegate does accept lambdas carrying capture variables! Read the description of at the top of util/delegate.h");
148 Assign((
void*)(&lambda), LambdaStub<LAMBDA>);
154template<
typename RETTYPE,
typename ... ARGTYPES>
156Delegate<RETTYPE(ARGTYPES...)>::operator=(Delegate<RETTYPE(ARGTYPES...)>
const& rhs)
160 this->objPtr = rhs.objPtr;
161 this->stubPtr = rhs.stubPtr;
168template<
typename RETTYPE,
typename ... ARGTYPES>
170Delegate<RETTYPE(ARGTYPES...)>::operator=(Delegate<RETTYPE(ARGTYPES...)>&& rhs)
174 this->objPtr = rhs.objPtr;
175 this->stubPtr = rhs.stubPtr;
176 rhs.objPtr =
nullptr;
177 rhs.stubPtr =
nullptr;
184template<
typename RETTYPE,
typename ... ARGTYPES>
185template <
typename LAMBDA>
186Delegate<RETTYPE(ARGTYPES...)>&
187Delegate<RETTYPE(ARGTYPES...)>::operator=(LAMBDA
const& instance)
189 static_assert(
sizeof(LAMBDA) == 1ULL,
"Util::Delegate does accept lambdas carrying capture variables! Read the description of at the top of util/delegate.h");
190 Assign((
void*)(&instance), LambdaStub<LAMBDA>);
197template<
typename RETTYPE,
typename ... ARGTYPES>
199Delegate<RETTYPE(ARGTYPES...)>::operator==(std::nullptr_t)
201 return this->stubPtr ==
nullptr;
207template<
typename RETTYPE,
typename ... ARGTYPES>
209Delegate<RETTYPE(ARGTYPES...)>::operator!()
211 return this->stubPtr ==
nullptr;
217template<
typename RETTYPE,
typename ... ARGTYPES> RETTYPE
218Delegate<RETTYPE(ARGTYPES...)>::operator()(ARGTYPES ... args)
const
220 return (*this->stubPtr)(this->objPtr, args...);
226template<
typename RETTYPE,
typename ... ARGTYPES>
227template<
class CLASS, RETTYPE (CLASS::*METHOD)(ARGTYPES ...)>
228Delegate<RETTYPE(ARGTYPES...)>
229Delegate<RETTYPE(ARGTYPES...)>::FromMethod(CLASS* objPtr_)
231 Delegate<RETTYPE(ARGTYPES...)> del;
232 del.objPtr = objPtr_;
233 del.stubPtr = &MethodStub<CLASS,METHOD>;
240template<
typename RETTYPE,
typename ... ARGTYPES>
241template<RETTYPE(*FUNCTION)(ARGTYPES ...)>
242Delegate<RETTYPE(ARGTYPES...)>
243Delegate<RETTYPE(ARGTYPES...)>::FromFunction()
245 Delegate<RETTYPE(ARGTYPES...)> del;
247 del.stubPtr = &FunctionStub<FUNCTION>;
254template<
typename RETTYPE,
typename ... ARGTYPES>
255template<
typename LAMBDA>
256Delegate<RETTYPE(ARGTYPES...)>
257Delegate<RETTYPE(ARGTYPES...)>::FromLambda(
const LAMBDA & instance)
259 static_assert(
sizeof(LAMBDA) == 1ULL,
"Util::Delegate does accept lambdas carrying capture variables! Read the description of at the top of util/delegate.h");
260 return ((
void*)(&instance), LambdaStub<LAMBDA>);
266template<
typename RETTYPE,
typename ... ARGTYPES>
267template<
class CLASS, RETTYPE (CLASS::*METHOD)(ARGTYPES ...)>
269Delegate<RETTYPE(ARGTYPES...)>::MethodStub(
void* objPtr_, ARGTYPES ... arg_)
271 CLASS* obj =
static_cast<CLASS*
>(objPtr_);
272 return (obj->*METHOD)(arg_...);
278template<
typename RETTYPE,
typename ... ARGTYPES>
279template<RETTYPE(*FUNCTION)(ARGTYPES ...)>
281Delegate<RETTYPE(ARGTYPES...)>::FunctionStub(
void* dummyPtr, ARGTYPES ... arg_)
283 return (*FUNCTION)(arg_...);
289template<
typename RETTYPE,
typename ... ARGTYPES>
290template<
typename LAMBDA>
292Delegate<RETTYPE(ARGTYPES...)>::LambdaStub(
void* objPtr, ARGTYPES ... arg_)
294 LAMBDA* p =
static_cast<LAMBDA*
>(objPtr);
295 return (p->operator())(arg_...);
301template<
typename RETTYPE,
typename ... ARGTYPES>
304Delegate<RETTYPE(ARGTYPES...)>::GetObject()
const
306 return (CLASS*)this->objPtr;
312template<
typename RETTYPE,
typename ... ARGTYPES>
316 return (0 != this->stubPtr);
322template<
typename RETTYPE,
typename ... ARGTYPES>
324Delegate<RETTYPE(ARGTYPES...)>::Assign(
void* obj,
typename Delegate<RETTYPE(ARGTYPES...)>::StubType stub)
327 this->stubPtr = stub;
bool IsValid()
returns true if delegate is valid
static Delegate< RETTYPE(ARGTYPES ...)> FromMethod(CLASS *objPtr)
setup a new delegate from a method call
static RETTYPE MethodStub(void *objPtr, ARGTYPES ... args)
static method-call stub
void operator=(Delegate< RETTYPE(ARGTYPES...)> &&rhs)
move operator
RETTYPE operator()(ARGTYPES ... args) const
invokation operator
Delegate(Delegate< RETTYPE(ARGTYPES...)> &&rhs)
move constructor
static Delegate< RETTYPE(ARGTYPES ...)> FromFunction()
setup a new delegate from a function call
bool operator!()
check if null
Delegate(Delegate< RETTYPE(ARGTYPES...)> const &rhs)
copy constructor
const CLASS * GetObject() const
get object pointer
Delegate(LAMBDA const &lambda)
lambda constructor
Delegate< RETTYPE(ARGTYPES ...)> & operator=(LAMBDA const &instance)
lambda assignment operator
static Delegate< RETTYPE(ARGTYPES ...)> FromLambda(const LAMBDA &instance)
setup a new delegate from lambda
void Assign(void *obj, typename Delegate< RETTYPE(ARGTYPES...)>::StubType stub)
assignment method
RETTYPE(*)(void *, ARGTYPES...) StubType
method pointer typedef
Definition delegate.h:90
StubType stubPtr
Definition delegate.h:103
void operator=(Delegate< RETTYPE(ARGTYPES...)> const &rhs)
assignment operator
static RETTYPE LambdaStub(void *objPtr, ARGTYPES... arg)
static lambda-call stub
bool operator==(std::nullptr_t)
check if null
static RETTYPE FunctionStub(void *dummyPtr, ARGTYPES ... args)
static function-call stub
void * objPtr
Definition delegate.h:102
Nebula delegate class, allows to store a function, method or lambda call into a C++ object for later ...
Definition delegate.h:39
A pinned array is an array which manages its own virtual memory.
Definition String.cs:6