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
279 explicit Time(const std::string& s);
280
286 static Time Min()
287 {
288 return Time(std::numeric_limits<int64_t>::min());
289 }
290
296 static Time Max()
297 {
298 return Time(std::numeric_limits<int64_t>::max());
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 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 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 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 Information* info = PeekInformation(unit);
580
581 NS_ASSERT_MSG(info->isValid, "Attempted a conversion to an unavailable unit.");
582
583 int64x64_t retval(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:
633 {
634 bool toMul;
635 bool fromMul;
636 int64_t factor;
639 bool isValid;
640 };
641
644 {
647 };
648
654 static inline Resolution* PeekResolution()
655 {
656 static Time::Resolution& resolution{SetDefaultNsResolution()};
657 return &resolution;
658 }
659
666 static inline Information* PeekInformation(Unit timeUnit)
667 {
668 return &(PeekResolution()->info[timeUnit]);
669 }
670
676 static 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>
795 friend std::enable_if_t<std::is_integral_v<T>, Time> operator*(const Time& lhs, T rhs);
796
797 // Reversed arg version (forwards to `rhs * lhs`)
798 // Accepts both integers and decimal types
799 template <class T>
800 friend std::enable_if_t<std::is_arithmetic_v<T>, Time> operator*(T lhs, const Time& rhs);
801
802 template <class T>
803 friend std::enable_if_t<std::is_integral_v<T>, Time> operator/(const Time& lhs, T rhs);
804
805 friend Time Abs(const Time& time);
806 friend Time Max(const Time& timeA, const Time& timeB);
807 friend Time Min(const Time& timeA, const Time& timeB);
808 // Arithmetic operators
810
811 // Leave undocumented
812 template <class T>
813 friend std::enable_if_t<std::is_floating_point_v<T>, Time> operator*(const Time& lhs, T rhs);
814 template <class T>
815 friend std::enable_if_t<std::is_floating_point_v<T>, Time> operator/(const Time& lhs, T rhs);
816
821 friend Time& operator+=(Time& lhs, const Time& rhs);
822 friend Time& operator-=(Time& lhs, const Time& rhs); // Compound assignment
824
825 int64_t m_data;
826
827}; // class Time
828
829namespace TracedValueCallback
830{
831
838typedef void (*Time)(Time oldValue, Time newValue);
839
840} // namespace TracedValueCallback
841
847static bool g_TimeStaticInit [[maybe_unused]] = Time::StaticInit();
848
855inline bool
856operator==(const Time& lhs, const Time& rhs)
857{
858 return lhs.m_data == rhs.m_data;
859}
860
867inline bool
868operator!=(const Time& lhs, const Time& rhs)
869{
870 return lhs.m_data != rhs.m_data;
871}
872
879inline bool
880operator<=(const Time& lhs, const Time& rhs)
881{
882 return lhs.m_data <= rhs.m_data;
883}
884
891inline bool
892operator>=(const Time& lhs, const Time& rhs)
893{
894 return lhs.m_data >= rhs.m_data;
895}
896
903inline bool
904operator<(const Time& lhs, const Time& rhs)
905{
906 return lhs.m_data < rhs.m_data;
907}
908
915inline bool
916operator>(const Time& lhs, const Time& rhs)
917{
918 return lhs.m_data > rhs.m_data;
919}
920
938inline bool
939operator<(const Time& time, const EventId& event)
940{
941 // Negative Time is less than any possible EventId, which are all >= 0.
942 if (time.m_data < 0)
943 {
944 return true;
945 }
946 // Time must be >= 0 so casting to unsigned is safe.
947 return static_cast<uint64_t>(time.m_data) < event.GetTs();
948}
949
956inline Time
957operator+(const Time& lhs, const Time& rhs)
958{
959 return Time(lhs.m_data + rhs.m_data);
960}
961
968inline Time
969operator-(const Time& lhs, const Time& rhs)
970{
971 return Time(lhs.m_data - rhs.m_data);
972}
973
980inline Time
981operator*(const Time& lhs, const int64x64_t& rhs)
982{
983 int64x64_t res = lhs.m_data;
984 res *= rhs;
985 return Time(res);
986}
987
994inline Time
995operator*(const int64x64_t& lhs, const Time& rhs)
996{
997 return rhs * lhs;
998}
999
1009template <class T>
1010std::enable_if_t<std::is_integral_v<T>, Time>
1011operator*(const Time& lhs, T rhs)
1012{
1013 static_assert(!std::is_same_v<T, bool>, "Multiplying a Time by a boolean is not supported");
1014
1015 return Time(lhs.m_data * rhs);
1016}
1017
1018// Leave undocumented
1019template <class T>
1020std::enable_if_t<std::is_floating_point_v<T>, Time>
1021operator*(const Time& lhs, T rhs)
1022{
1023 return lhs * int64x64_t(rhs);
1024}
1025
1039template <class T>
1040std::enable_if_t<std::is_arithmetic_v<T>, Time>
1041operator*(T lhs, const Time& rhs)
1042{
1043 return rhs * lhs;
1044}
1045
1064inline int64x64_t
1065operator/(const Time& lhs, const Time& rhs)
1066{
1067 int64x64_t num = lhs.m_data;
1068 int64x64_t den = rhs.m_data;
1069 return num / den;
1070}
1071
1078inline Time
1079operator/(const Time& lhs, const int64x64_t& rhs)
1080{
1081 int64x64_t res = lhs.m_data;
1082 res /= rhs;
1083 return Time(res);
1084}
1085
1095template <class T>
1096std::enable_if_t<std::is_integral_v<T>, Time>
1097operator/(const Time& lhs, T rhs)
1098{
1099 static_assert(!std::is_same_v<T, bool>, "Dividing a Time by a boolean is not supported");
1100
1101 return Time(lhs.m_data / rhs);
1102}
1103
1104// Leave undocumented
1105template <class T>
1106std::enable_if_t<std::is_floating_point_v<T>, Time>
1107operator/(const Time& lhs, T rhs)
1108{
1109 return lhs / int64x64_t(rhs);
1110}
1111
1125inline Time
1126operator%(const Time& lhs, const Time& rhs)
1127{
1128 return Time(lhs.m_data % rhs.m_data);
1129}
1130
1131inline Time
1132Rem(const Time& lhs, const Time& rhs)
1133{
1134 return Time(lhs.m_data % rhs.m_data);
1135}
1136
1159inline int64_t
1160Div(const Time& lhs, const Time& rhs)
1161{
1162 return lhs.m_data / rhs.m_data;
1163}
1164
1171inline Time&
1172operator+=(Time& lhs, const Time& rhs)
1173{
1174 lhs.m_data += rhs.m_data;
1175 return lhs;
1176}
1177
1184inline Time&
1185operator-=(Time& lhs, const Time& rhs)
1186{
1187 lhs.m_data -= rhs.m_data;
1188 return lhs;
1189}
1190
1196inline Time
1197Abs(const Time& time)
1198{
1199 return Time((time.m_data < 0) ? -time.m_data : time.m_data);
1200}
1201
1208inline Time
1209Max(const Time& timeA, const Time& timeB)
1210{
1211 return Time((timeA.m_data < timeB.m_data) ? timeB : timeA);
1212}
1213
1220inline Time
1221Min(const Time& timeA, const Time& timeB)
1222{
1223 return Time((timeA.m_data > timeB.m_data) ? timeB : timeA);
1224}
1225
1246std::ostream& operator<<(std::ostream& os, const Time& time);
1256std::istream& operator>>(std::istream& is, Time& time);
1257
1276inline Time
1277Years(double value)
1278{
1279 return Time::FromDouble(value, Time::Y);
1280}
1281
1282inline Time
1284{
1285 return Time::From(value, Time::Y);
1286}
1287
1288inline Time
1289Days(double value)
1290{
1291 return Time::FromDouble(value, Time::D);
1292}
1293
1294inline Time
1296{
1297 return Time::From(value, Time::D);
1298}
1299
1300inline Time
1301Hours(double value)
1302{
1303 return Time::FromDouble(value, Time::H);
1304}
1305
1306inline Time
1308{
1309 return Time::From(value, Time::H);
1310}
1311
1312inline Time
1313Minutes(double value)
1314{
1315 return Time::FromDouble(value, Time::MIN);
1316}
1317
1318inline Time
1320{
1321 return Time::From(value, Time::MIN);
1322}
1323
1324inline Time
1325Seconds(double value)
1326{
1327 return Time::FromDouble(value, Time::S);
1328}
1329
1330inline Time
1332{
1333 return Time::From(value, Time::S);
1334}
1335
1336inline Time
1337MilliSeconds(uint64_t value)
1338{
1339 return Time::FromInteger(value, Time::MS);
1340}
1341
1342inline Time
1344{
1345 return Time::From(value, Time::MS);
1346}
1347
1348inline Time
1349MicroSeconds(uint64_t value)
1350{
1351 return Time::FromInteger(value, Time::US);
1352}
1353
1354inline Time
1356{
1357 return Time::From(value, Time::US);
1358}
1359
1360inline Time
1361NanoSeconds(uint64_t value)
1362{
1363 return Time::FromInteger(value, Time::NS);
1364}
1365
1366inline Time
1368{
1369 return Time::From(value, Time::NS);
1370}
1371
1372inline Time
1373PicoSeconds(uint64_t value)
1374{
1375 return Time::FromInteger(value, Time::PS);
1376}
1377
1378inline Time
1380{
1381 return Time::From(value, Time::PS);
1382}
1383
1384inline Time
1385FemtoSeconds(uint64_t value)
1386{
1387 return Time::FromInteger(value, Time::FS);
1388}
1389
1390inline Time
1392{
1393 return Time::From(value, Time::FS);
1394}
1395 // Construct a Time in the indicated unit.
1397
1406inline Time
1407TimeStep(uint64_t ts)
1408{
1409 return Time(ts);
1410}
1411
1414
1425
1434{
1435 return MakeTimeChecker(Time::Min(), Time::Max());
1436}
1437
1445inline Ptr<const AttributeChecker>
1447{
1448 return MakeTimeChecker(min, Time::Max());
1449}
1450
1456{
1457 public:
1464 TimeWithUnit(const Time time, const Time::Unit unit)
1465 : m_time(time),
1466 m_unit(unit)
1467 {
1468 }
1469
1470 private:
1473
1480 friend std::ostream& operator<<(std::ostream& os, const TimeWithUnit& timeU);
1481
1482}; // class TimeWithUnit
1483
1491
1492} // namespace ns3
1493
1494#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: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:1126
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
friend Time & operator-=(Time &lhs, const Time &rhs)
Compound subtraction assignment for Time.
Definition: nstime.h:1185
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
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:666
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
static Unit GetResolution()
Definition: time.cc:408
bool IsStrictlyPositive() const
Exactly equivalent to t > 0.
Definition: nstime.h:350
Time & operator=(const Time &o)
Assignment operator.
Definition: nstime.h:131
Time TimeStep(uint64_t ts)
Scheduler interface.
Definition: nstime.h:1407
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:856
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
friend Time & operator+=(Time &lhs, const Time &rhs)
Compound addition assignment for Time.
Definition: nstime.h:1172
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: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:892
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:880
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:825
friend Time Rem(const Time &lhs, const Time &rhs)
Addition operator for Time.
Definition: nstime.h:1132
static Resolution * PeekResolution()
Get the current Resolution.
Definition: nstime.h:654
friend int64_t Div(const Time &lhs, const Time &rhs)
Integer quotient from dividing two Times.
Definition: nstime.h:1160
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:904
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:868
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
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:969
friend Time operator+(const Time &lhs, const Time &rhs)
Addition operator for Time.
Definition: nstime.h:957
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:981
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:916
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:1197
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 int64x64_t operator/(const Time &lhs, const Time &rhs)
Exact division, returning a dimensionless fixed point number.
Definition: nstime.h:1065
std::set< Time * > MarkedTimes
Record all instances of Time, so we can rescale them when the resolution changes.
Definition: nstime.h:706
A Time with attached unit, to facilitate output in that unit.
Definition: nstime.h:1456
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:1464
Time m_time
The time.
Definition: nstime.h:1471
Time::Unit m_unit
The unit to use in output.
Definition: nstime.h:1472
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:1433
#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:1349
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1361
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1325
Time Days(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
Time Hours(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1301
Time PicoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1373
Time FemtoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1385
Time Minutes(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1313
Time Years(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1277
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1337
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:1132
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:1126
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:1172
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:1185
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.