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 // end of class Time
854};
855
856namespace TracedValueCallback
857{
858
859/**
860 * TracedValue callback signature for Time
861 *
862 * @param [in] oldValue Original value of the traced variable
863 * @param [in] newValue New value of the traced variable
864 */
865typedef void (*Time)(Time oldValue, Time newValue);
866
867} // namespace TracedValueCallback
868
869/**
870 * Equality operator for Time.
871 * @param [in] lhs The first value
872 * @param [in] rhs The second value
873 * @returns \c true if the two input values are equal.
874 */
875inline bool
876operator==(const Time& lhs, const Time& rhs)
877{
878 return lhs.m_data == rhs.m_data;
879}
880
881/**
882 * Inequality operator for Time.
883 * @param [in] lhs The first value
884 * @param [in] rhs The second value
885 * @returns \c true if the two input values not are equal.
886 */
887inline bool
888operator!=(const Time& lhs, const Time& rhs)
889{
890 return lhs.m_data != rhs.m_data;
891}
892
893/**
894 * Less than or equal operator for Time.
895 * @param [in] lhs The first value
896 * @param [in] rhs The second value
897 * @returns \c true if the first input value is less than or equal to the second input value.
898 */
899inline bool
900operator<=(const Time& lhs, const Time& rhs)
901{
902 return lhs.m_data <= rhs.m_data;
903}
904
905/**
906 * Greater than or equal operator for Time.
907 * @param [in] lhs The first value
908 * @param [in] rhs The second value
909 * @returns \c true if the first input value is greater than or equal to the second input value.
910 */
911inline bool
912operator>=(const Time& lhs, const Time& rhs)
913{
914 return lhs.m_data >= rhs.m_data;
915}
916
917/**
918 * Less than operator for Time.
919 * @param [in] lhs The first value
920 * @param [in] rhs The second value
921 * @returns \c true if the first input value is less than the second input value.
922 */
923inline bool
924operator<(const Time& lhs, const Time& rhs)
925{
926 return lhs.m_data < rhs.m_data;
927}
928
929/**
930 * Greater than operator for Time.
931 * @param [in] lhs The first value
932 * @param [in] rhs The second value
933 * @returns \c true if the first input value is greater than the second input value.
934 */
935inline bool
936operator>(const Time& lhs, const Time& rhs)
937{
938 return lhs.m_data > rhs.m_data;
939}
940
941/**
942 * Compare a Time to an EventId.
943 *
944 * This is useful when you have cached a previously scheduled event:
945 *
946 * m_event = Schedule (...);
947 *
948 * and later you want to know the relationship between that event
949 * and some other Time `when`:
950 *
951 * if (when < m_event) ...
952 *
953 * @param [in] time The Time operand.
954 * @param [in] event The EventId
955 * @returns \c true if \p time is before (less than) the
956 * time stamp of the EventId.
957 */
958inline bool
959operator<(const Time& time, const EventId& event)
960{
961 // Negative Time is less than any possible EventId, which are all >= 0.
962 if (time.m_data < 0)
963 {
964 return true;
965 }
966 // Time must be >= 0 so casting to unsigned is safe.
967 return static_cast<uint64_t>(time.m_data) < event.GetTs();
968}
969
970/**
971 * Addition operator for Time.
972 * @param [in] lhs The first value
973 * @param [in] rhs The second value
974 * @returns The sum of the two input values.
975 */
976inline Time
977operator+(const Time& lhs, const Time& rhs)
978{
979 return Time(lhs.m_data + rhs.m_data);
980}
981
982/**
983 * Subtraction operator for Time.
984 * @param [in] lhs The first value
985 * @param [in] rhs The second value
986 * @returns The difference of the two input values.
987 */
988inline Time
989operator-(const Time& lhs, const Time& rhs)
990{
991 return Time(lhs.m_data - rhs.m_data);
992}
993
994/**
995 * Scale a Time by a numeric value.
996 * @param [in] lhs The first value
997 * @param [in] rhs The second value
998 * @returns The Time scaled by the other operand.
999 */
1000inline Time
1001operator*(const Time& lhs, const int64x64_t& rhs)
1002{
1003 int64x64_t res = lhs.m_data;
1004 res *= rhs;
1005 return Time(res);
1006}
1007
1008/**
1009 * Scale a Time by a numeric value.
1010 * @param [in] lhs The first value
1011 * @param [in] rhs The second value
1012 * @returns The Time scaled by the other operand.
1013 */
1014inline Time
1015operator*(const int64x64_t& lhs, const Time& rhs)
1016{
1017 return rhs * lhs;
1018}
1019
1020/**
1021 * Scale a Time by an integer value.
1022 *
1023 * @tparam T Integer data type (int, long, etc.)
1024 *
1025 * @param [in] lhs The Time instance to scale
1026 * @param [in] rhs The scale value
1027 * @returns A new Time instance containing the scaled value
1028 */
1029template <class T>
1030std::enable_if_t<std::is_integral_v<T>, Time>
1031operator*(const Time& lhs, T rhs)
1032{
1033 static_assert(!std::is_same_v<T, bool>, "Multiplying a Time by a boolean is not supported");
1034
1035 return Time(lhs.m_data * rhs);
1036}
1037
1038// Leave undocumented
1039template <class T>
1040std::enable_if_t<std::is_floating_point_v<T>, Time>
1041operator*(const Time& lhs, T rhs)
1042{
1043 return lhs * int64x64_t(rhs);
1044}
1045
1046/**
1047 * Scale a Time by a numeric value.
1048 *
1049 * This overload handles the case where the scale value comes before the Time
1050 * value. It swaps the arguments so that the Time argument comes first
1051 * and calls the appropriate overload of operator*
1052 *
1053 * @tparam T Arithmetic data type (int, long, float, etc.)
1054 *
1055 * @param [in] lhs The scale value
1056 * @param [in] rhs The Time instance to scale
1057 * @returns A new Time instance containing the scaled value
1058 */
1059template <class T>
1060std::enable_if_t<std::is_arithmetic_v<T>, Time>
1061operator*(T lhs, const Time& rhs)
1062{
1063 return rhs * lhs;
1064}
1065
1066/**
1067 * Exact division, returning a dimensionless fixed point number.
1068 *
1069 * This can be truncated to integer, or converted to double
1070 * (with loss of precision). Assuming `ta` and `tb` are Times:
1071 *
1072 * @code
1073 * int64x64_t ratio = ta / tb;
1074 *
1075 * int64_t i = ratio.GetHigh (); // Get just the integer part, resulting in truncation
1076 *
1077 * double ratioD = double (ratio); // Convert to double, with loss of precision
1078 * @endcode
1079 *
1080 * @param [in] lhs The first value
1081 * @param [in] rhs The second value
1082 * @returns The exact ratio of the two operands.
1083 */
1084inline int64x64_t
1085operator/(const Time& lhs, const Time& rhs)
1086{
1087 int64x64_t num = lhs.m_data;
1088 int64x64_t den = rhs.m_data;
1089 return num / den;
1090}
1091
1092/**
1093 * Scale a Time by a numeric value.
1094 * @param [in] lhs The first value
1095 * @param [in] rhs The second value
1096 * @returns The Time divided by the scalar operand.
1097 */
1098inline Time
1099operator/(const Time& lhs, const int64x64_t& rhs)
1100{
1101 int64x64_t res = lhs.m_data;
1102 res /= rhs;
1103 return Time(res);
1104}
1105
1106/**
1107 * Divide a Time by an integer value.
1108 *
1109 * @tparam T Integer data type (int, long, etc.)
1110 *
1111 * @param [in] lhs The Time instance to scale
1112 * @param [in] rhs The scale value
1113 * @returns A new Time instance containing the scaled value
1114 */
1115template <class T>
1116std::enable_if_t<std::is_integral_v<T>, Time>
1117operator/(const Time& lhs, T rhs)
1118{
1119 static_assert(!std::is_same_v<T, bool>, "Dividing a Time by a boolean is not supported");
1120
1121 return Time(lhs.m_data / rhs);
1122}
1123
1124// Leave undocumented
1125template <class T>
1126std::enable_if_t<std::is_floating_point_v<T>, Time>
1127operator/(const Time& lhs, T rhs)
1128{
1129 return lhs / int64x64_t(rhs);
1130}
1131
1132/**
1133 * Remainder (modulus) from the quotient of two Times.
1134 *
1135 * Rem() and operator% are equivalent:
1136 *
1137 * Rem (ta, tb) == ta % tb;
1138 *
1139 * @see Div()
1140 * @param [in] lhs The first time value
1141 * @param [in] rhs The second time value
1142 * @returns The remainder of `lhs / rhs`.
1143 * @{
1144 */
1145inline Time
1146operator%(const Time& lhs, const Time& rhs)
1147{
1148 return Time(lhs.m_data % rhs.m_data);
1149}
1150
1151inline Time
1152Rem(const Time& lhs, const Time& rhs)
1153{
1154 return Time(lhs.m_data % rhs.m_data);
1155}
1156
1157/** @} */
1158
1159/**
1160 * Integer quotient from dividing two Times.
1161 *
1162 * This is the same as the "normal" C++ integer division,
1163 * which truncates (discarding any remainder).
1164 *
1165 * As usual, if `ta`, and `tb` are both Times
1166 *
1167 * @code
1168 * ta == tb * Div (ta, tb) + Rem (ta, tb);
1169 *
1170 * ta == tb * (ta / tb).GetHigh() + ta % tb;
1171 * @endcode
1172 *
1173 * @param [in] lhs The first value
1174 * @param [in] rhs The second value
1175 * @returns The integer portion of `lhs / rhs`.
1176 *
1177 * @see Rem()
1178 */
1179inline int64_t
1180Div(const Time& lhs, const Time& rhs)
1181{
1182 return lhs.m_data / rhs.m_data;
1183}
1184
1185/**
1186 * Compound addition assignment for Time.
1187 * @param [in] lhs The first value
1188 * @param [in] rhs The second value
1189 * @returns The sum of the two inputs.
1190 */
1191inline Time&
1192operator+=(Time& lhs, const Time& rhs)
1193{
1194 lhs.m_data += rhs.m_data;
1195 return lhs;
1196}
1197
1198/**
1199 * Compound subtraction assignment for Time.
1200 * @param [in] lhs The first value
1201 * @param [in] rhs The second value
1202 * @returns The difference of the two operands.
1203 */
1204inline Time&
1205operator-=(Time& lhs, const Time& rhs)
1206{
1207 lhs.m_data -= rhs.m_data;
1208 return lhs;
1209}
1210
1211/**
1212 * Absolute value for Time.
1213 * @param [in] time The Time value
1214 * @returns The absolute value of the input.
1215 */
1216inline Time
1217Abs(const Time& time)
1218{
1219 return Time((time.m_data < 0) ? -time.m_data : time.m_data);
1220}
1221
1222/**
1223 * Maximum of two Times.
1224 * @param [in] timeA The first value
1225 * @param [in] timeB The second value
1226 * @returns The larger of the two operands.
1227 */
1228inline Time
1229Max(const Time& timeA, const Time& timeB)
1230{
1231 return Time((timeA.m_data < timeB.m_data) ? timeB : timeA);
1232}
1233
1234/**
1235 * Minimum of two Times.
1236 * @param [in] timeA The first value
1237 * @param [in] timeB The second value
1238 * @returns The smaller of the two operands.
1239 */
1240inline Time
1241Min(const Time& timeA, const Time& timeB)
1242{
1243 return Time((timeA.m_data > timeB.m_data) ? timeB : timeA);
1244}
1245
1246/**
1247 * Time output streamer.
1248 *
1249 * Generates output such as "396.0ns".
1250 *
1251 * For historical reasons Times are printed with the
1252 * following format flags (independent of the stream flags):
1253 * - `showpos`
1254 * - `fixed`
1255 * - `left`
1256 *
1257 * The stream `width` and `precision` are ignored; Time output always
1258 * includes ".0".
1259 *
1260 * @see As() for more flexible output formatting.
1261 *
1262 * @param [in,out] os The output stream.
1263 * @param [in] time The Time to put on the stream.
1264 * @return The stream.
1265 */
1266std::ostream& operator<<(std::ostream& os, const Time& time);
1267/**
1268 * Time input streamer
1269 *
1270 * Uses the Time(const std::string &) constructor
1271 *
1272 * @param [in,out] is The input stream.
1273 * @param [out] time The Time variable to set from the stream data.
1274 * @return The stream.
1275 */
1276std::istream& operator>>(std::istream& is, Time& time);
1277
1278/**
1279 * @ingroup time
1280 * @defgroup timecivil Standard Time Units.
1281 * Convenience constructors in standard units.
1282 *
1283 * For example:
1284 * @code
1285 * Time t = Seconds (2.0);
1286 * Simulator::Schedule (Seconds (5.0), ...);
1287 * @endcode
1288 */
1289/**
1290 * @ingroup timecivil
1291 * Construct a Time in the indicated unit.
1292 * @param [in] value The value
1293 * @return The Time
1294 * @{
1295 */
1296inline Time
1297Years(double value)
1298{
1299 return Time::FromDouble(value, Time::Y);
1300}
1301
1302inline Time
1304{
1305 return Time::From(value, Time::Y);
1306}
1307
1308inline Time
1309Days(double value)
1310{
1311 return Time::FromDouble(value, Time::D);
1312}
1313
1314inline Time
1316{
1317 return Time::From(value, Time::D);
1318}
1319
1320inline Time
1321Hours(double value)
1322{
1323 return Time::FromDouble(value, Time::H);
1324}
1325
1326inline Time
1328{
1329 return Time::From(value, Time::H);
1330}
1331
1332inline Time
1333Minutes(double value)
1334{
1335 return Time::FromDouble(value, Time::MIN);
1336}
1337
1338inline Time
1340{
1341 return Time::From(value, Time::MIN);
1342}
1343
1344inline Time
1345Seconds(double value)
1346{
1347 return Time::FromDouble(value, Time::S);
1348}
1349
1350inline Time
1352{
1353 return Time::From(value, Time::S);
1354}
1355
1356inline Time
1357MilliSeconds(uint64_t value)
1358{
1359 return Time::FromInteger(value, Time::MS);
1360}
1361
1362inline Time
1364{
1365 return Time::From(value, Time::MS);
1366}
1367
1368inline Time
1369MicroSeconds(uint64_t value)
1370{
1371 return Time::FromInteger(value, Time::US);
1372}
1373
1374inline Time
1376{
1377 return Time::From(value, Time::US);
1378}
1379
1380inline Time
1381NanoSeconds(uint64_t value)
1382{
1383 return Time::FromInteger(value, Time::NS);
1384}
1385
1386inline Time
1388{
1389 return Time::From(value, Time::NS);
1390}
1391
1392inline Time
1393PicoSeconds(uint64_t value)
1394{
1395 return Time::FromInteger(value, Time::PS);
1396}
1397
1398inline Time
1400{
1401 return Time::From(value, Time::PS);
1402}
1403
1404inline Time
1405FemtoSeconds(uint64_t value)
1406{
1407 return Time::FromInteger(value, Time::FS);
1408}
1409
1410inline Time
1412{
1413 return Time::From(value, Time::FS);
1414}
1415
1416/**@}*/ // Construct a Time in the indicated unit.
1417
1418/**
1419 * Scheduler interface.
1420 *
1421 * @note This is internal to the Time implementation.
1422 * @param [in] ts The time value, in the current unit.
1423 * @return A Time.
1424 * @relates Time
1425 */
1426inline Time
1427TimeStep(uint64_t ts)
1428{
1429 return Time(ts);
1430}
1431
1434
1435/**
1436 * @ingroup attribute_Time
1437 * Helper to make a Time checker with bounded range.
1438 * Both limits are inclusive
1439 *
1440 * @param [in] min Minimum allowed value.
1441 * @param [in] max Maximum allowed value.
1442 * @return The AttributeChecker
1443 */
1445
1446/**
1447 * @ingroup attribute_Time
1448 * Helper to make an unbounded Time checker.
1449 *
1450 * @return The AttributeChecker
1451 */
1454{
1455 return MakeTimeChecker(Time::Min(), Time::Max());
1456}
1457
1458/**
1459 * @ingroup attribute_Time
1460 * Helper to make a Time checker with a lower bound.
1461 *
1462 * @param [in] min Minimum allowed value.
1463 * @return The AttributeChecker
1464 */
1465inline Ptr<const AttributeChecker>
1467{
1468 return MakeTimeChecker(min, Time::Max());
1469}
1470
1471/**
1472 * @ingroup time
1473 * A Time with attached unit, to facilitate output in that unit.
1474 */
1476{
1477 public:
1478 /**
1479 * Attach a unit to a Time
1480 *
1481 * @param [in] time The time.
1482 * @param [in] unit The unit to use for output
1483 */
1484 TimeWithUnit(const Time time, const Time::Unit unit)
1485 : m_time(time),
1486 m_unit(unit)
1487 {
1488 }
1489
1490 private:
1491 Time m_time; //!< The time
1492 Time::Unit m_unit; //!< The unit to use in output
1493
1494 /**
1495 * Output streamer
1496 * @param [in,out] os The stream.
1497 * @param [in] timeU The Time with desired unit
1498 * @returns The stream.
1499 */
1500 friend std::ostream& operator<<(std::ostream& os, const TimeWithUnit& timeU);
1501
1502 // end of class TimeWithUnit
1503};
1504
1505/**
1506 * @ingroup time
1507 *
1508 * ns3::TypeNameGet<Time>() specialization.
1509 * @returns The type name as a string.
1510 */
1512
1513/**
1514 * @ingroup time
1515 *
1516 * @brief Helper class to force static initialization
1517 * of Time in each compilation unit, ensuring it is
1518 * initialized before usage.
1519 * This is internal to the Time implementation.
1520 * @relates Time
1521 */
1523{
1524 public:
1525 /** Default constructor calls Time::StaticInit */
1530};
1531
1532static TimeInitializationHelper g_timeInitHelper; ///< Instance of Time static initialization helper
1533
1534} // namespace ns3
1535
1536#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:1146
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:1205
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:403
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:396
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:1427
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:876
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:1192
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:912
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:900
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:1152
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:1180
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:924
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:888
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:989
friend Time operator+(const Time &lhs, const Time &rhs)
Addition operator for Time.
Definition nstime.h:977
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:1001
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:936
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:1217
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:1085
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:1523
TimeInitializationHelper()
Default constructor calls Time::StaticInit.
Definition nstime.h:1526
A Time with attached unit, to facilitate output in that unit.
Definition nstime.h:1476
friend std::ostream & operator<<(std::ostream &os, const TimeWithUnit &timeU)
Output streamer.
Definition time.cc:416
TimeWithUnit(const Time time, const Time::Unit unit)
Attach a unit to a Time.
Definition nstime.h:1484
Time m_time
The time.
Definition nstime.h:1491
Time::Unit m_unit
The unit to use in output.
Definition nstime.h:1492
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:1453
#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:1369
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1381
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1345
Time Days(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1309
Time Hours(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1321
Time PicoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1393
Time FemtoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1405
Time Minutes(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1333
Time Years(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1297
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1357
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:1152
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:1146
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:1192
static TimeInitializationHelper g_timeInitHelper
Instance of Time static initialization helper.
Definition nstime.h:1532
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:1205
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.