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 Information* info = PeekInformation(unit);
491
492 NS_ASSERT_MSG(info->isValid, "Attempted a conversion from an unavailable unit.");
493
494 if (info->fromMul)
495 {
496 value *= info->factor;
497 }
498 else
499 {
500 value /= info->factor;
501 }
502 return Time(value);
503 }
504
505 inline static Time FromDouble(double value, Unit unit)
506 {
507 return From(int64x64_t(value), unit);
508 }
509
510 inline static Time From(const int64x64_t& value, Unit unit)
511 {
512 Information* info = PeekInformation(unit);
513
514 NS_ASSERT_MSG(info->isValid, "Attempted a conversion from an unavailable unit.");
515
516 // DO NOT REMOVE this temporary variable. It's here
517 // to work around a compiler bug in gcc 3.4
518 int64x64_t retval = value;
519 if (info->fromMul)
520 {
521 retval *= info->timeFrom;
522 }
523 else
524 {
525 retval.MulByInvert(info->timeFrom);
526 }
527 return Time(retval);
528 }
529
530 /**@}*/ // Create Times from Values and Units
531
532 /**
533 * \name Get Times as Numbers in Specified Units
534 * Get the Time as integers or doubles in the indicated unit.
535 *
536 * @{
537 */
538 /**
539 * Get the Time value expressed in a particular unit.
540 *
541 * \param [in] unit The desired unit
542 * \return The Time expressed in \pname{unit}
543 */
544 inline int64_t ToInteger(Unit unit) const
545 {
546 Information* info = PeekInformation(unit);
547
548 NS_ASSERT_MSG(info->isValid, "Attempted a conversion to an unavailable unit.");
549
550 int64_t v = m_data;
551 if (info->toMul)
552 {
553 v *= info->factor;
554 }
555 else
556 {
557 v /= info->factor;
558 }
559 return v;
560 }
561
562 inline double ToDouble(Unit unit) const
563 {
564 return To(unit).GetDouble();
565 }
566
567 inline int64x64_t To(Unit unit) const
568 {
569 Information* info = PeekInformation(unit);
570
571 NS_ASSERT_MSG(info->isValid, "Attempted a conversion to an unavailable unit.");
572
573 int64x64_t retval(m_data);
574 if (info->toMul)
575 {
576 retval *= info->timeTo;
577 }
578 else
579 {
580 retval.MulByInvert(info->timeTo);
581 }
582 return retval;
583 }
584
585 /**@}*/ // Get Times as Numbers in Specified Units
586
587 /**
588 * Round a Time to a specific unit.
589 * Rounding is to nearest integer.
590 * \param [in] unit The unit to round to.
591 * \return The Time rounded to the specific unit.
592 */
593 Time RoundTo(Unit unit) const
594 {
595 return From(this->To(unit).Round(), unit);
596 }
597
598 /**
599 * Attach a unit to a Time, to facilitate output in a specific unit.
600 *
601 * For example,
602 * \code
603 * Time t (3.14e9); // Pi seconds
604 * std::cout << t.As (Time::MS) << std::endl;
605 * \endcode
606 * will print ``+3140.0ms``
607 *
608 * \param [in] unit The unit to use.
609 * \return The Time with embedded unit.
610 */
611 TimeWithUnit As(const Unit unit = Time::AUTO) const;
612
613 /**
614 * TracedCallback signature for Time
615 *
616 * \param [in] value Current value of Time
617 */
618 typedef void (*TracedCallback)(Time value);
619
620 private:
621 /** How to convert between other units and the current unit. */
623 {
624 bool toMul; //!< Multiply when converting To, otherwise divide
625 bool fromMul; //!< Multiple when converting From, otherwise divide
626 int64_t factor; //!< Ratio of this unit / current unit
627 int64x64_t timeTo; //!< Multiplier to convert to this unit
628 int64x64_t timeFrom; //!< Multiplier to convert from this unit
629 bool isValid; //!< True if the current unit can be used
630 };
631
632 /** Current time unit, and conversion info. */
634 {
635 Information info[LAST]; //!< Conversion info from current unit
636 Time::Unit unit; //!< Current time unit
637 };
638
639 /**
640 * Get the current Resolution
641 *
642 * \return A pointer to the current Resolution
643 */
644 static inline Resolution* PeekResolution()
645 {
646 static Time::Resolution& resolution{SetDefaultNsResolution()};
647 return &resolution;
648 }
649
650 /**
651 * Get the Information record for \pname{timeUnit} for the current Resolution
652 *
653 * \param [in] timeUnit The Unit to get Information for
654 * \return The Information for \pname{timeUnit}
655 */
656 static inline Information* PeekInformation(Unit timeUnit)
657 {
658 return &(PeekResolution()->info[timeUnit]);
659 }
660
661 /**
662 * Set the default resolution
663 *
664 * \return The Resolution object for the default resolution.
665 */
666 static Resolution& SetDefaultNsResolution();
667 /**
668 * Set the current Resolution.
669 *
670 * \param [in] unit The unit to use as the new resolution.
671 * \param [in,out] resolution The Resolution record to update.
672 * \param [in] convert Whether to convert existing Time objects to the new resolution.
673 */
674 static void SetResolution(Unit unit, Resolution* resolution, const bool convert = true);
675
676 /**
677 * Record all instances of Time, so we can rescale them when
678 * the resolution changes.
679 *
680 * \internal
681 *
682 * We use a std::set so we can remove the record easily when
683 * ~Time() is called.
684 *
685 * We don't use Ptr<Time>, because we would have to bloat every Time
686 * instance with SimpleRefCount<Time>.
687 *
688 * Seems like this should be std::set< Time * const >, but
689 * [Stack
690 * Overflow](http://stackoverflow.com/questions/5526019/compile-errors-stdset-with-const-members)
691 * says otherwise, quoting the standard:
692 *
693 * > & sect;23.1/3 states that std::set key types must be assignable
694 * > and copy constructable; clearly a const type will not be assignable.
695 */
696 typedef std::set<Time*> MarkedTimes;
697 /**
698 * Record of outstanding Time objects which will need conversion
699 * when the resolution is set.
700 *
701 * \internal
702 *
703 * Use a classic static variable so we can check in Time ctors
704 * without a function call.
705 *
706 * We'd really like to initialize this here, but we don't want to require
707 * C++0x, so we init in time.cc. To ensure that happens before first use,
708 * we add a call to StaticInit (below) to every compilation unit which
709 * includes nstime.h.
710 */
712
713 public:
714 /**
715 * Function to force static initialization of Time.
716 *
717 * \return \c true on the first call
718 */
719 static bool StaticInit();
720
721 private:
722 /**
723 * \cond HIDE_FROM_DOXYGEN
724 * Doxygen bug throws a warning here, so hide from Doxygen.
725 *
726 * Friend the Simulator class so it can call the private function
727 * ClearMarkedTimes ()
728 */
729 friend class Simulator;
730 /** \endcond */
731
732 /**
733 * Remove all MarkedTimes.
734 *
735 * \internal
736 * Has to be visible to the Simulator class, hence the friending.
737 */
738 static void ClearMarkedTimes();
739 /**
740 * Record a Time instance with the MarkedTimes.
741 * \param [in] time The Time instance to record.
742 */
743 static void Mark(Time* const time);
744 /**
745 * Remove a Time instance from the MarkedTimes, called by ~Time().
746 * \param [in] time The Time instance to remove.
747 */
748 static void Clear(Time* const time);
749 /**
750 * Convert existing Times to the new unit.
751 * \param [in] unit The Unit to convert existing Times to.
752 */
753 static void ConvertTimes(const Unit unit);
754
755 // Operator and related functions which need access
756
757 /**
758 * \name Comparison operators
759 * @{
760 */
761 friend bool operator==(const Time& lhs, const Time& rhs);
762 friend bool operator!=(const Time& lhs, const Time& rhs);
763 friend bool operator<=(const Time& lhs, const Time& rhs);
764 friend bool operator>=(const Time& lhs, const Time& rhs);
765 friend bool operator<(const Time& lhs, const Time& rhs);
766 friend bool operator>(const Time& lhs, const Time& rhs);
767 friend bool operator<(const Time& time, const EventId& event);
768 /**@}*/ // Comparison operators
769
770 /**
771 * \name Arithmetic operators
772 * @{
773 */
774 friend Time operator+(const Time& lhs, const Time& rhs);
775 friend Time operator-(const Time& lhs, const Time& rhs);
776 friend Time operator*(const Time& lhs, const int64x64_t& rhs);
777 friend Time operator*(const int64x64_t& lhs, const Time& rhs);
778 friend int64x64_t operator/(const Time& lhs, const Time& rhs);
779 friend Time operator/(const Time& lhs, const int64x64_t& rhs);
780 friend Time operator%(const Time& lhs, const Time& rhs);
781 friend int64_t Div(const Time& lhs, const Time& rhs);
782 friend Time Rem(const Time& lhs, const Time& rhs);
783
784 template <class T>
785 friend std::enable_if_t<std::is_integral_v<T>, Time> operator*(const Time& lhs, T rhs);
786
787 // Reversed arg version (forwards to `rhs * lhs`)
788 // Accepts both integers and decimal types
789 template <class T>
790 friend std::enable_if_t<std::is_arithmetic_v<T>, Time> operator*(T lhs, const Time& rhs);
791
792 template <class T>
793 friend std::enable_if_t<std::is_integral_v<T>, Time> operator/(const Time& lhs, T rhs);
794
795 friend Time Abs(const Time& time);
796 friend Time Max(const Time& timeA, const Time& timeB);
797 friend Time Min(const Time& timeA, const Time& timeB);
798
799 /**@}*/ // Arithmetic operators
800
801 // Leave undocumented
802 template <class T>
803 friend std::enable_if_t<std::is_floating_point_v<T>, Time> operator*(const Time& lhs, T rhs);
804 template <class T>
805 friend std::enable_if_t<std::is_floating_point_v<T>, Time> operator/(const Time& lhs, T rhs);
806
807 /**
808 * \name Compound assignment operators
809 * @{
810 */
811 friend Time& operator+=(Time& lhs, const Time& rhs);
812 friend Time& operator-=(Time& lhs, const Time& rhs);
813 /**@}*/ // Compound assignment
814
815 int64_t m_data; //!< Virtual time value, in the current unit.
816
817}; // class Time
818
819namespace TracedValueCallback
820{
821
822/**
823 * TracedValue callback signature for Time
824 *
825 * \param [in] oldValue Original value of the traced variable
826 * \param [in] newValue New value of the traced variable
827 */
828typedef void (*Time)(Time oldValue, Time newValue);
829
830} // namespace TracedValueCallback
831
832/**
833 * Equality operator for Time.
834 * \param [in] lhs The first value
835 * \param [in] rhs The second value
836 * \returns \c true if the two input values are equal.
837 */
838inline bool
839operator==(const Time& lhs, const Time& rhs)
840{
841 return lhs.m_data == rhs.m_data;
842}
843
844/**
845 * Inequality operator for Time.
846 * \param [in] lhs The first value
847 * \param [in] rhs The second value
848 * \returns \c true if the two input values not are equal.
849 */
850inline bool
851operator!=(const Time& lhs, const Time& rhs)
852{
853 return lhs.m_data != rhs.m_data;
854}
855
856/**
857 * Less than or equal operator for Time.
858 * \param [in] lhs The first value
859 * \param [in] rhs The second value
860 * \returns \c true if the first input value is less than or equal to the second input value.
861 */
862inline bool
863operator<=(const Time& lhs, const Time& rhs)
864{
865 return lhs.m_data <= rhs.m_data;
866}
867
868/**
869 * Greater than or equal operator for Time.
870 * \param [in] lhs The first value
871 * \param [in] rhs The second value
872 * \returns \c true if the first input value is greater than or equal to the second input value.
873 */
874inline bool
875operator>=(const Time& lhs, const Time& rhs)
876{
877 return lhs.m_data >= rhs.m_data;
878}
879
880/**
881 * Less than operator for Time.
882 * \param [in] lhs The first value
883 * \param [in] rhs The second value
884 * \returns \c true if the first input value is less than the second input value.
885 */
886inline bool
887operator<(const Time& lhs, const Time& rhs)
888{
889 return lhs.m_data < rhs.m_data;
890}
891
892/**
893 * Greater than operator for Time.
894 * \param [in] lhs The first value
895 * \param [in] rhs The second value
896 * \returns \c true if the first input value is greater than the second input value.
897 */
898inline bool
899operator>(const Time& lhs, const Time& rhs)
900{
901 return lhs.m_data > rhs.m_data;
902}
903
904/**
905 * Compare a Time to an EventId.
906 *
907 * This is useful when you have cached a previously scheduled event:
908 *
909 * m_event = Schedule (...);
910 *
911 * and later you want to know the relationship between that event
912 * and some other Time `when`:
913 *
914 * if (when < m_event) ...
915 *
916 * \param [in] time The Time operand.
917 * \param [in] event The EventId
918 * \returns \c true if \p time is before (less than) the
919 * time stamp of the EventId.
920 */
921inline bool
922operator<(const Time& time, const EventId& event)
923{
924 // Negative Time is less than any possible EventId, which are all >= 0.
925 if (time.m_data < 0)
926 {
927 return true;
928 }
929 // Time must be >= 0 so casting to unsigned is safe.
930 return static_cast<uint64_t>(time.m_data) < event.GetTs();
931}
932
933/**
934 * Addition operator for Time.
935 * \param [in] lhs The first value
936 * \param [in] rhs The second value
937 * \returns The sum of the two input values.
938 */
939inline Time
940operator+(const Time& lhs, const Time& rhs)
941{
942 return Time(lhs.m_data + rhs.m_data);
943}
944
945/**
946 * Subtraction operator for Time.
947 * \param [in] lhs The first value
948 * \param [in] rhs The second value
949 * \returns The difference of the two input values.
950 */
951inline Time
952operator-(const Time& lhs, const Time& rhs)
953{
954 return Time(lhs.m_data - rhs.m_data);
955}
956
957/**
958 * Scale a Time by a numeric value.
959 * \param [in] lhs The first value
960 * \param [in] rhs The second value
961 * \returns The Time scaled by the other operand.
962 */
963inline Time
964operator*(const Time& lhs, const int64x64_t& rhs)
965{
966 int64x64_t res = lhs.m_data;
967 res *= rhs;
968 return Time(res);
969}
970
971/**
972 * Scale a Time by a numeric value.
973 * \param [in] lhs The first value
974 * \param [in] rhs The second value
975 * \returns The Time scaled by the other operand.
976 */
977inline Time
978operator*(const int64x64_t& lhs, const Time& rhs)
979{
980 return rhs * lhs;
981}
982
983/**
984 * Scale a Time by an integer value.
985 *
986 * \tparam T Integer data type (int, long, etc.)
987 *
988 * \param [in] lhs The Time instance to scale
989 * \param [in] rhs The scale value
990 * \returns A new Time instance containing the scaled value
991 */
992template <class T>
993std::enable_if_t<std::is_integral_v<T>, Time>
994operator*(const Time& lhs, T rhs)
995{
996 static_assert(!std::is_same_v<T, bool>, "Multiplying a Time by a boolean is not supported");
997
998 return Time(lhs.m_data * rhs);
999}
1000
1001// Leave undocumented
1002template <class T>
1003std::enable_if_t<std::is_floating_point_v<T>, Time>
1004operator*(const Time& lhs, T rhs)
1005{
1006 return lhs * int64x64_t(rhs);
1007}
1008
1009/**
1010 * Scale a Time by a numeric value.
1011 *
1012 * This overload handles the case where the scale value comes before the Time
1013 * value. It swaps the arguments so that the Time argument comes first
1014 * and calls the appropriate overload of operator*
1015 *
1016 * \tparam T Arithmetic data type (int, long, float, etc.)
1017 *
1018 * \param [in] lhs The scale value
1019 * \param [in] rhs The Time instance to scale
1020 * \returns A new Time instance containing the scaled value
1021 */
1022template <class T>
1023std::enable_if_t<std::is_arithmetic_v<T>, Time>
1024operator*(T lhs, const Time& rhs)
1025{
1026 return rhs * lhs;
1027}
1028
1029/**
1030 * Exact division, returning a dimensionless fixed point number.
1031 *
1032 * This can be truncated to integer, or converted to double
1033 * (with loss of precision). Assuming `ta` and `tb` are Times:
1034 *
1035 * \code
1036 * int64x64_t ratio = ta / tb;
1037 *
1038 * int64_t i = ratio.GetHigh (); // Get just the integer part, resulting in truncation
1039 *
1040 * double ratioD = double (ratio); // Convert to double, with loss of precision
1041 * \endcode
1042 *
1043 * \param [in] lhs The first value
1044 * \param [in] rhs The second value
1045 * \returns The exact ratio of the two operands.
1046 */
1047inline int64x64_t
1048operator/(const Time& lhs, const Time& rhs)
1049{
1050 int64x64_t num = lhs.m_data;
1051 int64x64_t den = rhs.m_data;
1052 return num / den;
1053}
1054
1055/**
1056 * Scale a Time by a numeric value.
1057 * \param [in] lhs The first value
1058 * \param [in] rhs The second value
1059 * \returns The Time divided by the scalar operand.
1060 */
1061inline Time
1062operator/(const Time& lhs, const int64x64_t& rhs)
1063{
1064 int64x64_t res = lhs.m_data;
1065 res /= rhs;
1066 return Time(res);
1067}
1068
1069/**
1070 * Divide a Time by an integer value.
1071 *
1072 * \tparam T Integer data type (int, long, etc.)
1073 *
1074 * \param [in] lhs The Time instance to scale
1075 * \param [in] rhs The scale value
1076 * \returns A new Time instance containing the scaled value
1077 */
1078template <class T>
1079std::enable_if_t<std::is_integral_v<T>, Time>
1080operator/(const Time& lhs, T rhs)
1081{
1082 static_assert(!std::is_same_v<T, bool>, "Dividing a Time by a boolean is not supported");
1083
1084 return Time(lhs.m_data / rhs);
1085}
1086
1087// Leave undocumented
1088template <class T>
1089std::enable_if_t<std::is_floating_point_v<T>, Time>
1090operator/(const Time& lhs, T rhs)
1091{
1092 return lhs / int64x64_t(rhs);
1093}
1094
1095/**
1096 * Remainder (modulus) from the quotient of two Times.
1097 *
1098 * Rem() and operator% are equivalent:
1099 *
1100 * Rem (ta, tb) == ta % tb;
1101 *
1102 * \see Div()
1103 * \param [in] lhs The first time value
1104 * \param [in] rhs The second time value
1105 * \returns The remainder of `lhs / rhs`.
1106 * @{
1107 */
1108inline Time
1109operator%(const Time& lhs, const Time& rhs)
1110{
1111 return Time(lhs.m_data % rhs.m_data);
1112}
1113
1114inline Time
1115Rem(const Time& lhs, const Time& rhs)
1116{
1117 return Time(lhs.m_data % rhs.m_data);
1118}
1119
1120/** @} */
1121
1122/**
1123 * Integer quotient from dividing two Times.
1124 *
1125 * This is the same as the "normal" C++ integer division,
1126 * which truncates (discarding any remainder).
1127 *
1128 * As usual, if `ta`, and `tb` are both Times
1129 *
1130 * \code
1131 * ta == tb * Div (ta, tb) + Rem (ta, tb);
1132 *
1133 * ta == tb * (ta / tb).GetHigh() + ta % tb;
1134 * \endcode
1135 *
1136 * \param [in] lhs The first value
1137 * \param [in] rhs The second value
1138 * \returns The integer portion of `lhs / rhs`.
1139 *
1140 * \see Rem()
1141 */
1142inline int64_t
1143Div(const Time& lhs, const Time& rhs)
1144{
1145 return lhs.m_data / rhs.m_data;
1146}
1147
1148/**
1149 * Compound addition assignment for Time.
1150 * \param [in] lhs The first value
1151 * \param [in] rhs The second value
1152 * \returns The sum of the two inputs.
1153 */
1154inline Time&
1155operator+=(Time& lhs, const Time& rhs)
1156{
1157 lhs.m_data += rhs.m_data;
1158 return lhs;
1159}
1160
1161/**
1162 * Compound subtraction assignment for Time.
1163 * \param [in] lhs The first value
1164 * \param [in] rhs The second value
1165 * \returns The difference of the two operands.
1166 */
1167inline Time&
1168operator-=(Time& lhs, const Time& rhs)
1169{
1170 lhs.m_data -= rhs.m_data;
1171 return lhs;
1172}
1173
1174/**
1175 * Absolute value for Time.
1176 * \param [in] time The Time value
1177 * \returns The absolute value of the input.
1178 */
1179inline Time
1180Abs(const Time& time)
1181{
1182 return Time((time.m_data < 0) ? -time.m_data : time.m_data);
1183}
1184
1185/**
1186 * Maximum of two Times.
1187 * \param [in] timeA The first value
1188 * \param [in] timeB The second value
1189 * \returns The larger of the two operands.
1190 */
1191inline Time
1192Max(const Time& timeA, const Time& timeB)
1193{
1194 return Time((timeA.m_data < timeB.m_data) ? timeB : timeA);
1195}
1196
1197/**
1198 * Minimum of two Times.
1199 * \param [in] timeA The first value
1200 * \param [in] timeB The second value
1201 * \returns The smaller of the two operands.
1202 */
1203inline Time
1204Min(const Time& timeA, const Time& timeB)
1205{
1206 return Time((timeA.m_data > timeB.m_data) ? timeB : timeA);
1207}
1208
1209/**
1210 * Time output streamer.
1211 *
1212 * Generates output such as "396.0ns".
1213 *
1214 * For historical reasons Times are printed with the
1215 * following format flags (independent of the stream flags):
1216 * - `showpos`
1217 * - `fixed`
1218 * - `left`
1219 *
1220 * The stream `width` and `precision` are ignored; Time output always
1221 * includes ".0".
1222 *
1223 * \see As() for more flexible output formatting.
1224 *
1225 * \param [in,out] os The output stream.
1226 * \param [in] time The Time to put on the stream.
1227 * \return The stream.
1228 */
1229std::ostream& operator<<(std::ostream& os, const Time& time);
1230/**
1231 * Time input streamer
1232 *
1233 * Uses the Time(const std::string &) constructor
1234 *
1235 * \param [in,out] is The input stream.
1236 * \param [out] time The Time variable to set from the stream data.
1237 * \return The stream.
1238 */
1239std::istream& operator>>(std::istream& is, Time& time);
1240
1241/**
1242 * \ingroup time
1243 * \defgroup timecivil Standard Time Units.
1244 * Convenience constructors in standard units.
1245 *
1246 * For example:
1247 * \code
1248 * Time t = Seconds (2.0);
1249 * Simulator::Schedule (Seconds (5.0), ...);
1250 * \endcode
1251 */
1252/**
1253 * \ingroup timecivil
1254 * Construct a Time in the indicated unit.
1255 * \param [in] value The value
1256 * \return The Time
1257 * @{
1258 */
1259inline Time
1260Years(double value)
1261{
1262 return Time::FromDouble(value, Time::Y);
1263}
1264
1265inline Time
1267{
1268 return Time::From(value, Time::Y);
1269}
1270
1271inline Time
1272Days(double value)
1273{
1274 return Time::FromDouble(value, Time::D);
1275}
1276
1277inline Time
1279{
1280 return Time::From(value, Time::D);
1281}
1282
1283inline Time
1284Hours(double value)
1285{
1286 return Time::FromDouble(value, Time::H);
1287}
1288
1289inline Time
1291{
1292 return Time::From(value, Time::H);
1293}
1294
1295inline Time
1296Minutes(double value)
1297{
1298 return Time::FromDouble(value, Time::MIN);
1299}
1300
1301inline Time
1303{
1304 return Time::From(value, Time::MIN);
1305}
1306
1307inline Time
1308Seconds(double value)
1309{
1310 return Time::FromDouble(value, Time::S);
1311}
1312
1313inline Time
1315{
1316 return Time::From(value, Time::S);
1317}
1318
1319inline Time
1320MilliSeconds(uint64_t value)
1321{
1322 return Time::FromInteger(value, Time::MS);
1323}
1324
1325inline Time
1327{
1328 return Time::From(value, Time::MS);
1329}
1330
1331inline Time
1332MicroSeconds(uint64_t value)
1333{
1334 return Time::FromInteger(value, Time::US);
1335}
1336
1337inline Time
1339{
1340 return Time::From(value, Time::US);
1341}
1342
1343inline Time
1344NanoSeconds(uint64_t value)
1345{
1346 return Time::FromInteger(value, Time::NS);
1347}
1348
1349inline Time
1351{
1352 return Time::From(value, Time::NS);
1353}
1354
1355inline Time
1356PicoSeconds(uint64_t value)
1357{
1358 return Time::FromInteger(value, Time::PS);
1359}
1360
1361inline Time
1363{
1364 return Time::From(value, Time::PS);
1365}
1366
1367inline Time
1368FemtoSeconds(uint64_t value)
1369{
1370 return Time::FromInteger(value, Time::FS);
1371}
1372
1373inline Time
1375{
1376 return Time::From(value, Time::FS);
1377}
1378
1379/**@}*/ // Construct a Time in the indicated unit.
1380
1381/**
1382 * Scheduler interface.
1383 *
1384 * \note This is internal to the Time implementation.
1385 * \param [in] ts The time value, in the current unit.
1386 * \return A Time.
1387 * \relates Time
1388 */
1389inline Time
1390TimeStep(uint64_t ts)
1391{
1392 return Time(ts);
1393}
1394
1397
1398/**
1399 * \ingroup attribute_Time
1400 * Helper to make a Time checker with bounded range.
1401 * Both limits are inclusive
1402 *
1403 * \param [in] min Minimum allowed value.
1404 * \param [in] max Maximum allowed value.
1405 * \return The AttributeChecker
1406 */
1408
1409/**
1410 * \ingroup attribute_Time
1411 * Helper to make an unbounded Time checker.
1412 *
1413 * \return The AttributeChecker
1414 */
1417{
1418 return MakeTimeChecker(Time::Min(), Time::Max());
1419}
1420
1421/**
1422 * \ingroup attribute_Time
1423 * Helper to make a Time checker with a lower bound.
1424 *
1425 * \param [in] min Minimum allowed value.
1426 * \return The AttributeChecker
1427 */
1428inline Ptr<const AttributeChecker>
1430{
1431 return MakeTimeChecker(min, Time::Max());
1432}
1433
1434/**
1435 * \ingroup time
1436 * A Time with attached unit, to facilitate output in that unit.
1437 */
1439{
1440 public:
1441 /**
1442 * Attach a unit to a Time
1443 *
1444 * \param [in] time The time.
1445 * \param [in] unit The unit to use for output
1446 */
1447 TimeWithUnit(const Time time, const Time::Unit unit)
1448 : m_time(time),
1449 m_unit(unit)
1450 {
1451 }
1452
1453 private:
1454 Time m_time; //!< The time
1455 Time::Unit m_unit; //!< The unit to use in output
1456
1457 /**
1458 * Output streamer
1459 * \param [in,out] os The stream.
1460 * \param [in] timeU The Time with desired unit
1461 * \returns The stream.
1462 */
1463 friend std::ostream& operator<<(std::ostream& os, const TimeWithUnit& timeU);
1464
1465}; // class TimeWithUnit
1466
1467/**
1468 * \ingroup time
1469 *
1470 * ns3::TypeNameGet<Time>() specialization.
1471 * \returns The type name as a string.
1472 */
1474
1475/**
1476 * \ingroup time
1477 *
1478 * \brief Helper class to force static initialization
1479 * of Time in each compilation unit, ensuring it is
1480 * initialized before usage.
1481 * This is internal to the Time implementation.
1482 * \relates Time
1483 */
1485{
1486 public:
1487 /** Default constructor calls Time::StaticInit */
1492};
1493
1494static TimeInitializationHelper g_timeInitHelper; ///< Instance of Time static initialization helper
1495
1496} // namespace ns3
1497
1498#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:1109
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:1168
static void ClearMarkedTimes()
Remove all MarkedTimes.
Definition time.cc:285
Time(unsigned long int v)
Construct from a numeric value.
Definition nstime.h:219
static Time From(const int64x64_t &value)
Create a Time in the current unit.
Definition nstime.h:470
~Time()
Destructor.
Definition nstime.h:292
int64_t GetMilliSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:397
static Resolution & SetDefaultNsResolution()
Set the default resolution.
Definition time.cc:192
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition time.cc:404
Time(long long int v)
Construct from a numeric value.
Definition nstime.h:201
static void ConvertTimes(const Unit unit)
Convert existing Times to the new unit.
Definition time.cc:365
static Information * PeekInformation(Unit timeUnit)
Get the Information record for timeUnit for the current Resolution.
Definition nstime.h:656
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:567
static Unit GetResolution()
Definition time.cc:397
bool IsStrictlyPositive() const
Exactly equivalent to t > 0.
Definition nstime.h:340
Time & operator=(const Time &o)
Assignment operator.
Definition nstime.h:120
Time TimeStep(uint64_t ts)
Scheduler interface.
Definition nstime.h:1390
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:839
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:1155
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:510
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:875
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:593
friend bool operator<=(const Time &lhs, const Time &rhs)
Less than or equal operator for Time.
Definition nstime.h:863
static MarkedTimes * g_markingTimes
Record of outstanding Time objects which will need conversion when the resolution is set.
Definition nstime.h:711
int64_t m_data
Virtual time value, in the current unit.
Definition nstime.h:815
friend Time Rem(const Time &lhs, const Time &rhs)
Addition operator for Time.
Definition nstime.h:1115
static Resolution * PeekResolution()
Get the current Resolution.
Definition nstime.h:644
friend int64_t Div(const Time &lhs, const Time &rhs)
Integer quotient from dividing two Times.
Definition nstime.h:1143
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:887
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:851
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:544
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:505
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:952
friend Time operator+(const Time &lhs, const Time &rhs)
Addition operator for Time.
Definition nstime.h:940
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:964
double ToDouble(Unit unit) const
Get the Time value expressed in a particular unit.
Definition nstime.h:562
friend bool operator>(const Time &lhs, const Time &rhs)
Greater than operator for Time.
Definition nstime.h:899
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:1180
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:1048
std::set< Time * > MarkedTimes
Record all instances of Time, so we can rescale them when the resolution changes.
Definition nstime.h:696
Helper class to force static initialization of Time in each compilation unit, ensuring it is initiali...
Definition nstime.h:1485
TimeInitializationHelper()
Default constructor calls Time::StaticInit.
Definition nstime.h:1488
A Time with attached unit, to facilitate output in that unit.
Definition nstime.h:1439
friend std::ostream & operator<<(std::ostream &os, const TimeWithUnit &timeU)
Output streamer.
Definition time.cc:417
TimeWithUnit(const Time time, const Time::Unit unit)
Attach a unit to a Time.
Definition nstime.h:1447
Time m_time
The time.
Definition nstime.h:1454
Time::Unit m_unit
The unit to use in output.
Definition nstime.h:1455
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
#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:1332
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1344
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
Time Days(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1272
Time Hours(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1284
Time PicoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1356
Time FemtoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1368
Time Minutes(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1296
Time Years(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1260
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1320
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:1115
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:1109
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:1155
static TimeInitializationHelper g_timeInitHelper
Instance of Time static initialization helper.
Definition nstime.h:1494
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:1168
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Definition nstime.h:1416
How to convert between other units and the current unit.
Definition nstime.h:623
int64_t factor
Ratio of this unit / current unit.
Definition nstime.h:626
bool toMul
Multiply when converting To, otherwise divide.
Definition nstime.h:624
int64x64_t timeFrom
Multiplier to convert from this unit.
Definition nstime.h:628
bool isValid
True if the current unit can be used.
Definition nstime.h:629
bool fromMul
Multiple when converting From, otherwise divide.
Definition nstime.h:625
int64x64_t timeTo
Multiplier to convert to this unit.
Definition nstime.h:627
Current time unit, and conversion info.
Definition nstime.h:634
Time::Unit unit
Current time unit.
Definition nstime.h:636
Information info[LAST]
Conversion info from current unit.
Definition nstime.h:635
ns3::TypeNameGet() function declarations.