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