src/core/model/time.cc
author Peter D. Barnes, Jr. <barnes26@llnl.gov>
Sat, 08 Dec 2012 21:23:44 -0800
changeset 9183 1a2abe07b53d
parent 9134 7a750f032acd
child 9186 8934b7c0c1cb
permissions -rw-r--r--
bug 954: Changing the simulation time resolution does not work well with attributes
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"
7383
c5e131450339 remove ns3/ prefix which is un-needed now that all files are in same module.
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7169
diff changeset
    23
#include "abort.h"
9183
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
    24
#include "log.h"
7383
c5e131450339 remove ns3/ prefix which is un-needed now that all files are in same module.
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7169
diff changeset
    25
#include "global-value.h"
c5e131450339 remove ns3/ prefix which is un-needed now that all files are in same module.
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7169
diff changeset
    26
#include "enum.h"
c5e131450339 remove ns3/ prefix which is un-needed now that all files are in same module.
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7169
diff changeset
    27
#include "string.h"
c5e131450339 remove ns3/ prefix which is un-needed now that all files are in same module.
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7169
diff changeset
    28
#include "object.h"
c5e131450339 remove ns3/ prefix which is un-needed now that all files are in same module.
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7169
diff changeset
    29
#include "config.h"
9183
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
    30
#include "simulator.h"
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 7579
diff changeset
    31
#include <cmath>
6511
d9f23a956ef2 add missing include
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6506
diff changeset
    32
#include <sstream>
25
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    33
9183
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
    34
NS_LOG_COMPONENT_DEFINE ("Time");
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
    35
25
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    36
namespace ns3 {
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    37
6514
92a84235d8f2 get rid of TimeUnit<N>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6511
diff changeset
    38
Time::Time (const std::string& s)
372
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    39
{
7579
91a0ff9ee4eb Bug 1204 - Can't Parse Time +100000000.0ns
Mitch Watrous <watrous@u.washington.edu>
parents: 7383
diff changeset
    40
  std::string::size_type n = s.find_first_not_of ("+-0123456789.");
372
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    41
  if (n != std::string::npos)
6180
cd0d8ba00e6c coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6177
diff changeset
    42
    { // Found non-numeric
cd0d8ba00e6c coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6177
diff changeset
    43
      std::istringstream iss;
cd0d8ba00e6c coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6177
diff changeset
    44
      iss.str (s.substr (0, n));
cd0d8ba00e6c coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6177
diff changeset
    45
      double r;
cd0d8ba00e6c coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6177
diff changeset
    46
      iss >> r;
cd0d8ba00e6c coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6177
diff changeset
    47
      std::string trailer = s.substr (n, std::string::npos);
cd0d8ba00e6c coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6177
diff changeset
    48
      if (trailer == std::string ("s"))
cd0d8ba00e6c coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6177
diff changeset
    49
        {
6496
ed210e7279a7 rewrite time integer support for 32bit systems.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6418
diff changeset
    50
          *this = Time::FromDouble (r, Time::S);
6180
cd0d8ba00e6c coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6177
diff changeset
    51
        }
9183
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
    52
      else if (trailer == std::string ("ms"))
6180
cd0d8ba00e6c coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6177
diff changeset
    53
        {
6496
ed210e7279a7 rewrite time integer support for 32bit systems.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6418
diff changeset
    54
          *this = Time::FromDouble (r, Time::MS);
6180
cd0d8ba00e6c coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6177
diff changeset
    55
        }
9183
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
    56
      else if (trailer == std::string ("us"))
6180
cd0d8ba00e6c coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6177
diff changeset
    57
        {
6496
ed210e7279a7 rewrite time integer support for 32bit systems.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6418
diff changeset
    58
          *this = Time::FromDouble (r, Time::US);
6180
cd0d8ba00e6c coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6177
diff changeset
    59
        }
9183
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
    60
      else if (trailer == std::string ("ns"))
6180
cd0d8ba00e6c coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6177
diff changeset
    61
        {
6496
ed210e7279a7 rewrite time integer support for 32bit systems.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6418
diff changeset
    62
          *this = Time::FromDouble (r, Time::NS);
6180
cd0d8ba00e6c coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6177
diff changeset
    63
        }
9183
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
    64
      else if (trailer == std::string ("ps"))
6180
cd0d8ba00e6c coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6177
diff changeset
    65
        {
6496
ed210e7279a7 rewrite time integer support for 32bit systems.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6418
diff changeset
    66
          *this = Time::FromDouble (r, Time::PS);
6180
cd0d8ba00e6c coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6177
diff changeset
    67
        }
9183
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
    68
      else if (trailer == std::string ("fs"))
6180
cd0d8ba00e6c coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6177
diff changeset
    69
        {
6496
ed210e7279a7 rewrite time integer support for 32bit systems.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6418
diff changeset
    70
          *this = Time::FromDouble (r, Time::FS);
6180
cd0d8ba00e6c coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6177
diff changeset
    71
        }
9183
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
    72
      else
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
    73
        {
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
    74
          NS_ABORT_MSG ("Can't Parse Time " << s);
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
    75
        }
372
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    76
    }
9183
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
    77
  else
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
    78
    {
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
    79
      // they didn't provide units, assume seconds
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
    80
      std::istringstream iss;
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
    81
      iss.str (s);
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
    82
      double v;
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
    83
      iss >> v;
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
    84
      *this = Time::FromDouble (v, Time::S);
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
    85
    }
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
    86
  
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
    87
  TimeSet (this);
143
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    88
}
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    89
9183
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
    90
// static
6514
92a84235d8f2 get rid of TimeUnit<N>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6511
diff changeset
    91
struct Time::Resolution
9183
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
    92
Time::SetDefaultNsResolution (void)
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7045
diff changeset
    93
{
9183
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
    94
  NS_LOG_FUNCTION_NOARGS();
6514
92a84235d8f2 get rid of TimeUnit<N>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6511
diff changeset
    95
  struct Resolution resolution;
9183
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
    96
  SetResolution (Time::NS, &resolution, false);
6514
92a84235d8f2 get rid of TimeUnit<N>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6511
diff changeset
    97
  return resolution;
92a84235d8f2 get rid of TimeUnit<N>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6511
diff changeset
    98
}
9183
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
    99
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   100
// static
6514
92a84235d8f2 get rid of TimeUnit<N>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6511
diff changeset
   101
void 
92a84235d8f2 get rid of TimeUnit<N>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6511
diff changeset
   102
Time::SetResolution (enum Unit resolution)
92a84235d8f2 get rid of TimeUnit<N>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6511
diff changeset
   103
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   104
  NS_LOG_FUNCTION (resolution);
6514
92a84235d8f2 get rid of TimeUnit<N>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6511
diff changeset
   105
  SetResolution (resolution, PeekResolution ());
92a84235d8f2 get rid of TimeUnit<N>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6511
diff changeset
   106
}
9183
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   107
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   108
// static
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   109
enum Time::Unit
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   110
Time::GetResolution (void)
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   111
{
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   112
  NS_LOG_FUNCTION_NOARGS();
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   113
  return PeekResolution ()->unit;
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   114
}
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   115
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   116
// static
6514
92a84235d8f2 get rid of TimeUnit<N>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6511
diff changeset
   117
