--- a/src/node/onoff-application.cc Sun Mar 25 15:33:24 2007 -0700
+++ b/src/node/onoff-application.cc Sun Mar 25 15:35:08 2007 -0700
@@ -60,7 +60,7 @@
m_cbrRate(rate),
m_pktSize(size),
m_residualBits(0),
- m_lastStartTime(0),
+ m_lastStartTime((HighPrecision)0),
m_maxBytes(0xffffffff),
m_totBytes(0),
m_startStopScheduled(false),
--- a/src/simulator/nstime.h Sun Mar 25 15:33:24 2007 -0700
+++ b/src/simulator/nstime.h Sun Mar 25 15:35:08 2007 -0700
@@ -309,6 +309,21 @@
public:
/**
+ * \brief String constructor
+ * Construct TimeUnit<1> object from common time expressions like "
+ * 1ms" or "10s". Supported units include:
+ * - s (seconds)
+ * - ms (milliseconds)
+ * - us (microseconds)
+ * - ns (nanoseconds)
+ *
+ * There can be no white space between the numerical portion
+ * and the units. Any otherwise malformed string causes a fatal error to
+ * occur.
+ * \param s The string to parse into a TimeUnit<1>
+ */
+ TimeUnit<1>(const std::string& s);
+ /**
* \returns an approximation in seconds of the time stored in this
* instance.
*/
--- a/src/simulator/time.cc Sun Mar 25 15:33:24 2007 -0700
+++ b/src/simulator/time.cc Sun Mar 25 15:35:08 2007 -0700
@@ -20,9 +20,43 @@
*/
#include "time.h"
#include "simulator.h"
+#include "ns3/fatal-error.h"
namespace ns3 {
+TimeUnit<1>::TimeUnit(const std::string& s)
+{
+ std::string::size_type n = s.find_first_not_of("0123456789.");
+ if (n != std::string::npos)
+ { // Found non-numeric
+ double r = atof(s.substr(0, n).c_str());
+ std::string trailer = s.substr(n, std::string::npos);
+ if (trailer == std::string("s"))
+ {
+ m_data = HighPrecision (r * 1000000000.0);
+ return;
+ }
+ if (trailer == std::string("ms"))
+ {
+ m_data = HighPrecision ((int64_t)(r * 1000000), false);
+ return;
+ }
+ if (trailer == std::string("us"))
+ {
+ m_data = HighPrecision ((int64_t)(r * 1000), false);
+ return;
+ }
+ if (trailer == std::string("ns"))
+ {
+ m_data = HighPrecision ((int64_t)r, false);
+ return;
+ }
+ NS_FATAL_ERROR("Can't Parse Time "<<s);
+ }
+ //else
+ //they didn't provide units, assume seconds
+ m_data = HighPrecision (atof(s.c_str()) * 1000000000.0);
+}
double
TimeUnit<1>::GetSeconds (void) const
{