15#define FASTDELEGATE_USESTATICFUNCTIONHACK
16#if defined(_MSC_VER) && !defined(__MWERKS__) && !defined(__VECTOR_C) && !defined(__ICL) && !defined(__BORLANDC__)
17#define FASTDLGT_ISMSVC
20#pragma warning(disable:4786)
23#if defined(_MSC_VER) && !defined(__MWERKS__)
24#define FASTDLGT_MICROSOFT_MFP
25#if !defined(__VECTOR_C)
26#define FASTDLGT_HASINHERITANCE_KEYWORDS
31#define FASTDELEGATE_GCC_BUG_8271
35namespace fastdelegate {
37 template <
class OutputClass,
class InputClass>
41 template <
class OutputClass,
class InputClass>
46 template <
class OutputClass,
class InputClass>
50 typedef int ERROR_CantUseHorrible_cast[
sizeof(InputClass)==
sizeof(u)
51 &&
sizeof(InputClass)==
sizeof(OutputClass) ? 1 : -1];
55#define FASTDELEGATEDECLARE(CLASSNAME) class CLASSNAME;
57#undef FASTDELEGATE_USESTATICFUNCTIONHACK
72#ifdef FASTDLGT_MICROSOFT_MFP
73#ifdef FASTDLGT_HASINHERITANCE_KEYWORDS
84 template <
class X,
class XFuncType,
class GenericMemFuncType>
86 GenericMemFuncType &bound_func) {
89 typedef char ERROR_Unsupported_member_function_pointer_on_this_compiler[N-100];
95 template <
class X,
class XFuncType,
class GenericMemFuncType>
97 GenericMemFuncType &bound_func) {
109#ifdef FASTDLGT_MICROSOFT_MFP
112 template <
class X,
class XFuncType,
class GenericMemFuncType>
144 template <
class X,
class XFuncType,
class GenericMemFuncType>
153 bound_func =
reinterpret_cast<GenericMemFuncType
>(
u.s.codeptr);
161 &&
sizeof(
u2.virtfunc)==
sizeof(
u2.s) ? 1 : -1];
163 u.s.codeptr =
u2.s.codeptr;
164 return (
pthis->*
u.ProbeFunc)();
171 template <
class X,
class XFuncType,
class GenericMemFuncType>
183 template <
class X,
class XFuncType,
class GenericMemFuncType>
204 if(
u.s.vtable_index) {
207 const int *
vtable = *
reinterpret_cast<const int *
const*
>(
208 reinterpret_cast<const char *
>(
pthis) +
u.s.vtordisp );
211 reinterpret_cast<const char *
>(
vtable) +
u.s.vtable_index);
226#if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK)
231#if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK)
241#if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK)
262#if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK)
279 SetMementoFrom(right);
286 return right.
IsLess(*
this);
290#
if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK)
298#if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK)
304 template <
class GenericMemFunc,
class StaticFuncPtr,
class Un
voidStaticFuncPtr>
308 template <
class X,
class XMemFunc >
312#if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK)
317 template <
class X,
class XMemFunc>
321#if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK)
325#ifdef FASTDELEGATE_GCC_BUG_8271
326 template <
class X,
class XMemFunc>
329#if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK)
337#if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK)
340 template<
class DerivedClass >
349 template <
class DerivedClass,
class ParentInvokerSig >
363 template<
class DerivedClass >
368 template <
class DerivedClass,
class ParentInvokerSig>
398 template<
class Param1,
class Param2,
class RetType=detail::DefaultVo
id>
402 typedef DesiredRetType (*StaticFunctionPtr)(Param1 p1, Param2 p2);
403 typedef RetType (*UnvoidStaticFunctionPtr)(Param1 p1, Param2 p2);
413 m_Closure.
CopyFrom(
this, x.m_Closure); }
415 m_Closure.
CopyFrom(
this, x.m_Closure); }
417 return m_Closure.
IsEqual(x.m_Closure); }
419 return !m_Closure.
IsEqual(x.m_Closure); }
421 return m_Closure.
IsLess(x.m_Closure); }
423 return x.m_Closure.
IsLess(m_Closure); }
425 template <
class X,
class Y >
426 FastDelegate2(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2) ) {
428 template <
class X,
class Y >
429 inline void bind(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2)) {
432 template <
class X,
class Y >
433 FastDelegate2(
const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2) const) {
435 template <
class X,
class Y >
436 inline void bind(
const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2) const) {
441 bind(function_to_bind); }
443 void operator = (DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2) ) {
444 bind(function_to_bind); }
445 inline void bind(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2)) {
446 m_Closure.
bindstaticfunc(
this, &FastDelegate2::InvokeStaticFunction,
453 typedef struct SafeBoolStruct {
454 int a_data_pointer_to_this_is_0_on_buggy_compilers;
455 StaticFunctionPtr m_nonzero;
457 typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type;
459 operator unspecified_bool_type()
const {
460 return empty()? 0: &SafeBoolStruct::m_nonzero;
476 RetType InvokeStaticFunction(Param1 p1, Param2 p2)
const {
bool operator>(const DelegateMemento &right)
bool IsEqual(const DelegateMemento &x) const
DelegateMemento(const DelegateMemento &right)
void(detail::GenericClass::* GenericMemFuncType)()
bool operator<(const DelegateMemento &right)
GenericMemFuncType m_pFunction
GenericFuncPtr m_pStaticFunction
DelegateMemento & operator=(const DelegateMemento &right)
detail::GenericClass * m_pthis
bool IsLess(const DelegateMemento &right) const
FastDelegate2(const Y *pthis, DesiredRetType(X::*function_to_bind)(Param1 p1, Param2 p2) const)
void operator=(const FastDelegate2 &x)
bool operator!=(StaticFunctionPtr funcptr)
void bind(const Y *pthis, DesiredRetType(X::*function_to_bind)(Param1 p1, Param2 p2) const)
RetType operator()(Param1 p1, Param2 p2) const
const DelegateMemento & GetMemento()
bool operator>(const FastDelegate2 &x) const
bool operator==(StaticFunctionPtr funcptr)
bool operator!=(const FastDelegate2 &x) const
bool operator==(const FastDelegate2 &x) const
FastDelegate2(Y *pthis, DesiredRetType(X::*function_to_bind)(Param1 p1, Param2 p2))
FastDelegate2(DesiredRetType(*function_to_bind)(Param1 p1, Param2 p2))
void SetMemento(const DelegateMemento &any)
void bind(DesiredRetType(*function_to_bind)(Param1 p1, Param2 p2))
bool operator<(const FastDelegate2 &x) const
FastDelegate2(const FastDelegate2 &x)
void bind(Y *pthis, DesiredRetType(X::*function_to_bind)(Param1 p1, Param2 p2))
GenericClass * GetClosureThis() const
UnvoidStaticFuncPtr GetStaticFunction() const
void bindconstmemfunc(const X *pthis, XMemFunc function_to_bind)
GenericMemFunc GetClosureMemPtr() const
void bindmemfunc(X *pthis, XMemFunc function_to_bind)
void CopyFrom(DerivedClass *pParent, const DelegateMemento &right)
void bindstaticfunc(DerivedClass *pParent, ParentInvokerSig static_function_invoker, StaticFuncPtr function_to_bind)
void bindmemfunc(const X *pthis, XMemFunc function_to_bind)
bool IsEqualToStaticFuncPtr(StaticFuncPtr funcptr)
void CopyFrom(DerivedClass *pParent, const DelegateMemento &x)
OutputClass horrible_cast(const InputClass input)
OutputClass implicit_cast(InputClass input)
const int SINGLE_MEMFUNCPTR_SIZE
GenericVirtualClass *(GenericVirtualClass::* ProbePtrType)()
GenericVirtualClass * GetThis()
void(GenericClass::* codeptr)()
static GenericClass * Convert(X *pthis, XFuncType function_to_bind, GenericMemFuncType &bound_func)
static GenericClass * Convert(X *pthis, XFuncType function_to_bind, GenericMemFuncType &bound_func)
static GenericClass * Convert(X *pthis, XFuncType function_to_bind, GenericMemFuncType &bound_func)
static GenericClass * Convert(X *pthis, XFuncType function_to_bind, GenericMemFuncType &bound_func)
static GenericClass * Convert(X *pthis, XFuncType function_to_bind, GenericMemFuncType &bound_func)