re-introduce Scalar class
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Wed, 14 Jul 2010 21:45:31 +0200
changeset 6518 687b051c3039
parent 6517 a0a4bad73684
child 6519 ba4b2956bd42
re-introduce Scalar class
src/simulator/nstime.h
src/simulator/time.cc
--- a/src/simulator/nstime.h	Wed Jul 14 21:43:55 2010 +0200
+++ b/src/simulator/nstime.h	Wed Jul 14 21:45:31 2010 +0200
@@ -178,34 +178,6 @@
   explicit inline Time (const HighPrecision &data)
     : m_data (data)
   {}
-  inline Time (double v)
-    : m_data (HighPrecision (v))
-  {}
-  inline Time (int64_t v)
-    : m_data (HighPrecision (v, false))
-  {}
-  inline Time (uint64_t v)
-    : m_data (HighPrecision (v, false))
-  {}
-  inline Time (int32_t v)
-    : m_data (HighPrecision (v, false))
-  {}
-  inline Time (uint32_t v)
-    : m_data (HighPrecision (v, false))
-  {}
-  inline Time (int16_t v)
-    : m_data (HighPrecision (v, false))
-  {}
-  inline Time (uint16_t v)
-    : m_data (HighPrecision (v, false))
-  {}
-  inline Time (int8_t v)
-    : m_data (HighPrecision (v, false))
-  {}
-  inline Time (uint8_t v)
-    : m_data (HighPrecision (v, false))
-  {}
-
 
   /**
    * \brief String constructor
@@ -340,14 +312,6 @@
     int64_t timeValue = m_data.GetInteger ();
     return timeValue;
   }
-  inline double GetDouble (void) const
-  {
-    return m_data.GetDouble ();
-  }
-  inline int64_t GetInteger (void) const
-  {
-    return GetTimeStep ();
-  }
 
 
   /**
@@ -698,7 +662,42 @@
   return Time (HighPrecision (ts, false));
 }
 
-typedef Time Scalar;
+class Scalar
+{
+public:
+  inline Scalar ()
+    : m_v (0.0)
+  {}
+  explicit inline Scalar (double v)
+    : m_v (v)
+  {}
+  explicit inline Scalar (uint32_t v)
+    : m_v (v)
+  {}
+  explicit inline Scalar (int32_t v)
+    : m_v (v)
+  {}
+  explicit inline Scalar (uint64_t v)
+    : m_v (v)
+  {}
+  explicit inline Scalar (int64_t v)
+    : m_v (v)
+  {}
+  inline Scalar (Time t)
+    : m_v (t.GetHighPrecision ().GetDouble ())
+  {}
+  inline operator Time ()
+  {
+    return Time (HighPrecision (m_v));
+  }
+  inline double GetDouble (void) const
+  {
+    return m_v;
+  }
+private:
+  double m_v;
+};
+
 typedef Time TimeInvert;
 typedef Time TimeSquare;
 
--- a/src/simulator/time.cc	Wed Jul 14 21:43:55 2010 +0200
+++ b/src/simulator/time.cc	Wed Jul 14 21:45:31 2010 +0200
@@ -252,6 +252,44 @@
   Time::SetResolution (m_originalResolution);
 }
 
+class ArithTestCase : public TestCase
+{
+public:
+  ArithTestCase ();
+private:
+  virtual bool DoRun (void);
+};
+
+ArithTestCase::ArithTestCase ()
+  : TestCase ("check arithmetic operators")
+{
+}
+bool 
+ArithTestCase::DoRun (void)
+{
+  Time a, b, c;
+  c = a + b;
+  c = a * b;
+  c = a / Seconds (1.0);
+  c = a - b;
+  c += a;
+  c -= a;
+  c /= Seconds (1.0);
+  c *= a;
+  bool x;
+  x = a < b;
+  x = a > b;
+  x = a <= b;
+  x = a >= b;
+  x = a == b;
+  x = a != b;
+  //a = 1.0;
+  //a = 1;
+  return false;
+}
+
+
+
 static class TimeTestSuite : public TestSuite
 {
 public:
@@ -260,6 +298,7 @@
   {
     AddTestCase (new Bug863TestCase ());
     AddTestCase (new TimeSimpleTestCase (Time::US));
+    AddTestCase (new ArithTestCase ());
   }
 } g_timeTestSuite;