A Discrete-Event Network Simulator
API
nstime.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2005,2006 INRIA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 #ifndef TIME_H
21 #define TIME_H
22 
23 #include "assert.h"
24 #include "attribute.h"
25 #include "attribute-helper.h"
26 #include "int64x64.h"
27 #include "unused.h"
28 #include <stdint.h>
29 #include <limits>
30 #include <cmath>
31 #include <ostream>
32 #include <set>
33 
41 namespace ns3 {
42 
43 class TimeWithUnit;
44 
102 class Time
103 {
104 public:
108  enum Unit
109  {
110  Y = 0,
111  D = 1,
112  H = 2,
113  MIN = 3,
114  S = 4,
115  MS = 5,
116  US = 6,
117  NS = 7,
118  PS = 8,
119  FS = 9,
120  LAST = 10
121  };
122 
128  inline Time & operator = (const Time & o)
129  {
130  m_data = o.m_data;
131  return *this;
132  }
134  inline Time ()
135  : m_data ()
136  {
137  if (g_markingTimes)
138  {
139  Mark (this);
140  }
141  }
147  inline Time(const Time & o)
148  : m_data (o.m_data)
149  {
150  if (g_markingTimes)
151  {
152  Mark (this);
153  }
154  }
165  explicit inline Time (double v)
166  : m_data (lround (v))
167  {
168  if (g_markingTimes)
169  {
170  Mark (this);
171  }
172  }
173  explicit inline Time (int v)
174  : m_data (v)
175  {
176  if (g_markingTimes)
177  {
178  Mark (this);
179  }
180  }
181  explicit inline Time (long int v)
182  : m_data (v)
183  {
184  if (g_markingTimes)
185  {
186  Mark (this);
187  }
188  }
189  explicit inline Time (long long int v)
190  : m_data (v)
191  {
192  if (g_markingTimes)
193  {
194  Mark (this);
195  }
196  }
197  explicit inline Time (unsigned int v)
198  : m_data (v)
199  {
200  if (g_markingTimes)
201  {
202  Mark (this);
203  }
204  }
205  explicit inline Time (unsigned long int v)
206  : m_data (v)
207  {
208  if (g_markingTimes)
209  {
210  Mark (this);
211  }
212  }
213  explicit inline Time (unsigned long long int v)
214  : m_data (v)
215  {
216  if (g_markingTimes)
217  {
218  Mark (this);
219  }
220  }
221  explicit inline Time (const int64x64_t & v)
222  : m_data (v.GetHigh ())
223  {
224  if (g_markingTimes)
225  {
226  Mark (this);
227  }
228  }
251  explicit Time (const std::string & s);
252 
254  static Time Min ()
255  {
257  }
259  static Time Max ()
260  {
262  }
263 
265  ~Time ()
266  {
267  if (g_markingTimes)
268  {
269  Clear (this);
270  }
271  }
272 
274  inline bool IsZero (void) const
275  {
276  return m_data == 0;
277  }
279  inline bool IsNegative (void) const
280  {
281  return m_data <= 0;
282  }
284  inline bool IsPositive (void) const
285  {
286  return m_data >= 0;
287  }
289  inline bool IsStrictlyNegative (void) const
290  {
291  return m_data < 0;
292  }
294  inline bool IsStrictlyPositive (void) const
295  {
296  return m_data > 0;
297  }
304  inline int Compare (const Time & o) const
305  {
306  return (m_data < o.m_data) ? -1 : (m_data == o.m_data) ? 0 : 1;
307  }
308 
325  inline double GetYears (void) const
326  {
327  return ToDouble (Time::Y);
328  }
329  inline double GetDays (void) const
330  {
331  return ToDouble (Time::D);
332  }
333  inline double GetHours (void) const
334  {
335  return ToDouble (Time::H);
336  }
337  inline double GetMinutes (void) const
338  {
339  return ToDouble (Time::MIN);
340  }
341  inline double GetSeconds (void) const
342  {
343  return ToDouble (Time::S);
344  }
345  inline int64_t GetMilliSeconds (void) const
346  {
347  return ToInteger (Time::MS);
348  }
349  inline int64_t GetMicroSeconds (void) const
350  {
351  return ToInteger (Time::US);
352  }
353  inline int64_t GetNanoSeconds (void) const
354  {
355  return ToInteger (Time::NS);
356  }
357  inline int64_t GetPicoSeconds (void) const
358  {
359  return ToInteger (Time::PS);
360  }
361  inline int64_t GetFemtoSeconds (void) const
362  {
363  return ToInteger (Time::FS);
364  }
377  inline int64_t GetTimeStep (void) const
378  {
379  return m_data;
380  }
381  inline double GetDouble (void) const
382  {
383  return m_data;
384  }
385  inline int64_t GetInteger (void) const
386  {
387  return GetTimeStep ();
388  }
399  static void SetResolution (enum Unit resolution);
403  static enum Unit GetResolution (void);
404 
405 
412  inline static Time From (const int64x64_t & value)
413  {
414  return Time (value);
415  }
429  inline static Time FromInteger (uint64_t value, enum Unit unit)
430  {
431  struct Information *info = PeekInformation (unit);
432  if (info->fromMul)
433  {
434  value *= info->factor;
435  }
436  else
437  {
438  value /= info->factor;
439  }
440  return Time (value);
441  }
442  inline static Time FromDouble (double value, enum Unit unit)
443  {
444  return From (int64x64_t (value), unit);
445  }
446  inline static Time From (const int64x64_t & value, enum Unit unit)
447  {
448  struct Information *info = PeekInformation (unit);
449  // DO NOT REMOVE this temporary variable. It's here
450  // to work around a compiler bug in gcc 3.4
451  int64x64_t retval = value;
452  if (info->fromMul)
453  {
454  retval *= info->timeFrom;
455  }
456  else
457  {
458  retval.MulByInvert (info->timeFrom);
459  }
460  return Time (retval);
461  }
477  inline int64_t ToInteger (enum Unit unit) const
478  {
479  struct Information *info = PeekInformation (unit);
480  int64_t v = m_data;
481  if (info->toMul)
482  {
483  v *= info->factor;
484  }
485  else
486  {
487  v /= info->factor;
488  }
489  return v;
490  }
491  inline double ToDouble (enum Unit unit) const
492  {
493  return To (unit).GetDouble ();
494  }
495  inline int64x64_t To (enum Unit unit) const
496  {
497  struct Information *info = PeekInformation (unit);
498  int64x64_t retval = int64x64_t (m_data);
499  if (info->toMul)
500  {
501  retval *= info->timeTo;
502  }
503  else
504  {
505  retval.MulByInvert (info->timeTo);
506  }
507  return retval;
508  }
513  inline operator int64x64_t () const
514  {
515  return int64x64_t (m_data);
516  }
517 
518 
532  TimeWithUnit As (const enum Unit unit) const;
533 
534 private:
536  struct Information
537  {
538  bool toMul;
539  bool fromMul;
540  int64_t factor;
543  };
545  struct Resolution
546  {
549  };
550 
556  static inline struct Resolution *PeekResolution (void)
557  {
558  static struct Time::Resolution resolution = SetDefaultNsResolution ();
559  return & resolution;
560  }
567  static inline struct Information *PeekInformation (enum Unit timeUnit)
568  {
569  return & (PeekResolution ()->info[timeUnit]);
570  }
571 
577  static struct Resolution SetDefaultNsResolution (void);
585  static void SetResolution (enum Unit unit, struct Resolution *resolution,
586  const bool convert = true);
587 
607  typedef std::set< Time * > MarkedTimes;
622  static MarkedTimes * g_markingTimes;
623 public:
629  static bool StaticInit ();
630 private:
631 
632  /* Friend the Simulator class so it can call the private function
633  ClearMarkedTimes ()
634  */
635  friend class Simulator;
642  static void ClearMarkedTimes ();
647  static void Mark (Time * const time);
652  static void Clear (Time * const time);
657  static void ConvertTimes (const enum Unit unit);
658 
659  /*
660  * \name Arithmetic Operators
661  * Arithmetic operators between Times, and scaling by scalars.
662  */
670  friend bool operator == (const Time & lhs, const Time & rhs);
671  friend bool operator != (const Time & lhs, const Time & rhs);
672  friend bool operator <= (const Time & lhs, const Time & rhs);
673  friend bool operator >= (const Time & lhs, const Time & rhs);
674  friend bool operator < (const Time & lhs, const Time & rhs);
675  friend bool operator > (const Time & lhs, const Time & rhs);
676  friend Time operator + (const Time & lhs, const Time & rhs);
677  friend Time operator - (const Time & lhs, const Time & rhs);
678  friend Time operator * (const Time & lhs, const int64_t & rhs);
679  friend Time operator * (const int64_t & lhs, const Time & rhs);
680  friend int64_t operator / (const Time & lhs, const Time & rhs);
681  friend Time operator / (const Time & lhs, const int64_t & rhs);
682  friend Time & operator += (Time & lhs, const Time & rhs);
683  friend Time & operator -= (Time & lhs, const Time & rhs);
691  friend Time Abs (const Time & time);
698  friend Time Max (const Time & ta, const Time & tb);
705  friend Time Min (const Time & ta, const Time & tb);
706 
707  int64_t m_data;
708 
709 }; // class Time
710 
711 namespace TracedValueCallback {
712 
719  typedef void (* Time)(Time oldValue, Time newValue);
720 
721 } // namespace TracedValueCallback
722 
724 static bool NS_UNUSED_GLOBAL (g_TimeStaticInit) = Time::StaticInit ();
725 
733 inline bool
734 operator == (const Time & lhs, const Time & rhs)
735 {
736  return lhs.m_data == rhs.m_data;
737 }
745 inline bool
746 operator != (const Time & lhs, const Time & rhs)
747 {
748  return lhs.m_data != rhs.m_data;
749 }
757 inline bool
758 operator <= (const Time & lhs, const Time & rhs)
759 {
760  return lhs.m_data <= rhs.m_data;
761 }
769 inline bool
770 operator >= (const Time & lhs, const Time & rhs)
771 {
772  return lhs.m_data >= rhs.m_data;
773 }
781 inline bool
782 operator < (const Time & lhs, const Time & rhs)
783 {
784  return lhs.m_data < rhs.m_data;
785 }
793 inline bool
794 operator > (const Time & lhs, const Time & rhs)
795 {
796  return lhs.m_data > rhs.m_data;
797 }
805 inline Time operator + (const Time & lhs, const Time & rhs)
806 {
807  return Time (lhs.m_data + rhs.m_data);
808 }
816 inline Time operator - (const Time & lhs, const Time & rhs)
817 {
818  return Time (lhs.m_data - rhs.m_data);
819 }
827 inline Time
828 operator * (const Time & lhs, const int64_t & rhs)
829 {
830  Time res = lhs;
831  res.m_data *= rhs;
832  return res;
833 }
841 inline Time
842 operator * (const int64_t & lhs, const Time & rhs)
843 {
844  Time res = rhs;
845  res.m_data *= lhs;
846  return res;
847 }
855 inline int64_t
856 operator / (const Time & lhs, const Time & rhs)
857 {
858  int64_t res = lhs.m_data / rhs.m_data;
859  return res;
860 }
868 inline Time
869 operator / (const Time & lhs, const int64_t & rhs)
870 {
871  Time res = lhs;
872  res.m_data /= rhs;
873  return res;
874 }
882 inline Time & operator += (Time & lhs, const Time & rhs)
883 {
884  lhs.m_data += rhs.m_data;
885  return lhs;
886 }
894 inline Time & operator -= (Time & lhs, const Time & rhs)
895 {
896  lhs.m_data -= rhs.m_data;
897  return lhs;
898 }
901 inline Time Abs (const Time & time)
902 {
903  return Time ((time.m_data < 0) ? -time.m_data : time.m_data);
904 }
905 inline Time Max (const Time & ta, const Time & tb)
906 {
907  return Time ((ta.m_data < tb.m_data) ? tb : ta);
908 }
909 inline Time Min (const Time & ta, const Time & tb)
910 {
911  return Time ((ta.m_data > tb.m_data) ? tb : ta);
912 }
913 
930 std::ostream & operator << (std::ostream & os, const Time & time);
941 std::istream & operator >> (std::istream & is, Time & time);
942 
961 inline Time Years (double value)
962 {
963  return Time::FromDouble (value, Time::Y);
964 }
965 inline Time Years (int64x64_t value)
966 {
967  return Time::From (value, Time::Y);
968 }
969 inline Time Days (double value)
970 {
971  return Time::FromDouble (value, Time::D);
972 }
973 inline Time Days (int64x64_t value)
974 {
975  return Time::From (value, Time::D);
976 }
977 inline Time Hours (double value)
978 {
979  return Time::FromDouble (value, Time::H);
980 }
981 inline Time Hours (int64x64_t value)
982 {
983  return Time::From (value, Time::H);
984 }
985 inline Time Minutes (double value)
986 {
987  return Time::FromDouble (value, Time::MIN);
988 }
989 inline Time Minutes (int64x64_t value)
990 {
991  return Time::From (value, Time::MIN);
992 }
993 inline Time Seconds (double value)
994 {
995  return Time::FromDouble (value, Time::S);
996 }
997 inline Time Seconds (int64x64_t value)
998 {
999  return Time::From (value, Time::S);
1000 }
1001 inline Time MilliSeconds (uint64_t value)
1002 {
1003  return Time::FromInteger (value, Time::MS);
1004 }
1006 {
1007  return Time::From (value, Time::MS);
1008 }
1009 inline Time MicroSeconds (uint64_t value)
1010 {
1011  return Time::FromInteger (value, Time::US);
1012 }
1014 {
1015  return Time::From (value, Time::US);
1016 }
1017 inline Time NanoSeconds (uint64_t value)
1018 {
1019  return Time::FromInteger (value, Time::NS);
1020 }
1022 {
1023  return Time::From (value, Time::NS);
1024 }
1025 inline Time PicoSeconds (uint64_t value)
1026 {
1027  return Time::FromInteger (value, Time::PS);
1028 }
1030 {
1031  return Time::From (value, Time::PS);
1032 }
1033 inline Time FemtoSeconds (uint64_t value)
1034 {
1035  return Time::FromInteger (value, Time::FS);
1036 }
1038 {
1039  return Time::From (value, Time::FS);
1040 }
1050 inline Time TimeStep (uint64_t ts)
1051 {
1052  return Time (ts);
1053 }
1054 
1057 
1068 
1075 inline
1077 {
1078  return MakeTimeChecker (Time::Min (), Time::Max ());
1079 }
1080 
1088 inline
1090 {
1091  return MakeTimeChecker (min, Time::Max ());
1092 }
1093 
1099 {
1100 public:
1107  TimeWithUnit (const Time time, const Time::Unit unit)
1108  : m_time (time),
1109  m_unit (unit)
1110  { };
1111 
1112 private:
1113  Time m_time;
1115 
1122  friend std::ostream & operator << (std::ostream & os, const TimeWithUnit & timeU);
1123 
1124 }; // class TimeWithUnit
1125 
1126 } // namespace ns3
1127 
1128 #endif /* TIME_H */
int64x64_t & operator+=(int64x64_t &lhs, const int64x64_t &rhs)
Compound addition operator.
Definition: int64x64-128.h:373
static struct Resolution * PeekResolution(void)
Get the current Resolution.
Definition: nstime.h:556
Unit
The unit to use to interpret a number representing time.
Definition: nstime.h:108
std::istream & operator>>(std::istream &is, Angles &a)
initialize a struct Angles from input
Definition: angles.cc:48
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
bool IsPositive(void) const
Definition: nstime.h:284
Control the scheduling of simulation events.
Definition: simulator.h:68
int64x64_t operator+(const int64x64_t &lhs)
Unary plus operator.
Definition: int64x64-128.h:410
friend Time operator*(const Time &lhs, const int64_t &rhs)
Multiplication operator for Time.
Definition: nstime.h:828
int64x64_t timeFrom
Multiplier to convert from this unit.
Definition: nstime.h:542
static Time Min()
Minimum representable Time.
Definition: nstime.h:254
A Time with attached unit, to facilitate output in that unit.
Definition: nstime.h:1098
int64_t ToInteger(enum Unit unit) const
Get the Time value expressed in a particular unit.
Definition: nstime.h:477
#define min(a, b)
Definition: 80211b.c:44
High precision numerical type, implementing Q64.64 fixed precision.
Definition: int64x64-128.h:45
bool IsZero(void) const
Definition: nstime.h:274
friend bool operator<(const Time &lhs, const Time &rhs)
Less than operator for Time.
Definition: nstime.h:782
friend bool operator!=(const Time &lhs, const Time &rhs)
Inequality operator for Time.
Definition: nstime.h:746
#define ATTRIBUTE_VALUE_DEFINE(name)
Declare the attribute value class nameValue for the class name.
int64x64_t operator-(const int64x64_t &lhs)
Unary negation operator (change sign operator).
Definition: int64x64-128.h:418
static Time From(const int64x64_t &value)
Create a Time in the current unit.
Definition: nstime.h:412
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1001
second
Definition: nstime.h:114
void MulByInvert(const int64x64_t &o)
Multiply this value by a Q0.128 value, presumably representing an inverse, completing a division oper...
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Definition: nstime.h:719
int64_t GetFemtoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:361
double GetDouble(void) const
Get this value as a double.
Definition: int64x64-128.h:203
Time(unsigned long int v)
Construct from a numeric value.
Definition: nstime.h:205
Time(const int64x64_t &v)
Construct from a numeric value.
Definition: nstime.h:221
bool operator>=(const int64x64_t &lhs, const int64x64_t &rhs)
Greater or equal operator.
Definition: int64x64.h:145
int Compare(const Time &o) const
Compare this to another Time.
Definition: nstime.h:304
millisecond
Definition: nstime.h:115
hour, 60 minutes
Definition: nstime.h:112
friend Time operator-(const Time &lhs, const Time &rhs)
Difference operator for Time.
Definition: nstime.h:816
int64x64_t To(enum Unit unit) const
Get the Time value expressed in a particular unit.
Definition: nstime.h:495
bool operator<(const EventId &a, const EventId &b)
Definition: event-id.h:153
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:446
Time PicoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1025
struct Information info[LAST]
Conversion info from current unit.
Definition: nstime.h:547
static bool NS_UNUSED_GLOBAL(g_TimeStaticInit)
Force static initialization of Time.
day, 24 hours
Definition: nstime.h:111
friend Time operator+(const Time &lhs, const Time &rhs)
Addition operator for Time.
Definition: nstime.h:805
static Time Max()
Maximum representable Time.
Definition: nstime.h:259
friend Time Abs(const Time &time)
Absolute value function for Time.
Definition: nstime.h:901
bool operator<=(const int64x64_t &lhs, const int64x64_t &rhs)
Less or equal operator.
Definition: int64x64.h:137
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:341
int64x64_t operator*(const int64x64_t &lhs, const int64x64_t &rhs)
Multiplication operator.
Definition: int64x64.h:108
int64x64_t Min(const int64x64_t &a, const int64x64_t &b)
Minimum.
Definition: int64x64.h:197
Time(int v)
Construct from a numeric value.
Definition: nstime.h:173
Time Years(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:961
#define max(a, b)
Definition: 80211b.c:45
static enum Unit GetResolution(void)
Definition: time.cc:380
int64_t GetMicroSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:349
friend Time & operator-=(Time &lhs, const Time &rhs)
Subtraction operator for Time.
Definition: nstime.h:894
Time(long long int v)
Construct from a numeric value.
Definition: nstime.h:189
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1017
Current time unit, and conversion info.
Definition: nstime.h:545
static bool StaticInit()
Function to force static initialization of Time.
Definition: time.cc:63
NS_ASSERT() and NS_ASSERT_MSG() macro definitions.
bool IsStrictlyPositive(void) const
Definition: nstime.h:294
bool fromMul
Multiple when converting From, otherwise divide.
Definition: nstime.h:539
friend std::ostream & operator<<(std::ostream &os, const TimeWithUnit &timeU)
Output streamer.
Definition: time.cc:403
static Time From(const int64x64_t &value, enum Unit unit)
Create a Time equal to value in unit unit.
Definition: nstime.h:446
double ToDouble(enum Unit unit) const
Get the Time value expressed in a particular unit.
Definition: nstime.h:491
ns3::AttributeValue, ns3::AttributeAccessor and ns3::AttributeChecker declarations.
int64x64_t Max(const int64x64_t &a, const int64x64_t &b)
Maximum.
Definition: int64x64.h:209
year, 365 days
Definition: nstime.h:110
static void ConvertTimes(const enum Unit unit)
Convert existing Times to the new unit.
Definition: time.cc:343
friend bool operator>=(const Time &lhs, const Time &rhs)
Greater than or equal operator for Time.
Definition: nstime.h:770
minute, 60 seconds
Definition: nstime.h:113
Time(long int v)
Construct from a numeric value.
Definition: nstime.h:181
static struct Resolution SetDefaultNsResolution(void)
Set the default resolution.
Definition: time.cc:170
femtosecond
Definition: nstime.h:119
int64_t factor
Ratio of this unit / current unit.
Definition: nstime.h:540
int64x64_t operator/(const int64x64_t &lhs, const int64x64_t &rhs)
Division operator.
Definition: int64x64.h:119
int64x64_t Abs(const int64x64_t &value)
Absolute value.
Definition: int64x64.h:184
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:42
Time(double v)
Construct from a numeric value.
Definition: nstime.h:165
bool operator!=(Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 > a, Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 > b)
Inequality test.
Definition: callback.h:1471
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Time(unsigned long long int v)
Construct from a numeric value.
Definition: nstime.h:213
friend Time & operator+=(Time &lhs, const Time &rhs)
Addition operator for Time.
Definition: nstime.h:882
friend bool operator==(const Time &lhs, const Time &rhs)
Arithmetic operator.
Definition: nstime.h:734
bool IsNegative(void) const
Definition: nstime.h:279
int64_t GetTimeStep(void) const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:377
friend int64_t operator/(const Time &lhs, const Time &rhs)
Division operator for Time.
Definition: nstime.h:856
Time Hours(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:977
Time TimeStep(uint64_t ts)
Definition: nstime.h:1050
double GetHours(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:333
Time()
Default constructor, with value 0.
Definition: nstime.h:134
int64_t GetInteger(void) const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:385
~Time()
Destructor.
Definition: nstime.h:265
double GetDouble(void) const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:381
static struct Information * PeekInformation(enum Unit timeUnit)
Get the Information record for timeUnit for the current Resolution.
Definition: nstime.h:567
Attribute helper (ATTRIBUTE_ )macros definition.
Time Minutes(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:985
int64_t GetNanoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:353
static Time FromDouble(double value, enum Unit unit)
Create a Time equal to value in unit unit.
Definition: nstime.h:442
#define ATTRIBUTE_ACCESSOR_DEFINE(type)
Define the attribute accessor functions MakeTypeAccessor for class type.
Time(unsigned int v)
Construct from a numeric value.
Definition: nstime.h:197
static void Mark(Time *const time)
Record a Time instance with the MarkedTimes.
Definition: time.cc:287
microsecond
Definition: nstime.h:116
friend bool operator>(const Time &lhs, const Time &rhs)
Greater than operator for Time.
Definition: nstime.h:794
int64_t GetPicoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:357
TimeWithUnit As(const enum Unit unit) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:388
How to convert between other units and the current unit.
Definition: nstime.h:536
static Time FromInteger(uint64_t value, enum Unit unit)
Create a Time equal to value in unit unit.
Definition: nstime.h:429
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:993
double GetDays(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:329
bool operator>(const int64x64_t &lhs, const int64x64_t &rhs)
Greater operator.
Definition: int64x64-128.h:364
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.h:135
enum Time::Unit unit
Current time unit.
Definition: nstime.h:548
Time::Unit m_unit
The unit to use in output.
Definition: nstime.h:1114
bool IsStrictlyNegative(void) const
Definition: nstime.h:289
static void SetResolution(enum Unit resolution)
Definition: time.cc:180
static void Clear(Time *const time)
Remove a Time instance from the MarkedTimes, called by ~Time().
Definition: time.cc:313
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1009
TimeWithUnit(const Time time, const Time::Unit unit)
Attach a unit to a Time.
Definition: nstime.h:1107
picosecond
Definition: nstime.h:118
int64x64_t & operator-=(int64x64_t &lhs, const int64x64_t &rhs)
Compound subtraction operator.
Definition: int64x64-128.h:382
nanosecond
Definition: nstime.h:117
std::set< Time * > MarkedTimes
Record all instances of Time, so we can rescale them when the resolution changes. ...
Definition: nstime.h:607
static MarkedTimes * g_markingTimes
Record of outstanding Time objects which will need conversion when the resolution is set...
Definition: nstime.h:622
Time Days(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:969
Time FemtoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1033
double GetYears(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:325
static void ClearMarkedTimes()
Remove all MarkedTimes.
Definition: time.cc:256
friend bool operator<=(const Time &lhs, const Time &rhs)
Less than or equal operator for Time.
Definition: nstime.h:758
int64_t GetMilliSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:345
Declaration of the ns3::int64x64_t type and associated operators.
double GetMinutes(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:337
Time & operator=(const Time &o)
Assignment operator.
Definition: nstime.h:128
Time m_time
The time.
Definition: nstime.h:1110
int64x64_t timeTo
Multiplier to convert to this unit.
Definition: nstime.h:541
Time(const Time &o)
Copy constructor.
Definition: nstime.h:147
int64_t m_data
Virtual time value, in the current unit.
Definition: nstime.h:707
bool toMul
Multiply when converting To, otherwise divide.
Definition: nstime.h:538
NS_UNUSED and NS_UNUSED_GLOBAL macro definitions.