src/simulator/nstime.h
author Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
Thu, 17 Apr 2008 17:19:24 +0100
changeset 2921 8a616a8b723a
parent 2451 8979f07befd5
child 2972 d76553495b91
permissions -rw-r--r--
Add assertion to detect TimeUnit<N> divide by zero (if not detected, it creates an infinite loop)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 144
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
25
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     2
/*
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     3
 * Copyright (c) 2005,2006 INRIA
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     4
 *
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     5
 * 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
     6
 * 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
     7
 * 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
     8
 *
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
 * 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
    10
 * 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
    11
 * 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
    12
 * 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
    13
 *
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    14
 * 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
    15
 * 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
    16
 * 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
    17
 *
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    19
 */
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
#ifndef TIME_H
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    21
#define TIME_H
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    22
2390
7e6dfae536cd add Value support to Time
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2170
diff changeset
    23
#include "ns3/assert.h"
2438
e2ac9f9aeeb9 value.h -> attribute.h
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2437
diff changeset
    24
#include "ns3/attribute.h"
2451
8979f07befd5 value-helper.h -> attribute-helper.h
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2447
diff changeset
    25
#include "ns3/attribute-helper.h"
25
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    26
#include <stdint.h>
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
    27
#include <math.h>
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
    28
#include <ostream>
156
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
    29
#include "high-precision.h"
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
    30
