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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 */
8#ifndef TIME_H
9#define TIME_H
10
11#include "assert.h"
12#include "attribute-helper.h"
13#include "attribute.h"
14#include "event-id.h"
15#include "int64x64.h"
16#include "type-name.h"
17
18#include <cmath>
19#include <limits>
20#include <ostream>
21#include <set>
22#include <stdint.h>
23
24/**
25 * @file
26 * @ingroup time
27 * Declaration of classes ns3::Time and ns3::TimeWithUnit,
28 * and the TimeValue implementation classes.
29 */
30
31namespace ns3
32{
33
34class TimeWithUnit;
35
36/**
37 * @ingroup core
38 * @defgroup time Virtual Time
39 * Management of virtual time in real world units.
40 *
41 * The underlying simulator is unit agnostic, just dealing with
42 * dimensionless virtual time. Models usually need to handle
43 * time in real world units, such as seconds, and conversions/scaling
44 * between different units, between minutes and seconds, for example.
45 *
46 * The convenience constructors in the \ref timecivil "Standard Units" module
47 * make it easy to create Times in specific units.
48 *
49 * The Time::SetResolution() function allows a one-time change of the
50 * base resolution, before Simulator::Run().
51 */
52/**
53 * @ingroup time
54 * Simulation virtual time values and global simulation resolution.
55 *
56 * This class defines all the classic C++ addition/subtraction
57 * operators: +, -, +=, -=; and all the classic comparison operators:
58 * ==, !=, <, >, <=, >=. It is thus easy to add, subtract, or
59 * compare Time objects.
60 *
61 * For example:
62 * @code
63 * Time t1 = Seconds (10.0);
64 * Time t2 = Seconds (10.0);
65 * Time t3 = t1;
66 * t3 += t2;
67 * @endcode
68 *
69 * You can also use the following non-member functions to manipulate
70 * any of these ns3::Time object:
71 * - Abs(Time)
72 * - Max(Time,Time)
73 * - Min(Time,Time)
74 *
75 * This class also controls the resolution of the underlying time representation.
76 * The resolution is the smallest representable time interval.
77 * The default resolution is nanoseconds.
78 *
79 * To change the resolution, use SetResolution(). All Time objects created
80 * before the call to SetResolution() will be updated to the new resolution.
81 * This can only be done once! (Tracking each Time object uses 4 pointers.
82 * For speed, once we convert the existing instances we discard the recording
83 * data structure and stop tracking new instances, so we have no way
84 * to do a second conversion.)
85 *
86 * If you increase the global resolution, you also implicitly decrease
87 * the maximum simulation duration. The global simulation time is stored
88 * in a 64 bit integer whose interpretation will depend on the global
89 * resolution. Therefore the maximum possible duration of your simulation
90 * if you use picoseconds is 2^64 ps = 2^24 s = 7 months, whereas,
91 * had you used nanoseconds, you could have run for 584 years.
92 */
93class Time
94{
95 public:
96 /**
97 * The unit to use to interpret a number representing time
98 */
99 enum Unit
100 {
101 Y = 0, //!< year, 365 days
102 D = 1, //!< day, 24 hours
103 H = 2, //!< hour, 60 minutes
104 MIN = 3, //!< minute, 60 seconds
105 S = 4, //!< second
106 MS = 5, //!< millisecond
107 US = 6, //!< microsecond
108 NS = 7, //!< nanosecond
109 PS = 8, //!< picosecond
110 FS = 9, //!< femtosecond
111 LAST = 10, //!< marker for last normal value
112 AUTO = 11 //!< auto-scale output when using Time::As()
113 };
114
115 /**
116 * Assignment operator
117 * @param [in] o Time to assign.
118 * @return The Time.
119 */
120 inline Time& operator=(const Time& o)
121 {
122 m_data = o.m_data;
123 return *this;
124 }
125
126 /** Default constructor, with value 0. */
127 inline Time()
128 : m_data()
129 {
130 if (g_markingTimes)
131 {
132 Mark(this);
133 }
134 }
135
136 /**
137 * Copy constructor
138 *
139 * @param [in] o Time to copy
140 */
141 inline Time(const Time& o)
142 : m_data(o.m_data)
143 {
144 if (g_markingTimes)
145 {
146 Mark(this);
147 }
148 }
149
150 /**
151 * Move constructor
152 *
153 * @param [in] o Time from which take the data
154 */
156 : m_data(o.m_data)
157 {
158 if (g_markingTimes)
159 {
160 Mark(this);
161 }
162 }
163
164 /**
165 * @name Numeric constructors
166 * Construct from a numeric value.
167 * @{
168 */
169 /**
170 * Construct from a numeric value.
171 * The current time resolution will be assumed as the unit.
172 * @param [in] v The value.
173 */
174 explicit inline Time(double v)
175 : m_data(llround(v))
176 {
177 if (g_markingTimes)
178 {
179 Mark(this);
180 }
181 }
182
183 explicit inline Time(int v)
184 : m_data(v)
185 {
186 if (g_markingTimes)
187 {
188 Mark(this);
189 }
190 }
191
192 explicit inline Time(long int v)
193 : m_data(v)
194 {
195 if (g_markingTimes)
196 {
197 Mark(this);
198 }
199 }
200
201 explicit inline Time(long long int v)
202 : m_data(v)
203 {
204 if (g_markingTimes)
205 {
206 Mark(this);
207 }
208 }
209
210 explicit inline Time(unsigned int v)
211 : m_data(v)
212 {
213 if (g_markingTimes)
214 {
215 Mark(this);
216 }
217 }
218
219 explicit inline Time(unsigned long int v)
220 : m_data(v)
221 {
222 if (g_markingTimes)
223 {
224 Mark(this);
225 }
226 }
227
228 explicit inline Time(unsigned long long int v)
229 : m_data(v)
230 {
231 if (g_markingTimes)
232 {
233 Mark(this);
234 }
235 }
236
237 explicit inline Time(const int64x64_t& v)
238 : m_data(v.Round())
239 {
240 if (g_markingTimes)
241 {
242 Mark(this);
243 }
244 }
245
246 /**@}*/ // Numeric constructors
247
248 /**
249 * Construct Time object from common time expressions like "1ms"
250 *
251 * Supported units include:
252 * - `s` (seconds)
253 * - `ms` (milliseconds)
254 * - `us` (microseconds)
255 * - `ns` (nanoseconds)
256 * - `ps` (picoseconds)
257 * - `fs` (femtoseconds)
258 * - `min` (minutes)
259 * - `h` (hours)
260 * - `d` (days)
261 * - `y` (years)
262 *
263 * There must be no whitespace between the numerical portion
264 * and the unit. If the string only contains a number, it is treated as seconds.
265 * Any otherwise malformed string causes a fatal error to occur.
266 *
267 * @param [in] s The string to parse into a Time
268 */
269 explicit Time(const std::string& s);
270
271 /**
272 * Minimum representable Time
273 * Not to be confused with Min(Time,Time).
274 * @returns the minimum representable Time.
275 */
276 static Time Min()
277 {
278 return Time(std::numeric_limits<int64_t>::min());
279 }
280
281 /**
282 * Maximum representable Time
283 * Not to be confused with Max(Time,Time).
284 * @returns the maximum representable Time.
285 */
286 static Time Max()
287 {
288 return Time(std::numeric_limits<int64_t>::max());
289 }
290
291 /** Destructor */
293 {
294 if (g_markingTimes)
295 {
296 Clear(this);
297 }
298 }
299
300 /**
301 * Exactly equivalent to `t == 0`.
302 * @return \c true if the time is zero, \c false otherwise.
303 */
304 inline bool IsZero() const
305 {
306 return m_data == 0;
307 }
308
309 /**
310 * Exactly equivalent to `t <= 0`.
311 * @return \c true if the time is negative or zero, \c false otherwise.
312 */
313 inline bool IsNegative() const
314 {
315 return m_data <= 0;
316 }
317
318 /**
319 * Exactly equivalent to `t >= 0`.
320 * @return \c true if the time is positive or zero, \c false otherwise.
321 */
322 inline bool IsPositive() const
323 {
324 return m_data >= 0;
325 }
326
327 /**
328 * Exactly equivalent to `t < 0`.
329 * @return \c true if the time is strictly negative, \c false otherwise.
330 */
331 inline bool IsStrictlyNegative() const
332 {
333 return m_data < 0;
334 }
335
336 /**
337 * Exactly equivalent to `t > 0`.
338 * @return \c true if the time is strictly positive, \c false otherwise.
339 */
340 inline bool IsStrictlyPositive() const
341 {
342 return m_data > 0;
343 }
344
345 /**
346 * Compare \pname{this} to another Time
347 *
348 * @param [in] o The other Time
349 * @return -1,0,+1 if `this < o`, `this == o`, or `this > o`
350 */
351 inline int Compare(const Time& o) const
352 {
353 return (m_data < o.m_data) ? -1 : (m_data == o.m_data) ? 0 : 1;
354 }
355
356 /**
357 * @name Convert to Number in a Unit
358 * Convert a Time to number, in indicated units.
359 *
360 * Conversions to seconds and larger will return doubles, with
361 * possible loss of precision. Conversions to units smaller than
362 * seconds will be rounded.
363 *
364 * @{
365 */
366 /**
367 * Get an approximation of the time stored in this instance
368 * in the indicated unit.
369 *
370 * @return An approximate value in the indicated unit.
371 */
372 inline double GetYears() const
373 {
374 return ToDouble(Time::Y);
375 }
376
377 inline double GetDays() const
378 {
379 return ToDouble(Time::D);
380 }
381
382 inline double GetHours() const
383 {
384 return ToDouble(Time::H);
385 }
386
387 inline double GetMinutes() const
388 {
389 return ToDouble(Time::MIN);
390 }
391
392 inline double GetSeconds() const
393 {
394 return ToDouble(Time::S);
395 }
396
397 inline int64_t GetMilliSeconds() const
398 {
399 return ToInteger(Time::MS);
400 }
401
402 inline int64_t GetMicroSeconds() const
403 {
404 return ToInteger(Time::US);
405 }
406
407 inline int64_t GetNanoSeconds() const
408 {
409 return ToInteger(Time::NS);
410 }
411
412 inline int64_t GetPicoSeconds() const
413 {
414 return ToInteger(Time::PS);
415 }
416
417 inline int64_t GetFemtoSeconds() const
418 {
419 return ToInteger(Time::FS);
420 }
421
422 /**@}*/ // Convert to Number in a Unit.
423
424 /**
425 * @name Convert to Raw Value
426 * Convert a Time to a number in the current resolution units.
427 *
428 * @{
429 */
430 /**
431 * Get the raw time value, in the current resolution unit.
432 * @returns The raw time value
433 */
434 inline int64_t GetTimeStep() const
435 {
436 return m_data;
437 }
438
439 inline double GetDouble() const
440 {
441 return static_cast<double>(m_data);
442 }
443
444 inline int64_t GetInteger() const
445 {
446 return GetTimeStep();
447 }
448
449 /**@}*/ // Convert to Raw Value
450
451 /**
452 * @param [in] resolution The new resolution to use
453 *
454 * Change the global resolution used to convert all
455 * user-provided time values in Time objects and Time objects
456 * in user-expected time units.
457 */
458 static void SetResolution(Unit resolution);
459 /**
460 * @returns The current global resolution.
461 */
462 static Unit GetResolution();
463
464 /**
465 * Create a Time in the current unit.
466 *
467 * @param [in] value The value of the new Time.
468 * @return A Time with \pname{value} in the current time unit.
469 */
470 inline static Time From(const int64x64_t& value)
471 {
472 return Time(value);
473 }
474
475 /**
476 * @name Create Times from Values and Units
477 * Create Times from values given in the indicated units.
478 *
479 * @{
480 */
481 /**
482 * Create a Time equal to \pname{value} in unit \c unit
483 *
484 * @param [in] value The new Time value, expressed in \c unit
485 * @param [in] unit The unit of \pname{value}
486 * @return The Time representing \pname{value} in \c unit
487 */
488 inline static Time FromInteger(uint64_t value, Unit unit)
489 {
490 // Optimization: if value is 0, don't process the unit
491 if (value == 0)
492 {
493 return Time();
494 }
495
496 Information* info = PeekInformation(unit);
497
498 NS_ASSERT_MSG(info->isValid, "Attempted a conversion from an unavailable unit.");
499
500 if (info->fromMul)
501 {
502 value *= info->factor;
503 }
504 else
505 {
506 value /= info->factor;
507 }
508 return Time(value);
509 }
510
511 inline static Time FromDouble(double value, Unit unit)
512 {
513 // Optimization: if value is 0, don't process the unit nor cast to int64x64_t
514 if (value == 0)
515 {
516 return Time();
517 }
518
519 return From(int64x64_t(value), unit);
520 }
521
522 inline static Time From(const int64x64_t& value, Unit unit)
523 {
524 // Optimization: if value is 0, don't process the unit
525 if (value == 0)
526 {
527 return Time();
528 }
529
530 Information* info = PeekInformation(unit);
531
532 NS_ASSERT_MSG(info->isValid, "Attempted a conversion from an unavailable unit.");
533
534 // DO NOT REMOVE this temporary variable. It's here
535 // to work around a compiler bug in gcc 3.4
536 int64x64_t retval = value;
537 if (info->fromMul)
538 {
539 retval *= info->timeFrom;
540 }
541 else
542 {
543 retval.MulByInvert(info->timeFrom);
544 }
545 return Time(retval);
546 }
547
548 /**@}*/ // Create Times from Values and Units
549
550 /**
551 * @name Get Times as Numbers in Specified Units
552 * Get the Time as integers or doubles in the indicated unit.
553 *
554 * @{
555 */
556 /**
557 * Get the Time value expressed in a particular unit.
558 *
559 * @param [in] unit The desired unit
560 * @return The Time expressed in \pname{unit}
561 */
562 inline int64_t ToInteger(Unit unit) const
563 {
564 // Optimization: if value is 0, don't process the unit
565 if (m_data == 0)
566 {
567 return 0;
568 }
569
570 Information* info = PeekInformation(unit);
571
572 NS_ASSERT_MSG(info->isValid, "Attempted a conversion to an unavailable unit.");
573
574 int64_t v = m_data;
575 if (info->toMul)
576 {
577 v *= info->factor;
578 }
579 else
580 {
581 v /= info->factor;
582 }
583 return v;
584 }
585
586 inline double ToDouble(Unit unit) const
587 {
588 // Optimization: if value is 0, don't process the unit nor cast from int64x64_t
589 if (m_data == 0)
590 {
591 return 0;
592 }
593
594 return To(unit).GetDouble();
595 }
596
597 inline int64x64_t To(Unit unit) const
598 {
599 // Optimization: if value is 0, don't process the unit
600 if (m_data == 0)
601 {
602 return 0;
603 }
604
605 Information* info = PeekInformation(unit);
606
607 NS_ASSERT_MSG(info->isValid, "Attempted a conversion to an unavailable unit.");
608
609 int64x64_t retval(m_data);
610 if (info->toMul)
611 {
612 retval *= info->timeTo;
613 }
614 else
615 {
616 retval.MulByInvert(info->timeTo);
617 }
618 return retval;
619 }
620
621 /**@}*/ // Get Times as Numbers in Specified Units
622
623 /**
624 * Round a Time to a specific unit.
625 * Rounding is to nearest integer.
626 * @param [in] unit The unit to round to.
627 * @return The Time rounded to the specific unit.
628 */
629 Time RoundTo(Unit unit) const
630 {
631 return From(this->To(unit).Round(), unit);
632 }
633
634 /**
635 * Attach a unit to a Time, to facilitate output in a specific unit.
636 *
637 * For example,
638 * @code
639 * Time t (3.14e9); // Pi seconds
640 * std::cout << t.As (Time::MS) << std::endl;
641 * @endcode
642 * will print ``+3140.0ms``
643 *
644 * @param [in] unit The unit to use.
645 * @return The Time with embedded unit.
646 */
647 TimeWithUnit As(const Unit unit = Time::AUTO) const;
648
649 /**
650 * TracedCallback signature for Time
651 *
652 * @param [in] value Current value of Time
653 */
654 typedef void (*TracedCallback)(Time value);
655
656 private:
657 /** How to convert between other units and the current unit. */
659 {
660 bool toMul; //!< Multiply when converting To, otherwise divide
661 bool fromMul; //!< Multiple when converting From, otherwise divide
662 int64_t factor; //!< Ratio of this unit / current unit
663 int64x64_t timeTo; //!< Multiplier to convert to this unit
664 int64x64_t timeFrom; //!< Multiplier to convert from this unit
665 bool isValid; //!< True if the current unit can be used
666 };
667
668 /** Current time unit, and conversion info. */
670 {
671 Information info[LAST]; //!< Conversion info from current unit
672 Time::Unit unit; //!< Current time unit
673 };
674
675 /**
676 * Get the current Resolution
677 *
678 * @return A pointer to the current Resolution
679 */
680 static inline Resolution* PeekResolution()
681 {
682 static Time::Resolution& resolution{SetDefaultNsResolution()};
683 return &resolution;
684 }
685
686 /**
687 * Get the Information record for \pname{timeUnit} for the current Resolution
688 *
689 * @param [in] timeUnit The Unit to get Information for
690 * @return The Information for \pname{timeUnit}
691 */
692 static inline Information* PeekInformation(Unit timeUnit)
693 {
694 return &(PeekResolution()->info[timeUnit]);
695 }
696
697 /**
698 * Set the default resolution
699 *
700 * @return The Resolution object for the default resolution.
701 */
702 static Resolution& SetDefaultNsResolution();
703 /**
704 * Set the current Resolution.
705 *
706 * @param [in] unit The unit to use as the new resolution.
707 * @param [in,out] resolution The Resolution record to update.
708 * @param [in] convert Whether to convert existing Time objects to the new resolution.
709 */
710 static void SetResolution(Unit unit, Resolution* resolution, const bool convert = true);
711
712 /**
713 * Record all instances of Time, so we can rescale them when
714 * the resolution changes.
715 *
716 * @internal
717 *
718 * We use a std::set so we can remove the record easily when
719 * ~Time() is called.
720 *
721 * We don't use Ptr<Time>, because we would have to bloat every Time
722 * instance with SimpleRefCount<Time>.
723 *
724 * Seems like this should be std::set< Time * const >, but
725 * [Stack
726 * Overflow](http://stackoverflow.com/questions/5526019/compile-errors-stdset-with-const-members)
727 * says otherwise, quoting the standard:
728 *
729 * > & sect;23.1/3 states that std::set key types must be assignable
730 * > and copy constructable; clearly a const type will not be assignable.
731 */
732 typedef std::set<Time*> MarkedTimes;
733 /**
734 * Record of outstanding Time objects which will need conversion
735 * when the resolution is set.
736 *
737 * @internal
738 *
739 * Use a classic static variable so we can check in Time ctors
740 * without a function call.
741 *
742 * We'd really like to initialize this here, but we don't want to require
743 * C++0x, so we init in time.cc. To ensure that happens before first use,
744 * we add a call to StaticInit (below) to every compilation unit which
745 * includes nstime.h.
746 */
748
749 public:
750 /**
751 * Function to force static initialization of Time.
752 *
753 * @return \c true on the first call
754 */
755 static bool StaticInit();
756
757 private:
758 /**
759 * @cond HIDE_FROM_DOXYGEN
760 * Doxygen bug throws a warning here, so hide from Doxygen.
761 *
762 * Friend the Simulator class so it can call the private function
763 * ClearMarkedTimes ()
764 */
765 friend class Simulator;
766 /** @endcond */
767
768 /**
769 * Remove all MarkedTimes.
770 *
771 * @internal
772 * Has to be visible to the Simulator class, hence the friending.
773 */
774 static void ClearMarkedTimes();
775 /**
776 * Record a Time instance with the MarkedTimes.
777 * @param [in] time The Time instance to record.
778 */
779 static void Mark(Time* const time);
780 /**
781 * Remove a Time instance from the MarkedTimes, called by ~Time().
782 * @param [in] time The Time instance to remove.
783 */
784 static void Clear(Time* const time);
785 /**
786 * Convert existing Times to the new unit.
787 * @param [in] unit The Unit to convert existing Times to.
788 */
789 static void ConvertTimes(const Unit unit);
790
791 // Operator and related functions which need access
792
793 /**
794 * @name Comparison operators
795 * @{
796 */
797 friend bool operator==(const Time& lhs, const Time& rhs);
798 friend bool operator!=(const Time& lhs, const Time& rhs);
799 friend bool operator<=(const Time& lhs, const Time& rhs);
800 friend bool operator>=(const Time& lhs, const Time& rhs);
801 friend bool operator<(const Time& lhs, const Time& rhs);
802 friend bool operator>(const Time& lhs, const Time& rhs);
803 friend bool operator<(const Time& time, const EventId& event);
804 /**@}*/ // Comparison operators
805
806 /**
807 * @name Arithmetic operators
808 * @{
809 */
810 friend Time operator+(const Time& lhs, const Time& rhs);
811 friend Time operator-(const Time& lhs, const Time& rhs);
812 friend Time operator*(const Time& lhs, const int64x64_t& rhs);
813 friend Time operator*(const int64x64_t& lhs, const Time& rhs);
814 friend int64x64_t operator/(const Time& lhs, const Time& rhs);
815 friend Time operator/(const Time& lhs, const int64x64_t& rhs);
816 friend Time operator%(const Time& lhs, const Time& rhs);
817 friend int64_t Div(const Time& lhs, const Time& rhs);
818 friend Time Rem(const Time& lhs, const Time& rhs);
819
820 template <class T>
821 friend std::enable_if_t<std::is_integral_v<T>, Time> operator*(const Time& lhs, T rhs);
822
823 // Reversed arg version (forwards to `rhs * lhs`)
824 // Accepts both integers and decimal types
825 template <class T>
826 friend std::enable_if_t<std::is_arithmetic_v<T>, Time> operator*(T lhs, const Time& rhs);
827
828 template <class T>
829 friend std::enable_if_t<std::is_integral_v<T>, Time> operator/(const Time& lhs, T rhs);
830
831 friend Time Abs(const Time& time);
832 friend Time Max(const Time& timeA, const Time& timeB);
833 friend Time Min(const Time& timeA, const Time& timeB);
834
835 /**@}*/ // Arithmetic operators
836
837 // Leave undocumented
838 template <class T>
839 friend std::enable_if_t<std::is_floating_point_v<T>, Time> operator*(const Time& lhs, T rhs);
840 template <class T>
841 friend std::enable_if_t<std::is_floating_point_v<T>, Time> operator/(const Time& lhs, T rhs);
842
843 /**
844 * @name Compound assignment operators
845 * @{
846 */
847 friend Time& operator+=(Time& lhs, const Time& rhs);
848 friend Time& operator-=(Time& lhs, const Time& rhs);
849 /**@}*/ // Compound assignment
850
851 int64_t m_data; //!< Virtual time value, in the current unit.
852
853}; // class Time
854
855namespace TracedValueCallback
856{
857
858/**
859 * TracedValue callback signature for Time
860 *
861 * @param [in] oldValue Original value of the traced variable
862 * @param [in] newValue New value of the traced variable
863 */
864typedef void (*Time)(Time oldValue, Time newValue);
865
866} // namespace TracedValueCallback
867
868/**
869 * Equality operator for Time.
870 * @param [in] lhs The first value
871 * @param [in] rhs The second value
872 * @returns \c true if the two input values are equal.
873 */
874inline bool
875operator==(const Time& lhs, const Time& rhs)
876{
877 return lhs.m_data == rhs.m_data;
878}
879
880/**
881 * Inequality operator for Time.
882 * @param [in] lhs The first value
883 * @param [in] rhs The second value
884 * @returns \c true if the two input values not are equal.
885 */
886inline bool
887operator!=(const Time& lhs, const Time& rhs)
888{
889 return lhs.m_data != rhs.m_data;
890}
891
892/**
893 * Less than or equal operator for Time.
894 * @param [in] lhs The first value
895 * @param [in] rhs The second value
896 * @returns \c true if the first input value is less than or equal to the second input value.
897 */
898inline bool
899operator<=(const Time& lhs, const Time& rhs)
900{
901 return lhs.m_data <= rhs.m_data;
902}
903
904/**
905 * Greater than or equal operator for Time.
906 * @param [in] lhs The first value
907 * @param [in] rhs The second value
908 * @returns \c true if the first input value is greater than or equal to the second input value.
909 */
910inline bool
911operator>=(const Time& lhs, const Time& rhs)
912{
913 return lhs.m_data >= rhs.m_data;
914}
915
916/**
917 * Less than operator for Time.
918 * @param [in] lhs The first value
919 * @param [in] rhs The second value
920 * @returns \c true if the first input value is less than the second input value.
921 */
922inline bool
923operator<(const Time& lhs, const Time& rhs)
924{
925 return lhs.m_data < rhs.m_data;
926}
927
928/**
929 * Greater than operator for Time.
930 * @param [in] lhs The first value
931 * @param [in] rhs The second value
932 * @returns \c true if the first input value is greater than the second input value.
933 */
934inline bool
935operator>(const Time& lhs, const Time& rhs)
936{
937 return lhs.m_data > rhs.m_data;
938}
939
940/**
941 * Compare a Time to an EventId.
942 *
943 * This is useful when you have cached a previously scheduled event:
944 *
945 * m_event = Schedule (...);
946 *
947 * and later you want to know the relationship between that event
948 * and some other Time `when`:
949 *
950 * if (when < m_event) ...
951 *
952 * @param [in] time The Time operand.
953 * @param [in] event The EventId
954 * @returns \c true if \p time is before (less than) the
955 * time stamp of the EventId.
956 */
957inline bool
958operator<(const Time& time, const EventId& event)
959{
960 // Negative Time is less than any possible EventId, which are all >= 0.
961 if (time.m_data < 0)
962 {
963 return true;
964 }
965 // Time must be >= 0 so casting to unsigned is safe.
966 return static_cast<uint64_t>(time.m_data) < event.GetTs();
967}
968
969/**
970 * Addition operator for Time.
971 * @param [in] lhs The first value
972 * @param [in] rhs The second value
973 * @returns The sum of the two input values.
974 */
975inline Time
976operator+(const Time& lhs, const Time& rhs)
977{
978 return Time(lhs.m_data + rhs.m_data);
979}
980
981/**
982 * Subtraction operator for Time.
983 * @param [in] lhs The first value
984 * @param [in] rhs The second value
985 * @returns The difference of the two input values.
986 */
987inline Time
988operator-(const Time& lhs, const Time& rhs)
989{
990 return Time(lhs.m_data - rhs.m_data);
991}
992
993/**
994 * Scale a Time by a numeric value.
995 * @param [in] lhs The first value
996 * @param [in] rhs The second value
997 * @returns The Time scaled by the other operand.
998 */
999inline Time
1000operator*(const Time& lhs, const int64x64_t& rhs)
1001{
1002 int64x64_t res = lhs.m_data;
1003 res *= rhs;
1004 return Time(res);
1005}
1006
1007/**
1008 * Scale a Time by a numeric value.
1009 * @param [in] lhs The first value
1010 * @param [in] rhs The second value
1011 * @returns The Time scaled by the other operand.
1012 */
1013inline Time
1014operator*(const int64x64_t& lhs, const Time& rhs)
1015{
1016 return rhs * lhs;
1017}
1018
1019/**
1020 * Scale a Time by an integer value.
1021 *
1022 * @tparam T Integer data type (int, long, etc.)
1023 *
1024 * @param [in] lhs The Time instance to scale
1025 * @param [in] rhs The scale value
1026 * @returns A new Time instance containing the scaled value
1027 */
1028template <class T>
1029std::enable_if_t<std::is_integral_v<T>, Time>
1030operator*(const Time& lhs, T rhs)
1031{
1032 static_assert(!std::is_same_v<T, bool>, "Multiplying a Time by a boolean is not supported");
1033
1034 return Time(lhs.m_data * rhs);
1035}
1036
1037// Leave undocumented
1038template <class T>
1039std::enable_if_t<std::is_floating_point_v<T>, Time>
1040operator*(const Time& lhs, T rhs)
1041{
1042 return lhs * int64x64_t(rhs);
1043}
1044
1045/**
1046 * Scale a Time by a numeric value.
1047 *
1048 * This overload handles the case where the scale value comes before the Time
1049 * value. It swaps the arguments so that the Time argument comes first
1050 * and calls the appropriate overload of operator*
1051 *
1052 * @tparam T Arithmetic data type (int, long, float, etc.)
1053 *
1054 * @param [in] lhs The scale value
1055 * @param [in] rhs The Time instance to scale
1056 * @returns A new Time instance containing the scaled value
1057 */
1058template <class T>
1059std::enable_if_t<std::is_arithmetic_v<T>, Time>
1060operator*(T lhs, const Time& rhs)
1061{
1062 return rhs * lhs;
1063}
1064
1065/**
1066 * Exact division, returning a dimensionless fixed point number.
1067 *
1068 * This can be truncated to integer, or converted to double
1069 * (with loss of precision). Assuming `ta` and `tb` are Times:
1070 *
1071 * @code
1072 * int64x64_t ratio = ta / tb;
1073 *
1074 * int64_t i = ratio.GetHigh (); // Get just the integer part, resulting in truncation
1075 *
1076 * double ratioD = double (ratio); // Convert to double, with loss of precision
1077 * @endcode
1078 *
1079 * @param [in] lhs The first value
1080 * @param [in] rhs The second value
1081 * @returns The exact ratio of the two operands.
1082 */
1083inline int64x64_t
1084operator/(const Time& lhs, const Time& rhs)
1085{
1086 int64x64_t num = lhs.m_data;
1087 int64x64_t den = rhs.m_data;
1088 return num / den;
1089}
1090
1091/**
1092 * Scale a Time by a numeric value.
1093 * @param [in] lhs The first value
1094 * @param [in] rhs The second value
1095 * @returns The Time divided by the scalar operand.
1096 */
1097inline Time
1098operator/(const Time& lhs, const int64x64_t& rhs)
1099{
1100 int64x64_t res = lhs.m_data;
1101 res /= rhs;
1102 return Time(res);
1103}
1104
1105/**
1106 * Divide a Time by an integer value.
1107 *
1108 * @tparam T Integer data type (int, long, etc.)
1109 *
1110 * @param [in] lhs The Time instance to scale
1111 * @param [in] rhs The scale value
1112 * @returns A new Time instance containing the scaled value
1113 */
1114template <class T>
1115std::enable_if_t<std::is_integral_v<T>, Time>
1116operator/(const Time& lhs, T rhs)
1117{
1118 static_assert(!std::is_same_v<T, bool>, "Dividing a Time by a boolean is not supported");
1119
1120 return Time(lhs.m_data / rhs);
1121}
1122
1123// Leave undocumented
1124template <class T>
1125std::enable_if_t<std::is_floating_point_v<T>, Time>
1126operator/(const Time& lhs, T rhs)
1127{
1128 return lhs / int64x64_t(rhs);
1129}
1130
1131/**
1132 * Remainder (modulus) from the quotient of two Times.
1133 *
1134 * Rem() and operator% are equivalent:
1135 *
1136 * Rem (ta, tb) == ta % tb;
1137 *
1138 * @see Div()
1139 * @param [in] lhs The first time value
1140 * @param [in] rhs The second time value
1141 * @returns The remainder of `lhs / rhs`.
1142 * @{
1143 */
1144inline Time
1145operator%(const Time& lhs, const Time& rhs)
1146{
1147 return Time(lhs.m_data % rhs.m_data);
1148}
1149
1150inline Time
1151Rem(const Time& lhs, const Time& rhs)
1152{
1153 return Time(lhs.m_data % rhs.m_data);
1154}
1155
1156/** @} */
1157
1158/**
1159 * Integer quotient from dividing two Times.
1160 *
1161 * This is the same as the "normal" C++ integer division,
1162 * which truncates (discarding any remainder).
1163 *
1164 * As usual, if `ta`, and `tb` are both Times
1165 *
1166 * @code
1167 * ta == tb * Div (ta, tb) + Rem (ta, tb);
1168 *
1169 * ta == tb * (ta / tb).GetHigh() + ta % tb;
1170 * @endcode
1171 *
1172 * @param [in] lhs The first value
1173 * @param [in] rhs The second value
1174 * @returns The integer portion of `lhs / rhs`.
1175 *
1176 * @see Rem()
1177 */
1178inline int64_t
1179Div(const Time& lhs, const Time& rhs)
1180{
1181 return lhs.m_data / rhs.m_data;
1182}
1183
1184/**
1185 * Compound addition assignment for Time.
1186 * @param [in] lhs The first value
1187 * @param [in] rhs The second value
1188 * @returns The sum of the two inputs.
1189 */
1190inline Time&
1191operator+=(Time& lhs, const Time& rhs)
1192{
1193 lhs.m_data += rhs.m_data;
1194 return lhs;
1195}
1196
1197/**
1198 * Compound subtraction assignment for Time.
1199 * @param [in] lhs The first value
1200 * @param [in] rhs The second value
1201 * @returns The difference of the two operands.
1202 */
1203inline Time&
1204operator-=(Time& lhs, const Time& rhs)
1205{
1206 lhs.m_data -= rhs.m_data;
1207 return lhs;
1208}
1209
1210/**
1211 * Absolute value for Time.
1212 * @param [in] time The Time value
1213 * @returns The absolute value of the input.
1214 */
1215inline Time
1216Abs(const Time& time)
1217{
1218 return Time((time.m_data < 0) ? -time.m_data : time.m_data);
1219}
1220
1221/**
1222 * Maximum of two Times.
1223 * @param [in] timeA The first value
1224 * @param [in] timeB The second value
1225 * @returns The larger of the two operands.
1226 */
1227inline Time
1228Max(const Time& timeA, const Time& timeB)
1229{
1230 return Time((timeA.m_data < timeB.m_data) ? timeB : timeA);
1231}
1232
1233/**
1234 * Minimum of two Times.
1235 * @param [in] timeA The first value
1236 * @param [in] timeB The second value
1237 * @returns The smaller of the two operands.
1238 */
1239inline Time
1240Min(const Time& timeA, const Time& timeB)
1241{
1242 return Time((timeA.m_data > timeB.m_data) ? timeB : timeA);
1243}
1244
1245/**
1246 * Time output streamer.
1247 *
1248 * Generates output such as "396.0ns".
1249 *
1250 * For historical reasons Times are printed with the
1251 * following format flags (independent of the stream flags):
1252 * - `showpos`
1253 * - `fixed`
1254 * - `left`
1255 *
1256 * The stream `width` and `precision` are ignored; Time output always
1257 * includes ".0".
1258 *
1259 * @see As() for more flexible output formatting.
1260 *
1261 * @param [in,out] os The output stream.
1262 * @param [in] time The Time to put on the stream.
1263 * @return The stream.
1264 */
1265std::ostream& operator<<(std::ostream& os, const Time& time);
1266/**
1267 * Time input streamer
1268 *
1269 * Uses the Time(const std::string &) constructor
1270 *
1271 * @param [in,out] is The input stream.
1272 * @param [out] time The Time variable to set from the stream data.
1273 * @return The stream.
1274 */
1275std::istream& operator>>(std::istream& is, Time& time);
1276
1277/**
1278 * @ingroup time
1279 * @defgroup timecivil Standard Time Units.
1280 * Convenience constructors in standard units.
1281 *
1282 * For example:
1283 * @code
1284 * Time t = Seconds (2.0);
1285 * Simulator::Schedule (Seconds (5.0), ...);
1286 * @endcode
1287 */
1288/**
1289 * @ingroup timecivil
1290 * Construct a Time in the indicated unit.
1291 * @param [in] value The value
1292 * @return The Time
1293 * @{
1294 */
1295inline Time
1296Years(double value)
1297{
1298 return Time::FromDouble(value, Time::Y);
1299}
1300
1301inline Time
1303{
1304 return Time::From(value, Time::Y);
1305}
1306
1307inline Time
1308Days(double value)
1309{
1310 return Time::FromDouble(value, Time::D);
1311}
1312
1313inline Time
1315{
1316 return Time::From(value, Time::D);
1317}
1318
1319inline Time
1320Hours(double value)
1321{
1322 return Time::FromDouble(value, Time::H);
1323}
1324
1325inline Time
1327{
1328 return Time::From(value, Time::H);
1329}
1330
1331inline Time
1332Minutes(double value)
1333{
1334 return Time::FromDouble(value, Time::MIN);
1335}
1336
1337inline Time
1339{
1340 return Time::From(value, Time::MIN);
1341}
1342
1343inline Time
1344Seconds(double value)
1345{
1346 return Time::FromDouble(value, Time::S);
1347}
1348
1349inline Time
1351{
1352 return Time::From(value, Time::S);
1353}
1354
1355inline Time
1356MilliSeconds(uint64_t value)
1357{
1358 return Time::FromInteger(value, Time::MS);
1359}
1360
1361inline Time
1363{
1364 return Time::From(value, Time::MS);
1365}
1366
1367inline Time
1368MicroSeconds(uint64_t value)
1369{
1370 return Time::FromInteger(value, Time::US);
1371}
1372
1373inline Time
1375{
1376 return Time::From(value, Time::US);
1377}
1378
1379inline Time
1380NanoSeconds(uint64_t value)
1381{
1382 return Time::FromInteger(value, Time::NS);
1383}
1384
1385inline Time
1387{
1388 return Time::From(value, Time::NS);
1389}
1390
1391inline Time
1392PicoSeconds(uint64_t value)
1393{
1394 return Time::FromInteger(value, Time::PS);
1395}
1396
1397inline Time
1399{
1400 return Time::From(value, Time::PS);
1401}
1402
1403inline Time
1404FemtoSeconds(uint64_t value)
1405{
1406 return Time::FromInteger(value, Time::FS);
1407}
1408
1409inline Time
1411{
1412 return Time::From(value, Time::FS);
1413}
1414
1415/**@}*/ // Construct a Time in the indicated unit.
1416
1417/**
1418 * Scheduler interface.
1419 *
1420 * @note This is internal to the Time implementation.
1421 * @param [in] ts The time value, in the current unit.
1422 * @return A Time.
1423 * @relates Time
1424 */
1425inline Time
1426TimeStep(uint64_t ts)
1427{
1428 return Time(ts);
1429}
1430
1433
1434/**
1435 * @ingroup attribute_Time
1436 * Helper to make a Time checker with bounded range.
1437 * Both limits are inclusive
1438 *
1439 * @param [in] min Minimum allowed value.
1440 * @param [in] max Maximum allowed value.
1441 * @return The AttributeChecker
1442 */
1444
1445/**
1446 * @ingroup attribute_Time
1447 * Helper to make an unbounded Time checker.
1448 *
1449 * @return The AttributeChecker
1450 */
1453{
1454 return MakeTimeChecker(Time::Min(), Time::Max());
1455}
1456
1457/**
1458 * @ingroup attribute_Time
1459 * Helper to make a Time checker with a lower bound.
1460 *
1461 * @param [in] min Minimum allowed value.
1462 * @return The AttributeChecker
1463 */
1464inline Ptr<const AttributeChecker>
1466{
1467 return MakeTimeChecker(min, Time::Max());
1468}
1469
1470/**
1471 * @ingroup time
1472 * A Time with attached unit, to facilitate output in that unit.
1473 */
1475{
1476 public:
1477 /**
1478 * Attach a unit to a Time
1479 *
1480 * @param [in] time The time.
1481 * @param [in] unit The unit to use for output
1482 */
1483 TimeWithUnit(const Time time, const Time::Unit unit)
1484 : m_time(time),
1485 m_unit(unit)
1486 {
1487 }
1488
1489 private:
1490 Time m_time; //!< The time
1491 Time::Unit m_unit; //!< The unit to use in output
1492
1493 /**
1494 * Output streamer
1495 * @param [in,out] os The stream.
1496 * @param [in] timeU The Time with desired unit
1497 * @returns The stream.
1498 */
1499 friend std::ostream& operator<<(std::ostream& os, const TimeWithUnit& timeU);
1500
1501}; // class TimeWithUnit
1502
1503/**
1504 * @ingroup time
1505 *
1506 * ns3::TypeNameGet<Time>() specialization.
1507 * @returns The type name as a string.
1508 */
1510
1511/**
1512 * @ingroup time
1513 *
1514 * @brief Helper class to force static initialization
1515 * of Time in each compilation unit, ensuring it is
1516 * initialized before usage.
1517 * This is internal to the Time implementation.
1518 * @relates Time
1519 */
1521{
1522 public:
1523 /** Default constructor calls Time::StaticInit */
1528};
1529
1530static TimeInitializationHelper g_timeInitHelper; ///< Instance of Time static initialization helper
1531
1532} // namespace ns3
1533
1534#endif /* TIME_H */
#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:45
uint64_t GetTs() const
Definition event-id.cc:85
Smart pointer class similar to boost::intrusive_ptr.
Control the scheduling of simulation events.
Definition simulator.h:57
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
friend Time operator%(const Time &lhs, const Time &rhs)
Remainder (modulus) from the quotient of two Times.
Definition nstime.h:1145
int64_t GetNanoSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:407
bool IsPositive() const
Exactly equivalent to t >= 0.
Definition nstime.h:322
Time(const Time &o)
Copy constructor.
Definition nstime.h:141
Time(const int64x64_t &v)
Construct from a numeric value.
Definition nstime.h:237
friend Time & operator-=(Time &lhs, const Time &rhs)
Compound subtraction assignment for Time.
Definition nstime.h:1204
static void ClearMarkedTimes()
Remove all MarkedTimes.
Definition time.cc:285
Time(unsigned long int v)
Construct from a numeric value.
Definition nstime.h:219
static Time From(const int64x64_t &value)
Create a Time in the current unit.
Definition nstime.h:470
~Time()
Destructor.
Definition nstime.h:292
int64_t GetMilliSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:397
static Resolution & SetDefaultNsResolution()
Set the default resolution.
Definition time.cc:192
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition time.cc:404
Time(long long int v)
Construct from a numeric value.
Definition nstime.h:201
static void ConvertTimes(const Unit unit)
Convert existing Times to the new unit.
Definition time.cc:365
static Information * PeekInformation(Unit timeUnit)
Get the Information record for timeUnit for the current Resolution.
Definition nstime.h:692
int64_t GetFemtoSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:417
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:392
int64x64_t To(Unit unit) const
Get the Time value expressed in a particular unit.
Definition nstime.h:597
static Unit GetResolution()
Definition time.cc:397
bool IsStrictlyPositive() const
Exactly equivalent to t > 0.
Definition nstime.h:340
Time & operator=(const Time &o)
Assignment operator.
Definition nstime.h:120
Time TimeStep(uint64_t ts)
Scheduler interface.
Definition nstime.h:1426
Time(double v)
Construct from a numeric value.
Definition nstime.h:174
int64_t GetInteger() const
Get the raw time value, in the current resolution unit.
Definition nstime.h:444
bool IsNegative() const
Exactly equivalent to t <= 0.
Definition nstime.h:313
static bool StaticInit()
Function to force static initialization of Time.
Definition time.cc:86
friend bool operator==(const Time &lhs, const Time &rhs)
Equality operator for Time.
Definition nstime.h:875
Time(unsigned long long int v)
Construct from a numeric value.
Definition nstime.h:228
double GetMinutes() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:387
static Time Min()
Minimum representable Time Not to be confused with Min(Time,Time).
Definition nstime.h:276
friend Time & operator+=(Time &lhs, const Time &rhs)
Compound addition assignment for Time.
Definition nstime.h:1191
static void Clear(Time *const time)
Remove a Time instance from the MarkedTimes, called by ~Time().
Definition time.cc:337
static Time From(const int64x64_t &value, Unit unit)
Create a Time equal to value in unit unit.
Definition nstime.h:522
Unit
The unit to use to interpret a number representing time.
Definition nstime.h:100
@ AUTO
auto-scale output when using Time::As()
Definition nstime.h:112
@ D
day, 24 hours
Definition nstime.h:102
@ US
microsecond
Definition nstime.h:107
@ PS
picosecond
Definition nstime.h:109
@ LAST
marker for last normal value
Definition nstime.h:111
@ Y
year, 365 days
Definition nstime.h:101
@ FS
femtosecond
Definition nstime.h:110
@ H
hour, 60 minutes
Definition nstime.h:103
@ MIN
minute, 60 seconds
Definition nstime.h:104
@ MS
millisecond
Definition nstime.h:106
@ S
second
Definition nstime.h:105
@ NS
nanosecond
Definition nstime.h:108
Time()
Default constructor, with value 0.
Definition nstime.h:127
friend bool operator>=(const Time &lhs, const Time &rhs)
Greater than or equal operator for Time.
Definition nstime.h:911
double GetDays() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:377
Time RoundTo(Unit unit) const
Round a Time to a specific unit.
Definition nstime.h:629
friend bool operator<=(const Time &lhs, const Time &rhs)
Less than or equal operator for Time.
Definition nstime.h:899
static MarkedTimes * g_markingTimes
Record of outstanding Time objects which will need conversion when the resolution is set.
Definition nstime.h:747
int64_t m_data
Virtual time value, in the current unit.
Definition nstime.h:851
friend Time Rem(const Time &lhs, const Time &rhs)
Addition operator for Time.
Definition nstime.h:1151
static Resolution * PeekResolution()
Get the current Resolution.
Definition nstime.h:680
friend int64_t Div(const Time &lhs, const Time &rhs)
Integer quotient from dividing two Times.
Definition nstime.h:1179
static void Mark(Time *const time)
Record a Time instance with the MarkedTimes.
Definition time.cc:314
int64_t GetPicoSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:412
static void SetResolution(Unit resolution)
Definition time.cc:202
double GetYears() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:372
friend bool operator<(const Time &lhs, const Time &rhs)
Less than operator for Time.
Definition nstime.h:923
Time(int v)
Construct from a numeric value.
Definition nstime.h:183
friend bool operator!=(const Time &lhs, const Time &rhs)
Inequality operator for Time.
Definition nstime.h:887
Time(Time &&o)
Move constructor.
Definition nstime.h:155
int64_t ToInteger(Unit unit) const
Get the Time value expressed in a particular unit.
Definition nstime.h:562
static Time FromInteger(uint64_t value, Unit unit)
Create a Time equal to value in unit unit.
Definition nstime.h:488
bool IsStrictlyNegative() const
Exactly equivalent to t < 0.
Definition nstime.h:331
Time(unsigned int v)
Construct from a numeric value.
Definition nstime.h:210
int Compare(const Time &o) const
Compare this to another Time.
Definition nstime.h:351
static Time FromDouble(double value, Unit unit)
Create a Time equal to value in unit unit.
Definition nstime.h:511
double GetDouble() const
Get the raw time value, in the current resolution unit.
Definition nstime.h:439
friend Time operator-(const Time &lhs, const Time &rhs)
Subtraction operator for Time.
Definition nstime.h:988
friend Time operator+(const Time &lhs, const Time &rhs)
Addition operator for Time.
Definition nstime.h:976
static Time Max()
Maximum representable Time Not to be confused with Max(Time,Time).
Definition nstime.h:286
friend Time operator*(const Time &lhs, const int64x64_t &rhs)
Scale a Time by a numeric value.
Definition nstime.h:1000
double ToDouble(Unit unit) const
Get the Time value expressed in a particular unit.
Definition nstime.h:586
friend bool operator>(const Time &lhs, const Time &rhs)
Greater than operator for Time.
Definition nstime.h:935
bool IsZero() const
Exactly equivalent to t == 0.
Definition nstime.h:304
int64_t GetTimeStep() const
Get the raw time value, in the current resolution unit.
Definition nstime.h:434
int64_t GetMicroSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:402
friend Time Abs(const Time &time)
Absolute value for Time.
Definition nstime.h:1216
Time(long int v)
Construct from a numeric value.
Definition nstime.h:192
double GetHours() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:382
friend int64x64_t operator/(const Time &lhs, const Time &rhs)
Exact division, returning a dimensionless fixed point number.
Definition nstime.h:1084
std::set< Time * > MarkedTimes
Record all instances of Time, so we can rescale them when the resolution changes.
Definition nstime.h:732
Helper class to force static initialization of Time in each compilation unit, ensuring it is initiali...
Definition nstime.h:1521
TimeInitializationHelper()
Default constructor calls Time::StaticInit.
Definition nstime.h:1524
A Time with attached unit, to facilitate output in that unit.
Definition nstime.h:1475
friend std::ostream & operator<<(std::ostream &os, const TimeWithUnit &timeU)
Output streamer.
Definition time.cc:417
TimeWithUnit(const Time time, const Time::Unit unit)
Attach a unit to a Time.
Definition nstime.h:1483
Time m_time
The time.
Definition nstime.h:1490
Time::Unit m_unit
The unit to use in output.
Definition nstime.h:1491
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:75
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Definition nstime.h:1452
#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:49
int64x64_t operator/(const int64x64_t &lhs, const int64x64_t &rhs)
Division operator.
Definition int64x64.h:121
bool operator>=(const int64x64_t &lhs, const int64x64_t &rhs)
Greater or equal operator.
Definition int64x64.h:162
bool operator<=(const int64x64_t &lhs, const int64x64_t &rhs)
Less or equal operator.
Definition int64x64.h:149
int64x64_t operator-(const int64x64_t &lhs, const int64x64_t &rhs)
Subtraction operator.
Definition int64x64.h:91
int64x64_t operator+(const int64x64_t &lhs, const int64x64_t &rhs)
Addition operator.
Definition int64x64.h:76
int64x64_t Abs(const int64x64_t &value)
Absolute value.
Definition int64x64.h:203
int64x64_t operator*(const int64x64_t &lhs, const int64x64_t &rhs)
Multiplication operator.
Definition int64x64.h:106
bool operator>(const Length &left, const Length &right)
Check if left has a value greater than right.
Definition length.cc:410
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:471
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1368
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1380
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1344
Time Days(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
Time Hours(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1320
Time PicoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1392
Time FemtoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1404
Time Minutes(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1332
Time Years(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1296
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1356
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:1151
bool operator!=(Callback< R, Args... > a, Callback< R, Args... > b)
Inequality test.
Definition callback.h:658
Time operator%(const Time &lhs, const Time &rhs)
Remainder (modulus) from the quotient of two Times.
Definition nstime.h:1145
bool operator==(const EventId &a, const EventId &b)
Definition event-id.h:155
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition angles.cc:148
Time & operator+=(Time &lhs, const Time &rhs)
Compound addition assignment for Time.
Definition nstime.h:1191
static TimeInitializationHelper g_timeInitHelper
Instance of Time static initialization helper.
Definition nstime.h:1530
std::istream & operator>>(std::istream &is, Angles &a)
Definition angles.cc:172
bool operator<(const EventId &a, const EventId &b)
Definition event-id.h:168
Time & operator-=(Time &lhs, const Time &rhs)
Compound subtraction assignment for Time.
Definition nstime.h:1204
How to convert between other units and the current unit.
Definition nstime.h:659
int64_t factor
Ratio of this unit / current unit.
Definition nstime.h:662
bool toMul
Multiply when converting To, otherwise divide.
Definition nstime.h:660
int64x64_t timeFrom
Multiplier to convert from this unit.
Definition nstime.h:664
bool isValid
True if the current unit can be used.
Definition nstime.h:665
bool fromMul
Multiple when converting From, otherwise divide.
Definition nstime.h:661
int64x64_t timeTo
Multiplier to convert to this unit.
Definition nstime.h:663
Current time unit, and conversion info.
Definition nstime.h:670
Time::Unit unit
Current time unit.
Definition nstime.h:672
Information info[LAST]
Conversion info from current unit.
Definition nstime.h:671
ns3::TypeNameGet() function declarations.