implement the member function version of Timer::SetFunction (a1)

This commit is contained in:
Mathieu Lacage committed 2007-09-27 13:45:55 +02:00
1 parent 062c1636d1
commit af8917dd2b
2 files changed
+117 -1

No files matched your search

+27 -1
View File
@@ -84,6 +84,23 @@ Timer::~Timer ()
delete m_impl;
}
void
Timer::SetFunction (void (*fn) (void))
{
struct FnTimerImplZero : public TimerImpl
{
typedef void (*FN) (void);
FnTimerImplZero (FN fn)
: m_fn (fn) {}
virtual EventId Schedule (const Time &delay) {
return Simulator::Schedule (delay, m_fn);
}
FN m_fn;
} *function = new FnTimerImplZero (fn);
delete m_impl;
m_impl = function;
}
void
Timer::SetDelay (const Time &time)
{
@@ -171,6 +188,11 @@ class TimerTests : public Test
public:
TimerTests ();
virtual bool RunTests (void);
void bazi (int) {}
void bazcir (const int&) {}
void bazir (int&) {}
void bazip (int *) {}
void bazcip (const int *) {}
};
TimerTests::TimerTests ()
@@ -185,7 +207,7 @@ TimerTests::RunTests (void)
int a = 0;
int &b = a;
const int &c = a;
Timer timer;
Timer timer = Timer (0);
timer.SetFunction (&bari, a);
timer.SetArguments (2);
@@ -208,6 +230,10 @@ TimerTests::RunTests (void)
timer.SetDelay (Seconds (1.0));
timer.Schedule ();
timer.SetFunction (&TimerTests::bazi, this, 1);
timer.SetFunction (&TimerTests::bazir, this, 1);
timer.SetFunction (&TimerTests::bazcir, this, 1);
Simulator::Run ();
Simulator::Destroy ();
return ok;