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  };
123 
129  inline Time & operator = (const Time & o)
130  {
131  m_data = o.m_data;
132  return *this;
133  }
135  inline Time ()
136  : m_data ()
137  {
138  if (g_markingTimes)
139  {
140  Mark (this);
141  }
142  }
148  inline Time (const Time & o)
149  : m_data (o.m_data)
150  {
151  if (g_markingTimes)
152  {
153  Mark (this);
154  }
155  }
156 
162  Time (Time &&o)
163  : m_data (o.m_data)
164  {
165  if (g_markingTimes)
166  {
167  Mark (this);
168  }
169  }
180  explicit inline Time (double v)
181  : m_data (lround (v))
182  {
183  if (g_markingTimes)
184  {
185  Mark (this);
186  }
187  }
188  explicit inline Time (int v)
189  : m_data (v)
190  {
191  if (g_markingTimes)
192  {
193  Mark (this);
194  }
195  }
196  explicit inline Time (long int v)
197  : m_data (v)
198  {
199  if (g_markingTimes)
200  {
201  Mark (this);
202  }
203  }
204  explicit inline Time (long long int v)
205  : m_data (v)
206  {
207  if (g_markingTimes)
208  {
209  Mark (this);
210  }
211  }
212  explicit inline Time (unsigned int v)
213  : m_data (v)
214  {
215  if (g_markingTimes)
216  {
217  Mark (this);
218  }
219  }
220  explicit inline Time (unsigned long int v)
221  : m_data (v)
222  {
223  if (g_markingTimes)
224  {
225  Mark (this);
226  }
227  }
228  explicit inline Time (unsigned long long int v)
229  : m_data (v)
230  {
231  if (g_markingTimes)
232  {
233  Mark (this);
234  }
235  }
236  explicit inline Time (const int64x64_t & v)
237  : m_data (v.GetHigh ())
238  {
239  if (g_markingTimes)
240  {
241  Mark (this);
242  }
243  } // Numeric constructors
245 
266  explicit Time (const std::string & s);
267 
273  static Time Min ()
274  {
276  }
282  static Time Max ()
283  {
285  }
286 
288  ~Time ()
289  {
290  if (g_markingTimes)
291  {
292  Clear (this);
293  }
294  }
295 
300  inline bool IsZero (void) const
301  {
302  return m_data == 0;
303  }
308  inline bool IsNegative (void) const
309  {
310  return m_data <= 0;
311  }
316  inline bool IsPositive (void) const
317  {
318  return m_data >= 0;
319  }
324  inline bool IsStrictlyNegative (void) const
325  {
326  return m_data < 0;
327  }
332  inline bool IsStrictlyPositive (void) const
333  {
334  return m_data > 0;
335  }
342  inline int Compare (const Time & o) const
343  {
344  return (m_data < o.m_data) ? -1 : (m_data == o.m_data) ? 0 : 1;
345  }
346 
363  inline double GetYears (void) const
364  {
365  return ToDouble (Time::Y);
366  }
367  inline double GetDays (void) const
368  {
369  return ToDouble (Time::D);
370  }
371  inline double GetHours (void) const
372  {
373  return ToDouble (Time::H);
374  }
375  inline double GetMinutes (void) const
376  {
377  return ToDouble (Time::MIN);
378  }
379  inline double GetSeconds (void) const
380  {
381  return ToDouble (Time::S);
382  }
383  inline int64_t GetMilliSeconds (void) const
384  {
385  return ToInteger (Time::MS);
386  }
387  inline int64_t GetMicroSeconds (void) const
388  {
389  return ToInteger (Time::US);
390  }
391  inline int64_t GetNanoSeconds (void) const
392  {
393  return ToInteger (Time::NS);
394  }
395  inline int64_t GetPicoSeconds (void) const
396  {
397  return ToInteger (Time::PS);
398  }
399  inline int64_t GetFemtoSeconds (void) const
400  {
401  return ToInteger (Time::FS);
402  } // Convert to Number in a Unit.
404 
415  inline int64_t GetTimeStep (void) const
416  {
417  return m_data;
418  }
419  inline double GetDouble (void) const
420  {
421  return static_cast<double> (m_data);
422  }
423  inline int64_t GetInteger (void) const
424  {
425  return GetTimeStep ();
426  } // Convert to Raw Value
428 
429 
437  static void SetResolution (enum Unit resolution);
441  static enum Unit GetResolution (void);
442 
443 
450  inline static Time From (const int64x64_t & value)
451  {
452  return Time (value);
453  }
467  inline static Time FromInteger (uint64_t value, enum Unit unit)
468  {
469  struct Information *info = PeekInformation (unit);
470  if (info->fromMul)
471  {
472  value *= info->factor;
473  }
474  else
475  {
476  value /= info->factor;
477  }
478  return Time (value);
479  }
480  inline static Time FromDouble (double value, enum Unit unit)
481  {
482  return From (int64x64_t (value), unit);
483  }
484  inline static Time From (const int64x64_t & value, enum Unit unit)
485  {
486  struct Information *info = PeekInformation (unit);
487  // DO NOT REMOVE this temporary variable. It's here
488  // to work around a compiler bug in gcc 3.4
489  int64x64_t retval = value;
490  if (info->fromMul)
491  {
492  retval *= info->timeFrom;
493  }
494  else
495  {
496  retval.MulByInvert (info->timeFrom);
497  }
498  return Time (retval);
499  } // Create Times from Values and Units
501 
502 
515  inline int64_t ToInteger (enum Unit unit) const
516  {
517  struct Information *info = PeekInformation (unit);
518  int64_t v = m_data;
519  if (info->toMul)
520  {
521  v *= info->factor;
522  }
523  else
524  {
525  v /= info->factor;
526  }
527  return v;
528  }
529  inline double ToDouble (enum Unit unit) const
530  {
531  return To (unit).GetDouble ();
532  }
533  inline int64x64_t To (enum Unit unit) const
534  {
535  struct Information *info = PeekInformation (unit);
536  int64x64_t retval = int64x64_t (m_data);
537  if (info->toMul)
538  {
539  retval *= info->timeTo;
540  }
541  else
542  {
543  retval.MulByInvert (info->timeTo);
544  }
545  return retval;
546  } // Get Times as Numbers in Specified Units
548 
562  TimeWithUnit As (const enum Unit unit) const;
563 
569  typedef void (* TracedCallback)(Time value);
570 
571 private:
573  struct Information
574  {
575  bool toMul;
576  bool fromMul;
577  int64_t factor;
580  };
582  struct Resolution
583  {
586  };
587 
593  static inline struct Resolution * PeekResolution (void)
594  {
595  static struct Time::Resolution resolution = SetDefaultNsResolution ();
596  return &resolution;
597  }
604  static inline struct Information * PeekInformation (enum Unit timeUnit)
605  {
606  return &(PeekResolution ()->info[timeUnit]);
607  }
608 
614  static struct Resolution SetDefaultNsResolution (void);
622  static void SetResolution (enum Unit unit, struct Resolution *resolution,
623  const bool convert = true);
624 
644  typedef std::set< Time * > MarkedTimes;
660 
661 public:
667  static bool StaticInit ();
668 private:
676  friend class Simulator;
685  static void ClearMarkedTimes ();
690  static void Mark (Time * const time);
695  static void Clear (Time * const time);
700  static void ConvertTimes (const enum Unit unit);
701 
702 
703  // Operator and related functions which need access
704 
709  friend bool operator == (const Time & lhs, const Time & rhs);
710  friend bool operator != (const Time & lhs, const Time & rhs);
711  friend bool operator <= (const Time & lhs, const Time & rhs);
712  friend bool operator >= (const Time & lhs, const Time & rhs);
713  friend bool operator < (const Time & lhs, const Time & rhs);
714  friend bool operator > (const Time & lhs, const Time & rhs);
715  friend bool operator < (const Time & time, const EventId & event);
721  friend Time operator + (const Time & lhs, const Time & rhs);
722  friend Time operator - (const Time & lhs, const Time & rhs);
723  friend Time operator * (const Time & lhs, const int64x64_t & rhs);
724  friend Time operator * (const int64x64_t & lhs, const Time & rhs);
725 
726  template<class T>
727  friend typename std::enable_if<std::is_integral<T>::value, Time>::type
728  operator * (const Time& lhs, T rhs);
729 
730  //this function uses is_arithmetic because it can be used by both
731  //integers and decimal types
736  template<class T>
737  friend typename std::enable_if<std::is_arithmetic<T>::value, Time>::type
738  operator * (T lhs, const Time& rhs);
739 
740  template<class T>
741  friend typename std::enable_if<std::is_floating_point<T>::value, Time>::type
742  operator * (const Time& lhs, T rhs);
743 
744  friend int64x64_t operator / (const Time & lhs, const Time & rhs);
745  friend Time operator / (const Time & lhs, const int64x64_t & rhs);
746 
747  template<class T>
748  friend typename std::enable_if<std::is_integral<T>::value, Time>::type
749  operator / (const Time& lhs, T 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 Time operator % (const Time & lhs, const Time & rhs);
756  friend int64_t Div (const Time & lhs, const Time & rhs);
757  friend Time Rem (const Time & lhs, const Time & rhs);
758 
764  friend Time & operator += (Time & lhs, const Time & rhs);
765  friend Time & operator -= (Time & lhs, const Time & rhs);
773  friend Time Abs (const Time & time);
780  friend Time Max (const Time & timeA, const Time & timeB);
787  friend Time Min (const Time & timeA, const Time & timeB);
788 
789 
790  int64_t m_data;
791 
792 }; // class Time
793 
794 namespace TracedValueCallback {
795 
802 typedef void (* Time)(Time oldValue, Time newValue);
803 
804 } // namespace TracedValueCallback
805 
811 static bool NS_UNUSED_GLOBAL (g_TimeStaticInit) = Time::StaticInit ();
812 
819 inline bool
820 operator == (const Time & lhs, const Time & rhs)
821 {
822  return lhs.m_data == rhs.m_data;
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 }
896 inline bool
897 operator < (const Time & time, const EventId & event)
898 {
899  // Negative Time is less than any possible EventId, which are all >= 0.
900  if (time.m_data < 0)
901  {
902  return true;
903  }
904  // Time must be >= 0 so casting to unsigned is safe.
905  return static_cast<uint64_t> (time.m_data) < event.GetTs ();
906 }
913 inline Time operator + (const Time & lhs, const Time & rhs)
914 {
915  return Time (lhs.m_data + rhs.m_data);
916 }
923 inline Time operator - (const Time & lhs, const Time & rhs)
924 {
925  return Time (lhs.m_data - rhs.m_data);
926 }
927 
934 inline Time
935 operator * (const Time & lhs, const int64x64_t & rhs)
936 {
937  int64x64_t res = lhs.m_data;
938  res *= rhs;
939  return Time (res);
940 }
947 inline Time
948 operator * (const int64x64_t & lhs, const Time & rhs)
949 {
950  return rhs * lhs;
951 }
952 
962 template<class T>
963 typename std::enable_if<std::is_integral<T>::value, Time>::type
964 operator * (const Time& lhs, T rhs)
965 {
966  static_assert(!std::is_same<T, bool>::value,
967  "Multiplying a Time by a boolean is not supported");
968 
969  return Time (lhs.m_data * rhs);
970 }
971 
985 template<class T>
986 typename std::enable_if<std::is_arithmetic<T>::value, Time>::type
987 operator * (T lhs, const Time& rhs)
988 {
989  return rhs * lhs;
990 }
991 
1001 template<class T>
1002 typename std::enable_if<std::is_floating_point<T>::value, Time>::type
1003 operator * (const Time& lhs, T rhs)
1004 {
1005  return lhs * int64x64_t(rhs);
1006 }
1007 
1026 inline int64x64_t
1027 operator / (const Time & lhs, const Time & rhs)
1028 {
1029  int64x64_t num = lhs.m_data;
1030  int64x64_t den = rhs.m_data;
1031  return num / den;
1032 }
1033 
1040 inline Time
1041 operator / (const Time & lhs, const int64x64_t & rhs)
1042 {
1043  int64x64_t res = lhs.m_data;
1044  res /= rhs;
1045  return Time (res);
1046 }
1047 
1057 template<class T>
1058 typename std::enable_if<std::is_integral<T>::value, Time>::type
1059 operator / (const Time& lhs, T rhs)
1060 {
1061  static_assert(!std::is_same<T, bool>::value,
1062  "Dividing a Time by a boolean is not supported");
1063 
1064  return Time(lhs.m_data / rhs);
1065 }
1066 
1076 template<class T>
1077 typename std::enable_if<std::is_floating_point<T>::value, Time>::type
1078 operator / (const Time& lhs, T rhs)
1079 {
1080  return lhs / int64x64_t(rhs);
1081 }
1082 
1095 inline Time
1096 operator % (const Time & lhs, const Time & rhs)
1097 {
1098  return Time (lhs.m_data % rhs.m_data);
1099 }
1120 inline int64_t
1121 Div (const Time & lhs, const Time & rhs)
1122 {
1123  return lhs.m_data / rhs.m_data;
1124 }
1137 inline Time
1138 Rem (const Time & lhs, const Time & rhs)
1139 {
1140  return Time (lhs.m_data % rhs.m_data);
1141 }
1142 
1149 inline Time & operator += (Time & lhs, const Time & rhs)
1150 {
1151  lhs.m_data += rhs.m_data;
1152  return lhs;
1153 }
1160 inline Time & operator -= (Time & lhs, const Time & rhs)
1161 {
1162  lhs.m_data -= rhs.m_data;
1163  return lhs;
1164 }
1170 inline Time Abs (const Time & time)
1171 {
1172  return Time ((time.m_data < 0) ? -time.m_data : time.m_data);
1173 }
1180 inline Time Max (const Time & timeA, const Time & timeB)
1181 {
1182  return Time ((timeA.m_data < timeB.m_data) ? timeB : timeA);
1183 }
1190 inline Time Min (const Time & timeA, const Time & timeB)
1191 {
1192  return Time ((timeA.m_data > timeB.m_data) ? timeB : timeA);
1193 }
1194 
1215 std::ostream & operator << (std::ostream & os, const Time & time);
1225 std::istream & operator >> (std::istream & is, Time & time);
1226 
1227 
1246 inline Time Years (double value)
1247 {
1248  return Time::FromDouble (value, Time::Y);
1249 }
1250 inline Time Years (int64x64_t value)
1251 {
1252  return Time::From (value, Time::Y);
1253 }
1254 inline Time Days (double value)
1255 {
1256  return Time::FromDouble (value, Time::D);
1257 }
1258 inline Time Days (int64x64_t value)
1259 {
1260  return Time::From (value, Time::D);
1261 }
1262 inline Time Hours (double value)
1263 {
1264  return Time::FromDouble (value, Time::H);
1265 }
1266 inline Time Hours (int64x64_t value)
1267 {
1268  return Time::From (value, Time::H);
1269 }
1270 inline Time Minutes (double value)
1271 {
1272  return Time::FromDouble (value, Time::MIN);
1273 }
1274 inline Time Minutes (int64x64_t value)
1275 {
1276  return Time::From (value, Time::MIN);
1277 }
1278 inline Time Seconds (double value)
1279 {
1280  return Time::FromDouble (value, Time::S);
1281 }
1282 inline Time Seconds (int64x64_t value)
1283 {
1284  return Time::From (value, Time::S);
1285 }
1286 inline Time MilliSeconds (uint64_t value)
1287 {
1288  return Time::FromInteger (value, Time::MS);
1289 }
1291 {
1292  return Time::From (value, Time::MS);
1293 }
1294 inline Time MicroSeconds (uint64_t value)
1295 {
1296  return Time::FromInteger (value, Time::US);
1297 }
1299 {
1300  return Time::From (value, Time::US);
1301 }
1302 inline Time NanoSeconds (uint64_t value)
1303 {
1304  return Time::FromInteger (value, Time::NS);
1305 }
1307 {
1308  return Time::From (value, Time::NS);
1309 }
1310 inline Time PicoSeconds (uint64_t value)
1311 {
1312  return Time::FromInteger (value, Time::PS);
1313 }
1315 {
1316  return Time::From (value, Time::PS);
1317 }
1318 inline Time FemtoSeconds (uint64_t value)
1319 {
1320  return Time::FromInteger (value, Time::FS);
1321 }
1323 {
1324  return Time::From (value, Time::FS);
1325 } // Construct a Time in the indicated unit.
1327 
1328 
1337 inline Time TimeStep (uint64_t ts)
1338 {
1339  return Time (ts);
1340 }
1341 
1344 
1355 
1362 inline
1364 {
1365  return MakeTimeChecker (Time::Min (), Time::Max ());
1366 }
1367 
1375 inline
1377 {
1378  return MakeTimeChecker (min, Time::Max ());
1379 }
1380 
1386 {
1387 public:
1394  TimeWithUnit (const Time time, const Time::Unit unit)
1395  : m_time (time),
1396  m_unit (unit)
1397  { }
1398 
1399 private:
1402 
1409  friend std::ostream & operator << (std::ostream & os, const TimeWithUnit & timeU);
1410 
1411 }; // class TimeWithUnit
1412 
1413 } // namespace ns3
1414 
1415 #endif /* TIME_H */
int64x64_t & operator+=(int64x64_t &lhs, const int64x64_t &rhs)
Compound addition operator.
Definition: int64x64-128.h:412
static struct Resolution * PeekResolution(void)
Get the current Resolution.
Definition: nstime.h:593
std::istream & operator>>(std::istream &is, Angles &a)
initialize a struct Angles from input
Definition: angles.cc:48
nanosecond
Definition: nstime.h:118
Time operator%(const Time &lhs, const Time &rhs)
Remainder (modulus) from the quotient of two Times.
Definition: nstime.h:1096
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
int64_t Div(const Time &lhs, const Time &rhs)
Integer quotient from dividing two Times.
Definition: nstime.h:1121
int64x64_t operator+(const int64x64_t &lhs)
Unary plus operator.
Definition: int64x64-128.h:460
int64_t GetInteger(void) const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:423
#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:579
static Time Min()
Minimum representable Time Not to be confused with Min(Time,Time).
Definition: nstime.h:273
A Time with attached unit, to facilitate output in that unit.
Definition: nstime.h:1385
#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:515
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:864
friend bool operator!=(const Time &lhs, const Time &rhs)
Inequality operator for Time.
Definition: nstime.h:831
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:379
#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:470
static Time From(const int64x64_t &value)
Create a Time in the current unit.
Definition: nstime.h:450
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1286
double ToDouble(enum Unit unit) const
Get the Time value expressed in a particular unit.
Definition: nstime.h:529
bool IsStrictlyPositive(void) const
Exactly equivalent to t > 0.
Definition: nstime.h:332
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:802
double GetYears(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:363
hour, 60 minutes
Definition: nstime.h:113
friend Time operator%(const Time &lhs, const Time &rhs)
Remainder (modulus) from the quotient of two Times.
Definition: nstime.h:1096
TimeWithUnit As(const enum Unit unit) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:389
Time(unsigned long int v)
Construct from a numeric value.
Definition: nstime.h:220
Time(const int64x64_t &v)
Construct from a numeric value.
Definition: nstime.h:236
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:395
friend Time operator-(const Time &lhs, const Time &rhs)
Subtraction operator for Time.
Definition: nstime.h:923
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:1310
struct Information info[LAST]
Conversion info from current unit.
Definition: nstime.h:584
friend Time operator+(const Time &lhs, const Time &rhs)
Addition operator for Time.
Definition: nstime.h:913
static Time Max()
Maximum representable Time Not to be confused with Max(Time,Time).
Definition: nstime.h:282
friend Time Abs(const Time &time)
Absolute value function for Time.
Definition: nstime.h:1170
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:188
Time Years(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1246
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:381
bool IsZero(void) const
Exactly equivalent to t == 0.
Definition: nstime.h:300
friend Time & operator-=(Time &lhs, const Time &rhs)
Compound subtraction assignment for Time.
Definition: nstime.h:1160
Time TimeStep(uint64_t ts)
Scheduler interface.
Definition: nstime.h:1337
Time(long long int v)
Construct from a numeric value.
Definition: nstime.h:204
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1302
Current time unit, and conversion info.
Definition: nstime.h:582
static bool StaticInit()
Function to force static initialization of Time.
Definition: time.cc:63
NS_ASSERT() and NS_ASSERT_MSG() macro definitions.
bool fromMul
Multiple when converting From, otherwise divide.
Definition: nstime.h:576
friend std::ostream & operator<<(std::ostream &os, const TimeWithUnit &timeU)
Output streamer.
Definition: time.cc:404
static Time From(const int64x64_t &value, enum Unit unit)
Create a Time equal to value in unit unit.
Definition: nstime.h:484
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:1138
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:344
friend bool operator>=(const Time &lhs, const Time &rhs)
Greater than or equal operator for Time.
Definition: nstime.h:853
double GetDouble(void) const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:419
Time(long int v)
Construct from a numeric value.
Definition: nstime.h:196
static struct Resolution SetDefaultNsResolution(void)
Set the default resolution.
Definition: time.cc:170
int64_t factor
Ratio of this unit / current unit.
Definition: nstime.h:577
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
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:42
int64_t GetMicroSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:387
friend int64x64_t operator/(const Time &lhs, const Time &rhs)
Exact division, returning a dimensionless fixed point number.
Definition: nstime.h:1027
double GetDays(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:367
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:1121
Time(double v)
Construct from a numeric value.
Definition: nstime.h:180
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:228
int64_t GetNanoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:391
friend Time & operator+=(Time &lhs, const Time &rhs)
Compound addition assignment for Time.
Definition: nstime.h:1149
friend bool operator==(const Time &lhs, const Time &rhs)
Equality operator for Time.
Definition: nstime.h:820
Time Hours(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1262
Time()
Default constructor, with value 0.
Definition: nstime.h:135
~Time()
Destructor.
Definition: nstime.h:288
static struct Information * PeekInformation(enum Unit timeUnit)
Get the Information record for timeUnit for the current Resolution.
Definition: nstime.h:604
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:935
Time Minutes(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1270
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:480
#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:212
static void Mark(Time *const time)
Record a Time instance with the MarkedTimes.
Definition: time.cc:288
friend bool operator>(const Time &lhs, const Time &rhs)
Greater than operator for Time.
Definition: nstime.h:875
double GetMinutes(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:375
An identifier for simulation events.
Definition: event-id.h:53
int Compare(const Time &o) const
Compare this to another Time.
Definition: nstime.h:342
friend Time Rem(const Time &lhs, const Time &rhs)
Remainder (modulus) from the quotient of two Times.
Definition: nstime.h:1138
int64_t GetMilliSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:383
bool IsPositive(void) const
Exactly equivalent to t >= 0.
Definition: nstime.h:316
How to convert between other units and the current unit.
Definition: nstime.h:573
bool IsStrictlyNegative(void) const
Exactly equivalent to t < 0.
Definition: nstime.h:324
static Time FromInteger(uint64_t value, enum Unit unit)
Create a Time equal to value in unit unit.
Definition: nstime.h:467
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1278
bool operator>(const int64x64_t &lhs, const int64x64_t &rhs)
Greater operator.
Definition: int64x64-128.h:400
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:585
Time::Unit m_unit
The unit to use in output.
Definition: nstime.h:1401
static void SetResolution(enum Unit resolution)
Definition: time.cc:180
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:449
int64x64_t To(enum Unit unit) const
Get the Time value expressed in a particular unit.
Definition: nstime.h:533
static void Clear(Time *const time)
Remove a Time instance from the MarkedTimes, called by ~Time().
Definition: time.cc:314
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1294
TimeWithUnit(const Time time, const Time::Unit unit)
Attach a unit to a Time.
Definition: nstime.h:1394
int64x64_t & operator-=(int64x64_t &lhs, const int64x64_t &rhs)
Compound subtraction operator.
Definition: int64x64-128.h:424
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:644
static MarkedTimes * g_markingTimes
Record of outstanding Time objects which will need conversion when the resolution is set...
Definition: nstime.h:659
Time Days(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1254
Time FemtoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1318
int64_t GetFemtoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:399
static void ClearMarkedTimes()
Remove all MarkedTimes.
Definition: time.cc:257
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:842
ns3::EventId declarations.
Declaration of the ns3::int64x64_t type and associated operators.
Time & operator=(const Time &o)
Assignment operator.
Definition: nstime.h:129
double GetHours(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:371
Time m_time
The time.
Definition: nstime.h:1400
int64x64_t timeTo
Multiplier to convert to this unit.
Definition: nstime.h:578
Time(const Time &o)
Copy constructor.
Definition: nstime.h:148
bool IsNegative(void) const
Exactly equivalent to t <= 0.
Definition: nstime.h:308
int64_t m_data
Virtual time value, in the current unit.
Definition: nstime.h:790
bool toMul
Multiply when converting To, otherwise divide.
Definition: nstime.h:575
Time(Time &&o)
Move constructor.
Definition: nstime.h:162
int64_t GetTimeStep(void) const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:415
NS_UNUSED and NS_UNUSED_GLOBAL macro definitions.