From aa2ba3ea2799877dbe4d66834eaaf2ee669e42bb Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 1 Nov 2006 13:27:32 +0100 Subject: [PATCH] add Scale/Min/Max/Abs non-member functions --- src/simulator/nstime.h | 6 ++++++ src/simulator/time.cc | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/simulator/nstime.h b/src/simulator/nstime.h index 89f41be44..5009969ea 100644 --- a/src/simulator/nstime.h +++ b/src/simulator/nstime.h @@ -57,6 +57,12 @@ class Time { int64_t m_ns; }; +Time Scale (Time const &time, double scale); +Time Abs (Time const &time); +Time Max (Time const &a, Time const &b); +Time Min (Time const &a, Time const &b); + + Time operator + (Time const &lhs, Time const &rhs); Time operator - (Time const &lhs, Time const &rhs); bool operator == (Time const &lhs, Time const &rhs); diff --git a/src/simulator/time.cc b/src/simulator/time.cc index 358144e9f..7da6cd4ec 100644 --- a/src/simulator/time.cc +++ b/src/simulator/time.cc @@ -118,6 +118,32 @@ GetNs (Time const &time) return time.ApproximateToNanoSeconds (); } +Time Scale (Time const &time, double scale) +{ + return NanoSeconds ((int64_t) (GetNs (time) * scale)); +} +Time Abs (Time const &time) +{ + int64_t retval = GetNs (time); + retval = (retval<0)?(-retval):(retval); + return NanoSeconds (retval); +} +Time Max (Time const &ta, Time const &tb) +{ + int64_t a = GetNs (ta); + int64_t b = GetNs (tb); + int64_t retval = (a>b)?(a):(b); + return NanoSeconds (retval); +} +Time Min (Time const &ta, Time const &tb) +{ + int64_t a = GetNs (ta); + int64_t b = GetNs (tb); + int64_t retval = (a