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 
268  static Time Min ()
269  {
271  }
273  static Time Max ()
274  {
276  }
277 
279  ~Time ()
280  {
281  if (g_markingTimes)
282  {
283  Clear (this);
284  }
285  }
286 
288  inline bool IsZero (void) const
289  {
290  return m_data == 0;
291  }
293  inline bool IsNegative (void) const
294  {
295  return m_data <= 0;
296  }
298  inline bool IsPositive (void) const
299  {
300  return m_data >= 0;
301  }
303  inline bool IsStrictlyNegative (void) const
304  {
305  return m_data < 0;
306  }
308  inline bool IsStrictlyPositive (void) const
309  {
310  return m_data > 0;
311  }
318  inline int Compare (const Time & o) const
319  {
320  return (m_data < o.m_data) ? -1 : (m_data == o.m_data) ? 0 : 1;
321  }
322 
339  inline double GetYears (void) const
340  {
341  return ToDouble (Time::Y);
342  }
343  inline double GetDays (void) const
344  {
345  return ToDouble (Time::D);
346  }
347  inline double GetHours (void) const
348  {
349  return ToDouble (Time::H);
350  }
351  inline double GetMinutes (void) const
352  {
353  return ToDouble (Time::MIN);
354  }
355  inline double GetSeconds (void) const
356  {
357  return ToDouble (Time::S);
358  }
359  inline int64_t GetMilliSeconds (void) const
360  {
361  return ToInteger (Time::MS);
362  }
363  inline int64_t GetMicroSeconds (void) const
364  {
365  return ToInteger (Time::US);
366  }
367  inline int64_t GetNanoSeconds (void) const
368  {
369  return ToInteger (Time::NS);
370  }
371  inline int64_t GetPicoSeconds (void) const
372  {
373  return ToInteger (Time::PS);
374  }
375  inline int64_t GetFemtoSeconds (void) const
376  {
377  return ToInteger (Time::FS);
378  }
391  inline int64_t GetTimeStep (void) const
392  {
393  return m_data;
394  }
395  inline double GetDouble (void) const
396  {
397  return static_cast<double> (m_data);
398  }
399  inline int64_t GetInteger (void) const
400  {
401  return GetTimeStep ();
402  }
413  static void SetResolution (enum Unit resolution);
417  static enum Unit GetResolution (void);
418 
419 
426  inline static Time From (const int64x64_t & value)
427  {
428  return Time (value);
429  }
443  inline static Time FromInteger (uint64_t value, enum Unit unit)
444  {
445  struct Information *info = PeekInformation (unit);
446  if (info->fromMul)
447  {
448  value *= info->factor;
449  }
450  else
451  {
452  value /= info->factor;
453  }
454  return Time (value);
455  }
456  inline static Time FromDouble (double value, enum Unit unit)
457  {
458  return From (int64x64_t (value), unit);
459  }
460  inline static Time From (const int64x64_t & value, enum Unit unit)
461  {
462  struct Information *info = PeekInformation (unit);
463  // DO NOT REMOVE this temporary variable. It's here
464  // to work around a compiler bug in gcc 3.4
465  int64x64_t retval = value;
466  if (info->fromMul)
467  {
468  retval *= info->timeFrom;
469  }
470  else
471  {
472  retval.MulByInvert (info->timeFrom);
473  }
474  return Time (retval);
475  }
491  inline int64_t ToInteger (enum Unit unit) const
492  {
493  struct Information *info = PeekInformation (unit);
494  int64_t v = m_data;
495  if (info->toMul)
496  {
497  v *= info->factor;
498  }
499  else
500  {
501  v /= info->factor;
502  }
503  return v;
504  }
505  inline double ToDouble (enum Unit unit) const
506  {
507  return To (unit).GetDouble ();
508  }
509  inline int64x64_t To (enum Unit unit) const
510  {
511  struct Information *info = PeekInformation (unit);
512  int64x64_t retval = int64x64_t (m_data);
513  if (info->toMul)
514  {
515  retval *= info->timeTo;
516  }
517  else
518  {
519  retval.MulByInvert (info->timeTo);
520  }
521  return retval;
522  }
527  inline operator int64x64_t () const
528  {
529  return int64x64_t (m_data);
530  }
531 
532 
546  TimeWithUnit As (const enum Unit unit) const;
547 
553  typedef void (* TracedCallback)(Time value);
554 
555 private:
557  struct Information
558  {
559  bool toMul;
560  bool fromMul;
561  int64_t factor;
564  };
566  struct Resolution
567  {
570  };
571 
577  static inline struct Resolution *PeekResolution (void)
578  {
579  static struct Time::Resolution resolution = SetDefaultNsResolution ();
580  return & resolution;
581  }
588  static inline struct Information *PeekInformation (enum Unit timeUnit)
589  {
590  return & (PeekResolution ()->info[timeUnit]);
591  }
592 
598  static struct Resolution SetDefaultNsResolution (void);
606  static void SetResolution (enum Unit unit, struct Resolution *resolution,
607  const bool convert = true);
608 
628  typedef std::set< Time * > MarkedTimes;
644 public:
650  static bool StaticInit ();
651 private:
652 
653  /* Friend the Simulator class so it can call the private function
654  ClearMarkedTimes ()
655  */
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 int64_t operator / (const Time & lhs, const Time & rhs);
702  friend Time operator / (const Time & lhs, const int64_t & rhs);
703  friend Time & operator += (Time & lhs, const Time & rhs);
704  friend Time & operator -= (Time & lhs, const Time & rhs);
712  friend Time Abs (const Time & time);
719  friend Time Max (const Time & ta, const Time & tb);
726  friend Time Min (const Time & ta, const Time & tb);
727 
728  int64_t m_data;
729 
730 }; // class Time
731 
732 namespace TracedValueCallback {
733 
740  typedef void (* Time)(Time oldValue, Time newValue);
741 
742 } // namespace TracedValueCallback
743 
745 static bool NS_UNUSED_GLOBAL (g_TimeStaticInit) = Time::StaticInit ();
746 
754 inline bool
755 operator == (const Time & lhs, const Time & rhs)
756 {
757  return lhs.m_data == rhs.m_data;
758 }
766 inline bool
767 operator != (const Time & lhs, const Time & rhs)
768 {
769  return lhs.m_data != rhs.m_data;
770 }
778 inline bool
779 operator <= (const Time & lhs, const Time & rhs)
780 {
781  return lhs.m_data <= rhs.m_data;
782 }
790 inline bool
791 operator >= (const Time & lhs, const Time & rhs)
792 {
793  return lhs.m_data >= rhs.m_data;
794 }
802 inline bool
803 operator < (const Time & lhs, const Time & rhs)
804 {
805  return lhs.m_data < rhs.m_data;
806 }
814 inline bool
815 operator > (const Time & lhs, const Time & rhs)
816 {
817  return lhs.m_data > rhs.m_data;
818 }
826 inline Time operator + (const Time & lhs, const Time & rhs)
827 {
828  return Time (lhs.m_data + rhs.m_data);
829 }
837 inline Time operator - (const Time & lhs, const Time & rhs)
838 {
839  return Time (lhs.m_data - rhs.m_data);
840 }
848 inline Time
849 operator * (const Time & lhs, const int64_t & rhs)
850 {
851  Time res = lhs;
852  res.m_data *= rhs;
853  return res;
854 }
862 inline Time
863 operator * (const int64_t & lhs, const Time & rhs)
864 {
865  Time res = rhs;
866  res.m_data *= lhs;
867  return res;
868 }
876 inline int64_t
877 operator / (const Time & lhs, const Time & rhs)
878 {
879  int64_t res = lhs.m_data / rhs.m_data;
880  return res;
881 }
889 inline Time
890 operator / (const Time & lhs, const int64_t & rhs)
891 {
892  Time res = lhs;
893  res.m_data /= rhs;
894  return res;
895 }
903 inline Time & operator += (Time & lhs, const Time & rhs)
904 {
905  lhs.m_data += rhs.m_data;
906  return lhs;
907 }
915 inline Time & operator -= (Time & lhs, const Time & rhs)
916 {
917  lhs.m_data -= rhs.m_data;
918  return lhs;
919 }
922 inline Time Abs (const Time & time)
923 {
924  return Time ((time.m_data < 0) ? -time.m_data : time.m_data);
925 }
926 inline Time Max (const Time & ta, const Time & tb)
927 {
928  return Time ((ta.m_data < tb.m_data) ? tb : ta);
929 }
930 inline Time Min (const Time & ta, const Time & tb)
931 {
932  return Time ((ta.m_data > tb.m_data) ? tb : ta);
933 }
934 
951 std::ostream & operator << (std::ostream & os, const Time & time);
962 std::istream & operator >> (std::istream & is, Time & time);
963 
982 inline Time Years (double value)
983 {
984  return Time::FromDouble (value, Time::Y);
985 }
986 inline Time Years (int64x64_t value)
987 {
988  return Time::From (value, Time::Y);
989 }
990 inline Time Days (double value)
991 {
992  return Time::FromDouble (value, Time::D);
993 }
994 inline Time Days (int64x64_t value)
995 {
996  return Time::From (value, Time::D);
997 }
998 inline Time Hours (double value)
999 {
1000  return Time::FromDouble (value, Time::H);
1001 }
1002 inline Time Hours (int64x64_t value)
1003 {
1004  return Time::From (value, Time::H);
1005 }
1006 inline Time Minutes (double value)
1007 {
1008  return Time::FromDouble (value, Time::MIN);
1009 }
1010 inline Time Minutes (int64x64_t value)
1011 {
1012  return Time::From (value, Time::MIN);
1013 }
1014 inline Time Seconds (double value)
1015 {
1016  return Time::FromDouble (value, Time::S);
1017 }
1018 inline Time Seconds (int64x64_t value)
1019 {
1020  return Time::From (value, Time::S);
1021 }
1022 inline Time MilliSeconds (uint64_t value)
1023 {
1024  return Time::FromInteger (value, Time::MS);
1025 }
1027 {
1028  return Time::From (value, Time::MS);
1029 }
1030 inline Time MicroSeconds (uint64_t value)
1031 {
1032  return Time::FromInteger (value, Time::US);
1033 }
1035 {
1036  return Time::From (value, Time::US);
1037 }
1038 inline Time NanoSeconds (uint64_t value)
1039 {
1040  return Time::FromInteger (value, Time::NS);
1041 }
1043 {
1044  return Time::From (value, Time::NS);
1045 }
1046 inline Time PicoSeconds (uint64_t value)
1047 {
1048  return Time::FromInteger (value, Time::PS);
1049 }
1051 {
1052  return Time::From (value, Time::PS);
1053 }
1054 inline Time FemtoSeconds (uint64_t value)
1055 {
1056  return Time::FromInteger (value, Time::FS);
1057 }
1059 {
1060  return Time::From (value, Time::FS);
1061 }
1071 inline Time TimeStep (uint64_t ts)
1072 {
1073  return Time (ts);
1074 }
1075 
1078 
1089 
1096 inline
1098 {
1099  return MakeTimeChecker (Time::Min (), Time::Max ());
1100 }
1101 
1109 inline
1111 {
1112  return MakeTimeChecker (min, Time::Max ());
1113 }
1114 
1120 {
1121 public:
1128  TimeWithUnit (const Time time, const Time::Unit unit)
1129  : m_time (time),
1130  m_unit (unit)
1131  { };
1132 
1133 private:
1134  Time m_time;
1136 
1143  friend std::ostream & operator << (std::ostream & os, const TimeWithUnit & timeU);
1144 
1145 }; // class TimeWithUnit
1146 
1147 } // namespace ns3
1148 
1149 #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:577
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:410
int64_t GetInteger(void) const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:399
friend Time operator*(const Time &lhs, const int64_t &rhs)
Multiplication operator for Time.
Definition: nstime.h:849
int64x64_t timeFrom
Multiplier to convert from this unit.
Definition: nstime.h:563
static Time Min()
Minimum representable Time.
Definition: nstime.h:268
A Time with attached unit, to facilitate output in that unit.
Definition: nstime.h:1119
#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:491
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:803
friend bool operator!=(const Time &lhs, const Time &rhs)
Inequality operator for Time.
Definition: nstime.h:767
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:355
#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:418
static Time From(const int64x64_t &value)
Create a Time in the current unit.
Definition: nstime.h:426
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1022
double ToDouble(enum Unit unit) const
Get the Time value expressed in a particular unit.
Definition: nstime.h:505
bool IsStrictlyPositive(void) const
Definition: nstime.h:308
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:740
double GetYears(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:339
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:388
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:145
int64_t GetPicoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:371
friend Time operator-(const Time &lhs, const Time &rhs)
Difference operator for Time.
Definition: nstime.h:837
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:1046
struct Information info[LAST]
Conversion info from current unit.
Definition: nstime.h:568
static bool NS_UNUSED_GLOBAL(g_TimeStaticInit)
Force static initialization of Time.
friend Time operator+(const Time &lhs, const Time &rhs)
Addition operator for Time.
Definition: nstime.h:826
static Time Max()
Maximum representable Time.
Definition: nstime.h:273
friend Time Abs(const Time &time)
Absolute value function for Time.
Definition: nstime.h:922
bool operator<=(const int64x64_t &lhs, const int64x64_t &rhs)
Less or equal operator.
Definition: int64x64.h:137
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:187
Time Years(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:982
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:380
bool IsZero(void) const
Definition: nstime.h:288
friend Time & operator-=(Time &lhs, const Time &rhs)
Subtraction operator for Time.
Definition: nstime.h:915
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:1038
Current time unit, and conversion info.
Definition: nstime.h:566
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:560
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:460
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:209
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:791
double GetDouble(void) const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:395
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:561
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
int64_t GetMicroSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:363
double GetDays(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:343
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: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:227
int64_t GetNanoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:367
friend Time & operator+=(Time &lhs, const Time &rhs)
Addition operator for Time.
Definition: nstime.h:903
friend bool operator==(const Time &lhs, const Time &rhs)
Arithmetic operator.
Definition: nstime.h:755
friend int64_t operator/(const Time &lhs, const Time &rhs)
Division operator for Time.
Definition: nstime.h:877
Time Hours(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:998
Time TimeStep(uint64_t ts)
Definition: nstime.h:1071
Time()
Default constructor, with value 0.
Definition: nstime.h:134
~Time()
Destructor.
Definition: nstime.h:279
static struct Information * PeekInformation(enum Unit timeUnit)
Get the Information record for timeUnit for the current Resolution.
Definition: nstime.h:588
Attribute helper (ATTRIBUTE_ )macros definition.
Time Minutes(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1006
static Time FromDouble(double value, enum Unit unit)
Create a Time equal to value in unit unit.
Definition: nstime.h:456
#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:287
friend bool operator>(const Time &lhs, const Time &rhs)
Greater than operator for Time.
Definition: nstime.h:815
double GetMinutes(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:351
int Compare(const Time &o) const
Compare this to another Time.
Definition: nstime.h:318
int64_t GetMilliSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:359
bool IsPositive(void) const
Definition: nstime.h:298
How to convert between other units and the current unit.
Definition: nstime.h:557
bool IsStrictlyNegative(void) const
Definition: nstime.h:303
static Time FromInteger(uint64_t value, enum Unit unit)
Create a Time equal to value in unit unit.
Definition: nstime.h:443
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1014
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
double GetDouble(void) const
Get this value as a double.
Definition: int64x64-128.h:203
enum Time::Unit unit
Current time unit.
Definition: nstime.h:569
Time::Unit m_unit
The unit to use in output.
Definition: nstime.h:1135
static void SetResolution(enum Unit resolution)
Definition: time.cc:180
int64x64_t To(enum Unit unit) const
Get the Time value expressed in a particular unit.
Definition: nstime.h:509
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:1030
TimeWithUnit(const Time time, const Time::Unit unit)
Attach a unit to a Time.
Definition: nstime.h:1128
int64x64_t & operator-=(int64x64_t &lhs, const int64x64_t &rhs)
Compound subtraction operator.
Definition: int64x64-128.h:382
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:628
static MarkedTimes * g_markingTimes
Record of outstanding Time objects which will need conversion when the resolution is set...
Definition: nstime.h:643
Time Days(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:990
Time FemtoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1054
int64_t GetFemtoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:375
static void ClearMarkedTimes()
Remove all MarkedTimes.
Definition: time.cc:256
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:779
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:347
Time m_time
The time.
Definition: nstime.h:1131
int64x64_t timeTo
Multiplier to convert to this unit.
Definition: nstime.h:562
Time(const Time &o)
Copy constructor.
Definition: nstime.h:147
bool IsNegative(void) const
Definition: nstime.h:293
int64_t m_data
Virtual time value, in the current unit.
Definition: nstime.h:728
bool toMul
Multiply when converting To, otherwise divide.
Definition: nstime.h:559
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:391
NS_UNUSED and NS_UNUSED_GLOBAL macro definitions.