#include "cairo-wideint-private.h"
25
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    31
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    32
namespace ns3 {
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    33
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    34
namespace TimeStepPrecision {
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    35
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    36
enum precision_t {
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    37
  S  = 0,
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    38
  MS = 3,
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    39
  US = 6,
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    40
  NS = 9,
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    41
  PS = 12,
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    42
  FS = 15
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    43
};
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    44
/**
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    45
 * \param precision the new precision to use
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    46
 *
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    47
 * This should be invoked before any Time object 
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    48
 * is created. i.e., it should be invoked at the very start
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    49
 * of every simulation. The unit specified by this method
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    50
 * is used as the unit of the internal simulation time
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    51
 * which is stored as a 64 bit integer.
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    52
 */
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    53
void Set (precision_t precision);
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    54
/**
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    55
 * \returns the currently-used time precision.
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    56
 */
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    57
precision_t Get (void);
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    58
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    59
} // namespace TimeStepPrecision
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    60
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    61
159
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
    62
/**
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
    63
 * \brief keep track of time unit.
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
    64
 *
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
    65
 * This template class is used to keep track of the value 
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
    66
 * of a specific time unit: the type TimeUnit<1> is used to 
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
    67
 * keep track of seconds, the type TimeUnit<2> is used to keep
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
    68
 * track of seconds squared, the type TimeUnit<-1> is used to
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
    69
 * keep track of 1/seconds, etc.
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
    70
 *
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
    71
 * This base class defines all the functionality shared by all
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
    72
 * these time unit objects: it defines all the classic arithmetic
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
    73
 * operators +, -, *, /, and all the classic comparison operators:
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
    74
 * ==, !=, <, >, <=, >=. It is thus easy to add, substract, or 
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
    75
 * multiply multiple TimeUnit objects. The return type of any such
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
    76
 * arithmetic expression is always a TimeUnit object.
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
    77
 *
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
    78
 * The ns3::Scalar, ns3::Time, ns3::TimeSquare, and ns3::TimeInvert classes 
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
    79
 * are aliases for the TimeUnit<0>, TimeUnit<1>, TimeUnit<2> and TimeUnit<-1>
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
    80
 * types respectively.
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
    81
 *
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
    82
 * For example:
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
    83
 * \code
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
    84
 * Time<1> t1 = Seconds (10.0);
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
    85
 * Time<1> t2 = Seconds (10.0);
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
    86
 * Time<2> t3 = t1 * t2;
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
    87
 * Time<0> t4 = t1 / t2;
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
    88
 * Time<3> t5 = t3 * t1;
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
    89
 * Time<-2> t6 = t1 / t5;
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
    90
 * TimeSquare t7 = t3;
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
    91
 * Scalar s = t4;
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
    92
 * \endcode
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
    93
 *
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
    94
 * If you try to assign the result of an expression which does not 
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
    95
 * match the type of the variable it is assigned to, you will get a
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
    96
 * compiler error. For example, the following will not compile:
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
    97
 * \code
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
    98
 * Time<1> = Seconds (10.0) * Seconds (1.5);
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
    99
 * \endcode
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   100
 *
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   101
 * You can also use the following non-member functions to manipulate
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   102
 * any of these ns3::TimeUnit object:
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   103
 *  - \ref ns3-Time-Abs ns3::Abs
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   104
 *  - \ref ns3-Time-Max ns3::Max
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   105
 *  - \ref ns3-Time-Min ns3::Min
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   106
 */
156
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   107
template <int N>
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   108
class TimeUnit
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   109
{
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   110
public:
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   111
  TimeUnit ();
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   112
  TimeUnit (TimeUnit const &o);
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   113
  TimeUnit operator = (TimeUnit const &o);
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   114
  TimeUnit (HighPrecision data);
159
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   115
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   116
  /**
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   117
   * \return true if the time is zero, false otherwise.
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   118
   */
156
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   119
  bool IsZero (void) const;
159
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   120
  /**
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   121
   * \return true if the time is negative or zero, false otherwise.
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   122
   */
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 144
diff changeset
   123
  bool IsNegative (void) const;
159
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   124
  /**
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   125
   * \return true if the time is positive or zero, false otherwise.
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   126
   */
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 144
diff changeset
   127
  bool IsPositive (void) const;
159
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   128
  /**
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   129
   * \return true if the time is strictly negative, false otherwise.
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   130
   */
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 144
diff changeset
   131
  bool IsStrictlyNegative (void) const;
159
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   132
  /**
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   133
   * \return true if the time is strictly positive, false otherwise.
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   134
   */
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 144
diff changeset
   135
  bool IsStrictlyPositive (void) const;
143
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   136
170
9f68cb694f40 implement 128 bit arithmetic with cairo's internal types
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 163
diff changeset
   137
  /**
9f68cb694f40 implement 128 bit arithmetic with cairo's internal types
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 163
diff changeset
   138
   * This is really an internal method exported for the needs of
9f68cb694f40 implement 128 bit arithmetic with cairo's internal types
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 163
diff changeset
   139
   * the implementation. Please, Do not try to use this method, ever.
9f68cb694f40 implement 128 bit arithmetic with cairo's internal types
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 163
diff changeset
   140
   *
9f68cb694f40 implement 128 bit arithmetic with cairo's internal types
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 163
diff changeset
   141
   * \return the ns3::HighPrecision object which holds the value 
9f68cb694f40 implement 128 bit arithmetic with cairo's internal types
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 163
diff changeset
   142
   *         stored in this Time<N> type.
9f68cb694f40 implement 128 bit arithmetic with cairo's internal types
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 163
diff changeset
   143
   */
215
462cdd13a69e optimize Time::Get methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 212
diff changeset
   144
  HighPrecision const &GetHighPrecision (void) const;
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
   145
  HighPrecision *PeekHighPrecision (void);
170
9f68cb694f40 implement 128 bit arithmetic with cairo's internal types
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 163
diff changeset
   146
156
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   147
private:
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   148
  HighPrecision m_data;
25
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   149
};
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   150
156
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   151
template <int N>
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   152
TimeUnit<N>::TimeUnit ()
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   153
  : m_data ()
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   154
{}
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   155
template <int N>
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   156
TimeUnit<N>::TimeUnit (TimeUnit const &o)
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   157
  : m_data (o.m_data)
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   158
{}
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   159
template <int N>
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   160
TimeUnit<N>
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   161
TimeUnit<N>::operator = (TimeUnit const &o)
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   162
{
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   163
  m_data = o.m_data;
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   164
  return *this;
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   165
}
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   166
template <int N>
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   167
TimeUnit<N>::TimeUnit (HighPrecision data)
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   168
  : m_data (data)
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   169
{}
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   170
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   171
template <int N>
215
462cdd13a69e optimize Time::Get methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 212
diff changeset
   172
HighPrecision const &
156
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   173
TimeUnit<N>::GetHighPrecision (void) const
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   174
{
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   175
  return m_data;
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   176
}
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   177
template <int N>
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
   178
HighPrecision *
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
   179
TimeUnit<N>::PeekHighPrecision (void)
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
   180
{
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
   181
  return &m_data;
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
   182
}
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
   183
template <int N>
156
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   184
bool
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   185
TimeUnit<N>::IsZero (void) const
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   186
{
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   187
  return m_data.Compare (HighPrecision::Zero ()) == 0;
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   188
}
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   189
template <int N>
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   190
bool 
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   191
TimeUnit<N>::IsNegative (void) const
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   192
{
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   193
  return m_data.Compare (HighPrecision::Zero ()) <= 0;
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   194
}
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   195
template <int N>
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   196
bool 
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   197
TimeUnit<N>::IsPositive (void) const
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   198
{
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   199
  return m_data.Compare (HighPrecision::Zero ()) >= 0;
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   200
}
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   201
template <int N>
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   202
bool 
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   203
TimeUnit<N>::IsStrictlyNegative (void) const
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   204
{
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   205
  return m_data.Compare (HighPrecision::Zero ()) < 0;
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   206
}
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   207
template <int N>
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   208
bool 
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   209
TimeUnit<N>::IsStrictlyPositive (void) const
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   210
{
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   211
  return m_data.Compare (HighPrecision::Zero ()) > 0;
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   212
}
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   213
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   214
template <int N>
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   215
bool 
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   216
operator == (TimeUnit<N> const &lhs, TimeUnit<N> const &rhs)
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   217
{
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   218
  return lhs.GetHighPrecision ().Compare (rhs.GetHighPrecision ()) == 0;
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   219
}
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   220
template <int N>
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   221
bool 
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
   222
operator != (TimeUnit<N> const &lhs, TimeUnit<N> const &rhs)
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
   223
{
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
   224
  return lhs.GetHighPrecision ().Compare (rhs.GetHighPrecision ()) != 0;
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
   225
}
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
   226
template <int N>
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
   227
bool 
156
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   228
operator <= (TimeUnit<N> const &lhs, TimeUnit<N> const &rhs)
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   229
{
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   230
  return lhs.GetHighPrecision ().Compare (rhs.GetHighPrecision ()) <= 0;
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   231
}
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   232
template <int N>
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   233
bool 
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   234
operator >= (TimeUnit<N> const &lhs, TimeUnit<N> const &rhs)
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   235
{
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   236
  return lhs.GetHighPrecision ().Compare (rhs.GetHighPrecision ()) >= 0;
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   237
}
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   238
template <int N>
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   239
bool 
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   240
operator < (TimeUnit<N> const &lhs, TimeUnit<N> const &rhs)
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   241
{
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   242
  return lhs.GetHighPrecision ().Compare (rhs.GetHighPrecision ()) < 0;
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   243
}
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   244
template <int N>
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   245
bool 
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   246
operator > (TimeUnit<N> const &lhs, TimeUnit<N> const &rhs)
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   247
{
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   248
  return lhs.GetHighPrecision ().Compare (rhs.GetHighPrecision ()) > 0;
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   249
}
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   250
template <int N>
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   251
TimeUnit<N> operator + (TimeUnit<N> const &lhs, TimeUnit<N> const &rhs)
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   252
{
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   253
  HighPrecision retval = lhs.GetHighPrecision ();
192
cdb44e98954c fix warnings for optimized build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   254
  retval.Add (rhs.GetHighPrecision ());
156
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   255
  return TimeUnit<N> (retval);
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   256
}
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   257
template <int N>
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   258
TimeUnit<N> operator - (TimeUnit<N> const &lhs, TimeUnit<N> const &rhs)
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   259
{
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   260
  HighPrecision retval = lhs.GetHighPrecision ();
192
cdb44e98954c fix warnings for optimized build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   261
  retval.Sub (rhs.GetHighPrecision ());
156
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   262
  return TimeUnit<N> (retval);
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   263
}
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   264
template <int N1, int N2>
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   265
TimeUnit<N1+N2> operator * (TimeUnit<N1> const &lhs, TimeUnit<N2> const &rhs)
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   266
{
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   267
  HighPrecision retval = lhs.GetHighPrecision ();
192
cdb44e98954c fix warnings for optimized build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   268
  retval.Mul (rhs.GetHighPrecision ());
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
   269
  //    std::cout << lhs.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
   270
  //              << rhs.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
   271
  //              << " = " << retval.GetInteger() << std::endl;
156
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   272
  return TimeUnit<N1+N2> (retval);
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   273
}
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   274
template <int N1, int N2>
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   275
TimeUnit<N1-N2> operator / (TimeUnit<N1> const &lhs, TimeUnit<N2> const &rhs)
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   276
{
2921
8a616a8b723a Add assertion to detect TimeUnit<N> divide by zero (if not detected, it creates an infinite loop)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2451
diff changeset
   277
  NS_ASSERT (rhs.GetHighPrecision ().GetDouble () != 0);
156
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   278
  HighPrecision retval = lhs.GetHighPrecision ();
192
cdb44e98954c fix warnings for optimized build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   279
  retval.Div (rhs.GetHighPrecision ());
156
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   280
  return TimeUnit<N1-N2> (retval);
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   281
}
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
   282
template <int N>
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
   283
TimeUnit<N> &operator += (TimeUnit<N> &lhs, TimeUnit<N> const &rhs) {
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
   284
  HighPrecision *lhsv = lhs.PeekHighPrecision ();
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
  lhsv->Add (rhs.GetHighPrecision ());
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
  return lhs;
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
   287
}
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
   288
template <int N>
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
   289
TimeUnit<N> &operator -= (TimeUnit<N> &lhs, TimeUnit<N> const &rhs) {
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
  HighPrecision *lhsv = lhs.PeekHighPrecision ();
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
   291
  lhsv->Sub (rhs.GetHighPrecision ());
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
   292
  return lhs;
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
   293
}
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
   294
156
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   295
159
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   296
/**
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   297
 * \anchor ns3-Time-Abs
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   298
 * \relates ns3::TimeUnit
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   299
 * \param time the input value
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   300
 * \returns the absolute value of the input value.
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   301
 */
156
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   302
template <int N>
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   303
TimeUnit<N> Abs (TimeUnit<N> const &time)
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   304
{
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   305
  return TimeUnit<N> (Abs (time.GetHighPrecision ()));
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   306
}
159
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   307
/**
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   308
 * \anchor ns3-Time-Max
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   309
 * \relates ns3::TimeUnit
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   310
 * \param ta the first value
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   311
 * \param tb the seconds value
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   312
 * \returns the max of the two input values.
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   313
 */
156
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   314
template <int N>
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   315
TimeUnit<N> Max (TimeUnit<N> const &ta, TimeUnit<N> const &tb)
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   316
{
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   317
  HighPrecision a = ta.GetHighPrecision ();
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   318
  HighPrecision b = tb.GetHighPrecision ();  
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   319
  return TimeUnit<N> (Max (a, b));
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   320
}
159
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   321
/**
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   322
 * \anchor ns3-Time-Min
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   323
 * \relates ns3::TimeUnit
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   324
 * \param ta the first value
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   325
 * \param tb the seconds value
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   326
 * \returns the min of the two input values.
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   327
 */
156
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   328
template <int N>
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   329
TimeUnit<N> Min (TimeUnit<N> const &ta, TimeUnit<N> const &tb)
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   330
{
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   331
  HighPrecision a = ta.GetHighPrecision ();
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   332
  HighPrecision b = tb.GetHighPrecision ();  
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   333
  return TimeUnit<N> (Max (a, b));
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   334
}
151
8395af452e55 add Scale/Min/Max/Abs non-member functions
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   335
339
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   336
// Explicit instatiation of the TimeUnit template for N=1, with a few
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   337
// additional methods that should not be available for N!=1
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   338
// \class TimeUnit<1>
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   339
2390
7e6dfae536cd add Value support to Time
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2170
diff changeset
   340
class TimeValue;
7e6dfae536cd add Value support to Time
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2170
diff changeset
   341
339
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   342
template <>
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   343
class TimeUnit<1>
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   344
{
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   345
  // -*- New methods -*-
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   346
public:
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   347
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   348
  /**
372
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
   349
   * \brief String constructor
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
   350
   * Construct TimeUnit<1> object from common time expressions like "
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
   351
   * 1ms" or "10s".  Supported units include:
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
   352
   * - s  (seconds)
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
   353
   * - ms (milliseconds)
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
   354
   * - us (microseconds)
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
   355
   * - ns (nanoseconds)
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
   356
   * - ps (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
   357
   * - fs (femtoseconds)
372
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
   358
   *
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
   359
   * There can be no white space between the numerical portion
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
   360
   * and the units.  Any otherwise malformed string causes a fatal error to
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
   361
   * occur.
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
   362
   * \param s The string to parse into a TimeUnit<1>
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
   363
   */
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
   364
  TimeUnit<1>(const std::string& s);
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
   365
  /**
339
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   366
   * \returns an approximation in seconds of the time stored in this
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   367
   *          instance.
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   368
   */
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   369
  double GetSeconds (void) const;
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   370
339
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   371
  /**
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   372
   * \returns an approximation in milliseconds of the time stored in this
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   373
   *          instance.
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   374
   */  
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
   375
  int64_t GetMilliSeconds (void) const;
339
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   376
  /**
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   377
   * \returns an approximation in microseconds of the time stored in this
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   378
   *          instance.
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   379
   */
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   380
  int64_t GetMicroSeconds (void) const;
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   381
  /**
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   382
   * \returns an approximation in nanoseconds of the time stored in this
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   383
   *          instance.
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   384
   */
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   385
  int64_t GetNanoSeconds (void) const;
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
   386
  /**
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   387
   * \returns an approximation in picoseconds of the time stored in this
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
   *          instance.
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
  int64_t 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
   391
  /**
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
   * \returns an approximation in femtoseconds of the time stored in this
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
   *          instance.
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   394
   */
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
  int64_t 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
   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
   * \returns an approximation of the time stored in this
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
   *          instance in the units specified in m_tsPrecision.
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   399
   */
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
  int64_t GetTimeStep (void) const;
339
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   401
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   402
  // -*- The rest is the the same as in the generic template class -*-
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   403
public:
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   404
  TimeUnit ()
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   405
    : m_data () 
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   406
  {}
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   407
  TimeUnit (TimeUnit const &o)
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   408
    : m_data (o.m_data) {}
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   409
  TimeUnit operator = (TimeUnit const &o) {
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   410
    m_data = o.m_data;
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   411
    return *this;
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   412
  }
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   413
  TimeUnit (HighPrecision data)
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   414
    : m_data (data) {}
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   415
  bool IsZero (void) const {
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   416
    return m_data.Compare (HighPrecision::Zero ()) == 0;
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   417
  }
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   418
  bool IsNegative (void) const {
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   419
    return m_data.Compare (HighPrecision::Zero ()) <= 0;
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   420
  }
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   421
  bool IsPositive (void) const {
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   422
    return m_data.Compare (HighPrecision::Zero ()) >= 0;
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   423
  }
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   424
  bool IsStrictlyNegative (void) const {
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   425
    return m_data.Compare (HighPrecision::Zero ()) < 0;
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   426
  }
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   427
  bool IsStrictlyPositive (void) const {
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   428
    return m_data.Compare (HighPrecision::Zero ()) > 0;
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   429
  }
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   430
  HighPrecision const &GetHighPrecision (void) const {
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   431
    return m_data;
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   432
  }
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   433
  HighPrecision *PeekHighPrecision (void) {
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   434
    return &m_data;
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   435
  }
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
   436
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   437
  static uint64_t UnitsToTimestep (uint64_t unitValue, 
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   438
                                   uint64_t unitFactor);
2390
7e6dfae536cd add Value support to Time
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2170
diff changeset
   439
2433
3a98e1db7f80 PValue -> Attribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2427
diff changeset
   440
  TimeUnit (Attribute value);
3a98e1db7f80 PValue -> Attribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2427
diff changeset
   441
  operator Attribute () const;
339
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   442
private:
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   443
  HighPrecision m_data;
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   444
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   445
  /*
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   446
   * \Returns the value of time_value in units of unitPrec. time_value
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   447
   * must be specified in timestep units (which are the same as the
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   448
   * m_tsPrecision units
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   449
   */
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   450
  int64_t ConvertToUnits (int64_t timeValue, uint64_t unitFactor) const;
339
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   451
};
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   452
159
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   453
/**
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   454
 * \brief keep track of seconds.
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   455
 *
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   456
 * This is an instance of type ns3::TimeUnit<1>: it is
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   457
 * the return value of the ns3::Simulator::Now method
682
d876b6dfb32e more dox improvements
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 681
diff changeset
   458
 * and is needed for the Simulator::Schedule methods.
d876b6dfb32e more dox improvements
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 681
diff changeset
   459
 * The precision of the underlying Time unit can be
d876b6dfb32e more dox improvements
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 681
diff changeset
   460
 * changed with calls to TimeStepPrecision::Set.
159
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   461
 *
681
e1696c31b6eb improve dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 679
diff changeset
   462
 * Time instances can be created through any of the following functions:
159
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   463
 *  - ns3::Seconds
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   464
 *  - ns3::MilliSeconds
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   465
 *  - ns3::MicroSeconds
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   466
 *  - ns3::NanoSeconds
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
   467
 *  - ns3::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
   468
 *  - ns3::FemtoSeconds
159
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   469
 *  - ns3::Now
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   470
 *
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   471
 * Time instances can be added, substracted, multipled and divided using
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   472
 * the standard C++ operators (if you make sure to obey the rules
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   473
 * of the ns3::TimeUnit class template)
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   474
 * To scale a Time instance, you can multiply it with an instance of
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   475
 * the ns3::Scalar class.
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   476
 * Time instances can also be manipulated through the following non-member 
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   477
 * functions:
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   478
 *  - \ref ns3-Time-Abs ns3::Abs
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   479
 *  - \ref ns3-Time-Max ns3::Max
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   480
 *  - \ref ns3-Time-Min ns3::Min
339
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   481
 *
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   482
 * The Time class has the following additional methods not available in
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   483
 * the generic TimeUnit template:
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   484
 * 
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   485
 * \code
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   486
 * double GetSeconds (void) const;
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   487
 * \endcode
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   488
 * returns an approximation in seconds of the time stored in this
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   489
 *          instance.
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   490
 *
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   491
 * \code
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
   492
 * int64_t GetMilliSeconds (void) const;
339
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   493
 * \endcode
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   494
 * returns an approximation in milliseconds of the time stored in this
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   495
 *          instance.
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   496
 *
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   497
 * \code
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   498
 * int64_t GetMicroSeconds (void) const;
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   499
 * \endcode
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   500
 * returns an approximation in microseconds of the time stored in this
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   501
 *          instance.
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   502
 *
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   503
 * \code
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   504
 * int64_t GetNanoSeconds (void) const;
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   505
 * \endcode
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   506
 * returns an approximation in nanoseconds of the time stored in this
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   507
 *          instance.
681
e1696c31b6eb improve dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 679
diff changeset
   508
 *
e1696c31b6eb improve dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 679
diff changeset
   509
 * \code
e1696c31b6eb improve dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 679
diff changeset
   510
 * int64_t GetPicoSeconds (void) const;
e1696c31b6eb improve dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 679
diff changeset
   511
 * \endcode
e1696c31b6eb improve dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 679
diff changeset
   512
 * returns an approximation in picoseconds of the time stored in this
e1696c31b6eb improve dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 679
diff changeset
   513
 *          instance.
e1696c31b6eb improve dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 679
diff changeset
   514
 *
e1696c31b6eb improve dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 679
diff changeset
   515
 * \code
e1696c31b6eb improve dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 679
diff changeset
   516
 * int64_t GetFemtoSeconds (void) const;
e1696c31b6eb improve dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 679
diff changeset
   517
 * \endcode
e1696c31b6eb improve dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 679
diff changeset
   518
 * returns an approximation in femtoseconds of the time stored in this
e1696c31b6eb improve dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 679
diff changeset
   519
 *          instance.
159
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   520
 */
339
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   521
typedef TimeUnit<1> 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
   522
143
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   523
2409
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2408
diff changeset
   524
std::ostream& operator<< (std::ostream& os, const Time & time);
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2408
diff changeset
   525
std::istream& operator>> (std::istream& is, 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
   526
159
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   527
/**
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   528
 * \brief create ns3::Time instances in units of seconds.
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   529
 *
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   530
 * For example:
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   531
 * \code
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   532
 * Time t = Seconds (2.0);
162
5b398ac221c7 make Time relative instead of Absolute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 159
diff changeset
   533
 * Simulator::Schedule (NanoSeconds (5.0), ...);
159
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   534
 * \endcode
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   535
 */
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
   536
Time Seconds (double seconds);
156
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   537
159
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   538
/**
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   539
 * \brief create ns3::Time instances in units of milliseconds.
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   540
 *
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   541
 * For example:
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   542
 * \code
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   543
 * Time t = MilliSeconds (2);
162
5b398ac221c7 make Time relative instead of Absolute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 159
diff changeset
   544
 * Simulator::Schedule (MilliSeconds (5), ...);
159
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   545
 * \endcode
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
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
Time MilliSeconds (uint64_t ms);
159
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   548
/**
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   549
 * \brief create ns3::Time instances in units of microseconds.
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   550
 *
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   551
 * For example:
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   552
 * \code
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   553
 * Time t = MicroSeconds (2);
162
5b398ac221c7 make Time relative instead of Absolute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 159
diff changeset
   554
 * Simulator::Schedule (MicroSeconds (5), ...);
159
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   555
 * \endcode
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   556
 */
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
   557
Time MicroSeconds (uint64_t us);
159
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   558
/**
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   559
 * \brief create ns3::Time instances in units of nanoseconds.
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   560
 *
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   561
 * For example:
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   562
 * \code
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   563
 * Time t = NanoSeconds (2);
162
5b398ac221c7 make Time relative instead of Absolute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 159
diff changeset
   564
 * Simulator::Schedule (NanoSeconds (5), ...);
159
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   565
 * \endcode
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   566
 */
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
   567
Time NanoSeconds (uint64_t 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
   568
/**
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   569
 * \brief create ns3::Time instances in units of 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
   570
 *
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   571
 * For example:
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   572
 * \code
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   573
 * Time t = PicoSeconds (2);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   574
 * Simulator::Schedule (PicoSeconds (5), ...);
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
 * \endcode
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
 */
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   577
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
   578
/**
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
 * \brief create ns3::Time instances in units of 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
   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
 * For example:
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
 * \code
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
 * Time t = FemtoSeconds (2);
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
 * Simulator::Schedule (FemtoSeconds (5), ...);
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
 * \endcode
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
 */
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   587
Time FemtoSeconds (uint64_t fs);
681
e1696c31b6eb improve dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 679
diff changeset
   588
e1696c31b6eb improve dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 679
diff changeset
   589
// internal function not publicly documented
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
   590
Time TimeStep (uint64_t ts);
156
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   591
339
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   592
// Explicit instatiation of the TimeUnit template for N=0, with a few
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   593
// additional methods that should not be available for N != 0
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   594
template <>
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   595
class TimeUnit<0>
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   596
{
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   597
  // -*- New methods -*-
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   598
public:
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   599
  double GetDouble (void) const;
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   600
  TimeUnit<0> (double scalar);
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   601
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   602
  // -*- The rest is the the same as in the generic template class -*-
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   603
public:
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   604
  TimeUnit ()
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   605
    : m_data () 
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   606
  {};
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   607
  TimeUnit (TimeUnit const &o)
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   608
    : m_data (o.m_data) {}
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   609
  TimeUnit operator = (TimeUnit const &o) {
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   610
    m_data = o.m_data;
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   611
    return *this;
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   612
  }
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   613
  TimeUnit (HighPrecision data)
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   614
    : m_data (data) {}
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   615
  bool IsZero (void) const {
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   616
    return m_data.Compare (HighPrecision::Zero ()) == 0;
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   617
  }
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   618
  bool IsNegative (void) const {
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   619
    return m_data.Compare (HighPrecision::Zero ()) <= 0;
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   620
  }
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   621
  bool IsPositive (void) const {
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   622
    return m_data.Compare (HighPrecision::Zero ()) >= 0;
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   623
  }
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   624
  bool IsStrictlyNegative (void) const {
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   625
    return m_data.Compare (HighPrecision::Zero ()) < 0;
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   626
  }
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   627
  bool IsStrictlyPositive (void) const {
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   628
    return m_data.Compare (HighPrecision::Zero ()) > 0;
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   629
  }
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   630
  HighPrecision const &GetHighPrecision (void) const {
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   631
    return m_data;
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   632
  }
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   633
  HighPrecision *PeekHighPrecision (void) {
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   634
    return &m_data;
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   635
  }
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
   636
339
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   637
private:
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   638
  HighPrecision m_data;
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   639
};
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   640
159
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   641
/**
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   642
 * \brief hold scalar values
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   643
 *
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   644
 * This class is used both to construct scalar values to multiply
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   645
 * ns3::Time instances and to hold the return value of
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   646
 * an expression which returns a scalar. For example, the 
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   647
 * following code will output on your terminal 1.5:
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   648
 * \code
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   649
 * Scalar s0 = Scalar (1.5);
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   650
 * Time t1 = Seconds (10.0) * s0;
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   651
 * Time t2 = Seconds (10.0) * Scalar (2.5);
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   652
 * Scalar s1 = Seconds (15.0) / Seconds (10.0);
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   653
 * std::cout << s1.GetDouble () << std::endl;
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   654
 * \endcode
339
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   655
 *
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   656
 * The Scalar class has the following additional methods not available in
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   657
 * the generic TimeUnit template:
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   658
 * \code
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   659
 * double GetDouble (void) const;
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   660
 * \endcode
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   661
 * returns the C double contained in the Scalar instance
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   662
 *
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   663
 * \code
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   664
 * Scalar(double scalar);
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   665
 * \endcode
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   666
 * Constructs a Scalar instance from a C double.
159
e2c8e211039e add doxygen dox for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 158
diff changeset
   667
 */
339
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   668
typedef TimeUnit<0> Scalar;
156
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   669
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   670
typedef TimeUnit<-1> TimeInvert;
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   671
typedef TimeUnit<2> TimeSquare;
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   672
2447
eee344085a96 convert to new helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2438
diff changeset
   673
ATTRIBUTE_ACCESSOR_DEFINE (Time);
eee344085a96 convert to new helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2438
diff changeset
   674
ATTRIBUTE_VALUE_DEFINE (Time);
eee344085a96 convert to new helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2438
diff changeset
   675
ATTRIBUTE_CHECKER_DEFINE (Time);
2427
9245ec163111 split checker from ParamSpec.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
   676
2390
7e6dfae536cd add Value support to Time
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2170
diff changeset
   677
} // namespace ns3
25
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   678
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   679
#endif /* TIME_H */