--- a/src/simulator/timer.cc Thu Sep 27 13:31:20 2007 +0200
+++ b/src/simulator/timer.cc Thu Sep 27 13:45:55 2007 +0200
@@ -85,6 +85,23 @@
}
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)
{
m_delay = time;
@@ -171,6 +188,11 @@
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 @@
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 @@
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;
--- a/src/simulator/timer.h Thu Sep 27 13:31:20 2007 +0200
+++ b/src/simulator/timer.h Thu Sep 27 13:45:55 2007 +0200
@@ -135,6 +135,52 @@
void SetFunction (void (*fn) (U1, U2, U3), T1 a1, T2 a2, T3 a3);
/**
+ * \param memPtr the member function pointer
+ * \param objPtr the pointer to object
+ *
+ * Store this function and object in this Timer for later use by Timer::Schedule.
+ */
+ template <typename MEM_PTR, typename OBJ_PTR>
+ void SetFunction (MEM_PTR memPtr, OBJ_PTR objPtr);
+ /**
+ * \param memPtr the member function pointer
+ * \param objPtr the pointer to object
+ * \param a1 the first argument
+ *
+ * Store this function and this argument in this Timer for later use by
+ * Timer::Schedule.
+ */
+ template <typename MEM_PTR, typename OBJ_PTR,
+ typename T1>
+ void SetFunction (MEM_PTR memPtr, OBJ_PTR objPtr, T1 a1);
+ /**
+ * \param memPtr the member function pointer
+ * \param objPtr the pointer to object
+ * \param a1 the first argument
+ * \param a2 the second argument
+ *
+ * Store this function and these arguments in this Timer for later use by
+ * Timer::Schedule.
+ */
+ template <typename MEM_PTR, typename OBJ_PTR,
+ typename T1, typename T2>
+ void SetFunction (MEM_PTR memPtr, OBJ_PTR objPtr, T1 a1, T2 a2);
+ /**
+ * \param memPtr the member function pointer
+ * \param objPtr the pointer to object
+ * \param a1 the first argument
+ * \param a2 the second argument
+ * \param a3 the third argument
+ *
+ * Store this function and these arguments in this Timer for later use by
+ * Timer::Schedule.
+ */
+ template <typename MEM_PTR, typename OBJ_PTR,
+ typename T1, typename T2, typename T3>
+ void SetFunction (MEM_PTR memPtr, OBJ_PTR objPtr, T1 a1, T2 a2, T3 a3);
+
+
+ /**
* \param a1 the first argument
*
* Store this argument in this Timer for later use by Timer::Schedule.
@@ -276,6 +322,50 @@
impl->SetArguments (a1);
}
+template <typename MEM_PTR, typename OBJ_PTR>
+void
+Timer::SetFunction (MEM_PTR memPtr, OBJ_PTR objPtr)
+{
+ struct MemFnTimerImplZero : public TimerImpl
+ {
+ MemFnTimerImplZero (MEM_PTR memPtr, OBJ_PTR objPtr)
+ : m_memPtr (memPtr), m_objPtr (objPtr) {}
+ virtual EventId Schedule (const Time &delay) {
+ return Simulator::Schedule (delay, m_memPtr, m_objPtr);
+ }
+ MEM_PTR m_memPtr;
+ OBJ_PTR m_objPtr;
+ } *function = new MemFnTimerImplZero (memPtr, objPtr);
+ delete m_impl;
+ m_impl = function;
+}
+
+
+
+template <typename MEM_PTR, typename OBJ_PTR,
+ typename T1>
+void
+Timer::SetFunction (MEM_PTR memPtr, OBJ_PTR objPtr, T1 a1)
+{
+ struct MemFnTimerImplZero : public TimerImpl
+ {
+ MemFnTimerImplZero (MEM_PTR memPtr, OBJ_PTR objPtr)
+ : m_memPtr (memPtr), m_objPtr (objPtr) {}
+ virtual void SetArguments (typename TimerTraits<T1>::ParameterType a1) {
+ m_a1 = a1;
+ }
+ virtual EventId Schedule (const Time &delay) {
+ return Simulator::Schedule (delay, m_memPtr, m_objPtr, m_a1);
+ }
+ MEM_PTR m_memPtr;
+ OBJ_PTR m_objPtr;
+ typename TimerTraits<T1>::StoredType m_a1;
+ } *function = new MemFnTimerImplZero (memPtr, objPtr);
+ function->SetArguments (a1);
+ delete m_impl;
+ m_impl = function;
+}
+