src/simulator/time.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Fri, 02 Feb 2007 19:14:16 +0100
changeset 212 e6c88c1bcc85
parent 211 395e8b0d32a9
child 215 462cdd13a69e
permissions -rw-r--r--
added useless Time::Seconds method when doing testing for the removal of the Seconds class. Remove it.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 144
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
25
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     2
/*
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     3
 * Copyright (c) 2005,2006 INRIA
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     4
 * All rights reserved.
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     5
 *
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     6
 * This program is free software; you can redistribute it and/or modify
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     7
 * it under the terms of the GNU General Public License version 2 as
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     8
 * published by the Free Software Foundation;
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
 *
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    13
 * GNU General Public License for more details.
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    14
 *
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    16
 * along with this program; if not, write to the Free Software
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    18
 *
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    19
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
 */
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    21
#include "time.h"
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    22
#include "simulator.h"
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    23
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    24
namespace ns3 {
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    25
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    26
Time::Time ()
156
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
    27
  : TimeUnit<1> ()
25
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    28
{}
156
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
    29
Time::Time (TimeUnit<1> time)
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
    30
  : TimeUnit<1> (time)
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
    31
{}
209
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
    32
Time::Time (HighPrecision const& value)
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
    33
  : TimeUnit<1> (value)
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
    34
{}
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
    35
143
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    36
double 
163
2a7e05018eeb rename Time::ApproximateTo methods to Time::Get
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 161
diff changeset
    37
Time::GetSeconds (void) const
36
e622fb7a8262 use ns as internal time and export time as ns.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 25
diff changeset
    38
{
156
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
    39
  HighPrecision seconds = GetHighPrecision ();
170
9f68cb694f40 implement 128 bit arithmetic with cairo's internal types
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 163
diff changeset
    40
  seconds.Div (HighPrecision (1000000000, false));
156
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
    41
  return seconds.GetDouble ();
25
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    42
}
156
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
    43
int32_t 
163
2a7e05018eeb rename Time::ApproximateTo methods to Time::Get
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 161
diff changeset
    44
Time::GetMilliSeconds (void) const
36
e622fb7a8262 use ns as internal time and export time as ns.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 25
diff changeset
    45
{
156
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
    46
  HighPrecision ms = GetHighPrecision ();
170
9f68cb694f40 implement 128 bit arithmetic with cairo's internal types
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 163
diff changeset
    47
  ms.Div (HighPrecision (1000000, false));
9f68cb694f40 implement 128 bit arithmetic with cairo's internal types
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 163
diff changeset
    48
  return (int32_t) ms.GetInteger ();
143
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    49
}
144
f07f6fb0f660 fix Time::ApproximateTo* return type
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
    50
int64_t 
163
2a7e05018eeb rename Time::ApproximateTo methods to Time::Get
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 161
diff changeset
    51
Time::GetMicroSeconds (void) const
143
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    52
{
156
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
    53
  HighPrecision us = GetHighPrecision ();
170
9f68cb694f40 implement 128 bit arithmetic with cairo's internal types
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 163
diff changeset
    54
  us.Div (HighPrecision (1000, false));
9f68cb694f40 implement 128 bit arithmetic with cairo's internal types
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 163
diff changeset
    55
  return us.GetInteger ();
36
e622fb7a8262 use ns as internal time and export time as ns.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 25
diff changeset
    56
}
144
f07f6fb0f660 fix Time::ApproximateTo* return type
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
    57
int64_t 
163
2a7e05018eeb rename Time::ApproximateTo methods to Time::Get
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 161
diff changeset
    58
Time::GetNanoSeconds (void) const
25
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    59
{
170
9f68cb694f40 implement 128 bit arithmetic with cairo's internal types
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 163
diff changeset
    60
  return GetHighPrecision ().GetInteger ();
36
e622fb7a8262 use ns as internal time and export time as ns.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 25
diff changeset
    61
}
143
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    62
209
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
    63
std::ostream& 
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
    64
operator<< (std::ostream& os, Time const& time)
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
    65
{
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
    66
  os << time.GetNanoSeconds () << "ns";
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
    67
  return os;
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
    68
}
143
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    69
209
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
    70
Time Seconds (double seconds)
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
    71
{
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
    72
  return Time (HighPrecision (seconds * 1000000000.0));
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
    73
}
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
    74
Time MilliSeconds (uint32_t ms)
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
    75
{
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
    76
  return Time (HighPrecision (ms * 1000000, false));
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
    77
}
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
    78
Time MicroSeconds (uint64_t us)
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
    79
{
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
    80
  return Time (HighPrecision (us * 1000, false));
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
    81
}
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
    82
Time NanoSeconds (uint64_t ns)
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
    83
{
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
    84
  return Time (HighPrecision (ns, false));
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
    85
}
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
    86
Time Now (void)
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
    87
{
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
    88
  return Time (Simulator::Now ());
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
    89
}
156
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
    90
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
    91
Scalar::Scalar ()
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
    92
  : TimeUnit<0> ()
143
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    93
{}
156
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
    94
Scalar::Scalar (TimeUnit<0> scalar)
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
    95
  : TimeUnit<0> (scalar)
143
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    96
{}
156
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
    97
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
    98
Scalar::Scalar (double scalar)
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
    99
  : TimeUnit<0> (HighPrecision (scalar))
143
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   100
{}
156
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   101
158
47af319de4b8 implement Scalar::GetDouble
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 157
diff changeset
   102
double
47af319de4b8 implement Scalar::GetDouble
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 157
diff changeset
   103
Scalar::GetDouble (void) const
47af319de4b8 implement Scalar::GetDouble
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 157
diff changeset
   104
{
47af319de4b8 implement Scalar::GetDouble
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 157
diff changeset
   105
  return GetHighPrecision ().GetDouble ();
47af319de4b8 implement Scalar::GetDouble
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 157
diff changeset
   106
}
47af319de4b8 implement Scalar::GetDouble
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 157
diff changeset
   107
156
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   108
}; // namespace ns3
143
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   109
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   110
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   111
#ifdef RUN_SELF_TESTS
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   112
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   113
#include "ns3/test.h"
211
395e8b0d32a9 add a few more tests for the Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 209
diff changeset
   114