void 
9183
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   118
Time::SetResolution (enum Unit unit, struct Resolution *resolution,
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   119
                     const bool convert /* = true */)
6514
92a84235d8f2 get rid of TimeUnit<N>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6511
diff changeset
   120
{
9183
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   121
  NS_LOG_FUNCTION (unit << resolution << convert);
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   122
  if (convert)
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   123
    { // We have to convert old values
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   124
      ConvertTimes (unit);
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   125
    }
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   126
  
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7045
diff changeset
   127
  int8_t power [LAST] = { 15, 12, 9, 6, 3, 0};
6514
92a84235d8f2 get rid of TimeUnit<N>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6511
diff changeset
   128
  for (int i = 0; i < Time::LAST; i++)
92a84235d8f2 get rid of TimeUnit<N>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6511
diff changeset
   129
    {
92a84235d8f2 get rid of TimeUnit<N>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6511
diff changeset
   130
      int shift = power[i] - power[(int)unit];
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 7579
diff changeset
   131
      uint64_t factor = (uint64_t) std::pow (10, std::fabs (shift));
6514
92a84235d8f2 get rid of TimeUnit<N>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6511
diff changeset
   132
      struct Information *info = &resolution->info[i];
92a84235d8f2 get rid of TimeUnit<N>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6511
diff changeset
   133
      info->factor = factor;
92a84235d8f2 get rid of TimeUnit<N>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6511
diff changeset
   134
      if (shift == 0)
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7045
diff changeset
   135
        {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7045
diff changeset
   136
          info->timeFrom = int64x64_t (1);
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7045
diff changeset
   137
          info->timeTo = int64x64_t (1);
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7045
diff changeset
   138
          info->toMul = true;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7045
diff changeset
   139
          info->fromMul = true;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7045
diff changeset
   140
        }
6514
92a84235d8f2 get rid of TimeUnit<N>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6511
diff changeset
   141
      else if (shift > 0)
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7045
diff changeset
   142
        {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7045
diff changeset
   143
          info->timeFrom = int64x64_t (factor);
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7045
diff changeset
   144
          info->timeTo = int64x64_t::Invert (factor);
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7045
diff changeset
   145
          info->toMul = false;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7045
diff changeset
   146
          info->fromMul = true;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7045
diff changeset
   147
        }
6514
92a84235d8f2 get rid of TimeUnit<N>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6511
diff changeset
   148
      else
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7045
diff changeset
   149
        {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7045
diff changeset
   150
          NS_ASSERT (shift < 0);
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7045
diff changeset
   151
          info->timeFrom = int64x64_t::Invert (factor);
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7045
diff changeset
   152
          info->timeTo = int64x64_t (factor);
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7045
diff changeset
   153
          info->toMul = true;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7045
diff changeset
   154
          info->fromMul = false;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7045
diff changeset
   155
        }
6514
92a84235d8f2 get rid of TimeUnit<N>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6511
diff changeset
   156
    }
92a84235d8f2 get rid of TimeUnit<N>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6511
diff changeset
   157
  resolution->unit = unit;
92a84235d8f2 get rid of TimeUnit<N>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6511
diff changeset
   158
}
9183
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   159
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   160
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   161
// static
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   162
Time::TimesSet *
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   163
Time::GetTimesSet ( const bool deleteMe /* = false */ )
6514
92a84235d8f2 get rid of TimeUnit<N>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6511
diff changeset
   164
{
9183
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   165
  static TimesSet * times = new TimesSet;  
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   166
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   167
  if (deleteMe)
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   168
    {
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   169
      NS_LOG_LOGIC ("deleting TimesSet");
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   170
      if (times)
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   171
        {
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   172
          delete times;
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   173
        }
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   174
      times = 0;
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   175
    }
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   176
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   177
  return times;
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   178
}
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   179
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   180
// static
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   181
void
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   182
Time::DeleteTimesSet ()
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   183
{
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   184
  NS_LOG_FUNCTION_NOARGS();
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   185
  Time::GetTimesSet (true);
6514
92a84235d8f2 get rid of TimeUnit<N>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6511
diff changeset
   186
}
92a84235d8f2 get rid of TimeUnit<N>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6511
diff changeset
   187
