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 "event-id.h"
27 #include "int64x64.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  AUTO = 11
122  };
123 
129  inline Time & operator = (const Time & o)
130  {
131  m_data = o.m_data;
132  return *this;
133  }
135  inline Time ()
136  : m_data ()
137  {
138  if (g_markingTimes)
139  {
140  Mark (this);
141  }
142  }
148  inline Time (const Time & o)
149  : m_data (o.m_data)
150  {
151  if (g_markingTimes)
152  {
153  Mark (this);
154  }
155  }
156 
162  Time (Time &&o)
163  : m_data (o.m_data)
164  {
165  if (g_markingTimes)
166  {
167  Mark (this);
168  }
169  }
180  explicit inline Time (double v)
181  : m_data (lround (v))
182  {
183  if (g_markingTimes)
184  {
185  Mark (this);
186  }
187  }
188  explicit inline Time (int v)
189  : m_data (v)
190  {
191  if (g_markingTimes)
192  {
193  Mark (this);
194  }
195  }
196  explicit inline Time (long int v)
197  : m_data (v)
198  {
199  if (g_markingTimes)
200  {
201  Mark (this);
202  }
203  }
204  explicit inline Time (long long int v)
205  : m_data (v)
206  {
207  if (g_markingTimes)
208  {
209  Mark (this);
210  }
211  }
212  explicit inline Time (unsigned int v)
213  : m_data (v)
214  {
215  if (g_markingTimes)
216  {
217  Mark (this);
218  }
219  }
220  explicit inline Time (unsigned long int v)
221  : m_data (v)
222  {
223  if (g_markingTimes)
224  {
225  Mark (this);
226  }
227  }
228  explicit inline Time (unsigned long long int v)
229  : m_data (v)
230  {
231  if (g_markingTimes)
232  {
233  Mark (this);
234  }
235  }
236  explicit inline Time (const int64x64_t & v)
237  : m_data (v.Round ())
238  {
239  if (g_markingTimes)
240  {
241  Mark (this);
242  }
243  } // Numeric constructors
245 
266  explicit Time (const std::string & s);
267 
273  static Time Min ()
274  {
276  }
282  static Time Max ()
283  {
285  }
286 
288  ~Time ()
289  {
290  if (g_markingTimes)
291  {
292  Clear (this);
293  }
294  }
295 
300  inline bool IsZero (void) const
301  {
302  return m_data == 0;
303  }
308  inline bool IsNegative (void) const
309  {
310  return m_data <= 0;
311  }
316  inline bool IsPositive (void) const
317  {
318  return m_data >= 0;
319  }
324  inline bool IsStrictlyNegative (void) const
325  {
326  return m_data < 0;
327  }
332  inline bool IsStrictlyPositive (void) const
333  {
334  return m_data > 0;
335  }
342  inline int Compare (const Time & o) const
343  {
344  return (m_data < o.m_data) ? -1 : (m_data == o.m_data) ? 0 : 1;
345  }
346 
363  inline double GetYears (void) const
364  {
365  return ToDouble (Time::Y);
366  }
367  inline double GetDays (void) const
368  {
369  return ToDouble (Time::D);
370  }
371  inline double GetHours (void) const
372  {
373  return ToDouble (Time::H);
374  }
375  inline double GetMinutes (void) const
376  {
377  return ToDouble (Time::MIN);
378  }
379  inline double GetSeconds (void) const
380  {
381  return ToDouble (Time::S);
382  }
383  inline int64_t GetMilliSeconds (void) const
384  {
385  return ToInteger (Time::MS);
386  }
387  inline int64_t GetMicroSeconds (void) const
388  {
389  return ToInteger (Time::US);
390  }
391  inline int64_t GetNanoSeconds (void) const
392  {
393  return ToInteger (Time::NS);
394  }
395  inline int64_t GetPicoSeconds (void) const
396  {
397  return ToInteger (Time::PS);
398  }
399  inline int64_t GetFemtoSeconds (void) const
400  {
401  return ToInteger (Time::FS);
402  } // Convert to Number in a Unit.
404 
415  inline int64_t GetTimeStep (void) const
416  {
417  return m_data;
418  }
419  inline double GetDouble (void) const
420  {
421  return static_cast<double> (m_data);
422  }
423  inline int64_t GetInteger (void) const
424  {
425  return GetTimeStep ();
426  } // Convert to Raw Value
428 
429 
437  static void SetResolution (enum Unit resolution);
441  static enum Unit GetResolution (void);
442 
443 
450  inline static Time From (const int64x64_t & value)
451  {
452  return Time (value);
453  }
467  inline static Time FromInteger (uint64_t value, enum Unit unit)
468  {
469  struct Information *info = PeekInformation (unit);
470  if (info->fromMul)
471  {
472  value *= info->factor;
473  }
474  else
475  {
476  value /= info->factor;
477  }
478  return Time (value);
479  }
480  inline static Time FromDouble (double value, enum Unit unit)
481  {
482  return From (int64x64_t (value), unit);
483  }
484  inline static Time From (const int64x64_t & value, enum Unit unit)
485  {
486  struct Information *info = PeekInformation (unit);
487  // DO NOT REMOVE this temporary variable. It's here
488  // to work around a compiler bug in gcc 3.4
489  int64x64_t retval = value;
490  if (info->fromMul)
491  {
492  retval *= info->timeFrom;
493  }
494  else
495  {
496  retval.MulByInvert (info->timeFrom);
497  }
498  return Time (retval);
499  } // Create Times from Values and Units
501 
502 
515  inline int64_t ToInteger (enum Unit unit) const
516  {
517  struct Information *info = PeekInformation (unit);
518  int64_t v = m_data;
519  if (info->toMul)
520  {
521  v *= info->factor;
522  }
523  else
524  {
525  v /= info->factor;
526  }
527  return v;
528  }
529  inline double ToDouble (enum Unit unit) const
530  {
531  return To (unit).GetDouble ();
532  }
533  inline int64x64_t To (enum Unit unit) const
534  {
535  struct Information *info = PeekInformation (unit);
536  int64x64_t retval = int64x64_t (m_data);
537  if (info->toMul)
538  {
539  retval *= info->timeTo;
540  }
541  else
542  {
543  retval.MulByInvert (info->timeTo);
544  }
545  return retval;
546  } // Get Times as Numbers in Specified Units
548 
555  Time RoundTo (enum Unit unit) const
556  {
557  return From (this->To (unit).Round (), unit);
558  }
559 
573  TimeWithUnit As (const enum Unit unit = Time::AUTO) const;
574 
580  typedef void (* TracedCallback)(Time value);
581 
582 private:
584  struct Information
585  {
586  bool toMul;
587  bool fromMul;
588  int64_t factor;
591  };
593  struct Resolution
594  {
595  struct Information info[LAST];
596  enum Time::Unit unit;
597  };
598 
604  static inline struct Resolution * PeekResolution (void)
605  {
606  static struct Time::Resolution resolution = SetDefaultNsResolution ();
607  return &resolution;
608  }
615  static inline struct Information * PeekInformation (enum Unit timeUnit)
616  {
617  return &(PeekResolution ()->info[timeUnit]);
618  }
619 
625  static struct Resolution SetDefaultNsResolution (void);
633  static void SetResolution (enum Unit unit, struct Resolution *resolution,
634  const bool convert = true);
635 
655  typedef std::set< Time * > MarkedTimes;
671 
672 public:
678  static bool StaticInit ();
679 private:
687  friend class Simulator;
696  static void ClearMarkedTimes ();
701  static void Mark (Time * const time);
706  static void Clear (Time * const time);
711  static void ConvertTimes (const enum Unit unit);
712 
713 
714  // Operator and related functions which need access
715 
720  friend bool operator == (const Time & lhs, const Time & rhs);
721  friend bool operator != (const Time & lhs, const Time & rhs);
722  friend bool operator <= (const Time & lhs, const Time & rhs);
723  friend bool operator >= (const Time & lhs, const Time & rhs);
724  friend bool operator < (const Time & lhs, const Time & rhs);
725  friend bool operator > (const Time & lhs, const Time & rhs);
726  friend bool operator < (const Time & time, const EventId & event); // Comparison operators
728 
733  friend Time operator + (const Time & lhs, const Time & rhs);
734  friend Time operator - (const Time & lhs, const Time & rhs);
735  friend Time operator * (const Time & lhs, const int64x64_t & rhs);
736  friend Time operator * (const int64x64_t & lhs, const Time & rhs);
737  friend int64x64_t operator / (const Time & lhs, const Time & rhs);
738  friend Time operator / (const Time & lhs, const int64x64_t & rhs);
739  friend Time operator % (const Time & lhs, const Time & rhs);
740  friend int64_t Div (const Time & lhs, const Time & rhs);
741  friend Time Rem (const Time & lhs, const Time & rhs);
742 
743  template<class T>
744  friend typename std::enable_if<std::is_integral<T>::value, Time>::type
745  operator * (const Time& lhs, T rhs);
746 
747  // Reversed arg version (forwards to `rhs * lhs`)
748  // Accepts both integers and decimal types
749  template<class T>
750  friend typename std::enable_if<std::is_arithmetic<T>::value, Time>::type
751  operator * (T lhs, const Time& rhs);
752 
753  template<class T>
754  friend typename std::enable_if<std::is_integral<T>::value, Time>::type
755  operator / (const Time& lhs, T rhs);
756 
757  friend Time Abs (const Time & time);
758  friend Time Max (const Time & timeA, const Time & timeB);
759  friend Time Min (const Time & timeA, const Time & timeB);
760  // Arithmetic operators
762 
763  // Leave undocumented
764  template<class T>
765  friend typename std::enable_if<std::is_floating_point<T>::value, Time>::type
766  operator * (const Time& lhs, T rhs);
767  template<class T>
768  friend typename std::enable_if<std::is_floating_point<T>::value, Time>::type
769  operator / (const Time& lhs, T rhs);
770 
771 
776  friend Time & operator += (Time & lhs, const Time & rhs);
777  friend Time & operator -= (Time & lhs, const Time & rhs); // Compound assignment
779 
780 
781  int64_t m_data;
782 
783 }; // class Time
784 
785 namespace TracedValueCallback {
786 
793 typedef void (* Time)(Time oldValue, Time newValue);
794 
795 } // namespace TracedValueCallback
796 
802 [[maybe_unused]] static bool g_TimeStaticInit = Time::StaticInit ();
803 
810 inline bool
811 operator == (const Time & lhs, const Time & rhs)
812 {
813  return lhs.m_data == rhs.m_data;
814 }
821 inline bool
822 operator != (const Time & lhs, const Time & rhs)
823 {
824  return lhs.m_data != rhs.m_data;
825 }
832 inline bool
833 operator <= (const Time & lhs, const Time & rhs)
834 {
835  return lhs.m_data <= rhs.m_data;
836 }
843 inline bool
844 operator >= (const Time & lhs, const Time & rhs)
845 {
846  return lhs.m_data >= rhs.m_data;
847 }
854 inline bool
855 operator < (const Time & lhs, const Time & rhs)
856 {
857  return lhs.m_data < rhs.m_data;
858 }
865 inline bool
866 operator > (const Time & lhs, const Time & rhs)
867 {
868  return lhs.m_data > rhs.m_data;
869 }
887 inline bool
888 operator < (const Time & time, const EventId & event)
889 {
890  // Negative Time is less than any possible EventId, which are all >= 0.
891  if (time.m_data < 0)
892  {
893  return true;
894  }
895  // Time must be >= 0 so casting to unsigned is safe.
896  return static_cast<uint64_t> (time.m_data) < event.GetTs ();
897 }
904 inline Time operator + (const Time & lhs, const Time & rhs)
905 {
906  return Time (lhs.m_data + rhs.m_data);
907 }
914 inline Time operator - (const Time & lhs, const Time & rhs)
915 {
916  return Time (lhs.m_data - rhs.m_data);
917 }
918 
925 inline Time
926 operator * (const Time & lhs, const int64x64_t & rhs)
927 {
928  int64x64_t res = lhs.m_data;
929  res *= rhs;
930  return Time (res);
931 }
938 inline Time
939 operator * (const int64x64_t & lhs, const Time & rhs)
940 {
941  return rhs * lhs;
942 }
943 
953 template<class T>
954 typename std::enable_if<std::is_integral<T>::value, Time>::type
955 operator * (const Time& lhs, T rhs)
956 {
957  static_assert(!std::is_same<T, bool>::value,
958  "Multiplying a Time by a boolean is not supported");
959 
960  return Time (lhs.m_data * rhs);
961 }
962 
963 // Leave undocumented
964 template<class T>
965 typename std::enable_if<std::is_floating_point<T>::value, Time>::type
966 operator * (const Time& lhs, T rhs)
967 {
968  return lhs * int64x64_t(rhs);
969 }
970 
984 template<class T>
985 typename std::enable_if<std::is_arithmetic<T>::value, Time>::type
986 operator * (T lhs, const Time& rhs)
987 {
988  return rhs * lhs;
989 }
990 
1009 inline int64x64_t
1010 operator / (const Time & lhs, const Time & rhs)
1011 {
1012  int64x64_t num = lhs.m_data;
1013  int64x64_t den = rhs.m_data;
1014  return num / den;
1015 }
1016 
1023 inline Time
1024 operator / (const Time & lhs, const int64x64_t & rhs)
1025 {
1026  int64x64_t res = lhs.m_data;
1027  res /= rhs;
1028  return Time (res);
1029 }
1030 
1040 template<class T>
1041 typename std::enable_if<std::is_integral<T>::value, Time>::type
1042 operator / (const Time& lhs, T rhs)
1043 {
1044  static_assert(!std::is_same<T, bool>::value,
1045  "Dividing a Time by a boolean is not supported");
1046 
1047  return Time(lhs.m_data / rhs);
1048 }
1049 
1050 // Leave undocumented
1051 template<class T>
1052 typename std::enable_if<std::is_floating_point<T>::value, Time>::type
1053 operator / (const Time& lhs, T rhs)
1054 {
1055  return lhs / int64x64_t(rhs);
1056 }
1057 
1058 
1072 inline Time
1073 operator % (const Time & lhs, const Time & rhs)
1074 {
1075  return Time (lhs.m_data % rhs.m_data);
1076 }
1077 inline Time
1078 Rem (const Time & lhs, const Time & rhs)
1079 {
1080  return Time (lhs.m_data % rhs.m_data);
1081 }
1104 inline int64_t
1105 Div (const Time & lhs, const Time & rhs)
1106 {
1107  return lhs.m_data / rhs.m_data;
1108 }
1115 inline Time & operator += (Time & lhs, const Time & rhs)
1116 {
1117  lhs.m_data += rhs.m_data;
1118  return lhs;
1119 }
1126 inline Time & operator -= (Time & lhs, const Time & rhs)
1127 {
1128  lhs.m_data -= rhs.m_data;
1129  return lhs;
1130 }
1136 inline Time Abs (const Time & time)
1137 {
1138  return Time ((time.m_data < 0) ? -time.m_data : time.m_data);
1139 }
1146 inline Time Max (const Time & timeA, const Time & timeB)
1147 {
1148  return Time ((timeA.m_data < timeB.m_data) ? timeB : timeA);
1149 }
1156 inline Time Min (const Time & timeA, const Time & timeB)
1157 {
1158  return Time ((timeA.m_data > timeB.m_data) ? timeB : timeA);
1159 }
1160 
1181 std::ostream & operator << (std::ostream & os, const Time & time);
1191 std::istream & operator >> (std::istream & is, Time & time);
1192 
1193 
1212 inline Time Years (double value)
1213 {
1214  return Time::FromDouble (value, Time::Y);
1215 }
1216 inline Time Years (int64x64_t value)
1217 {
1218  return Time::From (value, Time::Y);
1219 }
1220 inline Time Days (double value)
1221 {
1222  return Time::FromDouble (value, Time::D);
1223 }
1224 inline Time Days (int64x64_t value)
1225 {
1226  return Time::From (value, Time::D);
1227 }
1228 inline Time Hours (double value)
1229 {
1230  return Time::FromDouble (value, Time::H);
1231 }
1232 inline Time Hours (int64x64_t value)
1233 {
1234  return Time::From (value, Time::H);
1235 }
1236 inline Time Minutes (double value)
1237 {
1238  return Time::FromDouble (value, Time::MIN);
1239 }
1240 inline Time Minutes (int64x64_t value)
1241 {
1242  return Time::From (value, Time::MIN);
1243 }
1244 inline Time Seconds (double value)
1245 {
1246  return Time::FromDouble (value, Time::S);
1247 }
1248 inline Time Seconds (int64x64_t value)
1249 {
1250  return Time::From (value, Time::S);
1251 }
1252 inline Time MilliSeconds (uint64_t value)
1253 {
1254  return Time::FromInteger (value, Time::MS);
1255 }
1257 {
1258  return Time::From (value, Time::MS);
1259 }
1260 inline Time MicroSeconds (uint64_t value)
1261 {
1262  return Time::FromInteger (value, Time::US);
1263 }
1265 {
1266  return Time::From (value, Time::US);
1267 }
1268 inline Time NanoSeconds (uint64_t value)
1269 {
1270  return Time::FromInteger (value, Time::NS);
1271 }
1273 {
1274  return Time::From (value, Time::NS);
1275 }
1276 inline Time PicoSeconds (uint64_t value)
1277 {
1278  return Time::FromInteger (value, Time::PS);
1279 }
1281 {
1282  return Time::From (value, Time::PS);
1283 }
1284 inline Time FemtoSeconds (uint64_t value)
1285 {
1286  return Time::FromInteger (value, Time::FS);
1287 }
1289 {
1290  return Time::From (value, Time::FS);
1291 } // Construct a Time in the indicated unit.
1293 
1294 
1303 inline Time TimeStep (uint64_t ts)
1304 {
1305  return Time (ts);
1306 }
1307 
1310 
1321 
1328 inline
1330 {
1331  return MakeTimeChecker (Time::Min (), Time::Max ());
1332 }
1333 
1341 inline
1343 {
1344  return MakeTimeChecker (min, Time::Max ());
1345 }
1346 
1352 {
1353 public:
1360  TimeWithUnit (const Time time, const Time::Unit unit)
1361  : m_time (time),
1362  m_unit (unit)
1363  { }
1364 
1365 private:
1368 
1375  friend std::ostream & operator << (std::ostream & os, const TimeWithUnit & timeU);
1376 
1377 }; // class TimeWithUnit
1378 
1379 } // namespace ns3
1380 
1381 #endif /* TIME_H */
#define min(a, b)
Definition: 80211b.c:42
#define max(a, b)
Definition: 80211b.c:43
NS_ASSERT() and NS_ASSERT_MSG() macro definitions.
Attribute helper (ATTRIBUTE_ )macros definition.
ns3::AttributeValue, ns3::AttributeAccessor and ns3::AttributeChecker declarations.
An identifier for simulation events.
Definition: event-id.h:54
uint64_t GetTs(void) const
Definition: event-id.cc:83
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
Control the scheduling of simulation events.
Definition: simulator.h:69
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
int64_t GetFemtoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:399
friend Time operator%(const Time &lhs, const Time &rhs)
Remainder (modulus) from the quotient of two Times.
Definition: nstime.h:1073
double GetDays(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:367
int64_t GetMicroSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:387
static struct Information * PeekInformation(enum Unit timeUnit)
Get the Information record for timeUnit for the current Resolution.
Definition: nstime.h:615
bool IsStrictlyPositive(void) const
Exactly equivalent to t > 0.
Definition: nstime.h:332
int64x64_t To(enum Unit unit) const
Get the Time value expressed in a particular unit.
Definition: nstime.h:533
double GetMinutes(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:375
static Time From(const int64x64_t &value, enum Unit unit)
Create a Time equal to value in unit unit.
Definition: nstime.h:484
double GetHours(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:371
static enum Unit GetResolution(void)
Definition: time.cc:410
double GetDouble(void) const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:419
double ToDouble(enum Unit unit) const
Get the Time value expressed in a particular unit.
Definition: nstime.h:529
Time RoundTo(enum Unit unit) const
Round a Time to a specific unit.
Definition: nstime.h:555
Time(const Time &o)
Copy constructor.
Definition: nstime.h:148
Time(const int64x64_t &v)
Construct from a numeric value.
Definition: nstime.h:236
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:379
static void ClearMarkedTimes()
Remove all MarkedTimes.
Definition: time.cc:287
Time(unsigned long int v)
Construct from a numeric value.
Definition: nstime.h:220
static Time From(const int64x64_t &value)
Create a Time in the current unit.
Definition: nstime.h:450
int64_t GetTimeStep(void) const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:415
~Time()
Destructor.
Definition: nstime.h:288
Time(long long int v)
Construct from a numeric value.
Definition: nstime.h:204
static Time FromInteger(uint64_t value, enum Unit unit)
Create a Time equal to value in unit unit.
Definition: nstime.h:467
int64_t ToInteger(enum Unit unit) const
Get the Time value expressed in a particular unit.
Definition: nstime.h:515
bool IsPositive(void) const
Exactly equivalent to t >= 0.
Definition: nstime.h:316
static Time FromDouble(double value, enum Unit unit)
Create a Time equal to value in unit unit.
Definition: nstime.h:480
Time TimeStep(uint64_t ts)
Scheduler interface.
Definition: nstime.h:1303
Time(double v)
Construct from a numeric value.
Definition: nstime.h:180
static struct Resolution SetDefaultNsResolution(void)
Set the default resolution.
Definition: time.cc:203
static bool StaticInit()
Function to force static initialization of Time.
Definition: time.cc:96
friend bool operator==(const Time &lhs, const Time &rhs)
Equality operator for Time.
Definition: nstime.h:811
Time(unsigned long long int v)
Construct from a numeric value.
Definition: nstime.h:228
static Time Min()
Minimum representable Time Not to be confused with Min(Time,Time).
Definition: nstime.h:273
int64_t GetInteger(void) const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:423
static void Clear(Time *const time)
Remove a Time instance from the MarkedTimes, called by ~Time().
Definition: time.cc:343
Unit
The unit to use to interpret a number representing time.
Definition: nstime.h:109
@ AUTO
auto-scale output when using Time::As()
Definition: nstime.h:121
@ D
day, 24 hours
Definition: nstime.h:111
@ US
microsecond
Definition: nstime.h:116
@ PS
picosecond
Definition: nstime.h:118
@ LAST
marker for last normal value
Definition: nstime.h:120
@ Y
year, 365 days
Definition: nstime.h:110
@ FS
femtosecond
Definition: nstime.h:119
@ H
hour, 60 minutes
Definition: nstime.h:112
@ MIN
minute, 60 seconds
Definition: nstime.h:113
@ MS
millisecond
Definition: nstime.h:115
@ S
second
Definition: nstime.h:114
@ NS
nanosecond
Definition: nstime.h:117
Time()
Default constructor, with value 0.
Definition: nstime.h:135
friend bool operator>=(const Time &lhs, const Time &rhs)
Greater than or equal operator for Time.
Definition: nstime.h:844
friend Time & operator+=(Time &lhs, const Time &rhs)
Compound addition assignment for Time.
Definition: nstime.h:1115
static struct Resolution * PeekResolution(void)
Get the current Resolution.
Definition: nstime.h:604
friend bool operator<=(const Time &lhs, const Time &rhs)
Less than or equal operator for Time.
Definition: nstime.h:833
static MarkedTimes * g_markingTimes
Record of outstanding Time objects which will need conversion when the resolution is set.
Definition: nstime.h:670
int64_t m_data
Virtual time value, in the current unit.
Definition: nstime.h:781
friend Time Rem(const Time &lhs, const Time &rhs)
Addition operator for Time.
Definition: nstime.h:1078
friend int64_t Div(const Time &lhs, const Time &rhs)
Integer quotient from dividing two Times.
Definition: nstime.h:1105
static void Mark(Time *const time)
Record a Time instance with the MarkedTimes.
Definition: time.cc:317
friend bool operator<(const Time &lhs, const Time &rhs)
Less than operator for Time.
Definition: nstime.h:855
Time(int v)
Construct from a numeric value.
Definition: nstime.h:188
friend bool operator!=(const Time &lhs, const Time &rhs)
Inequality operator for Time.
Definition: nstime.h:822
Time(Time &&o)
Move constructor.
Definition: nstime.h:162
static void ConvertTimes(const enum Unit unit)
Convert existing Times to the new unit.
Definition: time.cc:373
bool IsStrictlyNegative(void) const
Exactly equivalent to t < 0.
Definition: nstime.h:324
Time(unsigned int v)
Construct from a numeric value.
Definition: nstime.h:212
bool IsZero(void) const
Exactly equivalent to t == 0.
Definition: nstime.h:300
int Compare(const Time &o) const
Compare this to another Time.
Definition: nstime.h:342
static void SetResolution(enum Unit resolution)
Definition: time.cc:213
friend Time operator-(const Time &lhs, const Time &rhs)
Subtraction operator for Time.
Definition: nstime.h:914
int64_t GetMilliSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:383
friend Time operator+(const Time &lhs, const Time &rhs)
Addition operator for Time.
Definition: nstime.h:904
double GetYears(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:363
static Time Max()
Maximum representable Time Not to be confused with Max(Time,Time).
Definition: nstime.h:282
TimeWithUnit As(const enum Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:418
friend Time operator*(const Time &lhs, const int64x64_t &rhs)
Scale a Time by a numeric value.
Definition: nstime.h:926
std::set< Time * > MarkedTimes
Record all instances of Time, so we can rescale them when the resolution changes.
Definition: nstime.h:655
friend bool operator>(const Time &lhs, const Time &rhs)
Greater than operator for Time.
Definition: nstime.h:866
friend Time Abs(const Time &time)
Absolute value for Time.
Definition: nstime.h:1136
Time(long int v)
Construct from a numeric value.
Definition: nstime.h:196
friend Time & operator-=(Time &lhs, const Time &rhs)
Compound subtraction assignment for Time.
Definition: nstime.h:1126
friend int64x64_t operator/(const Time &lhs, const Time &rhs)
Exact division, returning a dimensionless fixed point number.
Definition: nstime.h:1010
bool IsNegative(void) const
Exactly equivalent to t <= 0.
Definition: nstime.h:308
Time & operator=(const Time &o)
Assignment operator.
Definition: nstime.h:129
int64_t GetPicoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:395
int64_t GetNanoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:391
A Time with attached unit, to facilitate output in that unit.
Definition: nstime.h:1352
friend std::ostream & operator<<(std::ostream &os, const TimeWithUnit &timeU)
Output streamer.
Definition: time.cc:433
TimeWithUnit(const Time time, const Time::Unit unit)
Attach a unit to a Time.
Definition: nstime.h:1360
Time m_time
The time.
Definition: nstime.h:1366
Time::Unit m_unit
The unit to use in output.
Definition: nstime.h:1367
Forward calls to a chain of Callback.
High precision numerical type, implementing Q64.64 fixed precision.
Definition: int64x64-128.h:56
void MulByInvert(const int64x64_t &o)
Multiply this value by a Q0.128 value, presumably representing an inverse, completing a division oper...
double GetDouble(void) const
Get this value as a double.
Definition: int64x64-128.h:231
ns3::EventId declarations.
#define ATTRIBUTE_ACCESSOR_DEFINE(type)
Define the attribute accessor functions MakeTypeAccessor for class type.
#define ATTRIBUTE_VALUE_DEFINE(name)
Declare the attribute value class nameValue for the class name
int64x64_t Max(const int64x64_t &a, const int64x64_t &b)
Maximum.
Definition: int64x64.h:230
int64x64_t operator/(const int64x64_t &lhs, const int64x64_t &rhs)
Division operator.
Definition: int64x64.h:131
bool operator>=(const int64x64_t &lhs, const int64x64_t &rhs)
Greater or equal operator.
Definition: int64x64.h:166
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)
Subtraction operator.
Definition: int64x64.h:103
int64x64_t operator+(const int64x64_t &lhs, const int64x64_t &rhs)
Addition operator.
Definition: int64x64.h:89
int64x64_t Abs(const int64x64_t &value)
Absolute value.
Definition: int64x64.h:205
int64x64_t Min(const int64x64_t &a, const int64x64_t &b)
Minimum.
Definition: int64x64.h:218
int64x64_t operator*(const int64x64_t &lhs, const int64x64_t &rhs)
Multiplication operator.
Definition: int64x64.h:117
bool operator>(const Length &left, const Length &right)
Check if left has a value greater than right.
Definition: length.cc:413
int64_t Div(const Length &numerator, const Length &denominator, Length *remainder)
Calculate how many times numerator can be split into denominator sized pieces.
Definition: length.cc:474
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1260
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1268
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
Time Days(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1220
Time Hours(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1228
Time PicoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1276
Time FemtoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1284
Time Minutes(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1236
Time Years(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1212
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1252
Declaration of the ns3::int64x64_t type and associated operators.
Length::Unit Unit
Save some typing by defining a short alias for Length::Unit.
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Definition: nstime.h:793
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Time Rem(const Time &lhs, const Time &rhs)
Remainder (modulus) from the quotient of two Times.
Definition: nstime.h:1078
Time operator%(const Time &lhs, const Time &rhs)
Remainder (modulus) from the quotient of two Times.
Definition: nstime.h:1073
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.h:158
Time & operator+=(Time &lhs, const Time &rhs)
Compound addition assignment for Time.
Definition: nstime.h:1115
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:522
bool operator<(const EventId &a, const EventId &b)
Definition: event-id.h:176
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:1612
std::istream & operator>>(std::istream &is, Angles &a)
Definition: angles.cc:162
Time & operator-=(Time &lhs, const Time &rhs)
Compound subtraction assignment for Time.
Definition: nstime.h:1126
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:139
How to convert between other units and the current unit.
Definition: nstime.h:585
int64_t factor
Ratio of this unit / current unit.
Definition: nstime.h:588
bool toMul
Multiply when converting To, otherwise divide.
Definition: nstime.h:586
int64x64_t timeFrom
Multiplier to convert from this unit.
Definition: nstime.h:590
bool fromMul
Multiple when converting From, otherwise divide.
Definition: nstime.h:587
int64x64_t timeTo
Multiplier to convert to this unit.
Definition: nstime.h:589
Current time unit, and conversion info.
Definition: nstime.h:594
struct Information info[LAST]
Conversion info from current unit.
Definition: nstime.h:595
enum Time::Unit unit
Current time unit.
Definition: nstime.h:596