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  }
155 
161  Time (Time &&o)
162  : m_data (o.m_data)
163  {
164  if (g_markingTimes)
165  {
166  Mark (this);
167  }
168  }
179  explicit inline Time (double v)
180  : m_data (lround (v))
181  {
182  if (g_markingTimes)
183  {
184  Mark (this);
185  }
186  }
187  explicit inline Time (int v)
188  : m_data (v)
189  {
190  if (g_markingTimes)
191  {
192  Mark (this);
193  }
194  }
195  explicit inline Time (long int v)
196  : m_data (v)
197  {
198  if (g_markingTimes)
199  {
200  Mark (this);
201  }
202  }
203  explicit inline Time (long long int v)
204  : m_data (v)
205  {
206  if (g_markingTimes)
207  {
208  Mark (this);
209  }
210  }
211  explicit inline Time (unsigned int v)
212  : m_data (v)
213  {
214  if (g_markingTimes)
215  {
216  Mark (this);
217  }
218  }
219  explicit inline Time (unsigned long int v)
220  : m_data (v)
221  {
222  if (g_markingTimes)
223  {
224  Mark (this);
225  }
226  }
227  explicit inline Time (unsigned long long int v)
228  : m_data (v)
229  {
230  if (g_markingTimes)
231  {
232  Mark (this);
233  }
234  }
235  explicit inline Time (const int64x64_t & v)
236  : m_data (v.GetHigh ())
237  {
238  if (g_markingTimes)
239  {
240  Mark (this);
241  }
242  }
265  explicit Time (const std::string & s);
266 
271  static Time Min ()
272  {
274  }
279  static Time Max ()
280  {
282  }
283 
285  ~Time ()
286  {
287  if (g_markingTimes)
288  {
289  Clear (this);
290  }
291  }
292 
294  inline bool IsZero (void) const
295  {
296  return m_data == 0;
297  }
299  inline bool IsNegative (void) const
300  {
301  return m_data <= 0;
302  }
304  inline bool IsPositive (void) const
305  {
306  return m_data >= 0;
307  }
309  inline bool IsStrictlyNegative (void) const
310  {
311  return m_data < 0;
312  }
314  inline bool IsStrictlyPositive (void) const
315  {
316  return m_data > 0;
317  }
324  inline int Compare (const Time & o) const
325  {
326  return (m_data < o.m_data) ? -1 : (m_data == o.m_data) ? 0 : 1;
327  }
328 
345  inline double GetYears (void) const
346  {
347  return ToDouble (Time::Y);
348  }
349  inline double GetDays (void) const
350  {
351  return ToDouble (Time::D);
352  }
353  inline double GetHours (void) const
354  {
355  return ToDouble (Time::H);
356  }
357  inline double GetMinutes (void) const
358  {
359  return ToDouble (Time::MIN);
360  }
361  inline double GetSeconds (void) const
362  {
363  return ToDouble (Time::S);
364  }
365  inline int64_t GetMilliSeconds (void) const
366  {
367  return ToInteger (Time::MS);
368  }
369  inline int64_t GetMicroSeconds (void) const
370  {
371  return ToInteger (Time::US);
372  }
373  inline int64_t GetNanoSeconds (void) const
374  {
375  return ToInteger (Time::NS);
376  }
377  inline int64_t GetPicoSeconds (void) const
378  {
379  return ToInteger (Time::PS);
380  }
381  inline int64_t GetFemtoSeconds (void) const
382  {
383  return ToInteger (Time::FS);
384  }
397  inline int64_t GetTimeStep (void) const
398  {
399  return m_data;
400  }
401  inline double GetDouble (void) const
402  {
403  return static_cast<double> (m_data);
404  }
405  inline int64_t GetInteger (void) const
406  {
407  return GetTimeStep ();
408  }
419  static void SetResolution (enum Unit resolution);
423  static enum Unit GetResolution (void);
424 
425 
432  inline static Time From (const int64x64_t & value)
433  {
434  return Time (value);
435  }
449  inline static Time FromInteger (uint64_t value, enum Unit unit)
450  {
451  struct Information *info = PeekInformation (unit);
452  if (info->fromMul)
453  {
454  value *= info->factor;
455  }
456  else
457  {
458  value /= info->factor;
459  }
460  return Time (value);
461  }
462  inline static Time FromDouble (double value, enum Unit unit)
463  {
464  return From (int64x64_t (value), unit);
465  }
466  inline static Time From (const int64x64_t & value, enum Unit unit)
467  {
468  struct Information *info = PeekInformation (unit);
469  // DO NOT REMOVE this temporary variable. It's here
470  // to work around a compiler bug in gcc 3.4
471  int64x64_t retval = value;
472  if (info->fromMul)
473  {
474  retval *= info->timeFrom;
475  }
476  else
477  {
478  retval.MulByInvert (info->timeFrom);
479  }
480  return Time (retval);
481  }
497  inline int64_t ToInteger (enum Unit unit) const
498  {
499  struct Information *info = PeekInformation (unit);
500  int64_t v = m_data;
501  if (info->toMul)
502  {
503  v *= info->factor;
504  }
505  else
506  {
507  v /= info->factor;
508  }
509  return v;
510  }
511  inline double ToDouble (enum Unit unit) const
512  {
513  return To (unit).GetDouble ();
514  }
515  inline int64x64_t To (enum Unit unit) const
516  {
517  struct Information *info = PeekInformation (unit);
518  int64x64_t retval = int64x64_t (m_data);
519  if (info->toMul)
520  {
521  retval *= info->timeTo;
522  }
523  else
524  {
525  retval.MulByInvert (info->timeTo);
526  }
527  return retval;
528  }
544  TimeWithUnit As (const enum Unit unit) const;
545 
551  typedef void (* TracedCallback)(Time value);
552 
553 private:
555  struct Information
556  {
557  bool toMul;
558  bool fromMul;
559  int64_t factor;
562  };
564  struct Resolution
565  {
568  };
569 
575  static inline struct Resolution * PeekResolution (void)
576  {
577  static struct Time::Resolution resolution = SetDefaultNsResolution ();
578  return &resolution;
579  }
586  static inline struct Information * PeekInformation (enum Unit timeUnit)
587  {
588  return &(PeekResolution ()->info[timeUnit]);
589  }
590 
596  static struct Resolution SetDefaultNsResolution (void);
604  static void SetResolution (enum Unit unit, struct Resolution *resolution,
605  const bool convert = true);
606 
626  typedef std::set< Time * > MarkedTimes;
642 
643 public:
649  static bool StaticInit ();
650 
651 private:
652 
656  friend class Simulator;
663  static void ClearMarkedTimes ();
668  static void Mark (Time * const time);
673  static void Clear (Time * const time);
678  static void ConvertTimes (const enum Unit unit);
679 
680  /*
681  * \name Arithmetic Operators
682  * Arithmetic operators between Times, and scaling by scalars.
683  */
691  friend bool operator == (const Time & lhs, const Time & rhs);
692  friend bool operator != (const Time & lhs, const Time & rhs);
693  friend bool operator <= (const Time & lhs, const Time & rhs);
694  friend bool operator >= (const Time & lhs, const Time & rhs);
695  friend bool operator < (const Time & lhs, const Time & rhs);
696  friend bool operator > (const Time & lhs, const Time & rhs);
697  friend Time operator + (const Time & lhs, const Time & rhs);
698  friend Time operator - (const Time & lhs, const Time & rhs);
699  friend Time operator * (const Time & lhs, const int64_t & rhs);
700  friend Time operator * (const int64_t & lhs, const Time & rhs);
701  friend Time operator * (const Time & lhs, const int64x64_t & rhs);
702  friend Time operator * (const int64x64_t & lhs, const Time & rhs);
703  friend int64x64_t operator / (const Time & lhs, const Time & rhs);
704  friend Time operator / (const Time & lhs, const int64_t & rhs);
705  friend Time operator / (const Time & lhs, const int64x64_t & rhs);
706  friend Time & operator += (Time & lhs, const Time & rhs);
707  friend Time & operator -= (Time & lhs, const Time & rhs);
715  friend Time Abs (const Time & time);
722  friend Time Max (const Time & ta, const Time & tb);
729  friend Time Min (const Time & ta, const Time & tb);
730 
731  int64_t m_data;
732 
733 }; // class Time
734 
735 namespace TracedValueCallback {
736 
743 typedef void (* Time)(Time oldValue, Time newValue);
744 
745 } // namespace TracedValueCallback
746 
749 
760 inline bool
761 operator == (const Time & lhs, const Time & rhs)
762 {
763  return lhs.m_data == rhs.m_data;
764 }
772 inline bool
773 operator != (const Time & lhs, const Time & rhs)
774 {
775  return lhs.m_data != rhs.m_data;
776 }
784 inline bool
785 operator <= (const Time & lhs, const Time & rhs)
786 {
787  return lhs.m_data <= rhs.m_data;
788 }
796 inline bool
797 operator >= (const Time & lhs, const Time & rhs)
798 {
799  return lhs.m_data >= rhs.m_data;
800 }
808 inline bool
809 operator < (const Time & lhs, const Time & rhs)
810 {
811  return lhs.m_data < rhs.m_data;
812 }
820 inline bool
821 operator > (const Time & lhs, const Time & rhs)
822 {
823  return lhs.m_data > rhs.m_data;
824 }
832 inline Time operator + (const Time & lhs, const Time & rhs)
833 {
834  return Time (lhs.m_data + rhs.m_data);
835 }
843 inline Time operator - (const Time & lhs, const Time & rhs)
844 {
845  return Time (lhs.m_data - rhs.m_data);
846 }
854 inline Time
855 operator * (const Time & lhs, const int64_t & rhs)
856 {
857  Time res = lhs;
858  res.m_data *= rhs;
859  return res;
860 }
868 inline Time
869 operator * (const int64_t & lhs, const Time & rhs)
870 {
871  Time res = rhs;
872  res.m_data *= lhs;
873  return res;
874 }
882 inline Time
883 operator * (const Time & lhs, const int64x64_t & rhs)
884 {
885  int64x64_t res = lhs.m_data;
886  res *= rhs;
887  return Time (res);
888 }
896 inline Time
897 operator * (const int64x64_t & lhs, const Time & rhs)
898 {
899  return rhs * lhs;
900 }
908 inline int64x64_t
909 operator / (const Time & lhs, const Time & rhs)
910 {
911  int64x64_t num = lhs.m_data;
912  int64x64_t den = rhs.m_data;
913  return num / den;
914 }
922 inline Time
923 operator / (const Time & lhs, const int64_t & rhs)
924 {
925  Time res = lhs;
926  res.m_data /= rhs;
927  return res;
928 }
936 inline Time
937 operator / (const Time & lhs, const int64x64_t & rhs)
938 {
939  int64x64_t res = lhs.m_data;
940  res /= rhs;
941  return Time (res);
942 }
950 inline Time & operator += (Time & lhs, const Time & rhs)
951 {
952  lhs.m_data += rhs.m_data;
953  return lhs;
954 }
962 inline Time & operator -= (Time & lhs, const Time & rhs)
963 {
964  lhs.m_data -= rhs.m_data;
965  return lhs;
966 }
967 
968 inline Time Abs (const Time & time)
969 {
970  return Time ((time.m_data < 0) ? -time.m_data : time.m_data);
971 }
972 inline Time Max (const Time & ta, const Time & tb)
973 {
974  return Time ((ta.m_data < tb.m_data) ? tb : ta);
975 }
976 inline Time Min (const Time & ta, const Time & tb)
977 {
978  return Time ((ta.m_data > tb.m_data) ? tb : ta);
979 }
980 
997 std::ostream & operator << (std::ostream & os, const Time & time);
1008 std::istream & operator >> (std::istream & is, Time & time);
1009  // \ingroup time
1011 
1030 inline Time Years (double value)
1031 {
1032  return Time::FromDouble (value, Time::Y);
1033 }
1034 inline Time Years (int64x64_t value)
1035 {
1036  return Time::From (value, Time::Y);
1037 }
1038 inline Time Days (double value)
1039 {
1040  return Time::FromDouble (value, Time::D);
1041 }
1042 inline Time Days (int64x64_t value)
1043 {
1044  return Time::From (value, Time::D);
1045 }
1046 inline Time Hours (double value)
1047 {
1048  return Time::FromDouble (value, Time::H);
1049 }
1050 inline Time Hours (int64x64_t value)
1051 {
1052  return Time::From (value, Time::H);
1053 }
1054 inline Time Minutes (double value)
1055 {
1056  return Time::FromDouble (value, Time::MIN);
1057 }
1058 inline Time Minutes (int64x64_t value)
1059 {
1060  return Time::From (value, Time::MIN);
1061 }
1062 inline Time Seconds (double value)
1063 {
1064  return Time::FromDouble (value, Time::S);
1065 }
1066 inline Time Seconds (int64x64_t value)
1067 {
1068  return Time::From (value, Time::S);
1069 }
1070 inline Time MilliSeconds (uint64_t value)
1071 {
1072  return Time::FromInteger (value, Time::MS);
1073 }
1075 {
1076  return Time::From (value, Time::MS);
1077 }
1078 inline Time MicroSeconds (uint64_t value)
1079 {
1080  return Time::FromInteger (value, Time::US);
1081 }
1083 {
1084  return Time::From (value, Time::US);
1085 }
1086 inline Time NanoSeconds (uint64_t value)
1087 {
1088  return Time::FromInteger (value, Time::NS);
1089 }
1091 {
1092  return Time::From (value, Time::NS);
1093 }
1094 inline Time PicoSeconds (uint64_t value)
1095 {
1096  return Time::FromInteger (value, Time::PS);
1097 }
1099 {
1100  return Time::From (value, Time::PS);
1101 }
1102 inline Time FemtoSeconds (uint64_t value)
1103 {
1104  return Time::FromInteger (value, Time::FS);
1105 }
1107 {
1108  return Time::From (value, Time::FS);
1109 }
1119 inline Time TimeStep (uint64_t ts)
1120 {
1121  return Time (ts);
1122 }
1123 
1126 
1137 
1144 inline
1146 {
1147  return MakeTimeChecker (Time::Min (), Time::Max ());
1148 }
1149 
1157 inline
1159 {
1160  return MakeTimeChecker (min, Time::Max ());
1161 }
1162 
1168 {
1169 public:
1176  TimeWithUnit (const Time time, const Time::Unit unit)
1177  : m_time (time),
1178  m_unit (unit)
1179  { }
1180 
1181 private:
1184 
1191  friend std::ostream & operator << (std::ostream & os, const TimeWithUnit & timeU);
1192 
1193 }; // class TimeWithUnit
1194 
1195 } // namespace ns3
1196 
1197 #endif /* TIME_H */
int64x64_t & operator+=(int64x64_t &lhs, const int64x64_t &rhs)
Compound addition operator.
Definition: int64x64-128.h:412
static struct Resolution * PeekResolution(void)
Get the current Resolution.
Definition: nstime.h:575
std::istream & operator>>(std::istream &is, Angles &a)
initialize a struct Angles from input
Definition: angles.cc:48
nanosecond
Definition: nstime.h:117
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
microsecond
Definition: nstime.h:116
Control the scheduling of simulation events.
Definition: simulator.h:68
int64x64_t operator+(const int64x64_t &lhs)
Unary plus operator.
Definition: int64x64-128.h:460
int64_t GetInteger(void) const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:405
#define NS_UNUSED_GLOBAL(x)
Mark a variable at file scope as unused.
Definition: unused.h:50
friend Time operator*(const Time &lhs, const int64_t &rhs)
Multiplication operator for Time.
Definition: nstime.h:855
int64x64_t timeFrom
Multiplier to convert from this unit.
Definition: nstime.h:561
static Time Min()
Minimum representable Time.
Definition: nstime.h:271
A Time with attached unit, to facilitate output in that unit.
Definition: nstime.h:1167
static bool g_TimeStaticInit
Force static initialization of Time.
Definition: nstime.h:748
#define min(a, b)
Definition: 80211b.c:42
int64_t ToInteger(enum Unit unit) const
Get the Time value expressed in a particular unit.
Definition: nstime.h:497
day, 24 hours
Definition: nstime.h:111
High precision numerical type, implementing Q64.64 fixed precision.
Definition: int64x64-128.h:45
Forward calls to a chain of Callback.
friend bool operator<(const Time &lhs, const Time &rhs)
Less than operator for Time.
Definition: nstime.h:809
friend bool operator!=(const Time &lhs, const Time &rhs)
Inequality operator for Time.
Definition: nstime.h:773
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:361
#define ATTRIBUTE_VALUE_DEFINE(name)
Declare the attribute value class nameValue for the class name
minute, 60 seconds
Definition: nstime.h:113
int64x64_t operator-(const int64x64_t &lhs)
Unary negation operator (change sign operator).
Definition: int64x64-128.h:470
static Time From(const int64x64_t &value)
Create a Time in the current unit.
Definition: nstime.h:432
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1070
double ToDouble(enum Unit unit) const
Get the Time value expressed in a particular unit.
Definition: nstime.h:511
bool IsStrictlyPositive(void) const
Definition: nstime.h:314
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:743
double GetYears(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:345
hour, 60 minutes
Definition: nstime.h:112
TimeWithUnit As(const enum Unit unit) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:389
Time(unsigned long int v)
Construct from a numeric value.
Definition: nstime.h:219
Time(const int64x64_t &v)
Construct from a numeric value.
Definition: nstime.h:235
bool operator>=(const int64x64_t &lhs, const int64x64_t &rhs)
Greater or equal operator.
Definition: int64x64.h:166
int64_t GetPicoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:377
friend Time operator-(const Time &lhs, const Time &rhs)
Difference operator for Time.
Definition: nstime.h:843
bool operator<(const EventId &a, const EventId &b)
Definition: event-id.h:160
Time PicoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1094
struct Information info[LAST]
Conversion info from current unit.
Definition: nstime.h:566
friend Time operator+(const Time &lhs, const Time &rhs)
Addition operator for Time.
Definition: nstime.h:832
static Time Max()
Maximum representable Time.
Definition: nstime.h:279
friend Time Abs(const Time &time)
Absolute value function for Time.
Definition: nstime.h:968
bool operator<=(const int64x64_t &lhs, const int64x64_t &rhs)
Less or equal operator.
Definition: int64x64.h:155
int64x64_t operator*(const int64x64_t &lhs, const int64x64_t &rhs)
Multiplication operator.
Definition: int64x64.h:117
int64x64_t Min(const int64x64_t &a, const int64x64_t &b)
Minimum.
Definition: int64x64.h:218
Time(int v)
Construct from a numeric value.
Definition: nstime.h:187
Time Years(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1030
picosecond
Definition: nstime.h:118
year, 365 days
Definition: nstime.h:110
#define max(a, b)
Definition: 80211b.c:43
static enum Unit GetResolution(void)
Definition: time.cc:381
bool IsZero(void) const
Definition: nstime.h:294
friend Time & operator-=(Time &lhs, const Time &rhs)
Subtraction operator for Time.
Definition: nstime.h:962
Time(long long int v)
Construct from a numeric value.
Definition: nstime.h:203
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1086
Current time unit, and conversion info.
Definition: nstime.h:564
static bool StaticInit()
Function to force static initialization of Time.
Definition: time.cc:63
NS_ASSERT() and NS_ASSERT_MSG() macro definitions.
bool fromMul
Multiple when converting From, otherwise divide.
Definition: nstime.h:558
friend std::ostream & operator<<(std::ostream &os, const TimeWithUnit &timeU)
Output streamer.
Definition: time.cc:404
static Time From(const int64x64_t &value, enum Unit unit)
Create a Time equal to value in unit unit.
Definition: nstime.h:466
ns3::AttributeValue, ns3::AttributeAccessor and ns3::AttributeChecker declarations.
Unit
The unit to use to interpret a number representing time.
Definition: nstime.h:108
int64x64_t Max(const int64x64_t &a, const int64x64_t &b)
Maximum.
Definition: int64x64.h:230
static void ConvertTimes(const enum Unit unit)
Convert existing Times to the new unit.
Definition: time.cc:344
friend bool operator>=(const Time &lhs, const Time &rhs)
Greater than or equal operator for Time.
Definition: nstime.h:797
double GetDouble(void) const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:401
Time(long int v)
Construct from a numeric value.
Definition: nstime.h:195
static struct Resolution SetDefaultNsResolution(void)
Set the default resolution.
Definition: time.cc:170
int64_t factor
Ratio of this unit / current unit.
Definition: nstime.h:559
int64x64_t operator/(const int64x64_t &lhs, const int64x64_t &rhs)
Division operator.
Definition: int64x64.h:131
int64x64_t Abs(const int64x64_t &value)
Absolute value.
Definition: int64x64.h:205
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:42
int64_t GetMicroSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:369
friend int64x64_t operator/(const Time &lhs, const Time &rhs)
Division operator for Time.
Definition: nstime.h:909
double GetDays(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:349
Time(double v)
Construct from a numeric value.
Definition: nstime.h:179
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:1606
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:227
int64_t GetNanoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:373
friend Time & operator+=(Time &lhs, const Time &rhs)
Addition operator for Time.
Definition: nstime.h:950
friend bool operator==(const Time &lhs, const Time &rhs)
Arithmetic operator.
Definition: nstime.h:761
Time Hours(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1046
Time TimeStep(uint64_t ts)
Definition: nstime.h:1119
Time()
Default constructor, with value 0.
Definition: nstime.h:134
~Time()
Destructor.
Definition: nstime.h:285
static struct Information * PeekInformation(enum Unit timeUnit)
Get the Information record for timeUnit for the current Resolution.
Definition: nstime.h:586
Attribute helper (ATTRIBUTE_ )macros definition.
Time Minutes(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1054
double max(double x, double y)
static Time FromDouble(double value, enum Unit unit)
Create a Time equal to value in unit unit.
Definition: nstime.h:462
#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:211
static void Mark(Time *const time)
Record a Time instance with the MarkedTimes.
Definition: time.cc:288
friend bool operator>(const Time &lhs, const Time &rhs)
Greater than operator for Time.
Definition: nstime.h:821
double GetMinutes(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:357
int Compare(const Time &o) const
Compare this to another Time.
Definition: nstime.h:324
int64_t GetMilliSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:365
bool IsPositive(void) const
Definition: nstime.h:304
How to convert between other units and the current unit.
Definition: nstime.h:555
bool IsStrictlyNegative(void) const
Definition: nstime.h:309
static Time FromInteger(uint64_t value, enum Unit unit)
Create a Time equal to value in unit unit.
Definition: nstime.h:449
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1062
bool operator>(const int64x64_t &lhs, const int64x64_t &rhs)
Greater operator.
Definition: int64x64-128.h:400
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.h:142
double GetDouble(void) const
Get this value as a double.
Definition: int64x64-128.h:206
enum Time::Unit unit
Current time unit.
Definition: nstime.h:567
Time::Unit m_unit
The unit to use in output.
Definition: nstime.h:1183
static void SetResolution(enum Unit resolution)
Definition: time.cc:180
double min(double x, double y)
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:449
int64x64_t To(enum Unit unit) const
Get the Time value expressed in a particular unit.
Definition: nstime.h:515
static void Clear(Time *const time)
Remove a Time instance from the MarkedTimes, called by ~Time().
Definition: time.cc:314
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1078
TimeWithUnit(const Time time, const Time::Unit unit)
Attach a unit to a Time.
Definition: nstime.h:1176
int64x64_t & operator-=(int64x64_t &lhs, const int64x64_t &rhs)
Compound subtraction operator.
Definition: int64x64-128.h:424
second
Definition: nstime.h:114
std::set< Time *> MarkedTimes
Record all instances of Time, so we can rescale them when the resolution changes. ...
Definition: nstime.h:626
static MarkedTimes * g_markingTimes
Record of outstanding Time objects which will need conversion when the resolution is set...
Definition: nstime.h:641
Time Days(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1038
Time FemtoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1102
int64_t GetFemtoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:381
static void ClearMarkedTimes()
Remove all MarkedTimes.
Definition: time.cc:257
femtosecond
Definition: nstime.h:119
millisecond
Definition: nstime.h:115
friend bool operator<=(const Time &lhs, const Time &rhs)
Less than or equal operator for Time.
Definition: nstime.h:785
Declaration of the ns3::int64x64_t type and associated operators.
Time & operator=(const Time &o)
Assignment operator.
Definition: nstime.h:128
double GetHours(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:353
Time m_time
The time.
Definition: nstime.h:1182
int64x64_t timeTo
Multiplier to convert to this unit.
Definition: nstime.h:560
Time(const Time &o)
Copy constructor.
Definition: nstime.h:147
bool IsNegative(void) const
Definition: nstime.h:299
int64_t m_data
Virtual time value, in the current unit.
Definition: nstime.h:731
bool toMul
Multiply when converting To, otherwise divide.
Definition: nstime.h:557
Time(Time &&o)
Move constructor.
Definition: nstime.h:161
int64_t GetTimeStep(void) const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:397
NS_UNUSED and NS_UNUSED_GLOBAL macro definitions.