A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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
42namespace ns3
43{
44
45class TimeWithUnit;
46
104class 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
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
280 explicit Time(const std::string& s);
281
287 static Time Min()
288 {
289 return Time(std::numeric_limits<int64_t>::min());
290 }
291
297 static Time Max()
298 {
299 return Time(std::numeric_limits<int64_t>::max());
300 }
301
304 {
305 if (g_markingTimes)
306 {
307 Clear(this);
308 }
309 }
310
315 inline bool IsZero() const
316 {
317 return m_data == 0;
318 }
319
324 inline bool IsNegative() const
325 {
326 return m_data <= 0;
327 }
328
333 inline bool IsPositive() const
334 {
335 return m_data >= 0;
336 }
337
342 inline bool IsStrictlyNegative() const
343 {
344 return m_data < 0;
345 }
346
351 inline bool IsStrictlyPositive() const
352 {
353 return m_data > 0;
354 }
355
362 inline int Compare(const Time& o) const
363 {
364 return (m_data < o.m_data) ? -1 : (m_data == o.m_data) ? 0 : 1;
365 }
366
383 inline double GetYears() const
384 {
385 return ToDouble(Time::Y);
386 }
387
388 inline double GetDays() const
389 {
390 return ToDouble(Time::D);
391 }
392
393 inline double GetHours() const
394 {
395 return ToDouble(Time::H);
396 }
397
398 inline double GetMinutes() const
399 {
400 return ToDouble(Time::MIN);
401 }
402
403 inline double GetSeconds() const
404 {
405 return ToDouble(Time::S);
406 }
407
408 inline int64_t GetMilliSeconds() const
409 {
410 return ToInteger(Time::MS);
411 }
412
413 inline int64_t GetMicroSeconds() const
414 {
415 return ToInteger(Time::US);
416 }
417
418 inline int64_t GetNanoSeconds() const
419 {
420 return ToInteger(Time::NS);
421 }
422
423 inline int64_t GetPicoSeconds() const
424 {
425 return ToInteger(Time::PS);
426 }
427
428 inline int64_t GetFemtoSeconds() const
429 {
430 return ToInteger(Time::FS);
431 }
432 // Convert to Number in a Unit.
434
445 inline int64_t GetTimeStep() const
446 {
447 return m_data;
448 }
449
450 inline double GetDouble() const
451 {
452 return static_cast<double>(m_data);
453 }
454
455 inline int64_t GetInteger() const
456 {
457 return GetTimeStep();
458 }
459 // Convert to Raw Value
461
469 static void SetResolution(Unit resolution);
473 static Unit GetResolution();
474
481 inline static Time From(const int64x64_t& value)
482 {
483 return Time(value);
484 }
485
499 inline static Time FromInteger(uint64_t value, Unit unit)
500 {
501 Information* info = PeekInformation(unit);
502
503 NS_ASSERT_MSG(info->isValid, "Attempted a conversion from an unavailable unit.");
504
505 if (info->fromMul)
506 {
507 value *= info->factor;
508 }
509 else
510 {
511 value /= info->factor;
512 }
513 return Time(value);
514 }
515
516 inline static Time FromDouble(double value, Unit unit)
517 {
518 return From(int64x64_t(value), unit);
519 }
520
521 inline static Time From(const int64x64_t& value, Unit unit)
522 {
523 Information* info = PeekInformation(unit);
524
525 NS_ASSERT_MSG(info->isValid, "Attempted a conversion from an unavailable unit.");
526
527 // DO NOT REMOVE this temporary variable. It's here
528 // to work around a compiler bug in gcc 3.4
529 int64x64_t retval = value;
530 if (info->fromMul)
531 {
532 retval *= info->timeFrom;
533 }
534 else
535 {
536 retval.MulByInvert(info->timeFrom);
537 }
538 return Time(retval);
539 }
540 // Create Times from Values and Units
542
555 inline int64_t ToInteger(Unit unit) const
556 {
557 Information* info = PeekInformation(unit);
558
559 NS_ASSERT_MSG(info->isValid, "Attempted a conversion to an unavailable unit.");
560
561 int64_t v = m_data;
562 if (info->toMul)
563 {
564 v *= info->factor;
565 }
566 else
567 {
568 v /= info->factor;
569 }
570 return v;
571 }
572
573 inline double ToDouble(Unit unit) const
574 {
575 return To(unit).GetDouble();
576 }
577
578 inline int64x64_t To(Unit unit) const
579 {
580 Information* info = PeekInformation(unit);
581
582 NS_ASSERT_MSG(info->isValid, "Attempted a conversion to an unavailable unit.");
583
584 int64x64_t retval(m_data);
585 if (info->toMul)
586 {
587 retval *= info->timeTo;
588 }
589 else
590 {
591 retval.MulByInvert(info->timeTo);
592 }
593 return retval;
594 }
595 // Get Times as Numbers in Specified Units
597
604 Time RoundTo(Unit unit) const
605 {
606 return From(this->To(unit).Round(), unit);
607 }
608
622 TimeWithUnit As(const Unit unit = Time::AUTO) const;
623
629 typedef void (*TracedCallback)(Time value);
630
631 private:
634 {
635 bool toMul;
636 bool fromMul;
637 int64_t factor;
640 bool isValid;
641 };
642
645 {
648 };
649
655 static inline Resolution* PeekResolution()
656 {
657 static Time::Resolution& resolution{SetDefaultNsResolution()};
658 return &resolution;
659 }
660
667 static inline Information* PeekInformation(Unit timeUnit)
668 {
669 return &(PeekResolution()->info[timeUnit]);
670 }
671
677 static Resolution& SetDefaultNsResolution();
685 static void SetResolution(Unit unit, Resolution* resolution, const bool convert = true);
686
707 typedef std::set<Time*> MarkedTimes;
723
724 public:
730 static bool StaticInit();
731
732 private:
740 friend class Simulator;
749 static void ClearMarkedTimes();
754 static void Mark(Time* const time);
759 static void Clear(Time* const time);
764 static void ConvertTimes(const Unit unit);
765
766 // Operator and related functions which need access
767
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& lhs, const Time& rhs);
778 friend bool operator<(const Time& time, const EventId& event); // Comparison operators
780
785 friend Time operator+(const Time& lhs, const Time& rhs);
786 friend Time operator-(const Time& lhs, const Time& rhs);
787 friend Time operator*(const Time& lhs, const int64x64_t& rhs);
788 friend Time operator*(const int64x64_t& lhs, const Time& rhs);
789 friend int64x64_t operator/(const Time& lhs, const Time& rhs);
790 friend Time operator/(const Time& lhs, const int64x64_t& rhs);
791 friend Time operator%(const Time& lhs, const Time& rhs);
792 friend int64_t Div(const Time& lhs, const Time& rhs);
793 friend Time Rem(const Time& lhs, const Time& rhs);
794
795 template <class T>
796 friend std::enable_if_t<std::is_integral_v<T>, Time> operator*(const Time& lhs, T rhs);
797
798 // Reversed arg version (forwards to `rhs * lhs`)
799 // Accepts both integers and decimal types
800 template <class T>
801 friend std::enable_if_t<std::is_arithmetic_v<T>, Time> operator*(T lhs, const Time& rhs);
802
803 template <class T>
804 friend std::enable_if_t<std::is_integral_v<T>, Time> operator/(const Time& lhs, T rhs);
805
806 friend Time Abs(const Time& time);
807 friend Time Max(const Time& timeA, const Time& timeB);
808 friend Time Min(const Time& timeA, const Time& timeB);
809 // Arithmetic operators
811
812 // Leave undocumented
813 template <class T>
814 friend std::enable_if_t<std::is_floating_point_v<T>, Time> operator*(const Time& lhs, T rhs);
815 template <class T>
816 friend std::enable_if_t<std::is_floating_point_v<T>, Time> operator/(const Time& lhs, T rhs);
817
822 friend Time& operator+=(Time& lhs, const Time& rhs);
823 friend Time& operator-=(Time& lhs, const Time& rhs); // Compound assignment
825
826 int64_t m_data;
827
828}; // class Time
829
830namespace TracedValueCallback
831{
832
839typedef void (*Time)(Time oldValue, Time newValue);
840
841} // namespace TracedValueCallback
842
848static bool g_TimeStaticInit [[maybe_unused]] = Time::StaticInit();
849
856inline bool
857operator==(const Time& lhs, const Time& rhs)
858{
859 return lhs.m_data == rhs.m_data;
860}
861
868inline bool
869operator!=(const Time& lhs, const Time& rhs)
870{
871 return lhs.m_data != rhs.m_data;
872}
873
880inline bool
881operator<=(const Time& lhs, const Time& rhs)
882{
883 return lhs.m_data <= rhs.m_data;
884}
885
892inline bool
893operator>=(const Time& lhs, const Time& rhs)
894{
895 return lhs.m_data >= rhs.m_data;
896}
897
904inline bool
905operator<(const Time& lhs, const Time& rhs)
906{
907 return lhs.m_data < rhs.m_data;
908}
909
916inline bool
917operator>(const Time& lhs, const Time& rhs)
918{
919 return lhs.m_data > rhs.m_data;
920}
921
939inline bool
940operator<(const Time& time, const EventId& event)
941{
942 // Negative Time is less than any possible EventId, which are all >= 0.
943 if (time.m_data < 0)
944 {
945 return true;
946 }
947 // Time must be >= 0 so casting to unsigned is safe.
948 return static_cast<uint64_t>(time.m_data) < event.GetTs();
949}
950
957inline Time
958operator+(const Time& lhs, const Time& rhs)
959{
960 return Time(lhs.m_data + rhs.m_data);
961}
962
969inline Time
970operator-(const Time& lhs, const Time& rhs)
971{
972 return Time(lhs.m_data - rhs.m_data);
973}
974
981inline Time
982operator*(const Time& lhs, const int64x64_t& rhs)
983{
984 int64x64_t res = lhs.m_data;
985 res *= rhs;
986 return Time(res);
987}
988
995inline Time
996operator*(const int64x64_t& lhs, const Time& rhs)
997{
998 return rhs * lhs;
999}
1000
1010template <class T>
1011std::enable_if_t<std::is_integral_v<T>, Time>
1012operator*(const Time& lhs, T rhs)
1013{
1014 static_assert(!std::is_same_v<T, bool>, "Multiplying a Time by a boolean is not supported");
1015
1016 return Time(lhs.m_data * rhs);
1017}
1018
1019// Leave undocumented
1020template <class T>
1021std::enable_if_t<std::is_floating_point_v<T>, Time>
1022operator*(const Time& lhs, T rhs)
1023{
1024 return lhs * int64x64_t(rhs);
1025}
1026
1040template <class T>
1041std::enable_if_t<std::is_arithmetic_v<T>, Time>
1042operator*(T lhs, const Time& rhs)
1043{
1044 return rhs * lhs;
1045}
1046
1065inline int64x64_t
1066operator/(const Time& lhs, const Time& rhs)
1067{
1068 int64x64_t num = lhs.m_data;
1069 int64x64_t den = rhs.m_data;
1070 return num / den;
1071}
1072
1079inline Time
1080operator/(const Time& lhs, const int64x64_t& rhs)
1081{
1082 int64x64_t res = lhs.m_data;
1083 res /= rhs;
1084 return Time(res);
1085}
1086
1096template <class T>
1097std::enable_if_t<std::is_integral_v<T>, Time>
1098operator/(const Time& lhs, T rhs)
1099{
1100 static_assert(!std::is_same_v<T, bool>, "Dividing a Time by a boolean is not supported");
1101
1102 return Time(lhs.m_data / rhs);
1103}
1104
1105// Leave undocumented
1106template <class T>
1107std::enable_if_t<std::is_floating_point_v<T>, Time>
1108operator/(const Time& lhs, T rhs)
1109{
1110 return lhs / int64x64_t(rhs);
1111}
1112
1126inline Time
1127operator%(const Time& lhs, const Time& rhs)
1128{
1129 return Time(lhs.m_data % rhs.m_data);
1130}
1131
1132inline Time
1133Rem(const Time& lhs, const Time& rhs)
1134{
1135 return Time(lhs.m_data % rhs.m_data);
1136}
1137
1160inline int64_t
1161Div(const Time& lhs, const Time& rhs)
1162{
1163 return lhs.m_data / rhs.m_data;
1164}
1165
1172inline Time&
1173operator+=(Time& lhs, const Time& rhs)
1174{
1175 lhs.m_data += rhs.m_data;
1176 return lhs;
1177}
1178
1185inline Time&
1186operator-=(Time& lhs, const Time& rhs)
1187{
1188 lhs.m_data -= rhs.m_data;
1189 return lhs;
1190}
1191
1197inline Time
1198Abs(const Time& time)
1199{
1200 return Time((time.m_data < 0) ? -time.m_data : time.m_data);
1201}
1202
1209inline Time
1210Max(const Time& timeA, const Time& timeB)
1211{
1212 return Time((timeA.m_data < timeB.m_data) ? timeB : timeA);
1213}
1214
1221inline Time
1222Min(const Time& timeA, const Time& timeB)
1223{
1224 return Time((timeA.m_data > timeB.m_data) ? timeB : timeA);
1225}
1226
1247std::ostream& operator<<(std::ostream& os, const Time& time);
1257std::istream& operator>>(std::istream& is, Time& time);
1258
1277inline Time
1278Years(double value)
1279{
1280 return Time::FromDouble(value, Time::Y);
1281}
1282
1283inline Time
1285{
1286 return Time::From(value, Time::Y);
1287}
1288
1289inline Time
1290Days(double value)
1291{
1292 return Time::FromDouble(value, Time::D);
1293}
1294
1295inline Time
1297{
1298 return Time::From(value, Time::D);
1299}
1300
1301inline Time
1302Hours(double value)
1303{
1304 return Time::FromDouble(value, Time::H);
1305}
1306
1307inline Time
1309{
1310 return Time::From(value, Time::H);
1311}
1312
1313inline Time
1314Minutes(double value)
1315{
1316 return Time::FromDouble(value, Time::MIN);
1317}
1318
1319inline Time
1321{
1322 return Time::From(value, Time::MIN);
1323}
1324
1325inline Time
1326Seconds(double value)
1327{
1328 return Time::FromDouble(value, Time::S);
1329}
1330
1331inline Time
1333{
1334 return Time::From(value, Time::S);
1335}
1336
1337inline Time
1338MilliSeconds(uint64_t value)
1339{
1340 return Time::FromInteger(value, Time::MS);
1341}
1342
1343inline Time
1345{
1346 return Time::From(value, Time::MS);
1347}
1348
1349inline Time
1350MicroSeconds(uint64_t value)
1351{
1352 return Time::FromInteger(value, Time::US);
1353}
1354
1355inline Time
1357{
1358 return Time::From(value, Time::US);
1359}
1360
1361inline Time
1362NanoSeconds(uint64_t value)
1363{
1364 return Time::FromInteger(value, Time::NS);
1365}
1366
1367inline Time
1369{
1370 return Time::From(value, Time::NS);
1371}
1372
1373inline Time
1374PicoSeconds(uint64_t value)
1375{
1376 return Time::FromInteger(value, Time::PS);
1377}
1378
1379inline Time
1381{
1382 return Time::From(value, Time::PS);
1383}
1384
1385inline Time
1386FemtoSeconds(uint64_t value)
1387{
1388 return Time::FromInteger(value, Time::FS);
1389}
1390
1391inline Time
1393{
1394 return Time::From(value, Time::FS);
1395}
1396 // Construct a Time in the indicated unit.
1398
1407inline Time
1408TimeStep(uint64_t ts)
1409{
1410 return Time(ts);
1411}
1412
1415
1426
1435{
1436 return MakeTimeChecker(Time::Min(), Time::Max());
1437}
1438
1446inline Ptr<const AttributeChecker>
1448{
1449 return MakeTimeChecker(min, Time::Max());
1450}
1451
1457{
1458 public:
1465 TimeWithUnit(const Time time, const Time::Unit unit)
1466 : m_time(time),
1467 m_unit(unit)
1468 {
1469 }
1470
1471 private:
1474
1481 friend std::ostream& operator<<(std::ostream& os, const TimeWithUnit& timeU);
1482
1483}; // class TimeWithUnit
1484
1492
1493} // namespace ns3
1494
1495#endif /* TIME_H */
#define min(a, b)
Definition: 80211b.c:41
#define max(a, b)
Definition: 80211b.c:42
#define Max(a, b)
#define Min(a, b)
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:77
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:1127
int64_t GetNanoSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:418
bool IsPositive() const
Exactly equivalent to t >= 0.
Definition: nstime.h:333
Time(const Time &o)
Copy constructor.
Definition: nstime.h:152
Time(const int64x64_t &v)
Construct from a numeric value.
Definition: nstime.h:248
friend Time & operator-=(Time &lhs, const Time &rhs)
Compound subtraction assignment for Time.
Definition: nstime.h:1186
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:481
~Time()
Destructor.
Definition: nstime.h:303
int64_t GetMilliSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:408
static Resolution & SetDefaultNsResolution()
Set the default resolution.
Definition: time.cc:203
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:415
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:376
static Information * PeekInformation(Unit timeUnit)
Get the Information record for timeUnit for the current Resolution.
Definition: nstime.h:667
int64_t GetFemtoSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:428
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:403
int64x64_t To(Unit unit) const
Get the Time value expressed in a particular unit.
Definition: nstime.h:578
static Unit GetResolution()
Definition: time.cc:408
bool IsStrictlyPositive() const
Exactly equivalent to t > 0.
Definition: nstime.h:351
Time & operator=(const Time &o)
Assignment operator.
Definition: nstime.h:131
Time TimeStep(uint64_t ts)
Scheduler interface.
Definition: nstime.h:1408
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:455
bool IsNegative() const
Exactly equivalent to t <= 0.
Definition: nstime.h:324
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:857
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:398
static Time Min()
Minimum representable Time Not to be confused with Min(Time,Time).
Definition: nstime.h:287
friend Time & operator+=(Time &lhs, const Time &rhs)
Compound addition assignment for Time.
Definition: nstime.h:1173
static void Clear(Time *const time)
Remove a Time instance from the MarkedTimes, called by ~Time().
Definition: time.cc:348
static Time From(const int64x64_t &value, Unit unit)
Create a Time equal to value in unit unit.
Definition: nstime.h:521
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:893
double GetDays() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:388
Time RoundTo(Unit unit) const
Round a Time to a specific unit.
Definition: nstime.h:604
friend bool operator<=(const Time &lhs, const Time &rhs)
Less than or equal operator for Time.
Definition: nstime.h:881
static MarkedTimes * g_markingTimes
Record of outstanding Time objects which will need conversion when the resolution is set.
Definition: nstime.h:722
int64_t m_data
Virtual time value, in the current unit.
Definition: nstime.h:826
friend Time Rem(const Time &lhs, const Time &rhs)
Addition operator for Time.
Definition: nstime.h:1133
static Resolution * PeekResolution()
Get the current Resolution.
Definition: nstime.h:655
friend int64_t Div(const Time &lhs, const Time &rhs)
Integer quotient from dividing two Times.
Definition: nstime.h:1161
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:423
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:383
friend bool operator<(const Time &lhs, const Time &rhs)
Less than operator for Time.
Definition: nstime.h:905
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:869
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:555
static Time FromInteger(uint64_t value, Unit unit)
Create a Time equal to value in unit unit.
Definition: nstime.h:499
bool IsStrictlyNegative() const
Exactly equivalent to t < 0.
Definition: nstime.h:342
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:362
static Time FromDouble(double value, Unit unit)
Create a Time equal to value in unit unit.
Definition: nstime.h:516
double GetDouble() const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:450
friend Time operator-(const Time &lhs, const Time &rhs)
Subtraction operator for Time.
Definition: nstime.h:970
friend Time operator+(const Time &lhs, const Time &rhs)
Addition operator for Time.
Definition: nstime.h:958
static Time Max()
Maximum representable Time Not to be confused with Max(Time,Time).
Definition: nstime.h:297
friend Time operator*(const Time &lhs, const int64x64_t &rhs)
Scale a Time by a numeric value.
Definition: nstime.h:982
double ToDouble(Unit unit) const
Get the Time value expressed in a particular unit.
Definition: nstime.h:573
friend bool operator>(const Time &lhs, const Time &rhs)
Greater than operator for Time.
Definition: nstime.h:917
bool IsZero() const
Exactly equivalent to t == 0.
Definition: nstime.h:315
int64_t GetTimeStep() const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:445
int64_t GetMicroSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:413
friend Time Abs(const Time &time)
Absolute value for Time.
Definition: nstime.h:1198
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:393
friend int64x64_t operator/(const Time &lhs, const Time &rhs)
Exact division, returning a dimensionless fixed point number.
Definition: nstime.h:1066
std::set< Time * > MarkedTimes
Record all instances of Time, so we can rescale them when the resolution changes.
Definition: nstime.h:707
A Time with attached unit, to facilitate output in that unit.
Definition: nstime.h:1457
friend std::ostream & operator<<(std::ostream &os, const TimeWithUnit &timeU)
Output streamer.
Definition: time.cc:428
TimeWithUnit(const Time time, const Time::Unit unit)
Attach a unit to a Time.
Definition: nstime.h:1465
Time m_time
The time.
Definition: nstime.h:1472
Time::Unit m_unit
The unit to use in output.
Definition: nstime.h:1473
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
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Definition: nstime.h:1434
#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
#define TYPENAMEGET_DEFINE(T)
Macro that defines a template specialization for TypeNameGet<T>() .
Definition: type-name.h:60
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 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
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1350
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1362
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
Time Days(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1290
Time Hours(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1302
Time PicoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1374
Time FemtoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1386
Time Minutes(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1314
Time Years(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1278
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1338
Declaration of the ns3::int64x64_t type and associated operators.
Length::Unit Unit
Save some typing by defining a short alias for Length::Unit.
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:1133
bool operator!=(Callback< R, Args... > a, Callback< R, Args... > b)
Inequality test.
Definition: callback.h:678
Time operator%(const Time &lhs, const Time &rhs)
Remainder (modulus) from the quotient of two Times.
Definition: nstime.h:1127
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.h:157
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:159
Time & operator+=(Time &lhs, const Time &rhs)
Compound addition assignment for Time.
Definition: nstime.h:1173
std::istream & operator>>(std::istream &is, Angles &a)
Definition: angles.cc:183
bool operator<(const EventId &a, const EventId &b)
Definition: event-id.h:170
Time & operator-=(Time &lhs, const Time &rhs)
Compound subtraction assignment for Time.
Definition: nstime.h:1186
How to convert between other units and the current unit.
Definition: nstime.h:634
int64_t factor
Ratio of this unit / current unit.
Definition: nstime.h:637
bool toMul
Multiply when converting To, otherwise divide.
Definition: nstime.h:635
int64x64_t timeFrom
Multiplier to convert from this unit.
Definition: nstime.h:639
bool isValid
True if the current unit can be used.
Definition: nstime.h:640
bool fromMul
Multiple when converting From, otherwise divide.
Definition: nstime.h:636
int64x64_t timeTo
Multiplier to convert to this unit.
Definition: nstime.h:638
Current time unit, and conversion info.
Definition: nstime.h:645
Time::Unit unit
Current time unit.
Definition: nstime.h:647
Information info[LAST]
Conversion info from current unit.
Definition: nstime.h:646
ns3::TypeNameGet() function declarations.