--- a/src/simulator/nstime.h Thu Feb 01 18:50:58 2007 +0100
+++ b/src/simulator/nstime.h Thu Feb 01 18:52:55 2007 +0100
@@ -23,6 +23,7 @@
#include <stdint.h>
#include <cassert>
+#include <ostream>
#include "high-precision.h"
namespace ns3 {
@@ -110,6 +111,7 @@
* stored in this Time<N> type.
*/
HighPrecision GetHighPrecision (void) const;
+ HighPrecision *PeekHighPrecision (void);
private:
HighPrecision m_data;
@@ -142,6 +144,12 @@
return m_data;
}
template <int N>
+HighPrecision *
+TimeUnit<N>::PeekHighPrecision (void)
+{
+ return &m_data;
+}
+template <int N>
bool
TimeUnit<N>::IsZero (void) const
{
@@ -180,6 +188,12 @@
}
template <int N>
bool
+operator != (TimeUnit<N> const &lhs, TimeUnit<N> const &rhs)
+{
+ return lhs.GetHighPrecision ().Compare (rhs.GetHighPrecision ()) != 0;
+}
+template <int N>
+bool
operator <= (TimeUnit<N> const &lhs, TimeUnit<N> const &rhs)
{
return lhs.GetHighPrecision ().Compare (rhs.GetHighPrecision ()) <= 0;
@@ -230,6 +244,19 @@
retval.Div (rhs.GetHighPrecision ());
return TimeUnit<N1-N2> (retval);
}
+template <int N>
+TimeUnit<N> &operator += (TimeUnit<N> &lhs, TimeUnit<N> const &rhs) {
+ HighPrecision *lhsv = lhs.PeekHighPrecision ();
+ lhsv->Add (rhs.GetHighPrecision ());
+ return lhs;
+}
+template <int N>
+TimeUnit<N> &operator -= (TimeUnit<N> &lhs, TimeUnit<N> const &rhs) {
+ HighPrecision *lhsv = lhs.PeekHighPrecision ();
+ lhsv->Sub (rhs.GetHighPrecision ());
+ return lhs;
+}
+
/**
* \anchor ns3-Time-Abs
@@ -301,6 +328,9 @@
public:
Time ();
Time (TimeUnit<1> time);
+ Time (HighPrecision const& value);
+
+ static Time Seconds (double seconds);
/**
* \returns an approximation in seconds of the time stored in this
@@ -324,6 +354,8 @@
int64_t GetNanoSeconds (void) const;
};
+std::ostream& operator<< (std::ostream& os, Time const& time);
+
/**
* \brief create ns3::Time instances in units of seconds.
*
@@ -333,12 +365,7 @@
* Simulator::Schedule (NanoSeconds (5.0), ...);
* \endcode
*/
-class Seconds : public TimeUnit<1>
-{
-public:
- Seconds ();
- Seconds (double seconds);
-};
+Time Seconds (double seconds);
/**
* \brief create ns3::Time instances in units of milliseconds.
@@ -349,12 +376,7 @@
* Simulator::Schedule (MilliSeconds (5), ...);
* \endcode
*/
-class MilliSeconds : public TimeUnit<1>
-{
-public:
- MilliSeconds ();
- MilliSeconds (uint32_t ms);
-};
+Time MilliSeconds (uint32_t ms);
/**
* \brief create ns3::Time instances in units of microseconds.
*
@@ -364,12 +386,7 @@
* Simulator::Schedule (MicroSeconds (5), ...);
* \endcode
*/
-class MicroSeconds : public TimeUnit<1>
-{
-public:
- MicroSeconds ();
- MicroSeconds (uint64_t ms);
-};
+Time MicroSeconds (uint64_t us);
/**
* \brief create ns3::Time instances in units of nanoseconds.
*
@@ -379,12 +396,7 @@
* Simulator::Schedule (NanoSeconds (5), ...);
* \endcode
*/
-class NanoSeconds : public TimeUnit<1>
-{
-public:
- NanoSeconds ();
- NanoSeconds (uint64_t ms);
-};
+Time NanoSeconds (uint64_t ns);
/**
* \brief create an ns3::Time instance which contains the
@@ -392,16 +404,12 @@
*
* This is really a shortcut for the ns3::Simulator::Now method.
* It is typically used as shown below to schedule an event
- * which expires in 2 seconds from now:
+ * which expires at the absolute time "2 seconds":
* \code
- * Simulator::Schedule (Seconds (2.0), &my_function);
+ * Simulator::Schedule (Seconds (2.0) - Now (), &my_function);
* \endcode
*/
-class Now : public Time
-{
-public:
- Now ();
-};
+Time Now (void);
/**
* \brief hold scalar values