9183
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   188
// static
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   189
void
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   190
Time::TimeSet (Time * const time)
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   191
{
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   192
  NS_ASSERT (time != 0);
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   193
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   194
  TimesSet * times = GetTimesSet();
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   195
  if (times)
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   196
    {
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   197
      std::pair< TimesSet::iterator, bool> ret;
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   198
      ret = times->insert ( time);
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   199
      NS_LOG_LOGIC ("\t[" << times->size () << "] recording " << time);
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   200
  
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   201
      if (ret.second == false)
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   202
        {
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   203
          NS_LOG_WARN ("already recorded " << time << "!");
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   204
        }
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   205
      // If this is the first Time, schedule the cleanup.
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   206
      if (times->size () == 1)
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   207
        {
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   208
          // We schedule here, after the first event has been added,
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   209
          // rather than in GetTimesSet when the set is empty.
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   210
          // Scheduling there creates another Time, which
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   211
          // finds an empty set and schedules an event . . .
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   212
          // Doing it here, the schedule creates the second Time,
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   213
          // which doesn't recurse.
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   214
          NS_LOG_LOGIC ("scheduling DeleteTimesSet()");
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   215
          Simulator::Schedule ( Seconds (0), & DeleteTimesSet);
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   216
        }
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   217
    }
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   218
}
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   219
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   220
// static
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   221
void
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   222
Time::TimeUnset (Time * const time)
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   223
{
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   224
  NS_ASSERT (time != 0);
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   225
  TimesSet * times = GetTimesSet ();
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   226
  if (times)
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   227
    {
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   228
      NS_ASSERT_MSG (times->count (time) == 1,
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   229
		     "Time object " << time << " registered "
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   230
		     << times->count (time) << " times (should be 1)." );
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   231
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   232
      TimesSet::size_type num = times->erase (time);
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   233
      if (num != 1)
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   234
        {
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   235
          NS_LOG_WARN ("unexpected result erasing " << time << "!");
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   236
          NS_LOG_WARN ("got " << num << ", expected 1");
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   237
        }
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   238
      else
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   239
        {
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   240
          NS_LOG_LOGIC ("\t[" << times->size () << "] removing  " << time);
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   241
        }
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   242
    }
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   243
}
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   244
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   245
// static
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   246
void
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   247
Time::ConvertTimes (const enum Unit unit)
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   248
{
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   249
  NS_LOG_FUNCTION_NOARGS();
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   250
  TimesSet * times = GetTimesSet ();
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   251
  NS_ASSERT_MSG (times != 0, "No Time registry. Time::SetResolution () called mare than once?");
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   252
  
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   253
  for ( TimesSet::iterator it = times->begin();
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   254
        it != times->end();
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   255
        it++ )
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   256
    {
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   257
      Time * const tp = *it;
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   258
      (*tp) = tp->ToInteger (unit);
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   259
    }
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   260
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   261
  NS_LOG_LOGIC ("logged " << GetTimesSet ()->size () << " Time objects.");
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   262
  GetTimesSet (true);
1a2abe07b53d bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9134
diff changeset
   263
}
6514
92a84235d8f2 get rid of TimeUnit<N>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6511
diff changeset
   264
