Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes

ns3::TimeBase Class Reference
[Time]

keep track of global simulation resolution More...

#include <time-base.h>

Collaboration diagram for ns3::TimeBase:
Collaboration graph
[legend]

List of all members.

Classes

struct  Information
struct  Resolution

Public Types

enum  Unit {
  S = 0, MS = 1, US = 2, NS = 3,
  PS = 4, FS = 5, LAST = 6
}

Public Member Functions

 TimeBase (const TimeBase &o)
TimeBase operator= (const TimeBase &o)
 TimeBase (const HighPrecision &data)
bool IsZero (void) const
bool IsNegative (void) const
bool IsPositive (void) const
bool IsStrictlyNegative (void) const
bool IsStrictlyPositive (void) const
HighPrecision const & GetHighPrecision (void) const
HighPrecisionPeekHighPrecision (void)

Static Public Member Functions

static void SetResolution (enum Unit resolution)
static enum Unit GetResolution (void)
static TimeBase FromInteger (uint64_t value, enum Unit timeUnit)
static TimeBase FromDouble (double value, enum Unit timeUnit)
static uint64_t ToInteger (const TimeBase &time, enum Unit timeUnit)
static double ToDouble (const TimeBase &time, enum Unit timeUnit)

Protected Attributes

HighPrecision m_data

Detailed Description

keep track of global simulation resolution

This class is the base class for all time-related classes. It controls the resolution of the underlying time value . The default resolution is nanoseconds. That is, TimeStep (1).GetNanoSeconds () will return 1. It is possible to either increase or decrease the resolution and the code tries really hard to make this easy.

If your resolution is X (say, nanoseconds) and if you create Time objects with a lower resolution (say, picoseconds), don't expect that this code will return 1: PicoSeconds (1).GetPicoSeconds (). It will most likely return 0 because the Time object has only 64 bits of fractional precision which means that PicoSeconds (1) is stored as a 64-bit aproximation of 1/1000 in the Time object. If you later multiply it again by the exact value 1000, the result is unlikely to be 1 exactly. It will be close to 1 but not exactly 1.

In general, it is thus a really bad idea to try to use time objects of a resolution higher than the global resolution controlled through TimeBase::SetResolution. If you do need to use picoseconds, it's thus best to switch the global resolution to picoseconds to avoid nasty surprises.

Another important issue to keep in mind is that if you increase the global resolution, you also implicitely decrease the range of your simulation. i.e., the global simulation time is stored in a 64 bit integer whose interpretation will depend on the global resolution so, 2^64 picoseconds which is the maximum duration of your simulation if the global resolution is picoseconds is smaller than 2^64 nanoseconds which is the maximum duration of your simulation if the global resolution is nanoseconds.

Finally, don't even think about ever changing the global resolution after creating Time objects: all Time objects created before the call to SetResolution will contain values which are not updated to the new resolution. In practice, the default value for the attributes of many models is indeed calculated before the main function of the main program enters. Because of this, if you use one of these models (and it's likely), it's going to be hard to change the global simulation resolution in a way which gives reasonable results. This issue has been filed as bug 954 in the ns-3 bugzilla installation.


Member Enumeration Documentation

The unit to use to interpret a number representing time


Member Function Documentation

TimeBase ns3::TimeBase::FromDouble ( double  value,
enum Unit  timeUnit 
) [inline, static]
Parameters:
value to convert into a Time object
timeUnit the unit of the value to convert
Returns:
a new Time object
See also:
FromInteger, ToInteger, ToDouble
TimeBase ns3::TimeBase::FromInteger ( uint64_t  value,
enum Unit  timeUnit 
) [inline, static]
Parameters:
value to convert into a Time object
timeUnit the unit of the value to convert
Returns:
a new Time object

This method interprets the input value according to the input unit and constructs a matching Time object.

See also:
FromDouble, ToDouble, ToInteger
HighPrecision const & ns3::TimeBase::GetHighPrecision ( void   )  const [inline]

This is really an internal method exported for the needs of the implementation. Please, Do not try to use this method, ever.

Returns:
the ns3::HighPrecision object which holds the value stored in this instance of Time type.
static enum Unit ns3::TimeBase::GetResolution ( void   )  [static]
Returns:
the current global resolution.
bool ns3::TimeBase::IsNegative ( void   )  const [inline]
Returns:
true if the time is negative or zero, false otherwise.
bool ns3::TimeBase::IsPositive ( void   )  const [inline]
Returns:
true if the time is positive or zero, false otherwise.
bool ns3::TimeBase::IsStrictlyNegative ( void   )  const [inline]
Returns:
true if the time is strictly negative, false otherwise.
bool ns3::TimeBase::IsStrictlyPositive ( void   )  const [inline]
Returns:
true if the time is strictly positive, false otherwise.
bool ns3::TimeBase::IsZero ( void   )  const [inline]
Returns:
true if the time is zero, false otherwise.
static void ns3::TimeBase::SetResolution ( enum Unit  resolution  )  [static]
Parameters:
resolution the new resolution to use

Change the global resolution used to convert all user-provided time values in Time objects and Time objects in user-expected time units.

double ns3::TimeBase::ToDouble ( const TimeBase time,
enum Unit  timeUnit 
) [inline, static]
Parameters:
time a Time object
timeUnit the unit of the value to return

Convert the input time into a floating point value according to the requested time unit.

uint64_t ns3::TimeBase::ToInteger ( const TimeBase time,
enum Unit  timeUnit 
) [inline, static]
Parameters:
time a Time object
timeUnit the unit of the value to return

Convert the input time into an integer value according to the requested time unit.


The documentation for this class was generated from the following file: