implement overloads for ScheduleNow and ScheduleDestroy

This commit is contained in:
Mathieu Lacage
2006-10-28 21:21:53 +02:00
parent 35eab87f76
commit ebd16ea6fc
2 changed files with 486 additions and 21 deletions

View File

@@ -356,26 +356,10 @@ Simulator::Now (void)
return GetPriv ()->Now ();
}
EventId
Simulator::Schedule (Time const &time, EventImpl *ev)
EventImpl *
Simulator::MakeEvent (void (*f) (void))
{
return GetPriv ()->Schedule (time, ev);
}
void
Simulator::ScheduleNow (EventImpl *ev)
{
GetPriv ()->ScheduleNow (ev);
}
void
Simulator::ScheduleDestroy (EventImpl *ev)
{
GetPriv ()->ScheduleDestroy (ev);
}
EventId
Simulator::Schedule (Time const &time, void (*f) (void))
{
// zero arg version
// zero arg version
class EventFunctionImpl0 : public EventImpl {
public:
typedef void (*F)(void);
@@ -391,7 +375,37 @@ Simulator::Schedule (Time const &time, void (*f) (void))
private:
F m_function;
} *ev = new EventFunctionImpl0 (f);
return Schedule (time, ev);
return ev;
}
EventId
Simulator::Schedule (Time const &time, EventImpl *ev)
{
return GetPriv ()->Schedule (time, ev);
}
void
Simulator::ScheduleNow (EventImpl *ev)
{
GetPriv ()->ScheduleNow (ev);
}
void
Simulator::ScheduleDestroy (EventImpl *ev)
{
GetPriv ()->ScheduleDestroy (ev);
}
EventId
Simulator::Schedule (Time const &time, void (*f) (void))
{
return Schedule (time, MakeEvent (f));
}
void
Simulator::ScheduleNow (void (*f) (void))
{
return ScheduleNow (MakeEvent (f));
}
void
Simulator::ScheduleDestroy (void (*f) (void))
{
return ScheduleDestroy (MakeEvent (f));
}
@@ -421,6 +435,20 @@ Simulator::IsExpired (EventId id)
namespace ns3 {
static void foo0 (void)
{}
static void foo1 (int)
{}
static void foo2 (int, int)
{}
static void foo3 (int, int, int)
{}
static void foo4 (int, int, int, int)
{}
static void foo5 (int, int, int, int, int)
{}
class SimulatorTests : public Test {
public:
SimulatorTests ();
@@ -433,6 +461,13 @@ private:
void B (int b);
void C (int c);
void D (int d);
void bar0 (void);
void bar1 (int);
void bar2 (int, int);
void bar3 (int, int, int);
void bar4 (int, int, int, int);
void bar5 (int, int, int, int, int);
bool m_b;
bool m_a;
bool m_c;
@@ -487,6 +522,25 @@ SimulatorTests::D (int d)
m_d = true;
}
}
void
SimulatorTests::bar0 (void)
{}
void
SimulatorTests::bar1 (int)
{}
void
SimulatorTests::bar2 (int, int)
{}
void
SimulatorTests::bar3 (int, int, int)
{}
void
SimulatorTests::bar4 (int, int, int, int)
{}
void
SimulatorTests::bar5 (int, int, int, int, int)
{}
bool
SimulatorTests::RunOneTest (void)
{
@@ -533,6 +587,45 @@ SimulatorTests::RunTests (void)
}
Simulator::Destroy ();
Simulator::Schedule (Seconds (0.0), &foo0);
Simulator::Schedule (Seconds (0.0), &foo1, 0);
Simulator::Schedule (Seconds (0.0), &foo2, 0, 0);
Simulator::Schedule (Seconds (0.0), &foo3, 0, 0, 0);
Simulator::Schedule (Seconds (0.0), &foo4, 0, 0, 0, 0);
Simulator::Schedule (Seconds (0.0), &foo5, 0, 0, 0, 0, 0);
Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar0, this);
Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar1, this, 0);
Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar2, this, 0, 0);
Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar3, this, 0, 0, 0);
Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar4, this, 0, 0, 0, 0);
Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar5, this, 0, 0, 0, 0, 0);
Simulator::ScheduleNow (&foo0);
Simulator::ScheduleNow (&foo1, 0);
Simulator::ScheduleNow (&foo2, 0, 0);
Simulator::ScheduleNow (&foo3, 0, 0, 0);
Simulator::ScheduleNow (&foo4, 0, 0, 0, 0);
Simulator::ScheduleNow (&foo5, 0, 0, 0, 0, 0);
Simulator::ScheduleNow (&SimulatorTests::bar0, this);
Simulator::ScheduleNow (&SimulatorTests::bar1, this, 0);
Simulator::ScheduleNow (&SimulatorTests::bar2, this, 0, 0);
Simulator::ScheduleNow (&SimulatorTests::bar3, this, 0, 0, 0);
Simulator::ScheduleNow (&SimulatorTests::bar4, this, 0, 0, 0, 0);
Simulator::ScheduleNow (&SimulatorTests::bar5, this, 0, 0, 0, 0, 0);
Simulator::ScheduleDestroy (&foo0);
Simulator::ScheduleDestroy (&foo1, 0);
Simulator::ScheduleDestroy (&foo2, 0, 0);
Simulator::ScheduleDestroy (&foo3, 0, 0, 0);
Simulator::ScheduleDestroy (&foo4, 0, 0, 0, 0);
Simulator::ScheduleDestroy (&foo5, 0, 0, 0, 0, 0);
Simulator::ScheduleDestroy (&SimulatorTests::bar0, this);
Simulator::ScheduleDestroy (&SimulatorTests::bar1, this, 0);
Simulator::ScheduleDestroy (&SimulatorTests::bar2, this, 0, 0);
Simulator::ScheduleDestroy (&SimulatorTests::bar3, this, 0, 0, 0);
Simulator::ScheduleDestroy (&SimulatorTests::bar4, this, 0, 0, 0, 0);
Simulator::ScheduleDestroy (&SimulatorTests::bar5, this, 0, 0, 0, 0, 0);
return ok;
}