6180
cd0d8ba00e6c coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6177
diff changeset
   265
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
   266
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
   267
{
911
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   268
  std::string unit;
6514
92a84235d8f2 get rid of TimeUnit<N>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6511
diff changeset
   269
  switch (Time::GetResolution ())
6180
cd0d8ba00e6c coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6177
diff changeset
   270
    {
6514
92a84235d8f2 get rid of TimeUnit<N>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6511
diff changeset
   271
    case Time::S:
6180
cd0d8ba00e6c coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6177
diff changeset
   272
      unit = "s";
cd0d8ba00e6c coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6177
diff changeset
   273
      break;
6514
92a84235d8f2 get rid of TimeUnit<N>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6511
diff changeset
   274
    case Time::MS:
6180
cd0d8ba00e6c coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6177
diff changeset
   275
      unit = "ms";
cd0d8ba00e6c coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6177
diff changeset
   276
      break;
6514
92a84235d8f2 get rid of TimeUnit<N>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6511
diff changeset
   277
    case Time::US:
6180
cd0d8ba00e6c coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6177
diff changeset
   278
      unit = "us";
cd0d8ba00e6c coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6177
diff changeset
   279
      break;
6514
92a84235d8f2 get rid of TimeUnit<N>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6511
diff changeset
   280
    case Time::NS:
6180
cd0d8ba00e6c coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6177
diff changeset
   281
      unit = "ns";
cd0d8ba00e6c coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6177
diff changeset
   282
      break;
6514
92a84235d8f2 get rid of TimeUnit<N>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6511
diff changeset
   283
    case Time::PS:
6180
cd0d8ba00e6c coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6177
diff changeset
   284
      unit = "ps";
cd0d8ba00e6c coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6177
diff changeset
   285
      break;
6514
92a84235d8f2 get rid of TimeUnit<N>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6511
diff changeset
   286
    case Time::FS:
6180
cd0d8ba00e6c coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6177
diff changeset
   287
      unit = "fs";
cd0d8ba00e6c coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6177
diff changeset
   288
      break;
6514
92a84235d8f2 get rid of TimeUnit<N>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6511
diff changeset
   289
    case Time::LAST:
6496
ed210e7279a7 rewrite time integer support for 32bit systems.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6418
diff changeset
   290
      NS_ABORT_MSG ("can't be reached");
ed210e7279a7 rewrite time integer support for 32bit systems.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6418
diff changeset
   291
      unit = "unreachable";
ed210e7279a7 rewrite time integer support for 32bit systems.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6418
diff changeset
   292
      break;
6180
cd0d8ba00e6c coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6177
diff changeset
   293
    }
7044
f94b264549d1 introduce implicit conversion operator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 7040
diff changeset
   294
  int64x64_t v = time;
6496
ed210e7279a7 rewrite time integer support for 32bit systems.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6418
diff changeset
   295
  os << v << 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
   296
  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
   297
}
2409
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   298
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
   299
{
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   300
  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
   301
  is >> value;
6496
ed210e7279a7 rewrite time integer support for 32bit systems.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6418
diff changeset
   302
  time = Time (value);
2409
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   303
  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
   304
}
143
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   305
2447
eee344085a96 convert to new helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2436
diff changeset
   306
ATTRIBUTE_VALUE_IMPLEMENT (Time);
eee344085a96 convert to new helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2436
diff changeset
   307
ATTRIBUTE_CHECKER_IMPLEMENT (Time);
2427
9245ec163111 split checker from ParamSpec.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2409
diff changeset
   308
2390
7e6dfae536cd add Value support to Time
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2170
diff changeset
   309
} // namespace ns3
143
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   310