This commit is contained in:
2025-05-13 02:46:21 +03:00
parent 143e16692e
commit 86914b7fcc
610 changed files with 92343 additions and 2 deletions
+125
View File
@@ -0,0 +1,125 @@
#ifndef Delegate_h__
#define Delegate_h__
class CDelegate
{
};
// 0 parameters...
#define SUFFIX 0
#define TEMPLATE_PARAMS
#define TEMPLATE_ARGS
#define PARAMS
#define ARGS
#include "Delegate_base.h"
#undef SUFFIX
#undef TEMPLATE_PARAMS
#undef TEMPLATE_ARGS
#undef PARAMS
#undef ARGS
// 1 parameter...
#define SUFFIX 1
#define TEMPLATE_PARAMS \
, class TP1
#define TEMPLATE_ARGS , TP1
#define PARAMS TP1 p1
#define ARGS p1
#include "Delegate_base.h"
#undef SUFFIX
#undef TEMPLATE_PARAMS
#undef TEMPLATE_ARGS
#undef PARAMS
#undef ARGS
// 2 parameters...
#define SUFFIX 2
#define TEMPLATE_PARAMS \
, class TP1, class TP2
#define TEMPLATE_ARGS \
,TP1, TP2
#define PARAMS TP1 p1, TP2 p2
#define ARGS p1, p2
#include "Delegate_base.h"
#undef SUFFIX
#undef TEMPLATE_PARAMS
#undef TEMPLATE_ARGS
#undef PARAMS
#undef ARGS
// 3 parameters...
#define SUFFIX 3
#define TEMPLATE_PARAMS \
, class TP1, class TP2, class TP3
#define TEMPLATE_ARGS \
,TP1, TP2, TP3
#define PARAMS TP1 p1, TP2 p2, TP3 p3
#define ARGS p1, p2, p3
#include "Delegate_base.h"
#undef SUFFIX
#undef TEMPLATE_PARAMS
#undef TEMPLATE_ARGS
#undef PARAMS
#undef ARGS
// 4 parameters...
#define SUFFIX 4
#define TEMPLATE_PARAMS \
, class TP1, class TP2, class TP3, class TP4
#define TEMPLATE_ARGS \
,TP1, TP2, TP3, TP4
#define PARAMS TP1 p1, TP2 p2, TP3 p3, TP4 p4
#define ARGS p1, p2, p3, p4
#include "Delegate_base.h"
#undef SUFFIX
#undef TEMPLATE_PARAMS
#undef TEMPLATE_ARGS
#undef PARAMS
#undef ARGS
// 5 parameters...
#define SUFFIX 5
#define TEMPLATE_PARAMS \
, class TP1, class TP2, class TP3, class TP4, class TP5
#define TEMPLATE_ARGS \
,TP1, TP2, TP3, TP4, TP5
#define PARAMS TP1 p1, TP2 p2, TP3 p3, TP4 p4, TP5 p5
#define ARGS p1, p2, p3, p4, p5
#include "Delegate_base.h"
#undef SUFFIX
#undef TEMPLATE_PARAMS
#undef TEMPLATE_ARGS
#undef PARAMS
#undef ARGS
//event declarations
#define EVENT(NAME) typedef Event0<void> NAME;
#define EVENT0(NAME) typedef Event0<void> NAME; //same as previous
#define EVENT1(NAME, P1) typedef Event1<void, P1> NAME;
#define EVENT2(NAME, P1, P2) typedef Event2<void, P1, P2> NAME;
#define EVENT3(NAME, P1, P2, P3) typedef Event3<void, P1, P2, P3> NAME;
#define EVENT4(NAME, P1, P2, P3, P4) typedef Event4<void, P1, P2, P3, P4> NAME;
#define EVENT5(NAME, P1, P2, P3, P4, P5) typedef Event5<void, P1, P2, P3, P4, P5> NAME;
//delegate declarations
#define DELEGATE0(NAME) typedef Delegate0<void> ##NAME;
#endif // Delegate_h__
+164
View File
@@ -0,0 +1,164 @@
#include <list>
#define COMBINE(a,b) COMBINE1(a,b)
#define COMBINE1(a,b) a##b
#define COMBINE3(a,b,c) COMBINE3(a,b,c)
#define COMBINE31(a,b,c) a##b##c
#define I_DELEGATE COMBINE(Delegate, SUFFIX)
#define I_EVENT COMBINE(Event, SUFFIX)
#define C_STATIC_DELEGATE COMBINE(StaticDelegate, SUFFIX)
#define C_METHOD_DELEGATE COMBINE(MethodDelegate, SUFFIX)
template<class TRet TEMPLATE_PARAMS>
class I_DELEGATE : public CDelegate
{
public:
virtual ~I_DELEGATE(){}
virtual TRet Invoke(PARAMS) = 0;
virtual bool Compare(I_DELEGATE<TRet TEMPLATE_ARGS>* other) = 0;
};
template<class TRet TEMPLATE_PARAMS>
class C_STATIC_DELEGATE : public I_DELEGATE<TRet TEMPLATE_ARGS>
{
public:
typedef TRet (*Func)(PARAMS);
C_STATIC_DELEGATE(Func func)
{
pFunc = func;
}
C_STATIC_DELEGATE(const C_STATIC_DELEGATE& other)
{
pFunc = other.pFunc;
}
const C_STATIC_DELEGATE& operator=(const C_STATIC_DELEGATE& other)
{
this->pFunc = other.pFunc;
return *this;
}
virtual TRet Invoke(PARAMS)
{
return pFunc(ARGS);
}
virtual bool Compare(I_DELEGATE<TRet TEMPLATE_ARGS>* other)
{
return true;
}
private:
Func pFunc;
};
template<class TBase, class TRet TEMPLATE_PARAMS>
class C_METHOD_DELEGATE : public I_DELEGATE<TRet TEMPLATE_ARGS>
{
public:
typedef TRet (TBase::*Func)(PARAMS);
C_METHOD_DELEGATE(TBase* base, Func func)
{
pBase = base;
pFunc = func;
}
C_METHOD_DELEGATE(const C_METHOD_DELEGATE& other)
{
pBase = other.pBase;
pFunc = other.pFunc;
}
const C_METHOD_DELEGATE& operator=(const C_METHOD_DELEGATE& other)
{
this->pFunc = other.pFunc;
this->pBase = other.pBase;
return *this;
}
virtual TRet Invoke(PARAMS)
{
return (pBase->*pFunc)(ARGS);
}
virtual bool Compare(I_DELEGATE<TRet TEMPLATE_ARGS>* other)
{
return true;
}
private:
Func pFunc;
TBase* pBase;
};
template<class TRet TEMPLATE_PARAMS>
__forceinline I_DELEGATE<TRet TEMPLATE_ARGS>* NewDelegate(TRet (*pFunc)(PARAMS))
{
return new C_STATIC_DELEGATE<TRet TEMPLATE_ARGS>(pFunc);
}
template<class TBase, class TRet TEMPLATE_PARAMS>
__forceinline I_DELEGATE<TRet TEMPLATE_ARGS>* NewDelegate(TBase* base, TRet (TBase::*pFunc)(PARAMS))
{
return new C_METHOD_DELEGATE<TBase, TRet TEMPLATE_ARGS>(base, pFunc);
}
template<class TRet TEMPLATE_PARAMS>
class I_EVENT
{
public:
typedef I_DELEGATE<TRet TEMPLATE_ARGS> IDelegate;
typedef std::list<IDelegate*> DelegateList;
DelegateList delegates;
void Clear()
{
for(DelegateList::iterator it = delegates.begin(); it != delegates.end(); ++it)
{
delete (*it);
}
delegates.clear();
}
void Remove(CDelegate* del)
{
for(DelegateList::iterator it = delegates.begin(); it != delegates.end(); ++it)
{
if(del == (*it))
{
delete (*it);
delegates.erase(it);
break;
}
}
}
void AddDelegate(IDelegate* pDelegate)
{
if(pDelegate)
{
delegates.push_back(pDelegate);
}
}
void Invoke(PARAMS)
{
for(DelegateList::iterator it = delegates.begin(); it != delegates.end(); ++it)
{
(*it)->Invoke(ARGS);
}
}
I_EVENT<TRet TEMPLATE_ARGS>& operator =(IDelegate* pDelegate)
{
Clear();
AddDelegate(pDelegate);
return *this;
}
I_EVENT<TRet TEMPLATE_ARGS>& operator +=(IDelegate* pDelegate)
{
AddDelegate(pDelegate);
return *this;
}
I_EVENT<TRet TEMPLATE_ARGS>& operator +=(CDelegate* pDelegate)
{
AddDelegate((IDelegate*)pDelegate);
return *this;
}
};