A Discrete-Event Network Simulator
API
nstime.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2005,2006 INRIA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 #ifndef TIME_H
21 #define TIME_H
22 
23 #include "assert.h"
24 #include "attribute.h"
25 #include "attribute-helper.h"
26 #include "int64x64.h"
27 #include "unused.h"
28 #include <stdint.h>
29 #include <limits>
30 #include <cmath>
31 #include <ostream>
32 #include <set>
33 
41 namespace ns3 {
42 
43 class TimeWithUnit;
44 
102 class Time
103 {
104 public:
108  enum Unit
109  {
110  Y = 0,
111  D = 1,
112  H = 2,
113  MIN = 3,
114  S = 4,
115  MS = 5,
116  US = 6,
117  NS = 7,
118  PS = 8,
119  FS = 9,
120  LAST = 10
121  };
122 
128  inline Time & operator = (const Time & o)
129  {
130  m_data = o.m_data;
131  return *this;
132  }
134  inline Time ()
135  : m_data ()
136  {
137  if (g_markingTimes)
138  {
139  Mark (this);
140  }
141  }
147  inline Time(const Time & o)
148  : m_data (o.m_data)
149  {
150  if (g_markingTimes)
151  {
152  Mark (this);
153  }
154  }
165  explicit inline Time (double v)
166  : m_data (lround (v))
167  {
168  if (g_markingTimes)
169  {
170  Mark (this);
171  }
172  }
173  explicit inline Time (int v)
174  : m_data (v)
175  {
176  if (g_markingTimes)
177  {
178  Mark (this);
179  }
180  }
181  explicit inline Time (long int v)
182  : m_data (v)
183  {
184  if (g_markingTimes)
185  {
186  Mark (this);
187  }
188  }
189  explicit inline Time (long long int v)
190  : m_data (v)
191  {
192  if (g_markingTimes)
193  {
194  Mark (this);
195  }
196  }
197  explicit inline Time (unsigned int v)
198  : m_data (v)
199  {
200  if (g_markingTimes)
201  {
202  Mark (this);
203  }
204  }
205  explicit inline Time (unsigned long int v)
206  : m_data (v)
207  {
208  if (g_markingTimes)
209  {
210  Mark (this);
211  }
212  }
213  explicit inline Time (unsigned long long int v)
214  : m_data (v)
215  {
216  if (g_markingTimes)
217  {
218  Mark (this);
219  }
220  }
221  explicit inline Time (const int64x64_t & v)
222  : m_data (v.GetHigh ())
223  {
224  if (g_markingTimes)
225  {
226  Mark (this);
227  }
228  }
251  explicit Time (const std::string & s);
252 
254  static Time Min ()
255  {
257  }
259  static Time Max ()
260  {
262  }
263 
265  ~Time ()
266  {
267  if (g_markingTimes)
268  {
269  Clear (this);
270  }
271  }
272 
274  inline bool IsZero (void) const
275  {
276  return m_data == 0;
277  }
279  inline bool IsNegative (void) const
280  {
281  return m_data <= 0;
282  }
284  inline bool IsPositive (void) const
285  {
286  return m_data >= 0;
287  }
289  inline bool IsStrictlyNegative (void) const
290  {
291  return m_data < 0;
292  }
294  inline bool IsStrictlyPositive (void) const
295  {
296  return m_data > 0;
297  }
304  inline int Compare (const Time & o) const
305  {
306  return (m_data < o.m_data) ? -1 : (m_data == o.m_data) ? 0 : 1;
307  }
308 
325  inline double GetYears (void) const
326  {
327  return ToDouble (Time::Y);
328  }
329  inline double GetDays (void) const
330  {
331  return ToDouble (Time::D);
332  }
333  inline double GetHours (void) const
334  {
335  return ToDouble (Time::H);
336  }
337  inline double GetMinutes (void) const
338  {
339  return ToDouble (Time::MIN);
340  }
341  inline double GetSeconds (void) const
342  {
343  return ToDouble (Time::S);
344  }
345  inline int64_t GetMilliSeconds (void) const
346  {
347  return ToInteger (Time::MS);
348  }
349  inline int64_t GetMicroSeconds (void) const
350  {
351  return ToInteger (Time::US);
352  }
353  inline int64_t GetNanoSeconds (void) const
354  {
355  return ToInteger (Time::NS);
356  }
357  inline int64_t GetPicoSeconds (void) const
358  {
359  return ToInteger (Time::PS);
360  }
361  inline int64_t GetFemtoSeconds (void) const
362  {
363  return ToInteger (Time::FS);
364  }
377  inline int64_t GetTimeStep (void) const
378  {
379  return m_data;
380  }
381  inline double GetDouble (void) const
382  {
383  return m_data;
384  }
385  inline int64_t GetInteger (void) const
386  {
387  return GetTimeStep ();
388  }
399  static void SetResolution (enum Unit resolution);
403  static enum Unit GetResolution (void);
404 
405 
412  inline static Time From (const int64x64_t & value)
413  {
414  return Time (value);
415  }
429  inline static Time FromInteger (uint64_t value, enum Unit unit)
430  {
431  struct Information *info = PeekInformation (unit);
432  if (info->fromMul)
433  {
434  value *= info->factor;
435  }
436  else
437  {
438  value /= info->factor;
439  }
440  return Time (value);
441  }
442  inline static Time FromDouble (double value, enum Unit unit)
443  {
444  return From (int64x64_t (value), unit);
445  }
446  inline static Time From (const int64x64_t & value, enum Unit unit)
447  {
448  struct Information *info = PeekInformation (unit);
449  // DO NOT REMOVE this temporary variable. It's here
450  // to work around a compiler bug in gcc 3.4
451  int64x64_t retval = value;
452  if (info->fromMul)
453  {
454  retval *= info->timeFrom;
455  }
456  else
457  {
458  retval.MulByInvert (info->timeFrom);
459  }
460  return Time (retval);
461  }
477  inline int64_t ToInteger (enum Unit unit) const
478  {
479  struct Information *info = PeekInformation (unit);
480  int64_t v = m_data;
481  if (info->toMul)
482  {
483  v *= info->factor;
484  }
485  else
486  {
487  v /= info->factor;
488  }
489  return v;
490  }
491  inline double ToDouble (enum Unit unit) const
492  {
493  return To (unit).GetDouble ();
494  }
495  inline int64x64_t To (enum Unit unit) const
496  {
497  struct Information *info = PeekInformation (unit);
498  int64x64_t retval = int64x64_t (m_data);
499  if (info->toMul)
500  {
501  retval *= info->timeTo;
502  }
503  else
504  {
505  retval.MulByInvert (info->timeTo);
506  }
507  return retval;
508  }
513  inline operator int64x64_t () const
514  {
515  return int64x64_t (m_data);
516  }
517 
518 
532  TimeWithUnit As (const enum Unit unit) const;
533 
534 private:
536  struct Information
537  {
538  bool toMul;
539  bool fromMul;
540  int64_t factor;
543  };
545  struct Resolution
546  {
549  };
550 
556  static inline struct Resolution *PeekResolution (void)
557  {
558  static struct Time::Resolution resolution = SetDefaultNsResolution ();
559  return & resolution;
560  }
567  static inline struct Information *PeekInformation (enum Unit timeUnit)
568  {
569  return & (PeekResolution ()->info[timeUnit]);
570  }
571 
577  static struct Resolution SetDefaultNsResolution (void);
585  static void SetResolution (enum Unit unit, struct Resolution *resolution,
586  const bool convert = true);
587 
607  typedef std::set< Time * > MarkedTimes;
622  static MarkedTimes * g_markingTimes;
623 public:
629  static bool StaticInit ();
630 private:
631 
632  /* Friend the Simulator class so it can call the private function
633  ClearMarkedTimes ()
634  */
635  friend class Simulator;
642  static void ClearMarkedTimes ();
647  static void Mark (Time * const time);
652  static void Clear (Time * const time);
657  static void ConvertTimes (const enum Unit unit);
658 
659  /*
660  * \name Arithmetic Operators
661  * Arithmetic operators between Times, and scaling by scalars.
662  */
670  friend bool operator == (const Time & lhs, const Time & rhs);
671  friend bool operator != (const Time & lhs, const Time & rhs);
672  friend bool operator <= (const Time & lhs, const Time & rhs);
673  friend bool operator >= (const Time & lhs, const Time & rhs);
674  friend bool operator < (const Time & lhs, const Time & rhs);
675  friend bool operator > (const Time & lhs, const Time & rhs);
676  friend Time operator + (const Time & lhs, const Time & rhs);
677  friend Time operator - (const Time & lhs, const Time & rhs);
678  friend Time operator * (const Time & lhs, const int64_t & rhs);
679  friend Time operator * (const int64_t & lhs, const Time & rhs);
680  friend int64_t operator / (const Time & lhs, const Time & rhs);
681  friend Time operator / (const Time & lhs, const int64_t & rhs);
682  friend Time & operator += (Time & lhs, const Time & rhs);
683  friend Time & operator -= (Time & lhs, const Time & rhs);
691  friend Time Abs (const Time & time);
698  friend Time Max (const Time & ta, const Time & tb);
705  friend Time Min (const Time & ta, const Time & tb);
706 
707  int64_t m_data;
708 
709 }; // class Time
710 
711 namespace TracedValueCallback {
712 
719  typedef void (* Time)(Time oldValue, Time newValue);
720 
721 } // namespace TracedValueCallback
722 
724 static bool NS_UNUSED_GLOBAL (g_TimeStaticInit) = Time::StaticInit ();
725 
726 inline bool
727 operator == (const Time & lhs, const Time & rhs)
728 {
729  return lhs.m_data == rhs.m_data;
730 }
731 inline bool
732 operator != (const Time & lhs, const Time & rhs)
733 {
734  return lhs.m_data != rhs.m_data;
735 }
736 inline bool
737 operator <= (const Time & lhs, const Time & rhs)
738 {
739  return lhs.m_data <= rhs.m_data;
740 }
741 inline bool
742 operator >= (const Time & lhs, const Time & rhs)
743 {
744  return lhs.m_data >= rhs.m_data;
745 }
746 inline bool
747 operator < (const Time & lhs, const Time & rhs)
748 {
749  return lhs.m_data < rhs.m_data;
750 }
751 inline bool
752 operator > (const Time & lhs, const Time & rhs)
753 {
754  return lhs.m_data > rhs.m_data;
755 }
756 inline Time operator + (const Time & lhs, const Time & rhs)
757 {
758  return Time (lhs.m_data + rhs.m_data);
759 }
760 inline Time operator - (const Time & lhs, const Time & rhs)
761 {
762  return Time (lhs.m_data - rhs.m_data);
763 }
764 inline Time
765 operator * (const Time & lhs, const int64_t & rhs)
766 {
767  Time res = lhs;
768  res.m_data *= rhs;
769  return res;
770 }
771 inline Time
772 operator * (const int64_t & lhs, const Time & rhs)
773 {
774  Time res = rhs;
775  res.m_data *= lhs;
776  return res;
777 }
778 inline int64_t
779 operator / (const Time & lhs, const Time & rhs)
780 {
781  int64_t res = lhs.m_data / rhs.m_data;
782  return res;
783 }
784 inline Time
785 operator / (const Time & lhs, const int64_t & rhs)
786 {
787  Time res = lhs;
788  res.m_data /= rhs;
789  return res;
790 }
791 inline Time & operator += (Time & lhs, const Time & rhs)
792 {
793  lhs.m_data += rhs.m_data;
794  return lhs;
795 }
796 inline Time & operator -= (Time & lhs, const Time & rhs)
797 {
798  lhs.m_data -= rhs.m_data;
799  return lhs;
800 }
803 inline Time Abs (const Time & time)
804 {
805  return Time ((time.m_data < 0) ? -time.m_data : time.m_data);
806 }
807 inline Time Max (const Time & ta, const Time & tb)
808 {
809  return Time ((ta.m_data < tb.m_data) ? tb : ta);
810 }
811 inline Time Min (const Time & ta, const Time & tb)
812 {
813  return Time ((ta.m_data > tb.m_data) ? tb : ta);
814 }
815 
832 std::ostream & operator << (std::ostream & os, const Time & time);
843 std::istream & operator >> (std::istream & is, Time & time);
844 
863 inline Time Years (double value)
864 {
865  return Time::FromDouble (value, Time::Y);
866 }
867 inline Time Years (int64x64_t value)
868 {
869  return Time::From (value, Time::Y);
870 }
871 inline Time Days (double value)
872 {
873  return Time::FromDouble (value, Time::D);
874 }
875 inline Time Days (int64x64_t value)
876 {
877  return Time::From (value, Time::D);
878 }
879 inline Time Hours (double value)
880 {
881  return Time::FromDouble (value, Time::H);
882 }
883 inline Time Hours (int64x64_t value)
884 {
885  return Time::From (value, Time::H);
886 }
887 inline Time Minutes (double value)
888 {
889  return Time::FromDouble (value, Time::MIN);
890 }
891 inline Time Minutes (int64x64_t value)
892 {
893  return Time::From (value, Time::MIN);
894 }
895 inline Time Seconds (double value)
896 {
897  return Time::FromDouble (value, Time::S);
898 }
899 inline Time Seconds (int64x64_t value)
900 {
901  return Time::From (value, Time::S);
902 }
903 inline Time MilliSeconds (uint64_t value)
904 {
905  return Time::FromInteger (value, Time::MS);
906 }
908 {
909  return Time::From (value, Time::MS);
910 }
911 inline Time MicroSeconds (uint64_t value)
912 {
913  return Time::FromInteger (value, Time::US);
914 }
916 {
917  return Time::From (value, Time::US);
918 }
919 inline Time NanoSeconds (uint64_t value)
920 {
921  return Time::FromInteger (value, Time::NS);
922 }
924 {
925  return Time::From (value, Time::NS);
926 }
927 inline Time PicoSeconds (uint64_t value)
928 {
929  return Time::FromInteger (value, Time::PS);
930 }
932 {
933  return Time::From (value, Time::PS);
934 }
935 inline Time FemtoSeconds (uint64_t value)
936 {
937  return Time::FromInteger (value, Time::FS);
938 }
940 {
941  return Time::From (value, Time::FS);
942 }
952 inline Time TimeStep (uint64_t ts)
953 {
954  return Time (ts);
955 }
956 
959 
970 
977 inline
979 {
980  return MakeTimeChecker (Time::Min (), Time::Max ());
981 }
982 
990 inline
992 {
993  return MakeTimeChecker (min, Time::Max ());
994 }
995 
1001 {
1002 public:
1009  TimeWithUnit (const Time time, const Time::Unit unit)
1010  : m_time (time),
1011  m_unit (unit)
1012  { };
1013 
1014 private:
1015  Time m_time;
1017 
1024  friend std::ostream & operator << (std::ostream & os, const TimeWithUnit & timeU);
1025 
1026 }; // class TimeWithUnit
1027 
1028 } // namespace ns3
1029 
1030 #endif /* TIME_H */
static struct Resolution * PeekResolution(void)
Get the current Resolution.
Definition: nstime.h:556
Unit
The unit to use to interpret a number representing time.
Definition: nstime.h:108
std::istream & operator>>(std::istream &is, Angles &a)
initialize a struct Angles from input
Definition: angles.cc:48
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
bool IsPositive(void) const
Definition: nstime.h:284
Control the scheduling of simulation events.
Definition: simulator.h:68
int64x64_t operator+(const int64x64_t &lhs)
Unary plus operator.
Definition: int64x64-128.h:410
friend Time operator*(const Time &lhs, const int64_t &rhs)
Arithmetic operator.
Definition: nstime.h:765
int64x64_t timeFrom
Multiplier to convert from this unit.
Definition: nstime.h:542
static Time Min()
Minimum representable Time.
Definition: nstime.h:254
A Time with attached unit, to facilitate output in that unit.
Definition: nstime.h:1000
int64_t ToInteger(enum Unit unit) const
Get the Time value expressed in a particular unit.
Definition: nstime.h:477
#define min(a, b)
Definition: 80211b.c:44
High precision numerical type, implementing Q64.64 fixed precision.
Definition: int64x64-128.h:45
bool IsZero(void) const
Definition: nstime.h:274
friend bool operator<(const Time &lhs, const Time &rhs)
Arithmetic operator.
Definition: nstime.h:747
friend bool operator!=(const Time &lhs, const Time &rhs)
Arithmetic operator.
Definition: nstime.h:732
int64x64_t operator-(const int64x64_t &lhs)
Unary negation operator (change sign operator).
Definition: int64x64-128.h:418
static Time From(const int64x64_t &value)
Create a Time in the current unit.
Definition: nstime.h:412
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:903
second
Definition: nstime.h:114
#define ATTRIBUTE_VALUE_DEFINE(Name)
Declare the attribute value class Value for the class Name.
int64x64_t & operator+=(int64x64_t &lhs, const int64x64_t &rhs)
Compound addition operator.
Definition: int64x64-128.h:373
void MulByInvert(const int64x64_t &o)
Multiply this value by a Q0.128 value, presumably representing an inverse, completing a division oper...
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Definition: nstime.h:719
int64_t GetFemtoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:361
double GetDouble(void) const
Get this value as a double.
Definition: int64x64-128.h:203
Time(unsigned long int v)
Construct from a numeric value.
Definition: nstime.h:205
Time(const int64x64_t &v)
Construct from a numeric value.
Definition: nstime.h:221
bool operator>=(const int64x64_t &lhs, const int64x64_t &rhs)
Greater or equal operator.
Definition: int64x64.h:145
int Compare(const Time &o) const
Compare this to another Time.
Definition: nstime.h:304
millisecond
Definition: nstime.h:115
hour, 60 minutes
Definition: nstime.h:112
friend Time operator-(const Time &lhs, const Time &rhs)
Arithmetic operator.
Definition: nstime.h:760
int64x64_t To(enum Unit unit) const
Get the Time value expressed in a particular unit.
Definition: nstime.h:495
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:446
Time PicoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:927
struct Information info[LAST]
Conversion info from current unit.
Definition: nstime.h:547
static bool NS_UNUSED_GLOBAL(g_TimeStaticInit)
Force static initialization of Time.
day, 24 hours
Definition: nstime.h:111
friend Time operator+(const Time &lhs, const Time &rhs)
Arithmetic operator.
Definition: nstime.h:756
static Time Max()
Maximum representable Time.
Definition: nstime.h:259
friend Time Abs(const Time &time)
Absolute value function for Time.
Definition: nstime.h:803
bool operator<=(const int64x64_t &lhs, const int64x64_t &rhs)
Less or equal operator.
Definition: int64x64.h:137
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:341
int64x64_t operator*(const int64x64_t &lhs, const int64x64_t &rhs)
Multiplication operator.
Definition: int64x64.h:108
int64x64_t Min(const int64x64_t &a, const int64x64_t &b)
Minimum.
Definition: int64x64.h:197
Time(int v)
Construct from a numeric value.
Definition: nstime.h:173
Time Years(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:863
#define max(a, b)
Definition: 80211b.c:45
static enum Unit GetResolution(void)
Definition: time.cc:380
int64_t GetMicroSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:349
friend Time & operator-=(Time &lhs, const Time &rhs)
Arithmetic operator.
Definition: nstime.h:796
Time(long long int v)
Construct from a numeric value.
Definition: nstime.h:189
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:919
Current time unit, and conversion info.
Definition: nstime.h:545
static bool StaticInit()
Function to force static initialization of Time.
Definition: time.cc:63
Definition of assertion macros NS_ASSERT() and NS_ASSERT_MSG().
bool IsStrictlyPositive(void) const
Definition: nstime.h:294
bool fromMul
Multiple when converting From, otherwise divide.
Definition: nstime.h:539
friend std::ostream & operator<<(std::ostream &os, const TimeWithUnit &timeU)
Output streamer.
Definition: time.cc:403
static Time From(const int64x64_t &value, enum Unit unit)
Create a Time equal to value in unit unit.
Definition: nstime.h:446
double ToDouble(enum Unit unit) const
Get the Time value expressed in a particular unit.
Definition: nstime.h:491
ns3::AttributeValue, ns3::AttributeAccessor and ns3::AttributeChecker declarations.
int64x64_t Max(const int64x64_t &a, const int64x64_t &b)
Maximum.
Definition: int64x64.h:209
year, 365 days
Definition: nstime.h:110
static void ConvertTimes(const enum Unit unit)
Convert existing Times to the new unit.
Definition: time.cc:343
friend bool operator>=(const Time &lhs, const Time &rhs)
Arithmetic operator.
Definition: nstime.h:742
minute, 60 seconds
Definition: nstime.h:113
Time(long int v)
Construct from a numeric value.
Definition: nstime.h:181
static struct Resolution SetDefaultNsResolution(void)
Set the default resolution.
Definition: time.cc:170
femtosecond
Definition: nstime.h:119
int64_t factor
Ratio of this unit / current unit.
Definition: nstime.h:540
bool operator<(const int64x64_t &lhs, const int64x64_t &rhs)
Less than operator.
Definition: int64x64-128.h:356
int64x64_t operator/(const int64x64_t &lhs, const int64x64_t &rhs)
Division operator.
Definition: int64x64.h:119
int64x64_t Abs(const int64x64_t &value)
Absolute value.
Definition: int64x64.h:184
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:42
Time(double v)
Construct from a numeric value.
Definition: nstime.h:165
bool operator!=(Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 > a, Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 > b)
Inequality test.
Definition: callback.h:1471
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Time(unsigned long long int v)
Construct from a numeric value.
Definition: nstime.h:213
friend Time & operator+=(Time &lhs, const Time &rhs)
Arithmetic operator.
Definition: nstime.h:791
friend bool operator==(const Time &lhs, const Time &rhs)
Arithmetic operator.
Definition: nstime.h:727
bool IsNegative(void) const
Definition: nstime.h:279
int64_t GetTimeStep(void) const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:377
friend int64_t operator/(const Time &lhs, const Time &rhs)
Arithmetic operator.
Definition: nstime.h:779
Time Hours(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:879
Time TimeStep(uint64_t ts)
Definition: nstime.h:952
double GetHours(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:333
Time()
Default constructor, with value 0.
Definition: nstime.h:134
int64_t GetInteger(void) const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:385
~Time()
Destructor.
Definition: nstime.h:265
double GetDouble(void) const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:381
static struct Information * PeekInformation(enum Unit timeUnit)
Get the Information record for timeUnit for the current Resolution.
Definition: nstime.h:567
Declaration of Attribute helper macros.
Time Minutes(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:887
int64_t GetNanoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:353
static Time FromDouble(double value, enum Unit unit)
Create a Time equal to value in unit unit.
Definition: nstime.h:442
#define ATTRIBUTE_ACCESSOR_DEFINE(type)
Define the attribute accessor functions MakeTypeAccessor for class type.
Time(unsigned int v)
Construct from a numeric value.
Definition: nstime.h:197
static void Mark(Time *const time)
Record a Time instance with the MarkedTimes.
Definition: time.cc:287
microsecond
Definition: nstime.h:116
friend bool operator>(const Time &lhs, const Time &rhs)
Arithmetic operator.
Definition: nstime.h:752
int64_t GetPicoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:357
TimeWithUnit As(const enum Unit unit) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:388
How to convert between other units and the current unit.
Definition: nstime.h:536
static Time FromInteger(uint64_t value, enum Unit unit)
Create a Time equal to value in unit unit.
Definition: nstime.h:429
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
double GetDays(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:329
bool operator>(const int64x64_t &lhs, const int64x64_t &rhs)
Greater operator.
Definition: int64x64-128.h:364
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.cc:95
enum Time::Unit unit
Current time unit.
Definition: nstime.h:548
Time::Unit m_unit
The unit to use in output.
Definition: nstime.h:1016
bool IsStrictlyNegative(void) const
Definition: nstime.h:289
static void SetResolution(enum Unit resolution)
Definition: time.cc:180
static void Clear(Time *const time)
Remove a Time instance from the MarkedTimes, called by ~Time().
Definition: time.cc:313
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:911
TimeWithUnit(const Time time, const Time::Unit unit)
Attach a unit to a Time.
Definition: nstime.h:1009
picosecond
Definition: nstime.h:118
nanosecond
Definition: nstime.h:117
std::set< Time * > MarkedTimes
Record all instances of Time, so we can rescale them when the resolution changes. ...
Definition: nstime.h:607
static MarkedTimes * g_markingTimes
Record of outstanding Time objects which will need conversion when the resolution is set...
Definition: nstime.h:622
Time Days(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:871
Time FemtoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:935
double GetYears(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:325
static void ClearMarkedTimes()
Remove all MarkedTimes.
Definition: time.cc:256
friend bool operator<=(const Time &lhs, const Time &rhs)
Arithmetic operator.
Definition: nstime.h:737
int64_t GetMilliSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:345
Declaration of the ns3::int64x64_t type and associated operators.
double GetMinutes(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:337
Time & operator=(const Time &o)
Assignment operator.
Definition: nstime.h:128
Time m_time
The time.
Definition: nstime.h:1012
int64x64_t timeTo
Multiplier to convert to this unit.
Definition: nstime.h:541
Time(const Time &o)
Copy constructor.
Definition: nstime.h:147
int64_t m_data
Virtual time value, in the current unit.
Definition: nstime.h:707
bool toMul
Multiply when converting To, otherwise divide.
Definition: nstime.h:538
int64x64_t & operator-=(int64x64_t &lhs, const int64x64_t &rhs)
Compound subtraction operator.
Definition: int64x64-128.h:382
Definition of the NS_UNUSED NS_UNUSED_GLOBAL macros.