add multiple argument versions

This commit is contained in:
Mathieu Lacage
2006-09-03 12:40:19 +02:00
parent 02fa792b81
commit 6f7c87a070

View File

@@ -141,6 +141,7 @@ public:
*/
template <typename T>
static EventId schedule (Time time, void (T::*mem_ptr) (void), T *obj) {
// zero argument version
class EventMemberImpl0 : public EventImpl {
public:
typedef void (T::*F)(void);
@@ -158,7 +159,149 @@ public:
} *ev = new EventMemberImpl0 (obj, mem_ptr);
return schedule (time, ev);
}
template <typename T, typename T1>
static EventId schedule (Time time, void (T::*f) (T1), T* t, T1 a1) {
// one argument version
class EventMemberImpl1 : public EventImpl {
public:
typedef void (T::*F)(T1);
EventMemberImpl1 (T *obj, F function, T1 a1)
: m_obj (obj),
m_function (function),
m_a1 (a1)
{}
protected:
virtual ~EventMemberImpl1 () {}
private:
virtual void notify (void) {
(m_obj->*m_function) (m_a1);
}
T* m_obj;
F m_function;
T1 m_a1;
} *ev = new EventMemberImpl1 (f, t, a1);
return schedule (time, ev);
}
template <typename T, typename T1, typename T2>
static EventId schedule (Time time, void (T::*f) (T1), T* t, T1 a1, T2 a2) {
// two argument version
class EventMemberImpl2 : public EventImpl {
public:
typedef void (T::*F)(T1, T2);
EventMemberImpl2 (T *obj, F function, T1 a1, T2 a2)
: m_obj (obj),
m_function (function),
m_a1 (a1),
m_a2 (a2)
{ }
protected:
virtual ~EventMemberImpl2 () {}
private:
virtual void notify (void) {
(m_obj->*m_function) (m_a1, m_a2);
}
T* m_obj;
F m_function;
T1 m_a1;
T2 m_a2;
} *ev = new EventMemberImpl2 (t, f, a1, a2);
return schedule (time, ev);
}
template <typename T, typename T1, typename T2, typename T3>
static EventId schedule (Time time, void (T::*f) (T1), T* t, T1 a1, T2 a2, T3 a3) {
// three argument version
class EventMemberImpl3 : public EventImpl {
public:
typedef void (T::*F)(T1, T2, T3);
EventMemberImpl3 (T *obj, F function, T1 a1, T2 a2, T3 a3)
: m_obj (obj),
m_function (function),
m_a1 (a1),
m_a2 (a2),
m_a3 (a3)
{ }
protected:
virtual ~EventMemberImpl3 () {}
private:
virtual void notify (void) {
(m_obj->*m_function) (m_a1, m_a2, m_a3);
}
T* m_obj;
F m_function;
T1 m_a1;
T2 m_a2;
T3 m_a3;
} *ev = new EventMemberImpl3 (t, f, a1, a2, a3);
return schedule (time, ev);
}
template <typename T, typename T1, typename T2, typename T3, typename T4>
static EventId schedule (Time time, void (T::*f) (T1), T* t, T1 a1, T2 a2, T3 a3, T4 a4) {
// four argument version
class EventMemberImpl4 : public EventImpl {
public:
typedef void (T::*F)(T1, T2, T3, T4);
EventMemberImpl4 (T *obj, F function, T1 a1, T2 a2, T3 a3, T4 a4)
: m_obj (obj),
m_function (function),
m_a1 (a1),
m_a2 (a2),
m_a3 (a3),
m_a4 (a4)
{ }
protected:
virtual ~EventMemberImpl4 () {}
private:
virtual void notify (void) {
(m_obj->*m_function) (m_a1, m_a2, m_a3, m_a4);
}
T* m_obj;
F m_function;
T1 m_a1;
T2 m_a2;
T3 m_a3;
T4 m_a4;
} *ev = new EventMemberImpl4 (t, f, a1, a2, a3, a4);
return schedule (time, ev);
}
template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5>
static EventId schedule (Time time, void (T::*f) (T1), T* t,
T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) {
// five argument version
class EventMemberImpl5 : public EventImpl {
public:
typedef void (T::*F)(T1, T2, T3, T4, T5);
EventMemberImpl5 (T *obj, F function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
: m_obj (obj),
m_function (function),
m_a1 (a1),
m_a2 (a2),
m_a3 (a3),
m_a4 (a4),
m_a5 (a5)
{ }
protected:
virtual ~EventMemberImpl5 () {}
private:
virtual void notify (void) {
(m_obj->*m_function) (m_a1, m_a2, m_a3, m_a4, m_a5);
}
T* m_obj;
F m_function;
T1 m_a1;
T2 m_a2;
T3 m_a3;
T4 m_a4;
T5 m_a5;
} *ev = new EventMemberImpl5 (t, f, a1, a2, a3, a4, a5);
return schedule (time, ev);
}
static EventId schedule (Time time, void (*f) (void)) {
// zero arg version
class EventFunctionImpl0 : public EventImpl {
public:
typedef void (*F)(void);
@@ -178,6 +321,7 @@ public:
}
template <typename T1>
static EventId schedule (Time time, void (*f) (T1), T1 a1) {
// one arg version
class EventFunctionImpl1 : public EventImpl {
public:
typedef void (*F)(T1);
@@ -197,6 +341,114 @@ public:
} *ev = new EventFunctionImpl1(f, a1);
return schedule (time, ev);
}
template <typename T1, typename T2>
static EventId schedule (Time time, void (*f) (T1), T1 a1, T2 a2) {
// two arg version
class EventFunctionImpl2 : public EventImpl {
public:
typedef void (*F)(T1, T2);
EventFunctionImpl2 (F function, T1 a1, T2 a2)
: m_function (function),
m_a1 (a1),
m_a2 (a2)
{ }
protected:
virtual ~EventFunctionImpl2 () {}
private:
virtual void notify (void) {
(*m_function) (m_a1, m_a2);
}
F m_function;
T1 m_a1;
T2 m_a2;
} *ev = new EventFunctionImpl2 (f, a1, a2);
return schedule (time, ev);
}
template <typename T1, typename T2, typename T3>
static EventId schedule (Time time, void (*f) (T1), T1 a1, T2 a2, T3 a3) {
// three arg version
class EventFunctionImpl3 : public EventImpl {
public:
typedef void (*F)(T1, T2, T3);
EventFunctionImpl3 (F function, T1 a1, T2 a2, T3 a3)
: m_function (function),
m_a1 (a1),
m_a2 (a2),
m_a3 (a3)
{ }
protected:
virtual ~EventFunctionImpl3 () {}
private:
virtual void notify (void) {
(*m_function) (m_a1, m_a2, m_a3);
}
F m_function;
T1 m_a1;
T2 m_a2;
T3 m_a3;
} *ev = new EventFunctionImpl3 (f, a1, a2, a3);
return schedule (time, ev);
}
template <typename T1, typename T2, typename T3, typename T4>
static EventId schedule (Time time, void (*f) (T1), T1 a1, T2 a2, T3 a3, T4 a4) {
// four arg version
class EventFunctionImpl4 : public EventImpl {
public:
typedef void (*F)(T1, T2, T3, T4);
EventFunctionImpl4 (F function, T1 a1, T2 a2, T3 a3, T4 a4)
: m_function (function),
m_a1 (a1),
m_a2 (a2),
m_a3 (a3),
m_a4 (a4)
{ }
protected:
virtual ~EventFunctionImpl4 () {}
private:
virtual void notify (void) {
(*m_function) (m_a1, m_a2, m_a3, m_a4);
}
F m_function;
T1 m_a1;
T2 m_a2;
T3 m_a3;
T4 m_a4;
} *ev = new EventFunctionImpl4 (f, a1, a2, a3, a4);
return schedule (time, ev);
}
template <typename T1, typename T2, typename T3, typename T4, typename T5>
static EventId schedule (Time time, void (*f) (T1), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) {
// five arg version
class EventFunctionImpl5 : public EventImpl {
public:
typedef void (*F)(T1, T2, T3, T4, T5);
EventFunctionImpl5 (F function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
: m_function (function),
m_a1 (a1),
m_a2 (a2),
m_a3 (a3),
m_a4 (a4),
m_a5 (a5)
{ }
protected:
virtual ~EventFunctionImpl5 () {}
private:
virtual void notify (void) {
(*m_function) (m_a1, m_a2, m_a3, m_a4, m_a5);
}
F m_function;
T1 m_a1;
T2 m_a2;
T3 m_a3;
T4 m_a4;
T5 m_a5;
} *ev = new EventFunctionImpl5 (f, a1, a2, a3, a4, a5);
return schedule (time, ev);
}
/**
* Unschedule the event. i.e.: the removed event never expires.
* @param id the event to remove from the list of scheduled events.