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