View File

@@ -275,6 +275,215 @@ public:
template <typename T1, typename T2, typename T3, typename T4, typename T5>
static EventId Schedule (Time const &time, void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
/**
* Schedule an event to expire Now. All events scheduled to
* to expire "Now" are scheduled FIFO, after all normal events
* have expired.
*
* @param mem_ptr member method pointer to invoke
* @param obj the object on which to invoke the member method
*/
template <typename T>
static void ScheduleNow (void (T::*mem_ptr) (void), T *obj);
/**
* @param mem_ptr member method pointer to invoke
* @param obj the object on which to invoke the member method
* @param a1 the first argument to pass to the invoked method
*/
template <typename T, typename T1>
static void ScheduleNow (void (T::*mem_ptr) (T1), T* obj, T1 a1);
/**
* @param mem_ptr member method pointer to invoke
* @param obj the object on which to invoke the member method
* @param a1 the first argument to pass to the invoked method
* @param a2 the second argument to pass to the invoked method
*/
template <typename T, typename T1, typename T2>
static void ScheduleNow (void (T::*mem_ptr) (T1,T2), T* obj, T1 a1, T2 a2);
/**
* @param time the expiration time of the event.
* @param mem_ptr member method pointer to invoke
* @param obj the object on which to invoke the member method
* @param a1 the first argument to pass to the invoked method
* @param a2 the second argument to pass to the invoked method
* @param a3 the third argument to pass to the invoked method
*/
template <typename T, typename T1, typename T2, typename T3>
static void ScheduleNow (void (T::*mem_ptr) (T1,T2,T3), T* obj, T1 a1, T2 a2, T3 a3);
/**
* @param mem_ptr member method pointer to invoke
* @param obj the object on which to invoke the member method
* @param a1 the first argument to pass to the invoked method
* @param a2 the second argument to pass to the invoked method
* @param a3 the third argument to pass to the invoked method
* @param a4 the fourth argument to pass to the invoked method
*/
template <typename T, typename T1, typename T2, typename T3, typename T4>
static void ScheduleNow (void (T::*mem_ptr) (T1,T2,T3,T4), T* obj,
T1 a1, T2 a2, T3 a3, T4 a4);
/**
* @param mem_ptr member method pointer to invoke
* @param obj the object on which to invoke the member method
* @param a1 the first argument to pass to the invoked method
* @param a2 the second argument to pass to the invoked method
* @param a3 the third argument to pass to the invoked method
* @param a4 the fourth argument to pass to the invoked method
* @param a5 the fifth argument to pass to the invoked method
*/
template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5>
static void ScheduleNow (void (T::*mem_ptr) (T1,T2,T3,T4,T5), T* obj,
T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
/**
* @param f the function to invoke
*/
static void ScheduleNow (void (*f) (void));
/**
* @param f the function to invoke
* @param a1 the first argument to pass to the function to invoke
*/
template <typename T1>
static void ScheduleNow (void (*f) (T1), T1 a1);
/**
* @param f the function to invoke
* @param a1 the first argument to pass to the function to invoke
* @param a2 the second argument to pass to the function to invoke
*/
template <typename T1, typename T2>
static void ScheduleNow (void (*f) (T1,T2), T1 a1, T2 a2);
/**
* @param f the function to invoke
* @param a1 the first argument to pass to the function to invoke
* @param a2 the second argument to pass to the function to invoke
* @param a3 the third argument to pass to the function to invoke
*/
template <typename T1, typename T2, typename T3>
static void ScheduleNow (void (*f) (T1,T2,T3), T1 a1, T2 a2, T3 a3);
/**
* @param f the function to invoke
* @param a1 the first argument to pass to the function to invoke
* @param a2 the second argument to pass to the function to invoke
* @param a3 the third argument to pass to the function to invoke
* @param a4 the fourth argument to pass to the function to invoke
*/
template <typename T1, typename T2, typename T3, typename T4>
static void ScheduleNow (void (*f) (T1,T2,T3,T4), T1 a1, T2 a2, T3 a3, T4 a4);
/**
* @param f the function to invoke
* @param a1 the first argument to pass to the function to invoke
* @param a2 the second argument to pass to the function to invoke
* @param a3 the third argument to pass to the function to invoke
* @param a4 the fourth argument to pass to the function to invoke
* @param a5 the fifth argument to pass to the function to invoke
*/
template <typename T1, typename T2, typename T3, typename T4, typename T5>
static void ScheduleNow (void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
/**
* Schedule an event to expire at Destroy time. All events
* scheduled to expire at "Destroy" time are scheduled FIFO,
* after all normal events have expired and only when
* Simulator::Destroy is invoked.
*
* @param mem_ptr member method pointer to invoke
* @param obj the object on which to invoke the member method
*/
template <typename T>
static void ScheduleDestroy (void (T::*mem_ptr) (void), T *obj);
/**
* @param mem_ptr member method pointer to invoke
* @param obj the object on which to invoke the member method
* @param a1 the first argument to pass to the invoked method
*/
template <typename T, typename T1>
static void ScheduleDestroy (void (T::*mem_ptr) (T1), T* obj, T1 a1);
/**
* @param mem_ptr member method pointer to invoke
* @param obj the object on which to invoke the member method
* @param a1 the first argument to pass to the invoked method
* @param a2 the second argument to pass to the invoked method
*/
template <typename T, typename T1, typename T2>
static void ScheduleDestroy (void (T::*mem_ptr) (T1,T2), T* obj, T1 a1, T2 a2);
/**
* @param time the expiration time of the event.
* @param mem_ptr member method pointer to invoke
* @param obj the object on which to invoke the member method
* @param a1 the first argument to pass to the invoked method
* @param a2 the second argument to pass to the invoked method
* @param a3 the third argument to pass to the invoked method
*/
template <typename T, typename T1, typename T2, typename T3>
static void ScheduleDestroy (void (T::*mem_ptr) (T1,T2,T3), T* obj, T1 a1, T2 a2, T3 a3);
/**
* @param mem_ptr member method pointer to invoke
* @param obj the object on which to invoke the member method
* @param a1 the first argument to pass to the invoked method
* @param a2 the second argument to pass to the invoked method
* @param a3 the third argument to pass to the invoked method
* @param a4 the fourth argument to pass to the invoked method
*/
template <typename T, typename T1, typename T2, typename T3, typename T4>
static void ScheduleDestroy (void (T::*mem_ptr) (T1,T2,T3,T4), T* obj,
T1 a1, T2 a2, T3 a3, T4 a4);
/**
* @param mem_ptr member method pointer to invoke
* @param obj the object on which to invoke the member method
* @param a1 the first argument to pass to the invoked method
* @param a2 the second argument to pass to the invoked method
* @param a3 the third argument to pass to the invoked method
* @param a4 the fourth argument to pass to the invoked method
* @param a5 the fifth argument to pass to the invoked method
*/
template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5>
static void ScheduleDestroy (void (T::*mem_ptr) (T1,T2,T3,T4,T5), T* obj,
T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
/**
* @param f the function to invoke
*/
static void ScheduleDestroy (void (*f) (void));
/**
* @param f the function to invoke
* @param a1 the first argument to pass to the function to invoke
*/
template <typename T1>
static void ScheduleDestroy (void (*f) (T1), T1 a1);
/**
* @param f the function to invoke
* @param a1 the first argument to pass to the function to invoke
* @param a2 the second argument to pass to the function to invoke
*/
template <typename T1, typename T2>
static void ScheduleDestroy (void (*f) (T1,T2), T1 a1, T2 a2);
/**
* @param f the function to invoke
* @param a1 the first argument to pass to the function to invoke
* @param a2 the second argument to pass to the function to invoke
* @param a3 the third argument to pass to the function to invoke
*/
template <typename T1, typename T2, typename T3>
static void ScheduleDestroy (void (*f) (T1,T2,T3), T1 a1, T2 a2, T3 a3);
/**
* @param f the function to invoke
* @param a1 the first argument to pass to the function to invoke
* @param a2 the second argument to pass to the function to invoke
* @param a3 the third argument to pass to the function to invoke
* @param a4 the fourth argument to pass to the function to invoke
*/
template <typename T1, typename T2, typename T3, typename T4>
static void ScheduleDestroy (void (*f) (T1,T2,T3,T4), T1 a1, T2 a2, T3 a3, T4 a4);
/**
* @param f the function to invoke
* @param a1 the first argument to pass to the function to invoke
* @param a2 the second argument to pass to the function to invoke
* @param a3 the third argument to pass to the function to invoke
* @param a4 the fourth argument to pass to the function to invoke
* @param a5 the fifth argument to pass to the function to invoke
*/
template <typename T1, typename T2, typename T3, typename T4, typename T5>
static void ScheduleDestroy (void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
/**
* Remove an event from the event list.
* This method has the same visible effect as the
@@ -744,11 +953,174 @@ EventId Simulator::Schedule (Time const &time, void (*f) (T1,T2,T3,T4), T1 a1, T
}
template <typename T1, typename T2, typename T3, typename T4, typename T5>
static EventId Schedule (Time const &time, void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
EventId Simulator::Schedule (Time const &time, void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
{
return Schedule (time, MakeEvent (f, a1, a2, a3, a4, a5));
}
template <typename T>
void
Simulator::ScheduleNow (void (T::*mem_ptr) (void), T *obj)
{
ScheduleNow (MakeEvent (mem_ptr, obj));
}
template <typename T, typename T1>
void
Simulator::ScheduleNow (void (T::*mem_ptr) (T1), T* obj, T1 a1)
{
ScheduleNow (MakeEvent (mem_ptr, obj, a1));
}
template <typename T, typename T1, typename T2>
void
Simulator::ScheduleNow (void (T::*mem_ptr) (T1,T2), T* obj, T1 a1, T2 a2)
{
ScheduleNow (MakeEvent (mem_ptr, obj, a1, a2));
}
template <typename T, typename T1, typename T2, typename T3>
void
Simulator::ScheduleNow (void (T::*mem_ptr) (T1,T2,T3), T* obj, T1 a1, T2 a2, T3 a3)
{
ScheduleNow (MakeEvent (mem_ptr, obj, a1, a2, a3));
}
template <typename T, typename T1, typename T2, typename T3, typename T4>
void
Simulator::ScheduleNow (void (T::*mem_ptr) (T1,T2,T3,T4), T* obj, T1 a1, T2 a2, T3 a3, T4 a4)
{
ScheduleNow (MakeEvent (mem_ptr, obj, a1, a2, a3, a4));
}
template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5>
void
Simulator::ScheduleNow (void (T::*mem_ptr) (T1,T2,T3,T4,T5), T* obj,
T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
{
ScheduleNow (MakeEvent (mem_ptr, obj, a1, a2, a3, a4, a5));
}
template <typename T1>
void
Simulator::ScheduleNow (void (*f) (T1), T1 a1)
{
ScheduleNow (MakeEvent (f, a1));
}
template <typename T1, typename T2>
void
Simulator::ScheduleNow (void (*f) (T1,T2), T1 a1, T2 a2)
{
ScheduleNow (MakeEvent (f, a1, a2));
}
template <typename T1, typename T2, typename T3>
void
Simulator::ScheduleNow (void (*f) (T1,T2,T3), T1 a1, T2 a2, T3 a3)
{
ScheduleNow (MakeEvent (f, a1, a2, a3));
}
template <typename T1, typename T2, typename T3, typename T4>
void
Simulator::ScheduleNow (void (*f) (T1,T2,T3,T4), T1 a1, T2 a2, T3 a3, T4 a4)
{
ScheduleNow (MakeEvent (f, a1, a2, a3, a4));
}
template <typename T1, typename T2, typename T3, typename T4, typename T5>
void
Simulator::ScheduleNow (void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
{
ScheduleNow (MakeEvent (f, a1, a2, a3, a4, a5));
}
template <typename T>
void
Simulator::ScheduleDestroy (void (T::*mem_ptr) (void), T *obj)
{
ScheduleDestroy (MakeEvent (mem_ptr, obj));
}
template <typename T, typename T1>
void
Simulator::ScheduleDestroy (void (T::*mem_ptr) (T1), T* obj, T1 a1)
{
ScheduleDestroy (MakeEvent (mem_ptr, obj, a1));
}
template <typename T, typename T1, typename T2>
void
Simulator::ScheduleDestroy (void (T::*mem_ptr) (T1,T2), T* obj, T1 a1, T2 a2)
{
ScheduleDestroy (MakeEvent (mem_ptr, obj, a1, a2));
}
template <typename T, typename T1, typename T2, typename T3>
void
Simulator::ScheduleDestroy (void (T::*mem_ptr) (T1,T2,T3), T* obj, T1 a1, T2 a2, T3 a3)
{
ScheduleDestroy (MakeEvent (mem_ptr, obj, a1, a2, a3));
}
template <typename T, typename T1, typename T2, typename T3, typename T4>
void
Simulator::ScheduleDestroy (void (T::*mem_ptr) (T1,T2,T3,T4), T* obj, T1 a1, T2 a2, T3 a3, T4 a4)
{
ScheduleDestroy (MakeEvent (mem_ptr, obj, a1, a2, a3, a4));
}
template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5>
void
Simulator::ScheduleDestroy (void (T::*mem_ptr) (T1,T2,T3,T4,T5), T* obj,
T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
{
ScheduleDestroy (MakeEvent (mem_ptr, obj, a1, a2, a3, a4, a5));
}
template <typename T1>
void
Simulator::ScheduleDestroy (void (*f) (T1), T1 a1)
{
ScheduleDestroy (MakeEvent (f, a1));
}
template <typename T1, typename T2>
void
Simulator::ScheduleDestroy (void (*f) (T1,T2), T1 a1, T2 a2)
{
ScheduleDestroy (MakeEvent (f, a1, a2));
}
template <typename T1, typename T2, typename T3>
void
Simulator::ScheduleDestroy (void (*f) (T1,T2,T3), T1 a1, T2 a2, T3 a3)
{
ScheduleDestroy (MakeEvent (f, a1, a2, a3));
}
template <typename T1, typename T2, typename T3, typename T4>
void
Simulator::ScheduleDestroy (void (*f) (T1,T2,T3,T4), T1 a1, T2 a2, T3 a3, T4 a4)
{
ScheduleDestroy (MakeEvent (f, a1, a2, a3, a4));
}
template <typename T1, typename T2, typename T3, typename T4, typename T5>
void
Simulator::ScheduleDestroy (void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
{
ScheduleDestroy (MakeEvent (f, a1, a2, a3, a4, a5));
}
}; // namespace ns3
#endif /* SIMULATOR_H */