src/simulator/time.cc
author Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
Tue, 26 Aug 2008 12:25:08 +0100
changeset 3554 6d041a5be1db
parent 3365 6409d2460601
child 4045 8b99076fcd96
permissions -rw-r--r--
Bridge documentation (#286)
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
680
0bbe0e4d73c6 add reference to Emmanuelle in Authors/Copyright
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 679
diff changeset
     4
 * Copyright (c) 2007 Emmanuelle Laprise
25
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>
680
0bbe0e4d73c6 add reference to Emmanuelle in Authors/Copyright
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 679
diff changeset
    20
 * TimeStep support by Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
25
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    21
 */
679
0c4773ca0f29 avoid cyclic dependency between Simulator and Time code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 678
diff changeset
    22
#include "nstime.h"
372
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    23
#include "ns3/fatal-error.h"
2577
5b41cb5c3fcf kill DefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2447
diff changeset
    24
#include "ns3/global-value.h"
5b41cb5c3fcf kill DefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2447
diff changeset
    25
#include "ns3/enum.h"
5b41cb5c3fcf kill DefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2447
diff changeset
    26
#include "ns3/string.h"
2390
7e6dfae536cd add Value support to Time
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2170
diff changeset
    27
#include "ns3/object.h"
2577
5b41cb5c3fcf kill DefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2447
diff changeset
    28
#include "ns3/config.h"
679
0c4773ca0f29 avoid cyclic dependency between Simulator and Time code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 678
diff changeset
    29
#include <math.h>
25
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    30
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    31
namespace ns3 {
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    32
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    33
namespace TimeStepPrecision {
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    34
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
    35
static const uint64_t MS_FACTOR = (uint64_t)pow(10,3);
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
    36
static const uint64_t US_FACTOR = (uint64_t)pow(10,6);
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
    37
static const uint64_t NS_FACTOR = (uint64_t)pow(10,9);
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
    38
static const uint64_t PS_FACTOR = (uint64_t)pow(10,12);
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
    39
static const uint64_t FS_FACTOR = (uint64_t)pow(10,15);
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    40
static uint64_t g_tsPrecFactor = NS_FACTOR;
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
    41
2577
5b41cb5c3fcf kill DefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2447
diff changeset
    42
static GlobalValue g_precisionDefaultValue ("TimeStepPrecision", 
5b41cb5c3fcf kill DefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2447
diff changeset
    43
                                            "The time unit of the internal 64 bit integer time.",
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2953
diff changeset
    44
                                            EnumValue (NS),
2577
5b41cb5c3fcf kill DefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2447
diff changeset
    45
                                            MakeEnumChecker (NS, "NS",
5b41cb5c3fcf kill DefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2447
diff changeset
    46
                                                             S, "S",
5b41cb5c3fcf kill DefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2447
diff changeset
    47
                                                             MS, "MS",
5b41cb5c3fcf kill DefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2447
diff changeset
    48
                                                             US, "US",
5b41cb5c3fcf kill DefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2447
diff changeset
    49
                                                             PS, "PS",
5b41cb5c3fcf kill DefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2447
diff changeset
    50
                                                             FS, "FS")
5b41cb5c3fcf kill DefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2447
diff changeset
    51
                                            );
684
333ec02c9cc9 add DefaultValue support for TimeStepPrecision
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 680
diff changeset
    52
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    53
precision_t
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    54
Get (void)
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
    55
{
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2953
diff changeset
    56
  EnumValue v;
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2953
diff changeset
    57
  g_precisionDefaultValue.GetValue (v);
2577
5b41cb5c3fcf kill DefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2447
diff changeset
    58
  return (precision_t) v.Get ();
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
    59
}
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
    60
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
    61
void 
684
333ec02c9cc9 add DefaultValue support for TimeStepPrecision
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 680
diff changeset
    62
Set (precision_t precision)
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
    63
{
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2953
diff changeset
    64
  g_precisionDefaultValue.SetValue (EnumValue (precision));
684
333ec02c9cc9 add DefaultValue support for TimeStepPrecision
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 680
diff changeset
    65
  g_tsPrecFactor = (uint64_t)pow(10, precision);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
    66
}
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
    67
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    68
} // namespace TimeStepPrecision
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    69
372
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    70
TimeUnit<1>::TimeUnit(const std::string& s)
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    71
{
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    72
  std::string::size_type n = s.find_first_not_of("0123456789.");
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    73
  if (n != std::string::npos)
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    74
  { // Found non-numeric
3365
6409d2460601 bug 245: build failure with gcc 4.3.x
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3188
diff changeset
    75
    std::istringstream iss;
6409d2460601 bug 245: build failure with gcc 4.3.x
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3188
diff changeset
    76
    iss.str (s.substr(0, n));
6409d2460601 bug 245: build failure with gcc 4.3.x
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3188
diff changeset
    77
    double r;
6409d2460601 bug 245: build failure with gcc 4.3.x
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3188
diff changeset
    78
    iss >> r;
372
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    79
    std::string trailer = s.substr(n, std::string::npos);
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    80
    if (trailer == std::string("s"))
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    81
    {
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    82
      m_data = HighPrecision (r * TimeStepPrecision::g_tsPrecFactor);
372
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    83
      return;
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    84
    }
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    85
    if (trailer == std::string("ms"))
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    86
    {
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    87
      m_data = HighPrecision ((int64_t)(r * (TimeStepPrecision::g_tsPrecFactor/pow(10,3))), 
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
    88
                              false);
372
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    89
      return;
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    90
    }
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    91
    if (trailer == std::string("us"))
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    92
    {
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    93
      m_data = HighPrecision ((int64_t)(r * (TimeStepPrecision::g_tsPrecFactor/pow(10,6))), 
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
    94
                              false);
372
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    95
      return;
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    96
    }
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    97
    if (trailer == std::string("ns"))
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    98
    {
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    99
      m_data = HighPrecision ((int64_t)(r * (TimeStepPrecision::g_tsPrecFactor/pow(10,9))), 
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   100
                              false);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   101
      return;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   102
    }
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   103
    if (trailer == std::string("ps"))
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   104
    {
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   105
      m_data = HighPrecision ((int64_t)(r * (TimeStepPrecision::g_tsPrecFactor/pow(10,12))), 
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   106
                              false);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   107
      return;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   108
    }
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   109
    if (trailer == std::string("fs"))
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   110
    {
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   111
      m_data = HighPrecision ((int64_t)(r * (TimeStepPrecision::g_tsPrecFactor/pow(10,15))), 
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   112
                              false);
372
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
   113
      return;
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
   114
    }
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
   115
    NS_FATAL_ERROR("Can't Parse Time "<<s);
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
   116
  }
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
   117
  //else
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
   118
  //they didn't provide units, assume seconds
3365
6409d2460601 bug 245: build failure with gcc 4.3.x
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3188
diff changeset
   119
  std::istringstream iss;
6409d2460601 bug 245: build failure with gcc 4.3.x
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3188
diff changeset
   120
  iss. str (s);
6409d2460601 bug 245: build failure with gcc 4.3.x
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3188
diff changeset
   121
  double v;
6409d2460601 bug 245: build failure with gcc 4.3.x
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3188
diff changeset
   122
  iss >> v;
6409d2460601 bug 245: build failure with gcc 4.3.x
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3188
diff changeset
   123
  m_data = HighPrecision (v * TimeStepPrecision::g_tsPrecFactor);
372
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
   124
}
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   125
143
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   126
double 
339
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 229
diff changeset
   127
TimeUnit<1>::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
   128
{
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   129
  double timeValue = GetHighPrecision ().GetDouble ();
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   130
  return timeValue/TimeStepPrecision::g_tsPrecFactor;
25
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   131
}
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   132
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   133
int64_t
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   134
TimeUnit<1>::ConvertToUnits (int64_t timeValue, uint64_t unitFactor) const
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   135
{
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   136
  uint64_t precFactor;
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   137
  // In order to avoid conversion to double, precFactor can't be less 1
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   138
  if (TimeStepPrecision::g_tsPrecFactor < unitFactor)
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   139
    {
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   140
      precFactor = unitFactor / TimeStepPrecision::g_tsPrecFactor;
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   141
      timeValue = timeValue * precFactor;
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   142
    }
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   143
  else
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   144
    {
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   145
      precFactor = TimeStepPrecision::g_tsPrecFactor / unitFactor;
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   146
      timeValue = timeValue / precFactor;
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   147
    }
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   148
  return timeValue;
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   149
}
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   150
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   151
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   152
int64_t 
339
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 229
diff changeset
   153
TimeUnit<1>::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
   154
{
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   155
  int64_t ts = GetTimeStep();
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   156
  int64_t ms = ConvertToUnits(ts, TimeStepPrecision::MS_FACTOR);
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   157
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   158
  return ms;
143
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   159
}
144
f07f6fb0f660 fix Time::ApproximateTo* return type
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
   160
int64_t 
339
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 229
diff changeset
   161
TimeUnit<1>::GetMicroSeconds (void) const
143
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   162
{
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   163
  int64_t ts = GetTimeStep();
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   164
  int64_t us = ConvertToUnits(ts, TimeStepPrecision::US_FACTOR);
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   165
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   166
  return us;
36
e622fb7a8262 use ns as internal time and export time as ns.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 25
diff changeset
   167
}
144
f07f6fb0f660 fix Time::ApproximateTo* return type
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
   168
int64_t 
339
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 229
diff changeset
   169
TimeUnit<1>::GetNanoSeconds (void) const
25
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   170
{
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   171
  int64_t ts = GetTimeStep();
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   172
  int64_t ns = ConvertToUnits(ts, TimeStepPrecision::NS_FACTOR);
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   173
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   174
  return ns;
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   175
}
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   176
int64_t 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   177
TimeUnit<1>::GetPicoSeconds (void) const
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   178
{
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   179
  int64_t ts = GetTimeStep();
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   180
  int64_t ps = ConvertToUnits(ts, TimeStepPrecision::PS_FACTOR);
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   181
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   182
  return ps;
36
e622fb7a8262 use ns as internal time and export time as ns.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 25
diff changeset
   183
}
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   184
int64_t 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   185
TimeUnit<1>::GetFemtoSeconds (void) const
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   186
{
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   187
  int64_t ts = GetTimeStep();
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   188
  int64_t fs = ConvertToUnits(ts, TimeStepPrecision::FS_FACTOR);
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   189
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   190
  return fs;
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   191
}
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   192
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   193
/**
684
333ec02c9cc9 add DefaultValue support for TimeStepPrecision
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 680
diff changeset
   194
 * This returns the value with the precision returned by TimeStepPrecision::Get
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   195
 */
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   196
int64_t
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   197
TimeUnit<1>::GetTimeStep (void) const
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   198
{
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   199
  int64_t timeValue = GetHighPrecision ().GetInteger ();
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   200
  return timeValue;
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   201
}
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   202
143
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   203
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
   204
std::ostream& 
2409
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   205
operator<< (std::ostream& os, const Time & time)
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
   206
{
911
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   207
  std::string unit;
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   208
  switch (TimeStepPrecision::Get ()) {
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   209
  case TimeStepPrecision::S:
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   210
    unit = "s";
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   211
    break;
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   212
  case TimeStepPrecision::MS:
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   213
    unit = "ms";
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   214
    break;
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   215
  case TimeStepPrecision::US:
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   216
    unit = "us";
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   217
    break;
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   218
  case TimeStepPrecision::NS:
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   219
    unit = "ns";
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   220
    break;
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   221
  case TimeStepPrecision::PS:
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   222
    unit = "ps";
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   223
    break;
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   224
  case TimeStepPrecision::FS:
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   225
    unit = "fs";
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   226
    break;
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   227
  }
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   228
  os << time.GetTimeStep () << unit;
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
   229
  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
   230
}
2409
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   231
std::istream& operator>> (std::istream& is, Time & time)
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   232
{
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   233
  std::string value;
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   234
  is >> value;
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   235
  std::string::size_type n = value.find_first_not_of("0123456789.");
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   236
  if (n == std::string::npos)
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   237
    {
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   238
      is.setstate (std::ios_base::failbit);
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   239
      return is;
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   240
    }
2953
db884a56c5c1 -1 cuts the trailing s if the time postfix is longer than 1 char.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2947
diff changeset
   241
  std::string trailer = value.substr(n, value.size ()-n);
2409
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   242
  std::istringstream iss;
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   243
  iss.str (value.substr(0, n));
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   244
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   245
  if (trailer == std::string("s"))
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   246
    {
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   247
      double v;
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   248
      iss >> v;
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   249
      time = Seconds (v);
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   250
      return is;
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   251
    }
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   252
  uint64_t integer;
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   253
  iss >> integer;
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   254
  if (is.bad () || is.fail ())
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   255
    {
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   256
      is.setstate (std::ios_base::failbit);
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   257
    }
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   258
  else if (trailer == std::string("ms"))
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   259
    {
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   260
      time = MilliSeconds (integer);
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   261
    }
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   262
  else if (trailer == std::string("us"))
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   263
    {
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   264
      time = MicroSeconds (integer);
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   265
    }
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   266
  else if (trailer == std::string("ns"))
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   267
    {
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   268
      time = NanoSeconds (integer);
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   269
    }
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   270
  else if (trailer == std::string("ps"))
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   271
    {
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   272
      time = PicoSeconds (integer);
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   273
    }
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   274
  else if (trailer == std::string("fs"))
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   275
    {
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   276
      time = FemtoSeconds (integer);
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   277
    }
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   278
  else
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   279
    {
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   280
      is.setstate (std::ios_base::failbit);
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   281
    }
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   282
  return is;
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   283
}
143
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   284
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
   285
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
   286
{
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   287
  double d_sec = seconds * TimeStepPrecision::g_tsPrecFactor;
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   288
  return Time (HighPrecision (d_sec));
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   289
  //  return Time (HighPrecision ((int64_t)d_sec, false));
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
   290
}
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   291
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   292
uint64_t
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   293
TimeUnit<1>::UnitsToTimestep (uint64_t unitValue, 
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   294
                              uint64_t unitFactor)
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   295
{
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   296
  uint64_t precFactor;
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   297
  // In order to avoid conversion to double, precFactor can't be less 1
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   298
  if (TimeStepPrecision::g_tsPrecFactor < unitFactor)
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   299
    {
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   300
      precFactor = unitFactor / TimeStepPrecision::g_tsPrecFactor;
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   301
      unitValue = unitValue / precFactor;
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   302
    }
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   303
  else
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   304
    {
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   305
      precFactor = TimeStepPrecision::g_tsPrecFactor / unitFactor;
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   306
      unitValue = unitValue * precFactor;
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   307
    }
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   308
  return unitValue;
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   309
}
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   310
2447
eee344085a96 convert to new helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2436
diff changeset
   311
ATTRIBUTE_VALUE_IMPLEMENT (Time);
eee344085a96 convert to new helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2436
diff changeset
   312
ATTRIBUTE_CHECKER_IMPLEMENT (Time);
2427
9245ec163111 split checker from ParamSpec.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2409
diff changeset
   313
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   314
Time MilliSeconds (uint64_t ms)
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
   315
{
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   316
  uint64_t ts = TimeUnit<1>::UnitsToTimestep(ms, TimeStepPrecision::MS_FACTOR);
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   317
  return TimeStep(ts);
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
   318
}
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   319
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
   320
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
   321
{
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   322
  uint64_t ts = TimeUnit<1>::UnitsToTimestep(us, TimeStepPrecision::US_FACTOR);
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   323
  return TimeStep(ts);
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
   324
}
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   325
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
   326
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
   327
{
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   328
  uint64_t ts = TimeUnit<1>::UnitsToTimestep(ns, TimeStepPrecision::NS_FACTOR);
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   329
  return TimeStep(ts);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   330
}
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   331
Time PicoSeconds (uint64_t ps)
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   332
{
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   333
  uint64_t ts = TimeUnit<1>::UnitsToTimestep(ps, TimeStepPrecision::PS_FACTOR);
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   334
  return TimeStep(ts);
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
   335
}
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   336
Time FemtoSeconds (uint64_t fs)
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   337
{
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   338
  uint64_t ts = TimeUnit<1>::UnitsToTimestep(fs, TimeStepPrecision::FS_FACTOR);
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   339
  return TimeStep(ts);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   340
}
2390
7e6dfae536cd add Value support to Time
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2170
diff changeset
   341
7e6dfae536cd add Value support to Time
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2170
diff changeset
   342
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   343
/*
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   344
 * The timestep value passed to this function must be of the precision
684
333ec02c9cc9 add DefaultValue support for TimeStepPrecision
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 680
diff changeset
   345
 * of TimeStepPrecision::Get
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   346
 */
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   347
Time TimeStep (uint64_t ts)
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   348
{
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   349
  return Time (HighPrecision (ts, false));
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   350
}
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   351
339
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 229
diff changeset
   352
TimeUnit<0>::TimeUnit (double scalar)
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 229
diff changeset
   353
  : m_data (HighPrecision (scalar))
143
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   354
{}
156
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   355
158
47af319de4b8 implement Scalar::GetDouble
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 157
diff changeset
   356
double
339
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 229
diff changeset
   357
TimeUnit<0>::GetDouble (void) const
158
47af319de4b8 implement Scalar::GetDouble
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 157
diff changeset
   358
{
47af319de4b8 implement Scalar::GetDouble
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 157
diff changeset
   359
  return GetHighPrecision ().GetDouble ();
47af319de4b8 implement Scalar::GetDouble
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 157
diff changeset
   360
}
47af319de4b8 implement Scalar::GetDouble
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 157
diff changeset
   361
2390
7e6dfae536cd add Value support to Time
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2170
diff changeset
   362
} // namespace ns3
143
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   363
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   364
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   365
#ifdef RUN_SELF_TESTS
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   366
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   367
#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
   368
//#include <iostream>
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   369
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   370
namespace ns3 {
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   371
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   372
class TimeTests : public Test
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   373
{
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   374
public:
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   375
  TimeTests ();
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   376
  virtual ~TimeTests ();
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   377
  virtual bool RunTests (void);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   378
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   379
  /*
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   380
   * Verifies that a calculated time value is as expected using
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   381
   * doubles since GetSeconds() returns a double
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   382
   */ 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   383
  void CheckTimeSec(std::string test_id, double actual, double expected, 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   384
                    bool *flag, double precMultFactor = 1, 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   385
                    bool verbose = false);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   386
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   387
  /*
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   388
   * Verifies that a calculated time value is as expected.
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   389
   */ 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   390
  void CheckTime(std::string test_id, int64_t actual, int64_t expected, 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   391
                 bool *flag, double precMultFactor = 1, 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   392
                 bool verbose = false);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   393
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   394
  /*
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   395
   * Verifies the +, -, * and / operations for the TimeUnit<1> or Time class
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   396
   */
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   397
  void CheckOperations(Time t0, Time t1, bool *ok, bool verbose = false);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   398
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   399
  /*
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   400
   * Verifies that the TimeUnit class stores values with the precision
684
333ec02c9cc9 add DefaultValue support for TimeStepPrecision
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 680
diff changeset
   401
   * set in the variable TimeStepPrecision::Get
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   402
   * Checks that overflow and underflow occur at expected numbers
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   403
   */
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   404
  void CheckPrecision(TimeStepPrecision::precision_t prec, uint64_t val, bool *ok,
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   405
                      bool verbose = false);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   406
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   407
  /*
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   408
   * Verifies that the conversion between units in the class
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   409
   * TimeUnit<1> or Time is done correctly. This is verified both when
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   410
   * setting and retrieving a Time value
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   411
   */
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   412
  void CheckConversions(uint64_t tval, bool *ok, bool verbose = false);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   413
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   414
  /*
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   415
   * These are the old tests that used to be run
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   416
   */
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   417
  void CheckOld(bool *ok);
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   418
};
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   419
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   420
TimeTests::TimeTests ()
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   421
  : Test ("Time")
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   422
{}
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   423
TimeTests::~TimeTests ()
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   424
{}
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   425
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   426
bool TimeTests::RunTests (void)
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   427
{
1829
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   428
  bool result = true;
176
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   429
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   430
  Time t0, t1;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   431
1829
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   432
  CheckOld(&result);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   433
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   434
  t0 = MilliSeconds ((uint64_t)10.0);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   435
  t1 = MilliSeconds ((uint64_t)11.0);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   436
1829
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   437
  CheckOperations(t0, t1, &result);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   438
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   439
  //  t0 = Seconds ((uint64_t)10.0);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   440
  //  t1 = Seconds ((uint64_t)11.0);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   441
1829
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   442
  //  CheckOperations(t0, t1, &result);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   443
1829
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   444
  CheckConversions((uint64_t)5, &result);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   445
  CheckConversions((uint64_t)0, &result);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   446
  CheckConversions((uint64_t)783, &result);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   447
  CheckConversions((uint64_t)1132, &result);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   448
  //  CheckConversions((uint64_t)3341039, &result);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   449
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   450
  // Now vary the precision and check the conversions
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   451
  if (TimeStepPrecision::Get () != TimeStepPrecision::NS) {
1829
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   452
    result = false;
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   453
  }
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   454
1829
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   455
  CheckPrecision(TimeStepPrecision::US, 7, &result);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   456
1829
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   457
  CheckConversions((uint64_t)7, &result);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   458
  CheckConversions((uint64_t)546, &result);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   459
  CheckConversions((uint64_t)6231, &result);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   460
  //  CheckConversions((uint64_t)1234639, &result);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   461
1829
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   462
  CheckPrecision(TimeStepPrecision::MS, 3, &result);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   463
1829
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   464
  CheckConversions((uint64_t)3, &result);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   465
  CheckConversions((uint64_t)134, &result);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   466
  CheckConversions((uint64_t)2341, &result);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   467
  //  CheckConversions((uint64_t)8956239, &result);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   468
1829
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   469
  CheckPrecision(TimeStepPrecision::PS, 21, &result);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   470
1829
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   471
  CheckConversions((uint64_t)4, &result);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   472
  CheckConversions((uint64_t)342, &result);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   473
  CheckConversions((uint64_t)1327, &result);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   474
  //  CheckConversions((uint64_t)5439627, &result);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   475
1829
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   476
  CheckPrecision(TimeStepPrecision::NS, 12, &result);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   477
  CheckConversions((uint64_t)12, &result);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   478
1829
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   479
  CheckPrecision(TimeStepPrecision::S, 7, &result);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   480
  CheckConversions((uint64_t)7, &result);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   481
1829
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   482
  CheckPrecision(TimeStepPrecision::FS, 5, &result);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   483
  CheckConversions((uint64_t)5, &result);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   484
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   485
  TimeStepPrecision::Set (TimeStepPrecision::NS);
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   486
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2953
diff changeset
   487
  Config::SetGlobal ("TimeStepPrecision", StringValue ("S"));
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2953
diff changeset
   488
  Config::SetGlobal ("TimeStepPrecision", StringValue ("MS"));
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2953
diff changeset
   489
  Config::SetGlobal ("TimeStepPrecision", StringValue ("US"));
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2953
diff changeset
   490
  Config::SetGlobal ("TimeStepPrecision", StringValue ("NS"));
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2953
diff changeset
   491
  Config::SetGlobal ("TimeStepPrecision", StringValue ("PS"));
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2953
diff changeset
   492
  Config::SetGlobal ("TimeStepPrecision", StringValue ("FS"));
684
333ec02c9cc9 add DefaultValue support for TimeStepPrecision
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 680
diff changeset
   493
1829
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   494
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   495
  Time tooBig = TimeStep (0x8000000000000000LL);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   496
  NS_TEST_ASSERT (tooBig.IsNegative ());
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   497
  tooBig = TimeStep (0xffffffffffffffffLL);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   498
  NS_TEST_ASSERT (tooBig.IsNegative ());
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   499
  tooBig = TimeStep (0x7fffffffffffffffLL);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   500
  NS_TEST_ASSERT (tooBig.IsPositive ());
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   501
  tooBig += TimeStep (1);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   502
  NS_TEST_ASSERT (tooBig.IsNegative ());
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   503
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   504
  return result;
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   505
}
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   506
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   507
void TimeTests::CheckOld (bool *ok)
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   508
{
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   509
  double dt0, dt1, dt2;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   510
  int64_t it0, it1;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   511
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   512
  Time t0 = Seconds (10.0);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   513
  CheckTimeSec("old 1", t0.GetSeconds(), 10.0, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   514
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   515
  Time t1 = Seconds (11.0);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   516
  CheckTimeSec("old 2", t1.GetSeconds(), 11.0, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   517
176
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   518
  t0 = Seconds (1.5);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   519
  CheckTimeSec("old 3", t0.GetSeconds(), 1.5, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   520
176
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   521
  t0 = Seconds (-1.5);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   522
  CheckTimeSec("old 4", t0.GetSeconds(), -1.5, ok);
176
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   523
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   524
  t0 = MilliSeconds ((uint64_t)10.0);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   525
  dt0 = t0.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   526
  CheckTimeSec("old 5", dt0, 0.01, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   527
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   528
  t1 = MilliSeconds ((uint64_t)11.0);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   529
  dt1 = t1.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   530
  CheckTimeSec("old 6", dt1, 0.011, ok);
176
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   531
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   532
  Time t2, t3;
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   533
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   534
  t2 = t1 - t0;
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   535
  if (!t2.IsStrictlyPositive ())
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   536
    {
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   537
      ok = false;
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   538
    }
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   539
  dt2 = t2.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   540
  CheckTimeSec("old 7", dt2, dt1-dt0, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   541
176
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   542
  t2 = t1 - t1;
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   543
  if (!t2.IsZero ())
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   544
    {
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   545
      ok = false;
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   546
    }
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   547
  dt2 = t2.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   548
  CheckTimeSec("old 8", dt2, dt1-dt1, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   549
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   550
  t2 = t0 - t1;
176
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   551
  if (!t2.IsStrictlyNegative ())
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   552
    {
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   553
      ok = false;
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   554
    }
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   555
  dt2 = t2.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   556
  CheckTimeSec("old 9", dt2, dt0-dt1, ok);
176
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   557
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   558
  t1 = NanoSeconds(15);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   559
  it0 = t0.GetNanoSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   560
  it1 = t1.GetNanoSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   561
  TimeUnit<-2> tu4 = t0 / (t1 * t1 * t1);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   562
  CheckTime("old 10", tu4.GetHighPrecision().GetInteger(), it0 / (it1*it1*it1), 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   563
            ok, 1e9);
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   564
211
395e8b0d32a9 add a few more tests for the Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 209
diff changeset
   565
  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
   566
  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
   567
      (tmp > NanoSeconds (0)) ||
395e8b0d32a9 add a few more tests for the Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 209
diff changeset
   568
      (tmp < NanoSeconds (0)))
395e8b0d32a9 add a few more tests for the Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 209
diff changeset
   569
    {
395e8b0d32a9 add a few more tests for the Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 209
diff changeset
   570
      ok = false;
395e8b0d32a9 add a few more tests for the Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 209
diff changeset
   571
    }
395e8b0d32a9 add a few more tests for the Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 209
diff changeset
   572
229
37f1ee32c76f avoid unused variable compiler warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 215
diff changeset
   573
  Time t4;
37f1ee32c76f avoid unused variable compiler warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 215
diff changeset
   574
  t4 = Seconds (10.0) * Scalar (1.5);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   575
  CheckTimeSec("old 11", t4.GetSeconds(), 10, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   576
229
37f1ee32c76f avoid unused variable compiler warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 215
diff changeset
   577
  Time t5;
37f1ee32c76f avoid unused variable compiler warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 215
diff changeset
   578
  t5 = NanoSeconds (10) * Scalar (1.5);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   579
  CheckTime("old 12", t5.GetNanoSeconds(), 10, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   580
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   581
  t4 = Seconds (10.0) * Scalar (15) / Scalar (10);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   582
  CheckTimeSec("old 13", t4.GetSeconds(), 15, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   583
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   584
  t5 = NanoSeconds (10) * Scalar (15) / Scalar (10);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   585
  CheckTime("old 14", t5.GetNanoSeconds(), 15, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   586
339
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 229
diff changeset
   587
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 229
diff changeset
   588
  double foo = (t1 + t2).GetSeconds ();
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   589
  dt1 = t1.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   590
  dt2 = t2.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   591
  CheckTimeSec("old 15", foo, dt1+dt2, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   592
339
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 229
diff changeset
   593
  foo += (t4 == t5)? 1 : 0;
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   594
  CheckTimeSec("old 16", foo, dt1+dt2, ok);
339
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 229
diff changeset
   595
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 229
diff changeset
   596
  foo = (t1/t2).GetDouble ();
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   597
  CheckTimeSec("old 17", foo, dt1/dt2, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   598
}
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   599
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   600
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   601
void TimeTests::CheckOperations(Time t0, Time t1, bool *ok, bool verbose) 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   602
{
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   603
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   604
  if (verbose) 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   605
    std::cout << std::endl << "Check operations: " 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   606
              << t0 << " " << t1 << std::endl;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   607
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   608
  Time t2, t3;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   609
  double it0, it1, it2, it3, itu2, itu3;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   610
  int64_t iti0;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   611
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   612
  it0 = t0.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   613
  it1 = t1.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   614
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   615
  t2 = t0 - t1;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   616
  it2 = t2.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   617
  CheckTimeSec("ops 1", it2, it0-it1, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   618
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   619
  t3 = t2 * t0 / t0;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   620
  it3 = t3.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   621
  CheckTimeSec("ops 2a", it3, it2*it0/it0, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   622
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   623
  t3 = t2 * t0 / t1;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   624
  it3 = t3.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   625
  CheckTimeSec("ops 2", it3, it2*it0/it1, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   626
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   627
  t3 = t0 * t2 / t1;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   628
  it3 = t3.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   629
  CheckTimeSec("ops 3", it3, it0*it2/it1, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   630
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   631
  t3 = t0 * t1 / t2;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   632
  it3 = t3.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   633
  CheckTimeSec("ops 4", it3, it0*it1/it2, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   634
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   635
  t3 = t0 * (t1 / t2);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   636
  it3 = t3.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   637
  CheckTimeSec("ops 5", it3, it0*(it1/it2), ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   638
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   639
  t3 = (t0 * t1) / t2;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   640
  it3 = t3.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   641
  CheckTimeSec("ops 6", it3, (it0*it1)/it2, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   642
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   643
  t3 = t0 / t1 * t2;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   644
  it3 = t3.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   645
  CheckTimeSec("ops 7", it3, it0/it1*it2, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   646
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   647
  t3 = (t0 / t1) * t2;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   648
  it3 = t3.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   649
  CheckTimeSec("ops 8", it3, (it0/it1)*it2, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   650
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   651
  t3 = t0 * Scalar (10.0);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   652
  it3 = t3.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   653
  CheckTimeSec("ops 9", it3, it0*10, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   654
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   655
  t3 = Scalar (10.0) * t0;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   656
  it3 = t3.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   657
  CheckTimeSec("ops 10", it3, 10 * it0, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   658
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   659
  t3 = Scalar (10.0) * t0 / t2 * t1;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   660
  it3 = t3.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   661
  CheckTimeSec("ops 11", it3, 10 * it0 / it2 * it1, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   662
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   663
  t3 = (Scalar (10.0) * t0 ) / t2 * t1;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   664
  it3 = t3.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   665
  CheckTimeSec("ops 12", it3, (10 * it0) / it2 * it1, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   666
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   667
  TimeInvert ti0;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   668
  ti0 = t0 / (t1 * t2);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   669
  iti0 = ti0.GetHighPrecision().GetInteger();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   670
  // This check is not quite working yet.
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   671
  //  CheckTime("ops 13", iti0, (int64_t)(it0/(it1*it2)), ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   672
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   673
  Scalar s0 = t0 / t1;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   674
  CheckTimeSec("ops 14", s0.GetDouble(), it0/it1, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   676
  Scalar s1;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   677
  s1 = t0 * t1 / (t2 * t0);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   678
  CheckTimeSec("ops 15", s1.GetDouble(), it0*it1/(it2*it0), ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   679
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   680
  TimeUnit<0> tu0;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   681
  tu0 = s0;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   682
  CheckTimeSec("ops 16", tu0.GetDouble(), s0.GetDouble(), ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   683
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   684
  TimeUnit<1> tu1;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   685
  tu1 = t0;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   686
  CheckTimeSec("ops 17", tu1.GetSeconds(), it0, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   687
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   688
  TimeUnit<2> tu2;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   689
  tu2 = t0 * t1;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   690
  CheckTimeSec("ops 18", tu2.GetHighPrecision().GetInteger()/(1e18), 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   691
               it0 * it1, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   692
  itu2 = tu2.GetHighPrecision().GetInteger()/(1e18);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   693
  
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   694
  TimeUnit<3> tu3;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   695
  tu3 = t0 / Scalar(10e6) * tu2;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   696
  CheckTimeSec("ops 19", tu3.GetHighPrecision().GetInteger()/(1e27), 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   697
               it0 / 1000000 * itu2, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   698
  itu3 = tu3.GetHighPrecision().GetInteger()/(1e27);
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   699
}
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   700
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   701
void TimeTests::CheckConversions(uint64_t tval, bool *ok, bool verbose) {
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   702
  Time t_sec, t_ms, t_us, t_ns, t_ps, t_fs;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   703
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   704
  if (verbose) 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   705
    std::cout << std::endl << "Check conversions: " << tval << std::endl;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   706
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   707
  // First check the seconds
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   708
  t_sec = Seconds((double)tval);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   709
  CheckTimeSec("conv sec sec", t_sec.GetSeconds(), (double)tval, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   710
  CheckTime("conv sec ms", t_sec.GetMilliSeconds(), (int64_t)(tval*1e3), ok, 1e3);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   711
  CheckTime("conv sec us", t_sec.GetMicroSeconds(), (int64_t)(tval*1e6), ok, 1e6);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   712
  CheckTime("conv sec ns", t_sec.GetNanoSeconds(), (int64_t)(tval*1e9), ok, 1e9);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   713
  CheckTime("conv sec ps", t_sec.GetPicoSeconds(), 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   714
            (int64_t)(tval*1e12), ok, 1e12);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   715
  CheckTime("conv sec fs", t_sec.GetFemtoSeconds(), 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   716
            (int64_t)(tval*1e15), ok, 1e15);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   717
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   718
  // Then check the milliseconds
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   719
  t_ms = MilliSeconds(tval);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   720
  CheckTimeSec("conv ms sec", t_ms.GetSeconds(), (double)tval/1e3, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   721
  CheckTime("conv ms ms", t_ms.GetMilliSeconds(), (int64_t)(tval), ok, 1e3);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   722
  CheckTime("conv ms us", t_ms.GetMicroSeconds(), (int64_t)(tval*1e3), ok, 1e6);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   723
  CheckTime("conv ms ns", t_ms.GetNanoSeconds(), (int64_t)(tval*1e6), ok, 1e9);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   724
  CheckTime("conv ms ps", t_ms.GetPicoSeconds(), (int64_t)(tval*1e9), ok, 1e12);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   725
  CheckTime("conv ms fs", t_ms.GetFemtoSeconds(), (int64_t)(tval*1e12), ok, 1e15);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   726
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   727
  // Then check the microseconds
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   728
  t_us = MicroSeconds(tval);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   729
  CheckTimeSec("conv us sec", t_us.GetSeconds(), (double)tval/1e6, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   730
  CheckTime("conv us ms", t_us.GetMilliSeconds(), (int64_t)(tval/1e3), ok, 1e3);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   731
  CheckTime("conv us us", t_us.GetMicroSeconds(), (int64_t)(tval), ok, 1e6);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   732
  CheckTime("conv us ns", t_us.GetNanoSeconds(), (int64_t)(tval*1e3), ok, 1e9);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   733
  CheckTime("conv us ps", t_us.GetPicoSeconds(), (int64_t)(tval*1e6), ok, 1e12);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   734
  CheckTime("conv us fs", t_us.GetFemtoSeconds(), (int64_t)(tval*1e9), ok, 1e15);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   735
  
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   736
  // Then check the nanoseconds
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   737
  t_ns = NanoSeconds(tval);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   738
  CheckTimeSec("conv ns sec", t_ns.GetSeconds(), (double)tval/1e9, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   739
  CheckTime("conv ns ms", t_ns.GetMilliSeconds(), (int64_t)(tval/1e6), ok, 1e3);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   740
  CheckTime("conv ns us", t_ns.GetMicroSeconds(), (int64_t)(tval/1e3), ok, 1e6);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   741
  CheckTime("conv ns ns", t_ns.GetNanoSeconds(), (int64_t)(tval), ok, 1e9);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   742
  CheckTime("conv ns ps", t_ns.GetPicoSeconds(), (int64_t)(tval*1e3), ok, 1e12);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   743
  CheckTime("conv ns fs", t_ns.GetFemtoSeconds(), (int64_t)(tval*1e6), ok, 1e15);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   744
  
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   745
  // Then check the picoseconds
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   746
  t_ps = PicoSeconds(tval);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   747
  CheckTimeSec("conv ps sec", t_ps.GetSeconds(), (double)tval/1e12, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   748
  CheckTime("conv ps ms", t_ps.GetMilliSeconds(), (int64_t)(tval/1e9), ok, 1e3);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   749
  CheckTime("conv ps us", t_ps.GetMicroSeconds(), (int64_t)(tval/1e6), ok, 1e6);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   750
  CheckTime("conv ps ns", t_ps.GetNanoSeconds(), (int64_t)(tval/1e3), ok, 1e9);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   751
  CheckTime("conv ps ps", t_ps.GetPicoSeconds(), (int64_t)(tval), ok, 1e12);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   752
  CheckTime("conv ps fs", t_ps.GetFemtoSeconds(), (int64_t)(tval*1e3), ok, 1e15);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   753
  
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   754
  // Then check the femtoseconds
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   755
  t_fs = FemtoSeconds(tval);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   756
  CheckTimeSec("conv fs sec", t_fs.GetSeconds(), (double)tval/1e15, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   757
  CheckTime("conv fs ms", t_fs.GetMilliSeconds(), (int64_t)(tval/1e12), ok, 1e3);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   758
  CheckTime("conv fs us", t_fs.GetMicroSeconds(), (int64_t)(tval/1e9), ok, 1e6);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   759
  CheckTime("conv fs ns", t_fs.GetNanoSeconds(), (int64_t)(tval/1e6), ok, 1e9);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   760
  CheckTime("conv fs ps", t_fs.GetPicoSeconds(), (int64_t)(tval/1e3), ok, 1e12);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   761
  CheckTime("conv fs fs", t_fs.GetFemtoSeconds(), (int64_t)(tval), ok, 1e15);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   762
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   763
  
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   764
}
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   765
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   766
void TimeTests::CheckPrecision(TimeStepPrecision::precision_t prec, uint64_t val, bool *ok, 
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   767
                               bool verbose) {
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   768
  if (verbose) {
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   769
    std::cout << "check precision 10^-" << prec << std::endl;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   770
  }
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   771
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   772
  TimeStepPrecision::Set (prec);
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   773
  if (TimeStepPrecision::Get () != prec) {
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   774
    ok = false;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   775
  }
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   776
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   777
  /* These still need to be fixed.
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   778
  // The smallest value that can be stored is 1x10^(-prec)
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   779
  Time smallest = Seconds(pow(10,-prec));
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   780
  CheckTimeSec("Prec small:     ", smallest.GetSeconds(), pow(10,-prec), ok, 0.1, 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   781
               true);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   782
  
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   783
  double d_ts = pow(10,-prec) - pow(10, -(prec+3));
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   784
  Time too_small = Seconds(d_ts);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   785
  CheckTimeSec("Prec too small: ", too_small.GetSeconds(), 0, ok, 0.1, true);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   786
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   787
  double d_la = 0xFFFFFFFF*pow(10,-prec);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   788
  Time largest = Seconds(d_la);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   789
  CheckTimeSec("Prec large:     ", largest.GetSeconds(), d_la, ok, 0.1, true);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   790
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   791
  double d_tl = (0xFFFFFFFF*pow(10,-prec)) + 1;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   792
  Time too_large = Seconds(d_tl);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   793
  if ((largest.GetSeconds() + 1) == too_large.GetSeconds())
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   794
    std::cout << "Overflow did not occur." << std::endl;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   795
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   796
  NS_ASSERT(d_la+1 == d_tl);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   797
  */  
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   798
}
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   799
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   800
void TimeTests::CheckTimeSec (std::string test_id, double actual, 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   801
                              double expected, bool *flag, double precMultFactor,
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   802
                              bool verbose)
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   803
{
684
333ec02c9cc9 add DefaultValue support for TimeStepPrecision
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 680
diff changeset
   804
  double prec = pow(10,-((double)(ns3::TimeStepPrecision::Get ()))) * precMultFactor;
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   805
  if ((actual < (expected-prec)) || (actual > (expected+prec))) {
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   806
    std::cout << "FAIL " << test_id 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   807
              << " Expected:" << expected 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   808
              << " Actual: " << actual
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   809
              << " Precision: " << prec << std::endl;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   810
    *flag = false;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   811
  } else {
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   812
    if (verbose) {
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   813
      std::cout << "PASS " << test_id 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   814
                << " Expected:" << expected 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   815
                << " Actual: " << actual
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   816
                << " Precision: " << prec << std::endl;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   817
    }
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   818
  }
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   819
}
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   820
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   821
void TimeTests::CheckTime (std::string test_id, int64_t actual, 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   822
                           int64_t expected, bool *flag, double precMultFactor,
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   823
                           bool verbose)
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   824
{
684
333ec02c9cc9 add DefaultValue support for TimeStepPrecision
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 680
diff changeset
   825
  double prec = pow(10,-((double)(ns3::TimeStepPrecision::Get ()))) * precMultFactor;
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   826
  if ((actual < (expected-prec)) || (actual > (expected+prec))) {
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   827
    std::cout << "FAIL " << test_id 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   828
              << " Expected:" << expected 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   829
              << " Actual: " << actual
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   830
              << " Precision: " << prec << std::endl;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   831
    *flag = false;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   832
  } else {
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   833
    if (verbose) {
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   834
      std::cout << "PASS " << test_id 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   835
                << " Expected:" << expected 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   836
                << " Actual: " << actual 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   837
                << " Precision: " << prec << std::endl;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   838
    }
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   839
  }
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   840
}
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   841
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   842
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   843
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
   844
  
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   845
};
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   846
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   847
#endif /* RUN_SELF_TESTS */