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 
34 namespace ns3 {
35 
36 class TimeWithUnit;
37 
95 class Time
96 {
97 public:
101  enum Unit
102  {
103  Y = 0,
104  D = 1,
105  H = 2,
106  MIN = 3,
107  S = 4,
108  MS = 5,
109  US = 6,
110  NS = 7,
111  PS = 8,
112  FS = 9,
113  LAST = 10
114  };
115 
121  inline Time & operator = (const Time & o)
122  {
123  m_data = o.m_data;
124  return *this;
125  }
127  inline Time ()
128  : m_data ()
129  {
130  if (g_markingTimes)
131  {
132  Mark (this);
133  }
134  }
140  inline Time(const Time & o)
141  : m_data (o.m_data)
142  {
143  if (g_markingTimes)
144  {
145  Mark (this);
146  }
147  }
159  explicit inline Time (double v)
160  : m_data (lround (v))
161  {
162  if (g_markingTimes)
163  {
164  Mark (this);
165  }
166  }
167  explicit inline Time (int v)
168  : m_data (v)
169  {
170  if (g_markingTimes)
171  {
172  Mark (this);
173  }
174  }
175  explicit inline Time (long int v)
176  : m_data (v)
177  {
178  if (g_markingTimes)
179  {
180  Mark (this);
181  }
182  }
183  explicit inline Time (long long int v)
184  : m_data (v)
185  {
186  if (g_markingTimes)
187  {
188  Mark (this);
189  }
190  }
191  explicit inline Time (unsigned int v)
192  : m_data (v)
193  {
194  if (g_markingTimes)
195  {
196  Mark (this);
197  }
198  }
199  explicit inline Time (unsigned long int v)
200  : m_data (v)
201  {
202  if (g_markingTimes)
203  {
204  Mark (this);
205  }
206  }
207  explicit inline Time (unsigned long long int v)
208  : m_data (v)
209  {
210  if (g_markingTimes)
211  {
212  Mark (this);
213  }
214  }
215  explicit inline Time (const int64x64_t & v)
216  : m_data (v.GetHigh ())
217  {
218  if (g_markingTimes)
219  {
220  Mark (this);
221  }
222  }
246  explicit Time (const std::string & s);
247 
249  static Time Min ()
250  {
251  return Time (std::numeric_limits<int64_t>::min ());
252  }
254  static Time Max ()
255  {
256  return Time (std::numeric_limits<int64_t>::max ());
257  }
258 
260  ~Time ()
261  {
262  if (g_markingTimes)
263  {
264  Clear (this);
265  }
266  }
267 
269  inline bool IsZero (void) const
270  {
271  return m_data == 0;
272  }
274  inline bool IsNegative (void) const
275  {
276  return m_data <= 0;
277  }
279  inline bool IsPositive (void) const
280  {
281  return m_data >= 0;
282  }
284  inline bool IsStrictlyNegative (void) const
285  {
286  return m_data < 0;
287  }
289  inline bool IsStrictlyPositive (void) const
290  {
291  return m_data > 0;
292  }
299  inline int Compare (const Time & o) const
300  {
301  return (m_data < o.m_data) ? -1 : (m_data == o.m_data) ? 0 : 1;
302  }
303 
311  inline double GetYears (void) const
312  {
313  return ToDouble (Time::Y);
314  }
315  inline double GetDays (void) const
316  {
317  return ToDouble (Time::D);
318  }
319  inline double GetHours (void) const
320  {
321  return ToDouble (Time::H);
322  }
323  inline double GetMinutes (void) const
324  {
325  return ToDouble (Time::MIN);
326  }
327  inline double GetSeconds (void) const
328  {
329  return ToDouble (Time::S);
330  }
331  inline int64_t GetMilliSeconds (void) const
332  {
333  return ToInteger (Time::MS);
334  }
335  inline int64_t GetMicroSeconds (void) const
336  {
337  return ToInteger (Time::US);
338  }
339  inline int64_t GetNanoSeconds (void) const
340  {
341  return ToInteger (Time::NS);
342  }
343  inline int64_t GetPicoSeconds (void) const
344  {
345  return ToInteger (Time::PS);
346  }
347  inline int64_t GetFemtoSeconds (void) const
348  {
349  return ToInteger (Time::FS);
350  }
357  inline int64_t GetTimeStep (void) const
358  {
359  return m_data;
360  }
361  inline double GetDouble (void) const
362  {
363  return m_data;
364  }
365  inline int64_t GetInteger (void) const
366  {
367  return GetTimeStep ();
368  }
379  static void SetResolution (enum Unit resolution);
383  static enum Unit GetResolution (void);
384 
385 
392  inline static Time From (const int64x64_t & value)
393  {
394  return Time (value);
395  }
404  inline static Time FromInteger (uint64_t value, enum Unit unit)
405  {
406  struct Information *info = PeekInformation (unit);
407  if (info->fromMul)
408  {
409  value *= info->factor;
410  }
411  else
412  {
413  value /= info->factor;
414  }
415  return Time (value);
416  }
417  inline static Time FromDouble (double value, enum Unit unit)
418  {
419  return From (int64x64_t (value), unit);
420  }
421  inline static Time From (const int64x64_t & value, enum Unit unit)
422  {
423  struct Information *info = PeekInformation (unit);
424  // DO NOT REMOVE this temporary variable. It's here
425  // to work around a compiler bug in gcc 3.4
426  int64x64_t retval = value;
427  if (info->fromMul)
428  {
429  retval *= info->timeFrom;
430  }
431  else
432  {
433  retval.MulByInvert (info->timeFrom);
434  }
435  return Time (retval);
436  }
447  inline int64_t ToInteger (enum Unit unit) const
448  {
449  struct Information *info = PeekInformation (unit);
450  int64_t v = m_data;
451  if (info->toMul)
452  {
453  v *= info->factor;
454  }
455  else
456  {
457  v /= info->factor;
458  }
459  return v;
460  }
461  inline double ToDouble (enum Unit unit) const
462  {
463  return To (unit).GetDouble ();
464  }
465  inline int64x64_t To (enum Unit unit) const
466  {
467  struct Information *info = PeekInformation (unit);
468  int64x64_t retval = int64x64_t (m_data);
469  if (info->toMul)
470  {
471  retval *= info->timeTo;
472  }
473  else
474  {
475  retval.MulByInvert (info->timeTo);
476  }
477  return retval;
478  }
483  inline operator int64x64_t () const
484  {
485  return int64x64_t (m_data);
486  }
487 
488 
502  TimeWithUnit As (const enum Unit unit) const;
503 
510  typedef void (* TracedValueCallback)(const Time oldValue,
511  const Time newValue);
512 
513 private:
515  struct Information
516  {
517  bool toMul;
518  bool fromMul;
519  int64_t factor;
522  };
524  struct Resolution
525  {
528  };
529 
535  static inline struct Resolution *PeekResolution (void)
536  {
537  static struct Time::Resolution resolution = SetDefaultNsResolution ();
538  return & resolution;
539  }
546  static inline struct Information *PeekInformation (enum Unit timeUnit)
547  {
548  return & (PeekResolution ()->info[timeUnit]);
549  }
550 
556  static struct Resolution SetDefaultNsResolution (void);
564  static void SetResolution (enum Unit unit, struct Resolution *resolution,
565  const bool convert = true);
566 
586  typedef std::set< Time * > MarkedTimes;
601  static MarkedTimes * g_markingTimes;
602 public:
608  static bool StaticInit ();
609 private:
610 
611  /* Friend the Simulator class so it can call the private function
612  ClearMarkedTimes ()
613  */
614  friend class Simulator;
621  static void ClearMarkedTimes ();
626  static void Mark (Time * const time);
631  static void Clear (Time * const time);
636  static void ConvertTimes (const enum Unit unit);
637 
645  friend bool operator == (const Time & lhs, const Time & rhs);
646  friend bool operator != (const Time & lhs, const Time & rhs);
647  friend bool operator <= (const Time & lhs, const Time & rhs);
648  friend bool operator >= (const Time & lhs, const Time & rhs);
649  friend bool operator < (const Time & lhs, const Time & rhs);
650  friend bool operator > (const Time & lhs, const Time & rhs);
651  friend Time operator + (const Time & lhs, const Time & rhs);
652  friend Time operator - (const Time & lhs, const Time & rhs);
653  friend Time operator * (const Time & lhs, const int64_t & rhs);
654  friend Time operator * (const int64_t & lhs, const Time & rhs);
655  friend int64_t operator / (const Time & lhs, const Time & rhs);
656  friend Time operator / (const Time & lhs, const int64_t & rhs);
657  friend Time & operator += (Time & lhs, const Time & rhs);
658  friend Time & operator -= (Time & lhs, const Time & rhs);
666  friend Time Abs (const Time & time);
673  friend Time Max (const Time & ta, const Time & tb);
680  friend Time Min (const Time & ta, const Time & tb);
681 
682  int64_t m_data;
683 
684 }; // class Time
685 
686 
688 static bool NS_UNUSED_GLOBAL (g_TimeStaticInit) = Time::StaticInit ();
689 
690 inline bool
691 operator == (const Time & lhs, const Time & rhs)
692 {
693  return lhs.m_data == rhs.m_data;
694 }
695 inline bool
696 operator != (const Time & lhs, const Time & rhs)
697 {
698  return lhs.m_data != rhs.m_data;
699 }
700 inline bool
701 operator <= (const Time & lhs, const Time & rhs)
702 {
703  return lhs.m_data <= rhs.m_data;
704 }
705 inline bool
706 operator >= (const Time & lhs, const Time & rhs)
707 {
708  return lhs.m_data >= rhs.m_data;
709 }
710 inline bool
711 operator < (const Time & lhs, const Time & rhs)
712 {
713  return lhs.m_data < rhs.m_data;
714 }
715 inline bool
716 operator > (const Time & lhs, const Time & rhs)
717 {
718  return lhs.m_data > rhs.m_data;
719 }
720 inline Time operator + (const Time & lhs, const Time & rhs)
721 {
722  return Time (lhs.m_data + rhs.m_data);
723 }
724 inline Time operator - (const Time & lhs, const Time & rhs)
725 {
726  return Time (lhs.m_data - rhs.m_data);
727 }
728 inline Time
729 operator * (const Time & lhs, const int64_t & rhs)
730 {
731  Time res = lhs;
732  res.m_data *= rhs;
733  return res;
734 }
735 inline Time
736 operator * (const int64_t & lhs, const Time & rhs)
737 {
738  Time res = rhs;
739  res.m_data *= lhs;
740  return res;
741 }
742 inline int64_t
743 operator / (const Time & lhs, const Time & rhs)
744 {
745  int64_t res = lhs.m_data / rhs.m_data;
746  return res;
747 }
748 inline Time
749 operator / (const Time & lhs, const int64_t & rhs)
750 {
751  Time res = lhs;
752  res.m_data /= rhs;
753  return res;
754 }
755 inline Time & operator += (Time & lhs, const Time & rhs)
756 {
757  lhs.m_data += rhs.m_data;
758  return lhs;
759 }
760 inline Time & operator -= (Time & lhs, const Time & rhs)
761 {
762  lhs.m_data -= rhs.m_data;
763  return lhs;
764 }
765 
766 
767 inline Time Abs (const Time & time)
768 {
769  return Time ((time.m_data < 0) ? -time.m_data : time.m_data);
770 }
771 inline Time Max (const Time & ta, const Time & tb)
772 {
773  return Time ((ta.m_data < tb.m_data) ? tb : ta);
774 }
775 inline Time Min (const Time & ta, const Time & tb)
776 {
777  return Time ((ta.m_data > tb.m_data) ? tb : ta);
778 }
779 
796 std::ostream & operator << (std::ostream & os, const Time & time);
807 std::istream & operator >> (std::istream & is, Time & time);
808 
827 inline Time Years (double value)
828 {
829  return Time::FromDouble (value, Time::Y);
830 }
831 inline Time Years (int64x64_t value)
832 {
833  return Time::From (value, Time::Y);
834 }
835 inline Time Days (double value)
836 {
837  return Time::FromDouble (value, Time::D);
838 }
839 inline Time Days (int64x64_t value)
840 {
841  return Time::From (value, Time::D);
842 }
843 inline Time Hours (double value)
844 {
845  return Time::FromDouble (value, Time::H);
846 }
847 inline Time Hours (int64x64_t value)
848 {
849  return Time::From (value, Time::H);
850 }
851 inline Time Minutes (double value)
852 {
853  return Time::FromDouble (value, Time::MIN);
854 }
855 inline Time Minutes (int64x64_t value)
856 {
857  return Time::From (value, Time::MIN);
858 }
859 inline Time Seconds (double value)
860 {
861  return Time::FromDouble (value, Time::S);
862 }
863 inline Time Seconds (int64x64_t value)
864 {
865  return Time::From (value, Time::S);
866 }
867 inline Time MilliSeconds (uint64_t value)
868 {
869  return Time::FromInteger (value, Time::MS);
870 }
872 {
873  return Time::From (value, Time::MS);
874 }
875 inline Time MicroSeconds (uint64_t value)
876 {
877  return Time::FromInteger (value, Time::US);
878 }
880 {
881  return Time::From (value, Time::US);
882 }
883 inline Time NanoSeconds (uint64_t value)
884 {
885  return Time::FromInteger (value, Time::NS);
886 }
888 {
889  return Time::From (value, Time::NS);
890 }
891 inline Time PicoSeconds (uint64_t value)
892 {
893  return Time::FromInteger (value, Time::PS);
894 }
896 {
897  return Time::From (value, Time::PS);
898 }
899 inline Time FemtoSeconds (uint64_t value)
900 {
901  return Time::FromInteger (value, Time::FS);
902 }
904 {
905  return Time::From (value, Time::FS);
906 }
916 inline Time TimeStep (uint64_t ts)
917 {
918  return Time (ts);
919 }
920 
923 
934 
941 inline
943 {
944  return MakeTimeChecker (Time::Min (), Time::Max ());
945 }
946 
954 inline
956 {
957  return MakeTimeChecker (min, Time::Max ());
958 }
959 
965 {
966 public:
973  TimeWithUnit (const Time time, const Time::Unit unit)
974  : m_time (time),
975  m_unit (unit)
976  { };
977 
978 private:
979  Time m_time;
981 
988  friend std::ostream & operator << (std::ostream & os, const TimeWithUnit & timeU);
989 
990 }; // class TimeWithUnit
991 
992 } // namespace ns3
993 
994 #endif /* TIME_H */
static struct Resolution * PeekResolution(void)
Get the current Resolution.
Definition: nstime.h:535
Unit
The unit to use to interpret a number representing time.
Definition: nstime.h:101
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:95
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
bool IsPositive(void) const
Definition: nstime.h:279
Control the scheduling of simulation events.
Definition: simulator.h:70
int64x64_t operator+(const int64x64_t &lhs)
Unary plus operator.
Definition: int64x64-128.h:404
friend Time operator*(const Time &lhs, const int64_t &rhs)
Arithmetic operator.
Definition: nstime.h:729
int64x64_t timeFrom
Multiplier to convert from this unit.
Definition: nstime.h:521
static Time Min()
Minimum representable Time.
Definition: nstime.h:249
A Time with attached unit, to facilitate output in that unit.
Definition: nstime.h:964
int64_t ToInteger(enum Unit unit) const
Get the Time value expressed in a particular unit.
Definition: nstime.h:447
High precision numerical type, implementing Q64.64 fixed precision.
Definition: int64x64-128.h:39
bool IsZero(void) const
Definition: nstime.h:269
friend bool operator<(const Time &lhs, const Time &rhs)
Arithmetic operator.
Definition: nstime.h:711
friend bool operator!=(const Time &lhs, const Time &rhs)
Arithmetic operator.
Definition: nstime.h:696
int64x64_t operator-(const int64x64_t &lhs)
Unary negation operator (change sign operator).
Definition: int64x64-128.h:412
static Time From(const int64x64_t &value)
Create a Time in the current unit.
Definition: nstime.h:392
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:867
second
Definition: nstime.h:107
#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:367
void MulByInvert(const int64x64_t &o)
Multiply this value by a Q0.128 value, presumably representing an inverse, completing a division oper...
int64_t GetFemtoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:347
double GetDouble(void) const
Get this value as a double.
Definition: int64x64-128.h:197
Time(unsigned long int v)
Construct from a numeric value.
Definition: nstime.h:199
Time(const int64x64_t &v)
Construct from a numeric value.
Definition: nstime.h:215
bool operator>=(const int64x64_t &lhs, const int64x64_t &rhs)
Greater or equal operator.
Definition: int64x64.h:139
int Compare(const Time &o) const
Compare this to another Time.
Definition: nstime.h:299
millisecond
Definition: nstime.h:108
hour, 60 minutes
Definition: nstime.h:105
friend Time operator-(const Time &lhs, const Time &rhs)
Arithmetic operator.
Definition: nstime.h:724
int64x64_t To(enum Unit unit) const
Get the Time value expressed in a particular unit.
Definition: nstime.h:465
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:439
Time PicoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:891
struct Information info[LAST]
Conversion info from current unit.
Definition: nstime.h:526
static bool NS_UNUSED_GLOBAL(g_TimeStaticInit)
Force static initialization of Time.
day, 24 hours
Definition: nstime.h:104
friend Time operator+(const Time &lhs, const Time &rhs)
Arithmetic operator.
Definition: nstime.h:720
static Time Max()
Maximum representable Time.
Definition: nstime.h:254
friend Time Abs(const Time &time)
Absolute value function for Time.
Definition: nstime.h:767
bool operator<=(const int64x64_t &lhs, const int64x64_t &rhs)
Less or equal operator.
Definition: int64x64.h:131
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:327
int64x64_t operator*(const int64x64_t &lhs, const int64x64_t &rhs)
Multiplication operator.
Definition: int64x64.h:102
int64x64_t Min(const int64x64_t &a, const int64x64_t &b)
Minimum.
Definition: int64x64.h:191
Time(int v)
Construct from a numeric value.
Definition: nstime.h:167
Time Years(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:827
static enum Unit GetResolution(void)
Definition: time.cc:373
int64_t GetMicroSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:335
friend Time & operator-=(Time &lhs, const Time &rhs)
Arithmetic operator.
Definition: nstime.h:760
Time(long long int v)
Construct from a numeric value.
Definition: nstime.h:183
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:883
Current time unit, and conversion info.
Definition: nstime.h:524
static bool StaticInit()
Function to force static initialization of Time.
Definition: time.cc:56
bool IsStrictlyPositive(void) const
Definition: nstime.h:289
bool fromMul
Multiple when converting From, otherwise divide.
Definition: nstime.h:518
friend std::ostream & operator<<(std::ostream &os, const TimeWithUnit &timeU)
Output streamer.
Definition: time.cc:396
static Time From(const int64x64_t &value, enum Unit unit)
Create a Time equal to value in unit unit.
Definition: nstime.h:421
Ptr< SampleEmitter > s
double ToDouble(enum Unit unit) const
Get the Time value expressed in a particular unit.
Definition: nstime.h:461
ns3::AttributeValue, ns3::AttributeAccessor and ns3::AttributeChecker declarations.
int64x64_t Max(const int64x64_t &a, const int64x64_t &b)
Maximum.
Definition: int64x64.h:203
year, 365 days
Definition: nstime.h:103
static void ConvertTimes(const enum Unit unit)
Convert existing Times to the new unit.
Definition: time.cc:336
friend bool operator>=(const Time &lhs, const Time &rhs)
Arithmetic operator.
Definition: nstime.h:706
minute, 60 seconds
Definition: nstime.h:106
Time(long int v)
Construct from a numeric value.
Definition: nstime.h:175
static struct Resolution SetDefaultNsResolution(void)
Set the default resolution.
Definition: time.cc:163
femtosecond
Definition: nstime.h:112
int64_t factor
Ratio of this unit / current unit.
Definition: nstime.h:519
bool operator<(const int64x64_t &lhs, const int64x64_t &rhs)
Less than operator.
Definition: int64x64-128.h:350
int64x64_t operator/(const int64x64_t &lhs, const int64x64_t &rhs)
Division operator.
Definition: int64x64.h:113
int64x64_t Abs(const int64x64_t &value)
Absolute value.
Definition: int64x64.h:178
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:159
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:1272
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:207
friend Time & operator+=(Time &lhs, const Time &rhs)
Arithmetic operator.
Definition: nstime.h:755
friend bool operator==(const Time &lhs, const Time &rhs)
Arithmetic operator.
Definition: nstime.h:691
bool IsNegative(void) const
Definition: nstime.h:274
int64_t GetTimeStep(void) const
Definition: nstime.h:357
friend int64_t operator/(const Time &lhs, const Time &rhs)
Arithmetic operator.
Definition: nstime.h:743
Time Hours(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:843
Time TimeStep(uint64_t ts)
Definition: nstime.h:916
double GetHours(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:319
Time()
Default constructor, with value 0.
Definition: nstime.h:127
int64_t GetInteger(void) const
Definition: nstime.h:365
~Time()
Destructor.
Definition: nstime.h:260
double GetDouble(void) const
Definition: nstime.h:361
static struct Information * PeekInformation(enum Unit timeUnit)
Get the Information record for timeUnit for the current Resolution.
Definition: nstime.h:546
Declaration of Attribute helper macros.
Time Minutes(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:851
int64_t GetNanoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:339
static Time FromDouble(double value, enum Unit unit)
Create a Time equal to value in unit unit.
Definition: nstime.h:417
#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:191
static void Mark(Time *const time)
Record a Time instance with the MarkedTimes.
Definition: time.cc:280
microsecond
Definition: nstime.h:109
friend bool operator>(const Time &lhs, const Time &rhs)
Arithmetic operator.
Definition: nstime.h:716
int64_t GetPicoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:343
TimeWithUnit As(const enum Unit unit) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:381
void(* TracedValueCallback)(const Time oldValue, const Time newValue)
TracedValue callback signature for Time.
Definition: nstime.h:510
How to convert between other units and the current unit.
Definition: nstime.h:515
static Time FromInteger(uint64_t value, enum Unit unit)
Create a Time equal to value in unit unit.
Definition: nstime.h:404
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:859
double GetDays(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:315
bool operator>(const int64x64_t &lhs, const int64x64_t &rhs)
Greater operator.
Definition: int64x64-128.h:358
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.cc:95
enum Time::Unit unit
Current time unit.
Definition: nstime.h:527
Time::Unit m_unit
The unit to use in output.
Definition: nstime.h:980
bool IsStrictlyNegative(void) const
Definition: nstime.h:284
static void SetResolution(enum Unit resolution)
Definition: time.cc:173
static void Clear(Time *const time)
Remove a Time instance from the MarkedTimes, called by ~Time().
Definition: time.cc:306
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:875
TimeWithUnit(const Time time, const Time::Unit unit)
Attach a unit to a Time.
Definition: nstime.h:973
picosecond
Definition: nstime.h:111
nanosecond
Definition: nstime.h:110
std::set< Time * > MarkedTimes
Record all instances of Time, so we can rescale them when the resolution changes. ...
Definition: nstime.h:586
static MarkedTimes * g_markingTimes
Record of outstanding Time objects which will need conversion when the resolution is set...
Definition: nstime.h:601
Time Days(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:835
Time FemtoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:899
double GetYears(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:311
static void ClearMarkedTimes()
Remove all MarkedTimes.
Definition: time.cc:249
friend bool operator<=(const Time &lhs, const Time &rhs)
Arithmetic operator.
Definition: nstime.h:701
int64_t GetMilliSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:331
double GetMinutes(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:323
Time & operator=(const Time &o)
Assignment operator.
Definition: nstime.h:121
Time m_time
The time.
Definition: nstime.h:976
int64x64_t timeTo
Multiplier to convert to this unit.
Definition: nstime.h:520
Time(const Time &o)
Copy constructor.
Definition: nstime.h:140
int64_t m_data
Virtual time value, in the current unit.
Definition: nstime.h:682
bool toMul
Multiply when converting To, otherwise divide.
Definition: nstime.h:517
int64x64_t & operator-=(int64x64_t &lhs, const int64x64_t &rhs)
Compound subtraction operator.
Definition: int64x64-128.h:376