A Discrete-Event Network Simulator
API
nstime.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2005,2006 INRIA
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18  */
19 #ifndef TIME_H
20 #define TIME_H
21 
22 #include "assert.h"
23 #include "attribute-helper.h"
24 #include "attribute.h"
25 #include "event-id.h"
26 #include "int64x64.h"
27 #include "type-name.h"
28 
29 #include <cmath>
30 #include <limits>
31 #include <ostream>
32 #include <set>
33 #include <stdint.h>
34 
42 namespace ns3
43 {
44 
45 class TimeWithUnit;
46 
104 class Time
105 {
106  public:
110  enum Unit
111  {
112  Y = 0,
113  D = 1,
114  H = 2,
115  MIN = 3,
116  S = 4,
117  MS = 5,
118  US = 6,
119  NS = 7,
120  PS = 8,
121  FS = 9,
122  LAST = 10,
123  AUTO = 11
124  };
125 
131  inline Time& operator=(const Time& o)
132  {
133  m_data = o.m_data;
134  return *this;
135  }
136 
138  inline Time()
139  : m_data()
140  {
141  if (g_markingTimes)
142  {
143  Mark(this);
144  }
145  }
146 
152  inline Time(const Time& o)
153  : m_data(o.m_data)
154  {
155  if (g_markingTimes)
156  {
157  Mark(this);
158  }
159  }
160 
166  Time(Time&& o)
167  : m_data(o.m_data)
168  {
169  if (g_markingTimes)
170  {
171  Mark(this);
172  }
173  }
174 
185  explicit inline Time(double v)
186  : m_data(llround(v))
187  {
188  if (g_markingTimes)
189  {
190  Mark(this);
191  }
192  }
193 
194  explicit inline Time(int v)
195  : m_data(v)
196  {
197  if (g_markingTimes)
198  {
199  Mark(this);
200  }
201  }
202 
203  explicit inline Time(long int v)
204  : m_data(v)
205  {
206  if (g_markingTimes)
207  {
208  Mark(this);
209  }
210  }
211 
212  explicit inline Time(long long int v)
213  : m_data(v)
214  {
215  if (g_markingTimes)
216  {
217  Mark(this);
218  }
219  }
220 
221  explicit inline Time(unsigned int v)
222  : m_data(v)
223  {
224  if (g_markingTimes)
225  {
226  Mark(this);
227  }
228  }
229 
230  explicit inline Time(unsigned long int v)
231  : m_data(v)
232  {
233  if (g_markingTimes)
234  {
235  Mark(this);
236  }
237  }
238 
239  explicit inline Time(unsigned long long int v)
240  : m_data(v)
241  {
242  if (g_markingTimes)
243  {
244  Mark(this);
245  }
246  }
247 
248  explicit inline Time(const int64x64_t& v)
249  : m_data(v.Round())
250  {
251  if (g_markingTimes)
252  {
253  Mark(this);
254  }
255  }
256  // Numeric constructors
258 
279  explicit Time(const std::string& s);
280 
286  static Time Min()
287  {
289  }
290 
296  static Time Max()
297  {
299  }
300 
303  {
304  if (g_markingTimes)
305  {
306  Clear(this);
307  }
308  }
309 
314  inline bool IsZero() const
315  {
316  return m_data == 0;
317  }
318 
323  inline bool IsNegative() const
324  {
325  return m_data <= 0;
326  }
327 
332  inline bool IsPositive() const
333  {
334  return m_data >= 0;
335  }
336 
341  inline bool IsStrictlyNegative() const
342  {
343  return m_data < 0;
344  }
345 
350  inline bool IsStrictlyPositive() const
351  {
352  return m_data > 0;
353  }
354 
361  inline int Compare(const Time& o) const
362  {
363  return (m_data < o.m_data) ? -1 : (m_data == o.m_data) ? 0 : 1;
364  }
365 
382  inline double GetYears() const
383  {
384  return ToDouble(Time::Y);
385  }
386 
387  inline double GetDays() const
388  {
389  return ToDouble(Time::D);
390  }
391 
392  inline double GetHours() const
393  {
394  return ToDouble(Time::H);
395  }
396 
397  inline double GetMinutes() const
398  {
399  return ToDouble(Time::MIN);
400  }
401 
402  inline double GetSeconds() const
403  {
404  return ToDouble(Time::S);
405  }
406 
407  inline int64_t GetMilliSeconds() const
408  {
409  return ToInteger(Time::MS);
410  }
411 
412  inline int64_t GetMicroSeconds() const
413  {
414  return ToInteger(Time::US);
415  }
416 
417  inline int64_t GetNanoSeconds() const
418  {
419  return ToInteger(Time::NS);
420  }
421 
422  inline int64_t GetPicoSeconds() const
423  {
424  return ToInteger(Time::PS);
425  }
426 
427  inline int64_t GetFemtoSeconds() const
428  {
429  return ToInteger(Time::FS);
430  }
431  // Convert to Number in a Unit.
433 
444  inline int64_t GetTimeStep() const
445  {
446  return m_data;
447  }
448 
449  inline double GetDouble() const
450  {
451  return static_cast<double>(m_data);
452  }
453 
454  inline int64_t GetInteger() const
455  {
456  return GetTimeStep();
457  }
458  // Convert to Raw Value
460 
468  static void SetResolution(Unit resolution);
472  static Unit GetResolution();
473 
480  inline static Time From(const int64x64_t& value)
481  {
482  return Time(value);
483  }
484 
498  inline static Time FromInteger(uint64_t value, Unit unit)
499  {
500  struct Information* info = PeekInformation(unit);
501 
502  NS_ASSERT_MSG(info->isValid, "Attempted a conversion from an unavailable unit.");
503 
504  if (info->fromMul)
505  {
506  value *= info->factor;
507  }
508  else
509  {
510  value /= info->factor;
511  }
512  return Time(value);
513  }
514 
515  inline static Time FromDouble(double value, Unit unit)
516  {
517  return From(int64x64_t(value), unit);
518  }
519 
520  inline static Time From(const int64x64_t& value, Unit unit)
521  {
522  struct Information* info = PeekInformation(unit);
523 
524  NS_ASSERT_MSG(info->isValid, "Attempted a conversion from an unavailable unit.");
525 
526  // DO NOT REMOVE this temporary variable. It's here
527  // to work around a compiler bug in gcc 3.4
528  int64x64_t retval = value;
529  if (info->fromMul)
530  {
531  retval *= info->timeFrom;
532  }
533  else
534  {
535  retval.MulByInvert(info->timeFrom);
536  }
537  return Time(retval);
538  }
539  // Create Times from Values and Units
541 
554  inline int64_t ToInteger(Unit unit) const
555  {
556  struct Information* info = PeekInformation(unit);
557 
558  NS_ASSERT_MSG(info->isValid, "Attempted a conversion to an unavailable unit.");
559 
560  int64_t v = m_data;
561  if (info->toMul)
562  {
563  v *= info->factor;
564  }
565  else
566  {
567  v /= info->factor;
568  }
569  return v;
570  }
571 
572  inline double ToDouble(Unit unit) const
573  {
574  return To(unit).GetDouble();
575  }
576 
577  inline int64x64_t To(Unit unit) const
578  {
579  struct Information* info = PeekInformation(unit);
580 
581  NS_ASSERT_MSG(info->isValid, "Attempted a conversion to an unavailable unit.");
582 
583  int64x64_t retval = int64x64_t(m_data);
584  if (info->toMul)
585  {
586  retval *= info->timeTo;
587  }
588  else
589  {
590  retval.MulByInvert(info->timeTo);
591  }
592  return retval;
593  }
594  // Get Times as Numbers in Specified Units
596 
603  Time RoundTo(Unit unit) const
604  {
605  return From(this->To(unit).Round(), unit);
606  }
607 
621  TimeWithUnit As(const Unit unit = Time::AUTO) const;
622 
628  typedef void (*TracedCallback)(Time value);
629 
630  private:
632  struct Information
633  {
634  bool toMul;
635  bool fromMul;
636  int64_t factor;
639  bool isValid;
640  };
641 
643  struct Resolution
644  {
647  };
648 
654  static inline struct Resolution* PeekResolution()
655  {
656  static struct Time::Resolution& resolution{SetDefaultNsResolution()};
657  return &resolution;
658  }
659 
666  static inline struct Information* PeekInformation(Unit timeUnit)
667  {
668  return &(PeekResolution()->info[timeUnit]);
669  }
670 
676  static struct Resolution& SetDefaultNsResolution();
684  static void SetResolution(Unit unit, Resolution* resolution, const bool convert = true);
685 
706  typedef std::set<Time*> MarkedTimes;
722 
723  public:
729  static bool StaticInit();
730 
731  private:
739  friend class Simulator;
748  static void ClearMarkedTimes();
753  static void Mark(Time* const time);
758  static void Clear(Time* const time);
763  static void ConvertTimes(const Unit unit);
764 
765  // Operator and related functions which need access
766 
771  friend bool operator==(const Time& lhs, const Time& rhs);
772  friend bool operator!=(const Time& lhs, const Time& rhs);
773  friend bool operator<=(const Time& lhs, const Time& rhs);
774  friend bool operator>=(const Time& lhs, const Time& rhs);
775  friend bool operator<(const Time& lhs, const Time& rhs);
776  friend bool operator>(const Time& lhs, const Time& rhs);
777  friend bool operator<(const Time& time, const EventId& event); // Comparison operators
779 
784  friend Time operator+(const Time& lhs, const Time& rhs);
785  friend Time operator-(const Time& lhs, const Time& rhs);
786  friend Time operator*(const Time& lhs, const int64x64_t& rhs);
787  friend Time operator*(const int64x64_t& lhs, const Time& rhs);
788  friend int64x64_t operator/(const Time& lhs, const Time& rhs);
789  friend Time operator/(const Time& lhs, const int64x64_t& rhs);
790  friend Time operator%(const Time& lhs, const Time& rhs);
791  friend int64_t Div(const Time& lhs, const Time& rhs);
792  friend Time Rem(const Time& lhs, const Time& rhs);
793 
794  template <class T>
796  const Time& lhs,
797  T rhs);
798 
799  // Reversed arg version (forwards to `rhs * lhs`)
800  // Accepts both integers and decimal types
801  template <class T>
803  T lhs,
804  const Time& rhs);
805 
806  template <class T>
808  const Time& lhs,
809  T rhs);
810 
811  friend Time Abs(const Time& time);
812  friend Time Max(const Time& timeA, const Time& timeB);
813  friend Time Min(const Time& timeA, const Time& timeB);
814  // Arithmetic operators
816 
817  // Leave undocumented
818  template <class T>
820  const Time& lhs,
821  T rhs);
822  template <class T>
824  const Time& lhs,
825  T rhs);
826 
831  friend Time& operator+=(Time& lhs, const Time& rhs);
832  friend Time& operator-=(Time& lhs, const Time& rhs); // Compound assignment
834 
835  int64_t m_data;
836 
837 }; // class Time
838 
839 namespace TracedValueCallback
840 {
841 
848 typedef void (*Time)(Time oldValue, Time newValue);
849 
850 } // namespace TracedValueCallback
851 
857 static bool g_TimeStaticInit [[maybe_unused]] = Time::StaticInit();
858 
865 inline bool
866 operator==(const Time& lhs, const Time& rhs)
867 {
868  return lhs.m_data == rhs.m_data;
869 }
870 
877 inline bool
878 operator!=(const Time& lhs, const Time& rhs)
879 {
880  return lhs.m_data != rhs.m_data;
881 }
882 
889 inline bool
890 operator<=(const Time& lhs, const Time& rhs)
891 {
892  return lhs.m_data <= rhs.m_data;
893 }
894 
901 inline bool
902 operator>=(const Time& lhs, const Time& rhs)
903 {
904  return lhs.m_data >= rhs.m_data;
905 }
906 
913 inline bool
914 operator<(const Time& lhs, const Time& rhs)
915 {
916  return lhs.m_data < rhs.m_data;
917 }
918 
925 inline bool
926 operator>(const Time& lhs, const Time& rhs)
927 {
928  return lhs.m_data > rhs.m_data;
929 }
930 
948 inline bool
949 operator<(const Time& time, const EventId& event)
950 {
951  // Negative Time is less than any possible EventId, which are all >= 0.
952  if (time.m_data < 0)
953  {
954  return true;
955  }
956  // Time must be >= 0 so casting to unsigned is safe.
957  return static_cast<uint64_t>(time.m_data) < event.GetTs();
958 }
959 
966 inline Time
967 operator+(const Time& lhs, const Time& rhs)
968 {
969  return Time(lhs.m_data + rhs.m_data);
970 }
971 
978 inline Time
979 operator-(const Time& lhs, const Time& rhs)
980 {
981  return Time(lhs.m_data - rhs.m_data);
982 }
983 
990 inline Time
991 operator*(const Time& lhs, const int64x64_t& rhs)
992 {
993  int64x64_t res = lhs.m_data;
994  res *= rhs;
995  return Time(res);
996 }
997 
1004 inline Time
1005 operator*(const int64x64_t& lhs, const Time& rhs)
1006 {
1007  return rhs * lhs;
1008 }
1009 
1019 template <class T>
1021 operator*(const Time& lhs, T rhs)
1022 {
1023  static_assert(!std::is_same<T, bool>::value,
1024  "Multiplying a Time by a boolean is not supported");
1025 
1026  return Time(lhs.m_data * rhs);
1027 }
1028 
1029 // Leave undocumented
1030 template <class T>
1032 operator*(const Time& lhs, T rhs)
1033 {
1034  return lhs * int64x64_t(rhs);
1035 }
1036 
1050 template <class T>
1052 operator*(T lhs, const Time& rhs)
1053 {
1054  return rhs * lhs;
1055 }
1056 
1075 inline int64x64_t
1076 operator/(const Time& lhs, const Time& rhs)
1077 {
1078  int64x64_t num = lhs.m_data;
1079  int64x64_t den = rhs.m_data;
1080  return num / den;
1081 }
1082 
1089 inline Time
1090 operator/(const Time& lhs, const int64x64_t& rhs)
1091 {
1092  int64x64_t res = lhs.m_data;
1093  res /= rhs;
1094  return Time(res);
1095 }
1096 
1106 template <class T>
1108 operator/(const Time& lhs, T rhs)
1109 {
1110  static_assert(!std::is_same<T, bool>::value, "Dividing a Time by a boolean is not supported");
1111 
1112  return Time(lhs.m_data / rhs);
1113 }
1114 
1115 // Leave undocumented
1116 template <class T>
1118 operator/(const Time& lhs, T rhs)
1119 {
1120  return lhs / int64x64_t(rhs);
1121 }
1122 
1136 inline Time
1137 operator%(const Time& lhs, const Time& rhs)
1138 {
1139  return Time(lhs.m_data % rhs.m_data);
1140 }
1141 
1142 inline Time
1143 Rem(const Time& lhs, const Time& rhs)
1144 {
1145  return Time(lhs.m_data % rhs.m_data);
1146 }
1147 
1170 inline int64_t
1171 Div(const Time& lhs, const Time& rhs)
1172 {
1173  return lhs.m_data / rhs.m_data;
1174 }
1175 
1182 inline Time&
1183 operator+=(Time& lhs, const Time& rhs)
1184 {
1185  lhs.m_data += rhs.m_data;
1186  return lhs;
1187 }
1188 
1195 inline Time&
1196 operator-=(Time& lhs, const Time& rhs)
1197 {
1198  lhs.m_data -= rhs.m_data;
1199  return lhs;
1200 }
1201 
1207 inline Time
1208 Abs(const Time& time)
1209 {
1210  return Time((time.m_data < 0) ? -time.m_data : time.m_data);
1211 }
1212 
1219 inline Time
1220 Max(const Time& timeA, const Time& timeB)
1221 {
1222  return Time((timeA.m_data < timeB.m_data) ? timeB : timeA);
1223 }
1224 
1231 inline Time
1232 Min(const Time& timeA, const Time& timeB)
1233 {
1234  return Time((timeA.m_data > timeB.m_data) ? timeB : timeA);
1235 }
1236 
1257 std::ostream& operator<<(std::ostream& os, const Time& time);
1267 std::istream& operator>>(std::istream& is, Time& time);
1268 
1287 inline Time
1288 Years(double value)
1289 {
1290  return Time::FromDouble(value, Time::Y);
1291 }
1292 
1293 inline Time
1295 {
1296  return Time::From(value, Time::Y);
1297 }
1298 
1299 inline Time
1300 Days(double value)
1301 {
1302  return Time::FromDouble(value, Time::D);
1303 }
1304 
1305 inline Time
1307 {
1308  return Time::From(value, Time::D);
1309 }
1310 
1311 inline Time
1312 Hours(double value)
1313 {
1314  return Time::FromDouble(value, Time::H);
1315 }
1316 
1317 inline Time
1319 {
1320  return Time::From(value, Time::H);
1321 }
1322 
1323 inline Time
1325 {
1326  return Time::FromDouble(value, Time::MIN);
1327 }
1328 
1329 inline Time
1331 {
1332  return Time::From(value, Time::MIN);
1333 }
1334 
1335 inline Time
1337 {
1338  return Time::FromDouble(value, Time::S);
1339 }
1340 
1341 inline Time
1343 {
1344  return Time::From(value, Time::S);
1345 }
1346 
1347 inline Time
1349 {
1350  return Time::FromInteger(value, Time::MS);
1351 }
1352 
1353 inline Time
1355 {
1356  return Time::From(value, Time::MS);
1357 }
1358 
1359 inline Time
1361 {
1362  return Time::FromInteger(value, Time::US);
1363 }
1364 
1365 inline Time
1367 {
1368  return Time::From(value, Time::US);
1369 }
1370 
1371 inline Time
1373 {
1374  return Time::FromInteger(value, Time::NS);
1375 }
1376 
1377 inline Time
1379 {
1380  return Time::From(value, Time::NS);
1381 }
1382 
1383 inline Time
1385 {
1386  return Time::FromInteger(value, Time::PS);
1387 }
1388 
1389 inline Time
1391 {
1392  return Time::From(value, Time::PS);
1393 }
1394 
1395 inline Time
1397 {
1398  return Time::FromInteger(value, Time::FS);
1399 }
1400 
1401 inline Time
1403 {
1404  return Time::From(value, Time::FS);
1405 }
1406  // Construct a Time in the indicated unit.
1408 
1417 inline Time
1418 TimeStep(uint64_t ts)
1419 {
1420  return Time(ts);
1421 }
1422 
1425 
1436 
1445 {
1446  return MakeTimeChecker(Time::Min(), Time::Max());
1447 }
1448 
1456 inline Ptr<const AttributeChecker>
1458 {
1459  return MakeTimeChecker(min, Time::Max());
1460 }
1461 
1467 {
1468  public:
1475  TimeWithUnit(const Time time, const Time::Unit unit)
1476  : m_time(time),
1477  m_unit(unit)
1478  {
1479  }
1480 
1481  private:
1484 
1491  friend std::ostream& operator<<(std::ostream& os, const TimeWithUnit& timeU);
1492 
1493 }; // class TimeWithUnit
1494 
1502 
1503 } // namespace ns3
1504 
1505 #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:55
uint64_t GetTs() const
Definition: event-id.cc:90
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
Control the scheduling of simulation events.
Definition: simulator.h:68
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
friend Time operator%(const Time &lhs, const Time &rhs)
Remainder (modulus) from the quotient of two Times.
Definition: nstime.h:1137
static Unit GetResolution()
Definition: time.cc:410
int64_t GetNanoSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:417
bool IsPositive() const
Exactly equivalent to t >= 0.
Definition: nstime.h:332
Time(const Time &o)
Copy constructor.
Definition: nstime.h:152
Time(const int64x64_t &v)
Construct from a numeric value.
Definition: nstime.h:248
static void ClearMarkedTimes()
Remove all MarkedTimes.
Definition: time.cc:296
Time(unsigned long int v)
Construct from a numeric value.
Definition: nstime.h:230
static Time From(const int64x64_t &value)
Create a Time in the current unit.
Definition: nstime.h:480
~Time()
Destructor.
Definition: nstime.h:302
int64_t GetMilliSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:407
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:417
Time(long long int v)
Construct from a numeric value.
Definition: nstime.h:212
static void ConvertTimes(const Unit unit)
Convert existing Times to the new unit.
Definition: time.cc:378
int64_t GetFemtoSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:427
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:402
int64x64_t To(Unit unit) const
Get the Time value expressed in a particular unit.
Definition: nstime.h:577
bool IsStrictlyPositive() const
Exactly equivalent to t > 0.
Definition: nstime.h:350
Time TimeStep(uint64_t ts)
Scheduler interface.
Definition: nstime.h:1418
Time(double v)
Construct from a numeric value.
Definition: nstime.h:185
int64_t GetInteger() const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:454
bool IsNegative() const
Exactly equivalent to t <= 0.
Definition: nstime.h:323
static bool StaticInit()
Function to force static initialization of Time.
Definition: time.cc:97
friend bool operator==(const Time &lhs, const Time &rhs)
Equality operator for Time.
Definition: nstime.h:866
Time(unsigned long long int v)
Construct from a numeric value.
Definition: nstime.h:239
double GetMinutes() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:397
static Time Min()
Minimum representable Time Not to be confused with Min(Time,Time).
Definition: nstime.h:286
static void Clear(Time *const time)
Remove a Time instance from the MarkedTimes, called by ~Time().
Definition: time.cc:350
static Time From(const int64x64_t &value, Unit unit)
Create a Time equal to value in unit unit.
Definition: nstime.h:520
Unit
The unit to use to interpret a number representing time.
Definition: nstime.h:111
@ AUTO
auto-scale output when using Time::As()
Definition: nstime.h:123
@ D
day, 24 hours
Definition: nstime.h:113
@ US
microsecond
Definition: nstime.h:118
@ PS
picosecond
Definition: nstime.h:120
@ LAST
marker for last normal value
Definition: nstime.h:122
@ Y
year, 365 days
Definition: nstime.h:112
@ FS
femtosecond
Definition: nstime.h:121
@ H
hour, 60 minutes
Definition: nstime.h:114
@ MIN
minute, 60 seconds
Definition: nstime.h:115
@ MS
millisecond
Definition: nstime.h:117
@ S
second
Definition: nstime.h:116
@ NS
nanosecond
Definition: nstime.h:119
Time()
Default constructor, with value 0.
Definition: nstime.h:138
friend bool operator>=(const Time &lhs, const Time &rhs)
Greater than or equal operator for Time.
Definition: nstime.h:902
friend Time & operator+=(Time &lhs, const Time &rhs)
Compound addition assignment for Time.
Definition: nstime.h:1183
double GetDays() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:387
Time RoundTo(Unit unit) const
Round a Time to a specific unit.
Definition: nstime.h:603
friend bool operator<=(const Time &lhs, const Time &rhs)
Less than or equal operator for Time.
Definition: nstime.h:890
static MarkedTimes * g_markingTimes
Record of outstanding Time objects which will need conversion when the resolution is set.
Definition: nstime.h:721
int64_t m_data
Virtual time value, in the current unit.
Definition: nstime.h:835
static struct Information * PeekInformation(Unit timeUnit)
Get the Information record for timeUnit for the current Resolution.
Definition: nstime.h:666
friend Time Rem(const Time &lhs, const Time &rhs)
Addition operator for Time.
Definition: nstime.h:1143
friend int64_t Div(const Time &lhs, const Time &rhs)
Integer quotient from dividing two Times.
Definition: nstime.h:1171
static void Mark(Time *const time)
Record a Time instance with the MarkedTimes.
Definition: time.cc:325
int64_t GetPicoSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:422
static void SetResolution(Unit resolution)
Definition: time.cc:213
double GetYears() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:382
friend bool operator<(const Time &lhs, const Time &rhs)
Less than operator for Time.
Definition: nstime.h:914
Time(int v)
Construct from a numeric value.
Definition: nstime.h:194
friend bool operator!=(const Time &lhs, const Time &rhs)
Inequality operator for Time.
Definition: nstime.h:878
Time(Time &&o)
Move constructor.
Definition: nstime.h:166
int64_t ToInteger(Unit unit) const
Get the Time value expressed in a particular unit.
Definition: nstime.h:554
static Time FromInteger(uint64_t value, Unit unit)
Create a Time equal to value in unit unit.
Definition: nstime.h:498
bool IsStrictlyNegative() const
Exactly equivalent to t < 0.
Definition: nstime.h:341
static struct Resolution & SetDefaultNsResolution()
Set the default resolution.
Definition: time.cc:203
Time(unsigned int v)
Construct from a numeric value.
Definition: nstime.h:221
int Compare(const Time &o) const
Compare this to another Time.
Definition: nstime.h:361
static Time FromDouble(double value, Unit unit)
Create a Time equal to value in unit unit.
Definition: nstime.h:515
double GetDouble() const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:449
friend Time operator-(const Time &lhs, const Time &rhs)
Subtraction operator for Time.
Definition: nstime.h:979
friend Time operator+(const Time &lhs, const Time &rhs)
Addition operator for Time.
Definition: nstime.h:967
static Time Max()
Maximum representable Time Not to be confused with Max(Time,Time).
Definition: nstime.h:296
friend Time operator*(const Time &lhs, const int64x64_t &rhs)
Scale a Time by a numeric value.
Definition: nstime.h:991
double ToDouble(Unit unit) const
Get the Time value expressed in a particular unit.
Definition: nstime.h:572
friend bool operator>(const Time &lhs, const Time &rhs)
Greater than operator for Time.
Definition: nstime.h:926
bool IsZero() const
Exactly equivalent to t == 0.
Definition: nstime.h:314
int64_t GetTimeStep() const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:444
int64_t GetMicroSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:412
friend Time Abs(const Time &time)
Absolute value for Time.
Definition: nstime.h:1208
static struct Resolution * PeekResolution()
Get the current Resolution.
Definition: nstime.h:654
Time(long int v)
Construct from a numeric value.
Definition: nstime.h:203
double GetHours() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:392
friend Time & operator-=(Time &lhs, const Time &rhs)
Compound subtraction assignment for Time.
Definition: nstime.h:1196
friend int64x64_t operator/(const Time &lhs, const Time &rhs)
Exact division, returning a dimensionless fixed point number.
Definition: nstime.h:1076
std::set< Time * > MarkedTimes
Record all instances of Time, so we can rescale them when the resolution changes.
Definition: nstime.h:706
Time & operator=(const Time &o)
Assignment operator.
Definition: nstime.h:131
A Time with attached unit, to facilitate output in that unit.
Definition: nstime.h:1467
friend std::ostream & operator<<(std::ostream &os, const TimeWithUnit &timeU)
Output streamer.
Definition: time.cc:430
TimeWithUnit(const Time time, const Time::Unit unit)
Attach a unit to a Time.
Definition: nstime.h:1475
Time m_time
The time.
Definition: nstime.h:1482
Time::Unit m_unit
The unit to use in output.
Definition: nstime.h:1483
Forward calls to a chain of Callback.
High precision numerical type, implementing Q64.64 fixed precision.
void MulByInvert(const int64x64_t &o)
Multiply this value by a Q0.128 value, presumably representing an inverse, completing a division oper...
double GetDouble() const
Get this value as a double.
ns3::EventId declarations.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:86
#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:243
int64x64_t operator/(const int64x64_t &lhs, const int64x64_t &rhs)
Division operator.
Definition: int64x64.h:133
bool operator>=(const int64x64_t &lhs, const int64x64_t &rhs)
Greater or equal operator.
Definition: int64x64.h:174
bool operator<=(const int64x64_t &lhs, const int64x64_t &rhs)
Less or equal operator.
Definition: int64x64.h:161
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:88
int64x64_t Abs(const int64x64_t &value)
Absolute value.
Definition: int64x64.h:215
int64x64_t Min(const int64x64_t &a, const int64x64_t &b)
Minimum.
Definition: int64x64.h:229
int64x64_t operator*(const int64x64_t &lhs, const int64x64_t &rhs)
Multiplication operator.
Definition: int64x64.h:118
bool operator>(const Length &left, const Length &right)
Check if left has a value greater than right.
Definition: length.cc:421
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:482
TYPENAMEGET_DEFINE(Time)
ns3::TypeNameGet<Time>() specialization.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1360
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1372
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1336
Time Days(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1300
Time Hours(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1312
Time PicoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1384
Time FemtoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1396
Time Minutes(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1324
Time Years(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1288
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1348
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:848
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:1143
bool operator!=(Callback< R, Args... > a, Callback< R, Args... > b)
Inequality test.
Definition: callback.h:681
Time operator%(const Time &lhs, const Time &rhs)
Remainder (modulus) from the quotient of two Times.
Definition: nstime.h:1137
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.h:157
Time & operator+=(Time &lhs, const Time &rhs)
Compound addition assignment for Time.
Definition: nstime.h:1183
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:535
bool operator<(const EventId &a, const EventId &b)
Definition: event-id.h:170
std::istream & operator>>(std::istream &is, Angles &a)
Definition: angles.cc:153
Time & operator-=(Time &lhs, const Time &rhs)
Compound subtraction assignment for Time.
Definition: nstime.h:1196
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:129
value
Definition: second.py:41
How to convert between other units and the current unit.
Definition: nstime.h:633
int64_t factor
Ratio of this unit / current unit.
Definition: nstime.h:636
bool toMul
Multiply when converting To, otherwise divide.
Definition: nstime.h:634
int64x64_t timeFrom
Multiplier to convert from this unit.
Definition: nstime.h:638
bool isValid
True if the current unit can be used.
Definition: nstime.h:639
bool fromMul
Multiple when converting From, otherwise divide.
Definition: nstime.h:635
int64x64_t timeTo
Multiplier to convert to this unit.
Definition: nstime.h:637
Current time unit, and conversion info.
Definition: nstime.h:644
Time::Unit unit
Current time unit.
Definition: nstime.h:646
Information info[LAST]
Conversion info from current unit.
Definition: nstime.h:645
ns3::TypeNameGet() function declarations.