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 * Equality operator for Time.
845 * \param [in] lhs The first value
846 * \param [in] rhs The second value
847 * \returns \c true if the two input values are equal.
848 */
849inline bool
850operator==(const Time& lhs, const Time& rhs)
851{
852 return lhs.m_data == rhs.m_data;
853}
854
855/**
856 * Inequality operator for Time.
857 * \param [in] lhs The first value
858 * \param [in] rhs The second value
859 * \returns \c true if the two input values not are equal.
860 */
861inline bool
862operator!=(const Time& lhs, const Time& rhs)
863{
864 return lhs.m_data != rhs.m_data;
865}
866
867/**
868 * Less than or equal operator for Time.
869 * \param [in] lhs The first value
870 * \param [in] rhs The second value
871 * \returns \c true if the first input value is less than or equal to the second input value.
872 */
873inline bool
874operator<=(const Time& lhs, const Time& rhs)
875{
876 return lhs.m_data <= rhs.m_data;
877}
878
879/**
880 * Greater than or equal operator for Time.
881 * \param [in] lhs The first value
882 * \param [in] rhs The second value
883 * \returns \c true if the first input value is greater than or equal to the second input value.
884 */
885inline bool
886operator>=(const Time& lhs, const Time& rhs)
887{
888 return lhs.m_data >= rhs.m_data;
889}
890
891/**
892 * Less than operator for Time.
893 * \param [in] lhs The first value
894 * \param [in] rhs The second value
895 * \returns \c true if the first input value is less than the second input value.
896 */
897inline bool
898operator<(const Time& lhs, const Time& rhs)
899{
900 return lhs.m_data < rhs.m_data;
901}
902
903/**
904 * Greater than operator for Time.
905 * \param [in] lhs The first value
906 * \param [in] rhs The second value
907 * \returns \c true if the first input value is greater than the second input value.
908 */
909inline bool
910operator>(const Time& lhs, const Time& rhs)
911{
912 return lhs.m_data > rhs.m_data;
913}
914
915/**
916 * Compare a Time to an EventId.
917 *
918 * This is useful when you have cached a previously scheduled event:
919 *
920 * m_event = Schedule (...);
921 *
922 * and later you want to know the relationship between that event
923 * and some other Time `when`:
924 *
925 * if (when < m_event) ...
926 *
927 * \param [in] time The Time operand.
928 * \param [in] event The EventId
929 * \returns \c true if \p time is before (less than) the
930 * time stamp of the EventId.
931 */
932inline bool
933operator<(const Time& time, const EventId& event)
934{
935 // Negative Time is less than any possible EventId, which are all >= 0.
936 if (time.m_data < 0)
937 {
938 return true;
939 }
940 // Time must be >= 0 so casting to unsigned is safe.
941 return static_cast<uint64_t>(time.m_data) < event.GetTs();
942}
943
944/**
945 * Addition operator for Time.
946 * \param [in] lhs The first value
947 * \param [in] rhs The second value
948 * \returns The sum of the two input values.
949 */
950inline Time
951operator+(const Time& lhs, const Time& rhs)
952{
953 return Time(lhs.m_data + rhs.m_data);
954}
955
956/**
957 * Subtraction operator for Time.
958 * \param [in] lhs The first value
959 * \param [in] rhs The second value
960 * \returns The difference of the two input values.
961 */
962inline Time
963operator-(const Time& lhs, const Time& rhs)
964{
965 return Time(lhs.m_data - rhs.m_data);
966}
967
968/**
969 * Scale a Time by a numeric value.
970 * \param [in] lhs The first value
971 * \param [in] rhs The second value
972 * \returns The Time scaled by the other operand.
973 */
974inline Time
975operator*(const Time& lhs, const int64x64_t& rhs)
976{
977 int64x64_t res = lhs.m_data;
978 res *= rhs;
979 return Time(res);
980}
981
982/**
983 * Scale a Time by a numeric value.
984 * \param [in] lhs The first value
985 * \param [in] rhs The second value
986 * \returns The Time scaled by the other operand.
987 */
988inline Time
989operator*(const int64x64_t& lhs, const Time& rhs)
990{
991 return rhs * lhs;
992}
993
994/**
995 * Scale a Time by an integer value.
996 *
997 * \tparam T Integer data type (int, long, etc.)
998 *
999 * \param [in] lhs The Time instance to scale
1000 * \param [in] rhs The scale value
1001 * \returns A new Time instance containing the scaled value
1002 */
1003template <class T>
1004std::enable_if_t<std::is_integral_v<T>, Time>
1005operator*(const Time& lhs, T rhs)
1006{
1007 static_assert(!std::is_same_v<T, bool>, "Multiplying a Time by a boolean is not supported");
1008
1009 return Time(lhs.m_data * rhs);
1010}
1011
1012// Leave undocumented
1013template <class T>
1014std::enable_if_t<std::is_floating_point_v<T>, Time>
1015operator*(const Time& lhs, T rhs)
1016{
1017 return lhs * int64x64_t(rhs);
1018}
1019
1020/**
1021 * Scale a Time by a numeric value.
1022 *
1023 * This overload handles the case where the scale value comes before the Time
1024 * value. It swaps the arguments so that the Time argument comes first
1025 * and calls the appropriate overload of operator*
1026 *
1027 * \tparam T Arithmetic data type (int, long, float, etc.)
1028 *
1029 * \param [in] lhs The scale value
1030 * \param [in] rhs The Time instance to scale
1031 * \returns A new Time instance containing the scaled value
1032 */
1033template <class T>
1034std::enable_if_t<std::is_arithmetic_v<T>, Time>
1035operator*(T lhs, const Time& rhs)
1036{
1037 return rhs * lhs;
1038}
1039
1040/**
1041 * Exact division, returning a dimensionless fixed point number.
1042 *
1043 * This can be truncated to integer, or converted to double
1044 * (with loss of precision). Assuming `ta` and `tb` are Times:
1045 *
1046 * \code
1047 * int64x64_t ratio = ta / tb;
1048 *
1049 * int64_t i = ratio.GetHigh (); // Get just the integer part, resulting in truncation
1050 *
1051 * double ratioD = double (ratio); // Convert to double, with loss of precision
1052 * \endcode
1053 *
1054 * \param [in] lhs The first value
1055 * \param [in] rhs The second value
1056 * \returns The exact ratio of the two operands.
1057 */
1058inline int64x64_t
1059operator/(const Time& lhs, const Time& rhs)
1060{
1061 int64x64_t num = lhs.m_data;
1062 int64x64_t den = rhs.m_data;
1063 return num / den;
1064}
1065
1066/**
1067 * Scale a Time by a numeric value.
1068 * \param [in] lhs The first value
1069 * \param [in] rhs The second value
1070 * \returns The Time divided by the scalar operand.
1071 */
1072inline Time
1073operator/(const Time& lhs, const int64x64_t& rhs)
1074{
1075 int64x64_t res = lhs.m_data;
1076 res /= rhs;
1077 return Time(res);
1078}
1079
1080/**
1081 * Divide a Time by an integer value.
1082 *
1083 * \tparam T Integer data type (int, long, etc.)
1084 *
1085 * \param [in] lhs The Time instance to scale
1086 * \param [in] rhs The scale value
1087 * \returns A new Time instance containing the scaled value
1088 */
1089template <class T>
1090std::enable_if_t<std::is_integral_v<T>, Time>
1091operator/(const Time& lhs, T rhs)
1092{
1093 static_assert(!std::is_same_v<T, bool>, "Dividing a Time by a boolean is not supported");
1094
1095 return Time(lhs.m_data / rhs);
1096}
1097
1098// Leave undocumented
1099template <class T>
1100std::enable_if_t<std::is_floating_point_v<T>, Time>
1101operator/(const Time& lhs, T rhs)
1102{
1103 return lhs / int64x64_t(rhs);
1104}
1105
1106/**
1107 * Remainder (modulus) from the quotient of two Times.
1108 *
1109 * Rem() and operator% are equivalent:
1110 *
1111 * Rem (ta, tb) == ta % tb;
1112 *
1113 * \see Div()
1114 * \param [in] lhs The first time value
1115 * \param [in] rhs The second time value
1116 * \returns The remainder of `lhs / rhs`.
1117 * @{
1118 */
1119inline Time
1120operator%(const Time& lhs, const Time& rhs)
1121{
1122 return Time(lhs.m_data % rhs.m_data);
1123}
1124
1125inline Time
1126Rem(const Time& lhs, const Time& rhs)
1127{
1128 return Time(lhs.m_data % rhs.m_data);
1129}
1130
1131/** @} */
1132
1133/**
1134 * Integer quotient from dividing two Times.
1135 *
1136 * This is the same as the "normal" C++ integer division,
1137 * which truncates (discarding any remainder).
1138 *
1139 * As usual, if `ta`, and `tb` are both Times
1140 *
1141 * \code
1142 * ta == tb * Div (ta, tb) + Rem (ta, tb);
1143 *
1144 * ta == tb * (ta / tb).GetHigh() + ta % tb;
1145 * \endcode
1146 *
1147 * \param [in] lhs The first value
1148 * \param [in] rhs The second value
1149 * \returns The integer portion of `lhs / rhs`.
1150 *
1151 * \see Rem()
1152 */
1153inline int64_t
1154Div(const Time& lhs, const Time& rhs)
1155{
1156 return lhs.m_data / rhs.m_data;
1157}
1158
1159/**
1160 * Compound addition assignment for Time.
1161 * \param [in] lhs The first value
1162 * \param [in] rhs The second value
1163 * \returns The sum of the two inputs.
1164 */
1165inline Time&
1166operator+=(Time& lhs, const Time& rhs)
1167{
1168 lhs.m_data += rhs.m_data;
1169 return lhs;
1170}
1171
1172/**
1173 * Compound subtraction assignment for Time.
1174 * \param [in] lhs The first value
1175 * \param [in] rhs The second value
1176 * \returns The difference of the two operands.
1177 */
1178inline Time&
1179operator-=(Time& lhs, const Time& rhs)
1180{
1181 lhs.m_data -= rhs.m_data;
1182 return lhs;
1183}
1184
1185/**
1186 * Absolute value for Time.
1187 * \param [in] time The Time value
1188 * \returns The absolute value of the input.
1189 */
1190inline Time
1191Abs(const Time& time)
1192{
1193 return Time((time.m_data < 0) ? -time.m_data : time.m_data);
1194}
1195
1196/**
1197 * Maximum of two Times.
1198 * \param [in] timeA The first value
1199 * \param [in] timeB The second value
1200 * \returns The larger of the two operands.
1201 */
1202inline Time
1203Max(const Time& timeA, const Time& timeB)
1204{
1205 return Time((timeA.m_data < timeB.m_data) ? timeB : timeA);
1206}
1207
1208/**
1209 * Minimum of two Times.
1210 * \param [in] timeA The first value
1211 * \param [in] timeB The second value
1212 * \returns The smaller of the two operands.
1213 */
1214inline Time
1215Min(const Time& timeA, const Time& timeB)
1216{
1217 return Time((timeA.m_data > timeB.m_data) ? timeB : timeA);
1218}
1219
1220/**
1221 * Time output streamer.
1222 *
1223 * Generates output such as "396.0ns".
1224 *
1225 * For historical reasons Times are printed with the
1226 * following format flags (independent of the stream flags):
1227 * - `showpos`
1228 * - `fixed`
1229 * - `left`
1230 *
1231 * The stream `width` and `precision` are ignored; Time output always
1232 * includes ".0".
1233 *
1234 * \see As() for more flexible output formatting.
1235 *
1236 * \param [in,out] os The output stream.
1237 * \param [in] time The Time to put on the stream.
1238 * \return The stream.
1239 */
1240std::ostream& operator<<(std::ostream& os, const Time& time);
1241/**
1242 * Time input streamer
1243 *
1244 * Uses the Time(const std::string &) constructor
1245 *
1246 * \param [in,out] is The input stream.
1247 * \param [out] time The Time variable to set from the stream data.
1248 * \return The stream.
1249 */
1250std::istream& operator>>(std::istream& is, Time& time);
1251
1252/**
1253 * \ingroup time
1254 * \defgroup timecivil Standard Time Units.
1255 * Convenience constructors in standard units.
1256 *
1257 * For example:
1258 * \code
1259 * Time t = Seconds (2.0);
1260 * Simulator::Schedule (Seconds (5.0), ...);
1261 * \endcode
1262 */
1263/**
1264 * \ingroup timecivil
1265 * Construct a Time in the indicated unit.
1266 * \param [in] value The value
1267 * \return The Time
1268 * @{
1269 */
1270inline Time
1271Years(double value)
1272{
1273 return Time::FromDouble(value, Time::Y);
1274}
1275
1276inline Time
1278{
1279 return Time::From(value, Time::Y);
1280}
1281
1282inline Time
1283Days(double value)
1284{
1285 return Time::FromDouble(value, Time::D);
1286}
1287
1288inline Time
1290{
1291 return Time::From(value, Time::D);
1292}
1293
1294inline Time
1295Hours(double value)
1296{
1297 return Time::FromDouble(value, Time::H);
1298}
1299
1300inline Time
1302{
1303 return Time::From(value, Time::H);
1304}
1305
1306inline Time
1307Minutes(double value)
1308{
1309 return Time::FromDouble(value, Time::MIN);
1310}
1311
1312inline Time
1314{
1315 return Time::From(value, Time::MIN);
1316}
1317
1318inline Time
1319Seconds(double value)
1320{
1321 return Time::FromDouble(value, Time::S);
1322}
1323
1324inline Time
1326{
1327 return Time::From(value, Time::S);
1328}
1329
1330inline Time
1331MilliSeconds(uint64_t value)
1332{
1333 return Time::FromInteger(value, Time::MS);
1334}
1335
1336inline Time
1338{
1339 return Time::From(value, Time::MS);
1340}
1341
1342inline Time
1343MicroSeconds(uint64_t value)
1344{
1345 return Time::FromInteger(value, Time::US);
1346}
1347
1348inline Time
1350{
1351 return Time::From(value, Time::US);
1352}
1353
1354inline Time
1355NanoSeconds(uint64_t value)
1356{
1357 return Time::FromInteger(value, Time::NS);
1358}
1359
1360inline Time
1362{
1363 return Time::From(value, Time::NS);
1364}
1365
1366inline Time
1367PicoSeconds(uint64_t value)
1368{
1369 return Time::FromInteger(value, Time::PS);
1370}
1371
1372inline Time
1374{
1375 return Time::From(value, Time::PS);
1376}
1377
1378inline Time
1379FemtoSeconds(uint64_t value)
1380{
1381 return Time::FromInteger(value, Time::FS);
1382}
1383
1384inline Time
1386{
1387 return Time::From(value, Time::FS);
1388}
1389
1390/**@}*/ // Construct a Time in the indicated unit.
1391
1392/**
1393 * Scheduler interface.
1394 *
1395 * \note This is internal to the Time implementation.
1396 * \param [in] ts The time value, in the current unit.
1397 * \return A Time.
1398 * \relates Time
1399 */
1400inline Time
1401TimeStep(uint64_t ts)
1402{
1403 return Time(ts);
1404}
1405
1408
1409/**
1410 * \ingroup attribute_Time
1411 * Helper to make a Time checker with bounded range.
1412 * Both limits are inclusive
1413 *
1414 * \param [in] min Minimum allowed value.
1415 * \param [in] max Maximum allowed value.
1416 * \return The AttributeChecker
1417 */
1419
1420/**
1421 * \ingroup attribute_Time
1422 * Helper to make an unbounded Time checker.
1423 *
1424 * \return The AttributeChecker
1425 */
1428{
1429 return MakeTimeChecker(Time::Min(), Time::Max());
1430}
1431
1432/**
1433 * \ingroup attribute_Time
1434 * Helper to make a Time checker with a lower bound.
1435 *
1436 * \param [in] min Minimum allowed value.
1437 * \return The AttributeChecker
1438 */
1439inline Ptr<const AttributeChecker>
1441{
1442 return MakeTimeChecker(min, Time::Max());
1443}
1444
1445/**
1446 * \ingroup time
1447 * A Time with attached unit, to facilitate output in that unit.
1448 */
1450{
1451 public:
1452 /**
1453 * Attach a unit to a Time
1454 *
1455 * \param [in] time The time.
1456 * \param [in] unit The unit to use for output
1457 */
1458 TimeWithUnit(const Time time, const Time::Unit unit)
1459 : m_time(time),
1460 m_unit(unit)
1461 {
1462 }
1463
1464 private:
1465 Time m_time; //!< The time
1466 Time::Unit m_unit; //!< The unit to use in output
1467
1468 /**
1469 * Output streamer
1470 * \param [in,out] os The stream.
1471 * \param [in] timeU The Time with desired unit
1472 * \returns The stream.
1473 */
1474 friend std::ostream& operator<<(std::ostream& os, const TimeWithUnit& timeU);
1475
1476}; // class TimeWithUnit
1477
1478/**
1479 * \ingroup time
1480 *
1481 * ns3::TypeNameGet<Time>() specialization.
1482 * \returns The type name as a string.
1483 */
1485
1486/**
1487 * \ingroup time
1488 *
1489 * \brief Helper class to force static initialization
1490 * of Time in each compilation unit, ensuring it is
1491 * initialized before usage.
1492 * This is internal to the Time implementation.
1493 * \relates Time
1494 */
1496{
1497 public:
1498 /** Default constructor calls Time::StaticInit */
1500 {
1502 }
1503};
1504
1505static TimeInitializationHelper g_timeInitHelper; ///< Instance of Time static initialization helper
1506
1507} // namespace ns3
1508
1509#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:1120
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:1179
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:1401
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:850
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:1166
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:886
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:874
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:1126
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:1154
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:898
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:862
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:963
friend Time operator+(const Time &lhs, const Time &rhs)
Addition operator for Time.
Definition: nstime.h:951
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:975
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:910
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:1191
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:1059
std::set< Time * > MarkedTimes
Record all instances of Time, so we can rescale them when the resolution changes.
Definition: nstime.h:707
Helper class to force static initialization of Time in each compilation unit, ensuring it is initiali...
Definition: nstime.h:1496
TimeInitializationHelper()
Default constructor calls Time::StaticInit.
Definition: nstime.h:1499
A Time with attached unit, to facilitate output in that unit.
Definition: nstime.h:1450
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:1458
Time m_time
The time.
Definition: nstime.h:1465
Time::Unit m_unit
The unit to use in output.
Definition: nstime.h:1466
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:1427
#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:1343
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1355
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1319
Time Days(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1283
Time Hours(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1295
Time PicoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1367
Time FemtoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1379
Time Minutes(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1307
Time Years(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1271
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1331
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:1126
bool operator!=(Callback< R, Args... > a, Callback< R, Args... > b)
Inequality test.
Definition: callback.h:680
Time operator%(const Time &lhs, const Time &rhs)
Remainder (modulus) from the quotient of two Times.
Definition: nstime.h:1120
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:1166
static TimeInitializationHelper g_timeInitHelper
Instance of Time static initialization helper.
Definition: nstime.h:1505
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:1179
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.