From b4e41a481bce8e1cba55b38bf6679b50dacbab64 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 21 Nov 2006 15:50:09 +0100 Subject: [PATCH] make Time relative instead of Absolute --- samples/main-simulator.cc | 4 ++-- src/simulator/nstime.h | 10 +++++----- src/simulator/simulator.cc | 10 +++++----- utils/bench-simulator.cc | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/samples/main-simulator.cc b/samples/main-simulator.cc index fa63f8e70..81764f6a8 100644 --- a/samples/main-simulator.cc +++ b/samples/main-simulator.cc @@ -15,7 +15,7 @@ private: void MyModel::Start (void) { - Simulator::Schedule (Now () + Seconds (10.0), + Simulator::Schedule (Seconds (10.0), &MyModel::DealWithEvent, this, Simulator::Now ().ApproximateToSeconds ()); } @@ -39,7 +39,7 @@ int main (int argc, char *argv[]) { MyModel model; - Simulator::Schedule (Now () + Seconds (10.0), &random_function, &model); + Simulator::Schedule (Seconds (10.0), &random_function, &model); Simulator::Run (); diff --git a/src/simulator/nstime.h b/src/simulator/nstime.h index 32b390981..37d1c634f 100644 --- a/src/simulator/nstime.h +++ b/src/simulator/nstime.h @@ -331,7 +331,7 @@ public: * For example: * \code * Time t = Seconds (2.0); - * Simulator::Schedule (Now () + NanoSeconds (5.0), ...); + * Simulator::Schedule (NanoSeconds (5.0), ...); * \endcode */ class Seconds : public TimeUnit<1> @@ -347,7 +347,7 @@ public: * For example: * \code * Time t = MilliSeconds (2); - * Simulator::Schedule (Now () + MilliSeconds (5), ...); + * Simulator::Schedule (MilliSeconds (5), ...); * \endcode */ class MilliSeconds : public TimeUnit<1> @@ -362,7 +362,7 @@ public: * For example: * \code * Time t = MicroSeconds (2); - * Simulator::Schedule (Now () + MicroSeconds (5), ...); + * Simulator::Schedule (MicroSeconds (5), ...); * \endcode */ class MicroSeconds : public TimeUnit<1> @@ -377,7 +377,7 @@ public: * For example: * \code * Time t = NanoSeconds (2); - * Simulator::Schedule (Now () + NanoSeconds (5), ...); + * Simulator::Schedule (NanoSeconds (5), ...); * \endcode */ class NanoSeconds : public TimeUnit<1> @@ -395,7 +395,7 @@ public: * It is typically used as shown below to schedule an event * which expires in 2 seconds from now: * \code - * Simulator::Schedule (Now () + Seconds (2.0), &my_function); + * Simulator::Schedule (Seconds (2.0), &my_function); * \endcode */ class Now : public Time diff --git a/src/simulator/simulator.cc b/src/simulator/simulator.cc index 9493d5e75..e78412c44 100644 --- a/src/simulator/simulator.cc +++ b/src/simulator/simulator.cc @@ -394,7 +394,7 @@ Simulator::MakeEvent (void (*f) (void)) EventId Simulator::Schedule (Time const &time, EventImpl *ev) { - return GetPriv ()->Schedule (time, ev); + return GetPriv ()->Schedule (Now () + time, ev); } void Simulator::ScheduleNow (EventImpl *ev) @@ -517,7 +517,7 @@ SimulatorTests::B (int b) m_b = true; } Simulator::Remove (m_idC); - Simulator::Schedule (Now () + MicroSeconds (10), &SimulatorTests::D, this, 4); + Simulator::Schedule (MicroSeconds (10), &SimulatorTests::D, this, 4); } void SimulatorTests::C (int c) @@ -564,9 +564,9 @@ SimulatorTests::RunOneTest (void) m_c = true; m_d = false; - EventId a = Simulator::Schedule (Now () + MicroSeconds (10), &SimulatorTests::A, this, 1); - Simulator::Schedule (Now () + MicroSeconds (11), &SimulatorTests::B, this, 2); - m_idC = Simulator::Schedule (Now () + MicroSeconds (12), &SimulatorTests::C, this, 3); + EventId a = Simulator::Schedule (MicroSeconds (10), &SimulatorTests::A, this, 1); + Simulator::Schedule (MicroSeconds (11), &SimulatorTests::B, this, 2); + m_idC = Simulator::Schedule (MicroSeconds (12), &SimulatorTests::C, this, 3); Simulator::Cancel (a); Simulator::Run (); diff --git a/utils/bench-simulator.cc b/utils/bench-simulator.cc index 567ca4c8b..ccc06d6bd 100644 --- a/utils/bench-simulator.cc +++ b/utils/bench-simulator.cc @@ -73,7 +73,7 @@ Bench::RunBench (void) time.Start (); for (std::vector::const_iterator i = m_distribution.begin (); i != m_distribution.end (); i++) { - Simulator::Schedule (Now () + NanoSeconds (*i), &Bench::Cb, this); + Simulator::Schedule (NanoSeconds (*i), &Bench::Cb, this); } init = time.End (); @@ -105,7 +105,7 @@ Bench::Cb (void) if (gDebug) { std::cerr << "event at " << Simulator::Now ().ApproximateToSeconds () << "s" << std::endl; } - Simulator::Schedule (Now () + NanoSeconds (*m_current), &Bench::Cb, this); + Simulator::Schedule (NanoSeconds (*m_current), &Bench::Cb, this); m_current++; m_n++; }