//#include <iostream>
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   115
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   116
namespace ns3 {
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   117
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   118
class TimeTests : public Test
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   119
{
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   120
public:
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   121
  TimeTests ();
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   122
  virtual ~TimeTests ();
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   123
  virtual bool RunTests (void);
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   124
};
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   125
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   126
TimeTests::TimeTests ()
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   127
  : Test ("Time")
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   128
{}
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   129
TimeTests::~TimeTests ()
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   130
{}
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   131
bool TimeTests::RunTests (void)
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   132
{
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   133
  bool ok = true;
176
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   134
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   135
  Time t0 = Seconds (10.0);
176
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   136
  //std::cout << "t0="<<t0.GetSeconds ()<<" (expected 10.0)"<<std::endl;
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   137
  Time t1 = Seconds (11.0);
176
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   138
  //std::cout << "t1="<<t1.GetSeconds ()<<" (expected 11.0)"<<std::endl;
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   139
  t0 = Seconds (1.5);
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   140
  //std::cout << "t0="<<t0.GetSeconds ()<<" (expected +1.5)"<<std::endl;
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   141
  t0 = Seconds (-1.5);
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   142
  //std::cout << "t0="<<t0.GetSeconds ()<<" (expected -1.5)"<<std::endl;
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   143
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   144
  t0 = Seconds (10.0);
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   145
  t1 = Seconds (11.0);
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   146
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   147
  Time t2, t3;
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   148
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   149
  t2 = t1 - t0;
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   150
  if (!t2.IsStrictlyPositive ())
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   151
    {
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   152
      ok = false;
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   153
    }
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   154
  t2 = t1 - t1;
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   155
  if (!t2.IsZero ())
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   156
    {
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   157
      ok = false;
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   158
    }
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   159
  t2 = t0 - t1;
176
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   160
  if (!t2.IsStrictlyNegative ())
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   161
    {
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   162
      ok = false;
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   163
    }
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   164
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   165
  t2 = t0 - t1;
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   166
  t3 = t2 * t0 / t1;
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   167
  t3 = t0 * t2 / t1;
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   168
  t3 = t0 * t1 / t2;
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   169
  t3 = t0 * (t1 / t2);
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   170
  t3 = (t0 * t1) / t2;
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   171
  t3 = t0 / t1 * t2;
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   172
  t3 = (t0 / t1) * t2;
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   173
  TimeInvert ti0 = t0 / (t1 * t2);
176
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   174
  t3 = t0 * Scalar (10.0);
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   175
  t3 = Scalar (10.0) * t0;
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   176
  t3 = Scalar (10.0) * t0 / t2 * t1;
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   177
  t3 = (Scalar (10.0) * t0 ) / t2 * t1;
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   178
  Scalar s0 = t0 / t1;
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   179
  Scalar s1;
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   180
  s1 = t0 * t1 / (t2 * t0);
161
c3aee00484fc more tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   181
  TimeUnit<0> tu0 = s0;
c3aee00484fc more tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   182
  TimeUnit<1> tu1 = t0;
c3aee00484fc more tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   183
  TimeUnit<2> tu2 = t0 * t1;
c3aee00484fc more tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   184
  TimeUnit<3> tu3 = t0 * tu2;
c3aee00484fc more tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   185
  TimeUnit<-2> tu4 = t0 / tu3;
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   186
211
395e8b0d32a9 add a few more tests for the Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 209
diff changeset
   187
  Time tmp = MilliSeconds (0);
395e8b0d32a9 add a few more tests for the Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 209
diff changeset
   188
  if ((tmp != NanoSeconds (0)) ||
395e8b0d32a9 add a few more tests for the Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 209
diff changeset
   189
      (tmp > NanoSeconds (0)) ||
395e8b0d32a9 add a few more tests for the Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 209
diff changeset
   190
      (tmp < NanoSeconds (0)))
395e8b0d32a9 add a few more tests for the Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 209
diff changeset
   191
    {
395e8b0d32a9 add a few more tests for the Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 209
diff changeset
   192
      ok = false;
395e8b0d32a9 add a few more tests for the Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 209
diff changeset
   193
    }
395e8b0d32a9 add a few more tests for the Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 209
diff changeset
   194
176
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   195
  Time t4 = Seconds (10.0) * Scalar (1.5);
211
395e8b0d32a9 add a few more tests for the Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 209
diff changeset
   196
  //std::cout << "10.0s * 1.5 = " << t4.GetSeconds () << "s" << std::endl;
176
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   197
  Time t5 = NanoSeconds (10) * Scalar (1.5);
211
395e8b0d32a9 add a few more tests for the Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 209
diff changeset
   198
  //std::cout << "10ns * 1.5 = " << t5.GetNanoSeconds () << "ns" << std::endl;
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   199
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   200
  return ok;
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   201
}
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   202
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   203
static TimeTests g_time_tests;
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   204
  
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   205
};
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   206
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   207
#endif /* RUN_SELF_TESTS */