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 "event-id.h"
27 #include "int64x64.h"
28 #include "unused.h"
29 #include <stdint.h>
30 #include <limits>
31 #include <cmath>
32 #include <ostream>
33 #include <set>
34 
42 namespace ns3 {
43 
44 class TimeWithUnit;
45 
103 class Time
104 {
105 public:
109  enum Unit
110  {
111  Y = 0,
112  D = 1,
113  H = 2,
114  MIN = 3,
115  S = 4,
116  MS = 5,
117  US = 6,
118  NS = 7,
119  PS = 8,
120  FS = 9,
121  LAST = 10,
122  AUTO = 11
123  };
124 
130  inline Time & operator = (const Time & o)
131  {
132  m_data = o.m_data;
133  return *this;
134  }
136  inline Time ()
137  : m_data ()
138  {
139  if (g_markingTimes)
140  {
141  Mark (this);
142  }
143  }
149  inline Time (const Time & o)
150  : m_data (o.m_data)
151  {
152  if (g_markingTimes)
153  {
154  Mark (this);
155  }
156  }
157 
163  Time (Time &&o)
164  : m_data (o.m_data)
165  {
166  if (g_markingTimes)
167  {
168  Mark (this);
169  }
170  }
181  explicit inline Time (double v)
182  : m_data (lround (v))
183  {
184  if (g_markingTimes)
185  {
186  Mark (this);
187  }
188  }
189  explicit inline Time (int v)
190  : m_data (v)
191  {
192  if (g_markingTimes)
193  {
194  Mark (this);
195  }
196  }
197  explicit inline Time (long int v)
198  : m_data (v)
199  {
200  if (g_markingTimes)
201  {
202  Mark (this);
203  }
204  }
205  explicit inline Time (long long int v)
206  : m_data (v)
207  {
208  if (g_markingTimes)
209  {
210  Mark (this);
211  }
212  }
213  explicit inline Time (unsigned int v)
214  : m_data (v)
215  {
216  if (g_markingTimes)
217  {
218  Mark (this);
219  }
220  }
221  explicit inline Time (unsigned long int v)
222  : m_data (v)
223  {
224  if (g_markingTimes)
225  {
226  Mark (this);
227  }
228  }
229  explicit inline Time (unsigned long long int v)
230  : m_data (v)
231  {
232  if (g_markingTimes)
233  {
234  Mark (this);
235  }
236  }
237  explicit inline Time (const int64x64_t & v)
238  : m_data (v.Round ())
239  {
240  if (g_markingTimes)
241  {
242  Mark (this);
243  }
244  } // Numeric constructors
246 
267  explicit Time (const std::string & s);
268 
274  static Time Min ()
275  {
277  }
283  static Time Max ()
284  {
286  }
287 
289  ~Time ()
290  {
291  if (g_markingTimes)
292  {
293  Clear (this);
294  }
295  }
296 
301  inline bool IsZero (void) const
302  {
303  return m_data == 0;
304  }
309  inline bool IsNegative (void) const
310  {
311  return m_data <= 0;
312  }
317  inline bool IsPositive (void) const
318  {
319  return m_data >= 0;
320  }
325  inline bool IsStrictlyNegative (void) const
326  {
327  return m_data < 0;
328  }
333  inline bool IsStrictlyPositive (void) const
334  {
335  return m_data > 0;
336  }
343  inline int Compare (const Time & o) const
344  {
345  return (m_data < o.m_data) ? -1 : (m_data == o.m_data) ? 0 : 1;
346  }
347 
364  inline double GetYears (void) const
365  {
366  return ToDouble (Time::Y);
367  }
368  inline double GetDays (void) const
369  {
370  return ToDouble (Time::D);
371  }
372  inline double GetHours (void) const
373  {
374  return ToDouble (Time::H);
375  }
376  inline double GetMinutes (void) const
377  {
378  return ToDouble (Time::MIN);
379  }
380  inline double GetSeconds (void) const
381  {
382  return ToDouble (Time::S);
383  }
384  inline int64_t GetMilliSeconds (void) const
385  {
386  return ToInteger (Time::MS);
387  }
388  inline int64_t GetMicroSeconds (void) const
389  {
390  return ToInteger (Time::US);
391  }
392  inline int64_t GetNanoSeconds (void) const
393  {
394  return ToInteger (Time::NS);
395  }
396  inline int64_t GetPicoSeconds (void) const
397  {
398  return ToInteger (Time::PS);
399  }
400  inline int64_t GetFemtoSeconds (void) const
401  {
402  return ToInteger (Time::FS);
403  } // Convert to Number in a Unit.
405 
416  inline int64_t GetTimeStep (void) const
417  {
418  return m_data;
419  }
420  inline double GetDouble (void) const
421  {
422  return static_cast<double> (m_data);
423  }
424  inline int64_t GetInteger (void) const
425  {
426  return GetTimeStep ();
427  } // Convert to Raw Value
429 
430 
438  static void SetResolution (enum Unit resolution);
442  static enum Unit GetResolution (void);
443 
444 
451  inline static Time From (const int64x64_t & value)
452  {
453  return Time (value);
454  }
468  inline static Time FromInteger (uint64_t value, enum Unit unit)
469  {
470  struct Information *info = PeekInformation (unit);
471  if (info->fromMul)
472  {
473  value *= info->factor;
474  }
475  else
476  {
477  value /= info->factor;
478  }
479  return Time (value);
480  }
481  inline static Time FromDouble (double value, enum Unit unit)
482  {
483  return From (int64x64_t (value), unit);
484  }
485  inline static Time From (const int64x64_t & value, enum Unit unit)
486  {
487  struct Information *info = PeekInformation (unit);
488  // DO NOT REMOVE this temporary variable. It's here
489  // to work around a compiler bug in gcc 3.4
490  int64x64_t retval = value;
491  if (info->fromMul)
492  {
493  retval *= info->timeFrom;
494  }
495  else
496  {
497  retval.MulByInvert (info->timeFrom);
498  }
499  return Time (retval);
500  } // Create Times from Values and Units
502 
503 
516  inline int64_t ToInteger (enum Unit unit) const
517  {
518  struct Information *info = PeekInformation (unit);
519  int64_t v = m_data;
520  if (info->toMul)
521  {
522  v *= info->factor;
523  }
524  else
525  {
526  v /= info->factor;
527  }
528  return v;
529  }
530  inline double ToDouble (enum Unit unit) const
531  {
532  return To (unit).GetDouble ();
533  }
534  inline int64x64_t To (enum Unit unit) const
535  {
536  struct Information *info = PeekInformation (unit);
537  int64x64_t retval = int64x64_t (m_data);
538  if (info->toMul)
539  {
540  retval *= info->timeTo;
541  }
542  else
543  {
544  retval.MulByInvert (info->timeTo);
545  }
546  return retval;
547  } // Get Times as Numbers in Specified Units
549 
555  Time RoundTo (enum Unit unit) const
556  {
557  return From (this->To (unit).Round (), unit);
558  }
559 
573  TimeWithUnit As (const enum Unit unit = Time::AUTO) const;
574 
580  typedef void (* TracedCallback)(Time value);
581 
582 private:
584  struct Information
585  {
586  bool toMul;
587  bool fromMul;
588  int64_t factor;
591  };
593  struct Resolution
594  {
597  };
598 
604  static inline struct Resolution * PeekResolution (void)
605  {
606  static struct Time::Resolution resolution = SetDefaultNsResolution ();
607  return &resolution;
608  }
615  static inline struct Information * PeekInformation (enum Unit timeUnit)
616  {
617  return &(PeekResolution ()->info[timeUnit]);
618  }
619 
625  static struct Resolution SetDefaultNsResolution (void);
633  static void SetResolution (enum Unit unit, struct Resolution *resolution,
634  const bool convert = true);
635 
655  typedef std::set< Time * > MarkedTimes;
671 
672 public:
678  static bool StaticInit ();
679 private:
687  friend class Simulator;
696  static void ClearMarkedTimes ();
701  static void Mark (Time * const time);
706  static void Clear (Time * const time);
711  static void ConvertTimes (const enum Unit unit);
712 
713 
714  // Operator and related functions which need access
715 
720  friend bool operator == (const Time & lhs, const Time & rhs);
721  friend bool operator != (const Time & lhs, const Time & rhs);
722  friend bool operator <= (const Time & lhs, const Time & rhs);
723  friend bool operator >= (const Time & lhs, const Time & rhs);
724  friend bool operator < (const Time & lhs, const Time & rhs);
725  friend bool operator > (const Time & lhs, const Time & rhs);
726  friend bool operator < (const Time & time, const EventId & event);
732  friend Time operator + (const Time & lhs, const Time & rhs);
733  friend Time operator - (const Time & lhs, const Time & rhs);
734  friend Time operator * (const Time & lhs, const int64x64_t & rhs);
735  friend Time operator * (const int64x64_t & lhs, const Time & rhs);
736 
737  template<class T>
738  friend typename std::enable_if<std::is_integral<T>::value, Time>::type
739  operator * (const Time& lhs, T rhs);
740 
741  //this function uses is_arithmetic because it can be used by both
742  //integers and decimal types
747  template<class T>
748  friend typename std::enable_if<std::is_arithmetic<T>::value, Time>::type
749  operator * (T lhs, const Time& rhs);
750 
751  template<class T>
752  friend typename std::enable_if<std::is_floating_point<T>::value, Time>::type
753  operator * (const Time& lhs, T rhs);
754 
755  friend int64x64_t operator / (const Time & lhs, const Time & rhs);
756  friend Time operator / (const Time & lhs, const int64x64_t & rhs);
757 
758  template<class T>
759  friend typename std::enable_if<std::is_integral<T>::value, Time>::type
760  operator / (const Time& lhs, T rhs);
761 
762  template<class T>
763  friend typename std::enable_if<std::is_floating_point<T>::value, Time>::type
764  operator / (const Time& lhs, T rhs);
765 
766  friend Time operator % (const Time & lhs, const Time & rhs);
767  friend int64_t Div (const Time & lhs, const Time & rhs);
768  friend Time Rem (const Time & lhs, const Time & rhs);
769 
775  friend Time & operator += (Time & lhs, const Time & rhs);
776  friend Time & operator -= (Time & lhs, const Time & rhs);
784  friend Time Abs (const Time & time);
791  friend Time Max (const Time & timeA, const Time & timeB);
798  friend Time Min (const Time & timeA, const Time & timeB);
799 
800 
801  int64_t m_data;
802 
803 }; // class Time
804 
805 namespace TracedValueCallback {
806 
813 typedef void (* Time)(Time oldValue, Time newValue);
814 
815 } // namespace TracedValueCallback
816 
822 static bool NS_UNUSED_GLOBAL (g_TimeStaticInit) = Time::StaticInit ();
823 
830 inline bool
831 operator == (const Time & lhs, const Time & rhs)
832 {
833  return lhs.m_data == rhs.m_data;
834 }
841 inline bool
842 operator != (const Time & lhs, const Time & rhs)
843 {
844  return lhs.m_data != rhs.m_data;
845 }
852 inline bool
853 operator <= (const Time & lhs, const Time & rhs)
854 {
855  return lhs.m_data <= rhs.m_data;
856 }
863 inline bool
864 operator >= (const Time & lhs, const Time & rhs)
865 {
866  return lhs.m_data >= rhs.m_data;
867 }
874 inline bool
875 operator < (const Time & lhs, const Time & rhs)
876 {
877  return lhs.m_data < rhs.m_data;
878 }
885 inline bool
886 operator > (const Time & lhs, const Time & rhs)
887 {
888  return lhs.m_data > rhs.m_data;
889 }
907 inline bool
908 operator < (const Time & time, const EventId & event)
909 {
910  // Negative Time is less than any possible EventId, which are all >= 0.
911  if (time.m_data < 0)
912  {
913  return true;
914  }
915  // Time must be >= 0 so casting to unsigned is safe.
916  return static_cast<uint64_t> (time.m_data) < event.GetTs ();
917 }
924 inline Time operator + (const Time & lhs, const Time & rhs)
925 {
926  return Time (lhs.m_data + rhs.m_data);
927 }
934 inline Time operator - (const Time & lhs, const Time & rhs)
935 {
936  return Time (lhs.m_data - rhs.m_data);
937 }
938 
945 inline Time
946 operator * (const Time & lhs, const int64x64_t & rhs)
947 {
948  int64x64_t res = lhs.m_data;
949  res *= rhs;
950  return Time (res);
951 }
958 inline Time
959 operator * (const int64x64_t & lhs, const Time & rhs)
960 {
961  return rhs * lhs;
962 }
963 
973 template<class T>
974 typename std::enable_if<std::is_integral<T>::value, Time>::type
975 operator * (const Time& lhs, T rhs)
976 {
977  static_assert(!std::is_same<T, bool>::value,
978  "Multiplying a Time by a boolean is not supported");
979 
980  return Time (lhs.m_data * rhs);
981 }
982 
996 template<class T>
997 typename std::enable_if<std::is_arithmetic<T>::value, Time>::type
998 operator * (T lhs, const Time& rhs)
999 {
1000  return rhs * lhs;
1001 }
1002 
1012 template<class T>
1013 typename std::enable_if<std::is_floating_point<T>::value, Time>::type
1014 operator * (const Time& lhs, T rhs)
1015 {
1016  return lhs * int64x64_t(rhs);
1017 }
1018 
1037 inline int64x64_t
1038 operator / (const Time & lhs, const Time & rhs)
1039 {
1040  int64x64_t num = lhs.m_data;
1041  int64x64_t den = rhs.m_data;
1042  return num / den;
1043 }
1044 
1051 inline Time
1052 operator / (const Time & lhs, const int64x64_t & rhs)
1053 {
1054  int64x64_t res = lhs.m_data;
1055  res /= rhs;
1056  return Time (res);
1057 }
1058 
1068 template<class T>
1069 typename std::enable_if<std::is_integral<T>::value, Time>::type
1070 operator / (const Time& lhs, T rhs)
1071 {
1072  static_assert(!std::is_same<T, bool>::value,
1073  "Dividing a Time by a boolean is not supported");
1074 
1075  return Time(lhs.m_data / rhs);
1076 }
1077 
1087 template<class T>
1088 typename std::enable_if<std::is_floating_point<T>::value, Time>::type
1089 operator / (const Time& lhs, T rhs)
1090 {
1091  return lhs / int64x64_t(rhs);
1092 }
1093 
1106 inline Time
1107 operator % (const Time & lhs, const Time & rhs)
1108 {
1109  return Time (lhs.m_data % rhs.m_data);
1110 }
1131 inline int64_t
1132 Div (const Time & lhs, const Time & rhs)
1133 {
1134  return lhs.m_data / rhs.m_data;
1135 }
1148 inline Time
1149 Rem (const Time & lhs, const Time & rhs)
1150 {
1151  return Time (lhs.m_data % rhs.m_data);
1152 }
1153 
1160 inline Time & operator += (Time & lhs, const Time & rhs)
1161 {
1162  lhs.m_data += rhs.m_data;
1163  return lhs;
1164 }
1171 inline Time & operator -= (Time & lhs, const Time & rhs)
1172 {
1173  lhs.m_data -= rhs.m_data;
1174  return lhs;
1175 }
1181 inline Time Abs (const Time & time)
1182 {
1183  return Time ((time.m_data < 0) ? -time.m_data : time.m_data);
1184 }
1191 inline Time Max (const Time & timeA, const Time & timeB)
1192 {
1193  return Time ((timeA.m_data < timeB.m_data) ? timeB : timeA);
1194 }
1201 inline Time Min (const Time & timeA, const Time & timeB)
1202 {
1203  return Time ((timeA.m_data > timeB.m_data) ? timeB : timeA);
1204 }
1205 
1226 std::ostream & operator << (std::ostream & os, const Time & time);
1236 std::istream & operator >> (std::istream & is, Time & time);
1237 
1238 
1257 inline Time Years (double value)
1258 {
1259  return Time::FromDouble (value, Time::Y);
1260 }
1261 inline Time Years (int64x64_t value)
1262 {
1263  return Time::From (value, Time::Y);
1264 }
1265 inline Time Days (double value)
1266 {
1267  return Time::FromDouble (value, Time::D);
1268 }
1269 inline Time Days (int64x64_t value)
1270 {
1271  return Time::From (value, Time::D);
1272 }
1273 inline Time Hours (double value)
1274 {
1275  return Time::FromDouble (value, Time::H);
1276 }
1277 inline Time Hours (int64x64_t value)
1278 {
1279  return Time::From (value, Time::H);
1280 }
1281 inline Time Minutes (double value)
1282 {
1283  return Time::FromDouble (value, Time::MIN);
1284 }
1285 inline Time Minutes (int64x64_t value)
1286 {
1287  return Time::From (value, Time::MIN);
1288 }
1289 inline Time Seconds (double value)
1290 {
1291  return Time::FromDouble (value, Time::S);
1292 }
1293 inline Time Seconds (int64x64_t value)
1294 {
1295  return Time::From (value, Time::S);
1296 }
1297 inline Time MilliSeconds (uint64_t value)
1298 {
1299  return Time::FromInteger (value, Time::MS);
1300 }
1302 {
1303  return Time::From (value, Time::MS);
1304 }
1305 inline Time MicroSeconds (uint64_t value)
1306 {
1307  return Time::FromInteger (value, Time::US);
1308 }
1310 {
1311  return Time::From (value, Time::US);
1312 }
1313 inline Time NanoSeconds (uint64_t value)
1314 {
1315  return Time::FromInteger (value, Time::NS);
1316 }
1318 {
1319  return Time::From (value, Time::NS);
1320 }
1321 inline Time PicoSeconds (uint64_t value)
1322 {
1323  return Time::FromInteger (value, Time::PS);
1324 }
1326 {
1327  return Time::From (value, Time::PS);
1328 }
1329 inline Time FemtoSeconds (uint64_t value)
1330 {
1331  return Time::FromInteger (value, Time::FS);
1332 }
1334 {
1335  return Time::From (value, Time::FS);
1336 } // Construct a Time in the indicated unit.
1338 
1339 
1348 inline Time TimeStep (uint64_t ts)
1349 {
1350  return Time (ts);
1351 }
1352 
1355 
1366 
1373 inline
1375 {
1376  return MakeTimeChecker (Time::Min (), Time::Max ());
1377 }
1378 
1386 inline
1388 {
1389  return MakeTimeChecker (min, Time::Max ());
1390 }
1391 
1397 {
1398 public:
1405  TimeWithUnit (const Time time, const Time::Unit unit)
1406  : m_time (time),
1407  m_unit (unit)
1408  { }
1409 
1410 private:
1413 
1420  friend std::ostream & operator << (std::ostream & os, const TimeWithUnit & timeU);
1421 
1422 }; // class TimeWithUnit
1423 
1424 } // namespace ns3
1425 
1426 #endif /* TIME_H */
int64x64_t & operator+=(int64x64_t &lhs, const int64x64_t &rhs)
Compound addition operator.
Definition: int64x64-128.h:443
static struct Resolution * PeekResolution(void)
Get the current Resolution.
Definition: nstime.h:604
TimeWithUnit As(const enum Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:429
nanosecond
Definition: nstime.h:118
Time operator%(const Time &lhs, const Time &rhs)
Remainder (modulus) from the quotient of two Times.
Definition: nstime.h:1107
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
microsecond
Definition: nstime.h:117
Control the scheduling of simulation events.
Definition: simulator.h:68
int64x64_t operator+(const int64x64_t &lhs)
Unary plus operator.
Definition: int64x64-128.h:491
int64_t GetInteger(void) const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:424
#define NS_UNUSED_GLOBAL(x)
Mark a variable at file scope as unused.
Definition: unused.h:50
int64x64_t timeFrom
Multiplier to convert from this unit.
Definition: nstime.h:590
static Time Min()
Minimum representable Time Not to be confused with Min(Time,Time).
Definition: nstime.h:274
A Time with attached unit, to facilitate output in that unit.
Definition: nstime.h:1396
#define min(a, b)
Definition: 80211b.c:42
int64_t ToInteger(enum Unit unit) const
Get the Time value expressed in a particular unit.
Definition: nstime.h:516
day, 24 hours
Definition: nstime.h:112
High precision numerical type, implementing Q64.64 fixed precision.
Definition: int64x64-128.h:45
Forward calls to a chain of Callback.
friend bool operator<(const Time &lhs, const Time &rhs)
Less than operator for Time.
Definition: nstime.h:875
friend bool operator!=(const Time &lhs, const Time &rhs)
Inequality operator for Time.
Definition: nstime.h:842
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:380
#define ATTRIBUTE_VALUE_DEFINE(name)
Declare the attribute value class nameValue for the class name
minute, 60 seconds
Definition: nstime.h:114
int64x64_t operator-(const int64x64_t &lhs)
Unary negation operator (change sign operator).
Definition: int64x64-128.h:501
static Time From(const int64x64_t &value)
Create a Time in the current unit.
Definition: nstime.h:451
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1297
double ToDouble(enum Unit unit) const
Get the Time value expressed in a particular unit.
Definition: nstime.h:530
bool IsStrictlyPositive(void) const
Exactly equivalent to t > 0.
Definition: nstime.h:333
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:813
double GetYears(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:364
hour, 60 minutes
Definition: nstime.h:113
std::istream & operator>>(std::istream &is, Angles &a)
Definition: angles.cc:160
friend Time operator%(const Time &lhs, const Time &rhs)
Remainder (modulus) from the quotient of two Times.
Definition: nstime.h:1107
Time(unsigned long int v)
Construct from a numeric value.
Definition: nstime.h:221
Time(const int64x64_t &v)
Construct from a numeric value.
Definition: nstime.h:237
bool operator>=(const int64x64_t &lhs, const int64x64_t &rhs)
Greater or equal operator.
Definition: int64x64.h:166
int64_t GetPicoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:396
auto-scale output when using Time::As()
Definition: nstime.h:122
friend Time operator-(const Time &lhs, const Time &rhs)
Subtraction operator for Time.
Definition: nstime.h:934
bool operator<(const EventId &a, const EventId &b)
Definition: event-id.h:160
Time PicoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1321
struct Information info[LAST]
Conversion info from current unit.
Definition: nstime.h:595
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:137
Time RoundTo(enum Unit unit) const
Round a Time to a specific unit.
Definition: nstime.h:555
friend Time operator+(const Time &lhs, const Time &rhs)
Addition operator for Time.
Definition: nstime.h:924
static Time Max()
Maximum representable Time Not to be confused with Max(Time,Time).
Definition: nstime.h:283
friend Time Abs(const Time &time)
Absolute value function for Time.
Definition: nstime.h:1181
bool operator<=(const int64x64_t &lhs, const int64x64_t &rhs)
Less or equal operator.
Definition: int64x64.h:155
int64x64_t operator*(const int64x64_t &lhs, const int64x64_t &rhs)
Multiplication operator.
Definition: int64x64.h:117
int64x64_t Min(const int64x64_t &a, const int64x64_t &b)
Minimum.
Definition: int64x64.h:218
Time(int v)
Construct from a numeric value.
Definition: nstime.h:189
Time Years(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1257
picosecond
Definition: nstime.h:119
year, 365 days
Definition: nstime.h:111
#define max(a, b)
Definition: 80211b.c:43
static enum Unit GetResolution(void)
Definition: time.cc:421
bool IsZero(void) const
Exactly equivalent to t == 0.
Definition: nstime.h:301
friend Time & operator-=(Time &lhs, const Time &rhs)
Compound subtraction assignment for Time.
Definition: nstime.h:1171
Time TimeStep(uint64_t ts)
Scheduler interface.
Definition: nstime.h:1348
Time(long long int v)
Construct from a numeric value.
Definition: nstime.h:205
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1313
Current time unit, and conversion info.
Definition: nstime.h:593
static bool StaticInit()
Function to force static initialization of Time.
Definition: time.cc:106
NS_ASSERT() and NS_ASSERT_MSG() macro definitions.
bool fromMul
Multiple when converting From, otherwise divide.
Definition: nstime.h:587
friend std::ostream & operator<<(std::ostream &os, const TimeWithUnit &timeU)
Output streamer.
Definition: time.cc:444
static Time From(const int64x64_t &value, enum Unit unit)
Create a Time equal to value in unit unit.
Definition: nstime.h:485
ns3::AttributeValue, ns3::AttributeAccessor and ns3::AttributeChecker declarations.
Unit
The unit to use to interpret a number representing time.
Definition: nstime.h:109
Time Rem(const Time &lhs, const Time &rhs)
Remainder (modulus) from the quotient of two Times.
Definition: nstime.h:1149
int64x64_t Max(const int64x64_t &a, const int64x64_t &b)
Maximum.
Definition: int64x64.h:230
static void ConvertTimes(const enum Unit unit)
Convert existing Times to the new unit.
Definition: time.cc:384
friend bool operator>=(const Time &lhs, const Time &rhs)
Greater than or equal operator for Time.
Definition: nstime.h:864
double GetDouble(void) const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:420
int64_t Div(const Length &numerator, const Length &denominator, Length *remainder)
This function provides a string parsing method that does not rely on istream, which has been found to...
Definition: length.cc:488
Time(long int v)
Construct from a numeric value.
Definition: nstime.h:197
static struct Resolution SetDefaultNsResolution(void)
Set the default resolution.
Definition: time.cc:213
int64_t factor
Ratio of this unit / current unit.
Definition: nstime.h:588
int64x64_t operator/(const int64x64_t &lhs, const int64x64_t &rhs)
Division operator.
Definition: int64x64.h:131
int64x64_t Abs(const int64x64_t &value)
Absolute value.
Definition: int64x64.h:205
int64_t GetMicroSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:388
friend int64x64_t operator/(const Time &lhs, const Time &rhs)
Exact division, returning a dimensionless fixed point number.
Definition: nstime.h:1038
double GetDays(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:368
uint64_t GetTs(void) const
Definition: event-id.cc:83
friend int64_t Div(const Time &lhs, const Time &rhs)
Integer quotient from dividing two Times.
Definition: nstime.h:1132
Time(double v)
Construct from a numeric value.
Definition: nstime.h:181
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:1606
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:229
int64_t GetNanoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:392
friend Time & operator+=(Time &lhs, const Time &rhs)
Compound addition assignment for Time.
Definition: nstime.h:1160
friend bool operator==(const Time &lhs, const Time &rhs)
Equality operator for Time.
Definition: nstime.h:831
Time Hours(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1273
Time()
Default constructor, with value 0.
Definition: nstime.h:136
~Time()
Destructor.
Definition: nstime.h:289
static struct Information * PeekInformation(enum Unit timeUnit)
Get the Information record for timeUnit for the current Resolution.
Definition: nstime.h:615
Attribute helper (ATTRIBUTE_ )macros definition.
friend Time operator*(const Time &lhs, const int64x64_t &rhs)
Scale a Time by a numeric value.
Definition: nstime.h:946
Time Minutes(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1281
double max(double x, double y)
static Time FromDouble(double value, enum Unit unit)
Create a Time equal to value in unit unit.
Definition: nstime.h:481
#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:213
static void Mark(Time *const time)
Record a Time instance with the MarkedTimes.
Definition: time.cc:328
friend bool operator>(const Time &lhs, const Time &rhs)
Greater than operator for Time.
Definition: nstime.h:886
double GetMinutes(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:376
An identifier for simulation events.
Definition: event-id.h:53
int Compare(const Time &o) const
Compare this to another Time.
Definition: nstime.h:343
friend Time Rem(const Time &lhs, const Time &rhs)
Remainder (modulus) from the quotient of two Times.
Definition: nstime.h:1149
int64_t GetMilliSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:384
bool IsPositive(void) const
Exactly equivalent to t >= 0.
Definition: nstime.h:317
How to convert between other units and the current unit.
Definition: nstime.h:584
Length::Unit Unit
bool IsStrictlyNegative(void) const
Exactly equivalent to t < 0.
Definition: nstime.h:325
static Time FromInteger(uint64_t value, enum Unit unit)
Create a Time equal to value in unit unit.
Definition: nstime.h:468
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
bool operator>(const int64x64_t &lhs, const int64x64_t &rhs)
Greater operator.
Definition: int64x64-128.h:431
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.h:142
double GetDouble(void) const
Get this value as a double.
Definition: int64x64-128.h:206
enum Time::Unit unit
Current time unit.
Definition: nstime.h:596
Time::Unit m_unit
The unit to use in output.
Definition: nstime.h:1412
static void SetResolution(enum Unit resolution)
Definition: time.cc:223
double min(double x, double y)
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:533
int64x64_t To(enum Unit unit) const
Get the Time value expressed in a particular unit.
Definition: nstime.h:534
static void Clear(Time *const time)
Remove a Time instance from the MarkedTimes, called by ~Time().
Definition: time.cc:354
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1305
TimeWithUnit(const Time time, const Time::Unit unit)
Attach a unit to a Time.
Definition: nstime.h:1405
int64x64_t & operator-=(int64x64_t &lhs, const int64x64_t &rhs)
Compound subtraction operator.
Definition: int64x64-128.h:455
second
Definition: nstime.h:115
std::set< Time *> MarkedTimes
Record all instances of Time, so we can rescale them when the resolution changes. ...
Definition: nstime.h:655
marker for last normal value
Definition: nstime.h:121
static MarkedTimes * g_markingTimes
Record of outstanding Time objects which will need conversion when the resolution is set...
Definition: nstime.h:670
Time Days(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1265
Time FemtoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1329
int64_t GetFemtoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:400
static void ClearMarkedTimes()
Remove all MarkedTimes.
Definition: time.cc:297
femtosecond
Definition: nstime.h:120
millisecond
Definition: nstime.h:116
friend bool operator<=(const Time &lhs, const Time &rhs)
Less than or equal operator for Time.
Definition: nstime.h:853
ns3::EventId declarations.
Declaration of the ns3::int64x64_t type and associated operators.
Time & operator=(const Time &o)
Assignment operator.
Definition: nstime.h:130
double GetHours(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:372
Time m_time
The time.
Definition: nstime.h:1411
int64x64_t timeTo
Multiplier to convert to this unit.
Definition: nstime.h:589
Time(const Time &o)
Copy constructor.
Definition: nstime.h:149
bool IsNegative(void) const
Exactly equivalent to t <= 0.
Definition: nstime.h:309
int64_t m_data
Virtual time value, in the current unit.
Definition: nstime.h:801
bool toMul
Multiply when converting To, otherwise divide.
Definition: nstime.h:586
Time(Time &&o)
Move constructor.
Definition: nstime.h:163
int64_t GetTimeStep(void) const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:416
NS_UNUSED and NS_UNUSED_GLOBAL macro definitions.