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