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
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 {
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(enum Unit resolution);
472 static enum 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, enum 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, enum Unit unit)
516 {
517 return From(int64x64_t(value), unit);
518 }
519
520 inline static Time From(const int64x64_t& value, enum 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(enum 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(enum Unit unit) const
573 {
574 return To(unit).GetDouble();
575 }
576
577 inline int64x64_t To(enum 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(enum Unit unit) const
604 {
605 return From(this->To(unit).Round(), unit);
606 }
607
621 TimeWithUnit As(const enum 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 struct Resolution* PeekResolution()
655 {
656 static struct Time::Resolution& resolution{SetDefaultNsResolution()};
657 return &resolution;
658 }
659
666 static inline struct Information* PeekInformation(enum Unit timeUnit)
667 {
668 return &(PeekResolution()->info[timeUnit]);
669 }
670
676 static struct Resolution& SetDefaultNsResolution();
684 static void SetResolution(enum Unit unit,
685 struct Resolution* resolution,
686 const bool convert = true);
687
708 typedef std::set<Time*> MarkedTimes;
724
725 public:
731 static bool StaticInit();
732
733 private:
741 friend class Simulator;
750 static void ClearMarkedTimes();
755 static void Mark(Time* const time);
760 static void Clear(Time* const time);
765 static void ConvertTimes(const enum Unit unit);
766
767 // Operator and related functions which need access
768
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& lhs, const Time& rhs);
779 friend bool operator<(const Time& time, const EventId& event); // Comparison operators
781
786 friend Time operator+(const Time& lhs, const Time& rhs);
787 friend Time operator-(const Time& lhs, const Time& rhs);
788 friend Time operator*(const Time& lhs, const int64x64_t& rhs);
789 friend Time operator*(const int64x64_t& lhs, const Time& rhs);
790 friend int64x64_t operator/(const Time& lhs, const Time& rhs);
791 friend Time operator/(const Time& lhs, const int64x64_t& rhs);
792 friend Time operator%(const Time& lhs, const Time& rhs);
793 friend int64_t Div(const Time& lhs, const Time& rhs);
794 friend Time Rem(const Time& lhs, const Time& rhs);
795
796 template <class T>
798 const Time& lhs,
799 T rhs);
800
801 // Reversed arg version (forwards to `rhs * lhs`)
802 // Accepts both integers and decimal types
803 template <class T>
805 T lhs,
806 const Time& rhs);
807
808 template <class T>
810 const Time& lhs,
811 T rhs);
812
813 friend Time Abs(const Time& time);
814 friend Time Max(const Time& timeA, const Time& timeB);
815 friend Time Min(const Time& timeA, const Time& timeB);
816 // Arithmetic operators
818
819 // Leave undocumented
820 template <class T>
822 const Time& lhs,
823 T rhs);
824 template <class T>
826 const Time& lhs,
827 T rhs);
828
833 friend Time& operator+=(Time& lhs, const Time& rhs);
834 friend Time& operator-=(Time& lhs, const Time& rhs); // Compound assignment
836
837 int64_t m_data;
838
839}; // class Time
840
841namespace TracedValueCallback
842{
843
850typedef void (*Time)(Time oldValue, Time newValue);
851
852} // namespace TracedValueCallback
853
859static bool g_TimeStaticInit [[maybe_unused]] = Time::StaticInit();
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
927inline bool
928operator>(const Time& lhs, const Time& rhs)
929{
930 return lhs.m_data > rhs.m_data;
931}
932
950inline bool
951operator<(const Time& time, const EventId& event)
952{
953 // Negative Time is less than any possible EventId, which are all >= 0.
954 if (time.m_data < 0)
955 {
956 return true;
957 }
958 // Time must be >= 0 so casting to unsigned is safe.
959 return static_cast<uint64_t>(time.m_data) < event.GetTs();
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 Time& rhs)
982{
983 return Time(lhs.m_data - rhs.m_data);
984}
985
992inline Time
993operator*(const Time& lhs, const int64x64_t& rhs)
994{
995 int64x64_t res = lhs.m_data;
996 res *= rhs;
997 return Time(res);
998}
999
1006inline Time
1007operator*(const int64x64_t& lhs, const Time& rhs)
1008{
1009 return rhs * lhs;
1010}
1011
1021template <class T>
1023operator*(const Time& lhs, T rhs)
1024{
1025 static_assert(!std::is_same<T, bool>::value,
1026 "Multiplying a Time by a boolean is not supported");
1027
1028 return Time(lhs.m_data * rhs);
1029}
1030
1031// Leave undocumented
1032template <class T>
1034operator*(const Time& lhs, T rhs)
1035{
1036 return lhs * int64x64_t(rhs);
1037}
1038
1052template <class T>
1054operator*(T lhs, const Time& rhs)
1055{
1056 return rhs * lhs;
1057}
1058
1077inline int64x64_t
1078operator/(const Time& lhs, const Time& rhs)
1079{
1080 int64x64_t num = lhs.m_data;
1081 int64x64_t den = rhs.m_data;
1082 return num / den;
1083}
1084
1091inline Time
1092operator/(const Time& lhs, const int64x64_t& rhs)
1093{
1094 int64x64_t res = lhs.m_data;
1095 res /= rhs;
1096 return Time(res);
1097}
1098
1108template <class T>
1110operator/(const Time& lhs, T rhs)
1111{
1112 static_assert(!std::is_same<T, bool>::value, "Dividing a Time by a boolean is not supported");
1113
1114 return Time(lhs.m_data / rhs);
1115}
1116
1117// Leave undocumented
1118template <class T>
1120operator/(const Time& lhs, T rhs)
1121{
1122 return lhs / int64x64_t(rhs);
1123}
1124
1138inline Time
1139operator%(const Time& lhs, const Time& rhs)
1140{
1141 return Time(lhs.m_data % rhs.m_data);
1142}
1143
1144inline Time
1145Rem(const Time& lhs, const Time& rhs)
1146{
1147 return Time(lhs.m_data % rhs.m_data);
1148}
1149
1172inline int64_t
1173Div(const Time& lhs, const Time& rhs)
1174{
1175 return lhs.m_data / rhs.m_data;
1176}
1177
1184inline Time&
1185operator+=(Time& lhs, const Time& rhs)
1186{
1187 lhs.m_data += rhs.m_data;
1188 return lhs;
1189}
1190
1197inline Time&
1198operator-=(Time& lhs, const Time& rhs)
1199{
1200 lhs.m_data -= rhs.m_data;
1201 return lhs;
1202}
1203
1209inline Time
1210Abs(const Time& time)
1211{
1212 return Time((time.m_data < 0) ? -time.m_data : time.m_data);
1213}
1214
1221inline Time
1222Max(const Time& timeA, const Time& timeB)
1223{
1224 return Time((timeA.m_data < timeB.m_data) ? timeB : timeA);
1225}
1226
1233inline Time
1234Min(const Time& timeA, const Time& timeB)
1235{
1236 return Time((timeA.m_data > timeB.m_data) ? timeB : timeA);
1237}
1238
1259std::ostream& operator<<(std::ostream& os, const Time& time);
1269std::istream& operator>>(std::istream& is, Time& time);
1270
1289inline Time
1291{
1293}
1294
1295inline Time
1297{
1298 return Time::From(value, Time::Y);
1299}
1300
1301inline Time
1303{
1305}
1306
1307inline Time
1309{
1310 return Time::From(value, Time::D);
1311}
1312
1313inline Time
1315{
1317}
1318
1319inline Time
1321{
1322 return Time::From(value, Time::H);
1323}
1324
1325inline Time
1327{
1329}
1330
1331inline Time
1333{
1334 return Time::From(value, Time::MIN);
1335}
1336
1337inline Time
1339{
1341}
1342
1343inline Time
1345{
1346 return Time::From(value, Time::S);
1347}
1348
1349inline Time
1351{
1353}
1354
1355inline Time
1357{
1358 return Time::From(value, Time::MS);
1359}
1360
1361inline Time
1363{
1365}
1366
1367inline Time
1369{
1370 return Time::From(value, Time::US);
1371}
1372
1373inline Time
1375{
1377}
1378
1379inline Time
1381{
1382 return Time::From(value, Time::NS);
1383}
1384
1385inline Time
1387{
1389}
1390
1391inline Time
1393{
1394 return Time::From(value, Time::PS);
1395}
1396
1397inline Time
1399{
1401}
1402
1403inline Time
1405{
1406 return Time::From(value, Time::FS);
1407}
1408 // Construct a Time in the indicated unit.
1410
1419inline Time
1420TimeStep(uint64_t ts)
1421{
1422 return Time(ts);
1423}
1424
1427
1438
1447{
1448 return MakeTimeChecker(Time::Min(), Time::Max());
1449}
1450
1458inline Ptr<const AttributeChecker>
1460{
1461 return MakeTimeChecker(min, Time::Max());
1462}
1463
1469{
1470 public:
1477 TimeWithUnit(const Time time, const Time::Unit unit)
1478 : m_time(time),
1479 m_unit(unit)
1480 {
1481 }
1482
1483 private:
1486
1493 friend std::ostream& operator<<(std::ostream& os, const TimeWithUnit& timeU);
1494
1495}; // class TimeWithUnit
1496
1504
1505} // namespace ns3
1506
1507#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:1139
static struct Information * PeekInformation(enum Unit timeUnit)
Get the Information record for timeUnit for the current Resolution.
Definition: nstime.h:666
static enum Unit GetResolution()
Definition: time.cc:410
int64x64_t To(enum Unit unit) const
Get the Time value expressed in a particular unit.
Definition: nstime.h:577
int64_t GetNanoSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:417
static Time From(const int64x64_t &value, enum Unit unit)
Create a Time equal to value in unit unit.
Definition: nstime.h:520
bool IsPositive() const
Exactly equivalent to t >= 0.
Definition: nstime.h:332
double ToDouble(enum Unit unit) const
Get the Time value expressed in a particular unit.
Definition: nstime.h:572
Time RoundTo(enum Unit unit) const
Round a Time to a specific unit.
Definition: nstime.h:603
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:1198
static struct Resolution * PeekResolution()
Get the current Resolution.
Definition: nstime.h:654
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
Time(long long int v)
Construct from a numeric value.
Definition: nstime.h:212
static Time FromInteger(uint64_t value, enum Unit unit)
Create a Time equal to value in unit unit.
Definition: nstime.h:498
int64_t ToInteger(enum Unit unit) const
Get the Time value expressed in a particular unit.
Definition: nstime.h:554
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
bool IsStrictlyPositive() const
Exactly equivalent to t > 0.
Definition: nstime.h:350
Time & operator=(const Time &o)
Assignment operator.
Definition: nstime.h:131
static Time FromDouble(double value, enum Unit unit)
Create a Time equal to value in unit unit.
Definition: nstime.h:515
Time TimeStep(uint64_t ts)
Scheduler interface.
Definition: nstime.h:1420
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:868
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:1185
static void Clear(Time *const time)
Remove a Time instance from the MarkedTimes, called by ~Time().
Definition: time.cc:350
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:904
double GetDays() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:387
friend bool operator<=(const Time &lhs, const Time &rhs)
Less than or equal operator for Time.
Definition: nstime.h:892
static MarkedTimes * g_markingTimes
Record of outstanding Time objects which will need conversion when the resolution is set.
Definition: nstime.h:723
int64_t m_data
Virtual time value, in the current unit.
Definition: nstime.h:837
friend Time Rem(const Time &lhs, const Time &rhs)
Addition operator for Time.
Definition: nstime.h:1145
friend int64_t Div(const Time &lhs, const Time &rhs)
Integer quotient from dividing two Times.
Definition: nstime.h:1173
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
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:916
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:880
Time(Time &&o)
Move constructor.
Definition: nstime.h:166
static void ConvertTimes(const enum Unit unit)
Convert existing Times to the new unit.
Definition: time.cc:378
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 void SetResolution(enum Unit resolution)
Definition: time.cc:213
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:981
friend Time operator+(const Time &lhs, const Time &rhs)
Addition operator for Time.
Definition: nstime.h:969
static Time Max()
Maximum representable Time Not to be confused with Max(Time,Time).
Definition: nstime.h:296
TimeWithUnit As(const enum Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:417
friend Time operator*(const Time &lhs, const int64x64_t &rhs)
Scale a Time by a numeric value.
Definition: nstime.h:993
friend bool operator>(const Time &lhs, const Time &rhs)
Greater than operator for Time.
Definition: nstime.h:928
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:1210
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:1078
std::set< Time * > MarkedTimes
Record all instances of Time, so we can rescale them when the resolution changes.
Definition: nstime.h:708
A Time with attached unit, to facilitate output in that unit.
Definition: nstime.h:1469
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:1477
Time m_time
The time.
Definition: nstime.h:1484
Time::Unit m_unit
The unit to use in output.
Definition: nstime.h:1485
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:420
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:481
TYPENAMEGET_DEFINE(Time)
ns3::TypeNameGet<Time>() specialization.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1362
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1374
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1338
Time Days(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1302
Time Hours(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1314
Time PicoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1386
Time FemtoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1398
Time Minutes(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
Time Years(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1290
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1350
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:850
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:1145
bool operator!=(Callback< R, Args... > a, Callback< R, Args... > b)
Inequality test.
Definition: callback.h:665
Time operator%(const Time &lhs, const Time &rhs)
Remainder (modulus) from the quotient of two Times.
Definition: nstime.h:1139
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:129
Time & operator+=(Time &lhs, const Time &rhs)
Compound addition assignment for Time.
Definition: nstime.h:1185
std::istream & operator>>(std::istream &is, Angles &a)
Definition: angles.cc:153
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
Time & operator-=(Time &lhs, const Time &rhs)
Compound subtraction assignment for Time.
Definition: nstime.h:1198
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
struct Information info[LAST]
Conversion info from current unit.
Definition: nstime.h:645
enum Time::Unit unit
Current time unit.
Definition: nstime.h:646
ns3::TypeNameGet() function declarations.