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