A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  }
155  explicit inline Time (double v)
156  : m_data (lround (v))
157  {
158  if (g_markingTimes)
159  {
160  Mark (this);
161  }
162  }
163  explicit inline Time (int v)
164  : m_data (v)
165  {
166  if (g_markingTimes)
167  {
168  Mark (this);
169  }
170  }
171  explicit inline Time (long int v)
172  : m_data (v)
173  {
174  if (g_markingTimes)
175  {
176  Mark (this);
177  }
178  }
179  explicit inline Time (long long int v)
180  : m_data (v)
181  {
182  if (g_markingTimes)
183  {
184  Mark (this);
185  }
186  }
187  explicit inline Time (unsigned int v)
188  : m_data (v)
189  {
190  if (g_markingTimes)
191  {
192  Mark (this);
193  }
194  }
195  explicit inline Time (unsigned long int v)
196  : m_data (v)
197  {
198  if (g_markingTimes)
199  {
200  Mark (this);
201  }
202  }
203  explicit inline Time (unsigned long long int v)
204  : m_data (v)
205  {
206  if (g_markingTimes)
207  {
208  Mark (this);
209  }
210  }
211  explicit inline Time (const int64x64_t & v)
212  : m_data (v.GetHigh ())
213  {
214  if (g_markingTimes)
215  {
216  Mark (this);
217  }
218  }
241  explicit Time (const std::string & s);
242 
244  static Time Min ()
245  {
246  return Time (std::numeric_limits<int64_t>::min ());
247  }
249  static Time Max ()
250  {
251  return Time (std::numeric_limits<int64_t>::max ());
252  }
253 
255  ~Time ()
256  {
257  if (g_markingTimes)
258  {
259  Clear (this);
260  }
261  }
262 
264  inline bool IsZero (void) const
265  {
266  return m_data == 0;
267  }
269  inline bool IsNegative (void) const
270  {
271  return m_data <= 0;
272  }
274  inline bool IsPositive (void) const
275  {
276  return m_data >= 0;
277  }
279  inline bool IsStrictlyNegative (void) const
280  {
281  return m_data < 0;
282  }
284  inline bool IsStrictlyPositive (void) const
285  {
286  return m_data > 0;
287  }
294  inline int Compare (const Time & o) const
295  {
296  return (m_data < o.m_data) ? -1 : (m_data == o.m_data) ? 0 : 1;
297  }
298 
306  inline double GetYears (void) const
307  {
308  return ToDouble (Time::Y);
309  }
310  inline double GetDays (void) const
311  {
312  return ToDouble (Time::D);
313  }
314  inline double GetHours (void) const
315  {
316  return ToDouble (Time::H);
317  }
318  inline double GetMinutes (void) const
319  {
320  return ToDouble (Time::MIN);
321  }
322  inline double GetSeconds (void) const
323  {
324  return ToDouble (Time::S);
325  }
326  inline int64_t GetMilliSeconds (void) const
327  {
328  return ToInteger (Time::MS);
329  }
330  inline int64_t GetMicroSeconds (void) const
331  {
332  return ToInteger (Time::US);
333  }
334  inline int64_t GetNanoSeconds (void) const
335  {
336  return ToInteger (Time::NS);
337  }
338  inline int64_t GetPicoSeconds (void) const
339  {
340  return ToInteger (Time::PS);
341  }
342  inline int64_t GetFemtoSeconds (void) const
343  {
344  return ToInteger (Time::FS);
345  }
352  inline int64_t GetTimeStep (void) const
353  {
354  return m_data;
355  }
356  inline double GetDouble (void) const
357  {
358  return m_data;
359  }
360  inline int64_t GetInteger (void) const
361  {
362  return GetTimeStep ();
363  }
374  static void SetResolution (enum Unit resolution);
378  static enum Unit GetResolution (void);
379 
380 
387  inline static Time From (const int64x64_t & value)
388  {
389  return Time (value);
390  }
399  inline static Time FromInteger (uint64_t value, enum Unit unit)
400  {
401  struct Information *info = PeekInformation (unit);
402  if (info->fromMul)
403  {
404  value *= info->factor;
405  }
406  else
407  {
408  value /= info->factor;
409  }
410  return Time (value);
411  }
412  inline static Time FromDouble (double value, enum Unit unit)
413  {
414  return From (int64x64_t (value), unit);
415  }
416  inline static Time From (const int64x64_t & value, enum Unit unit)
417  {
418  struct Information *info = PeekInformation (unit);
419  // DO NOT REMOVE this temporary variable. It's here
420  // to work around a compiler bug in gcc 3.4
421  int64x64_t retval = value;
422  if (info->fromMul)
423  {
424  retval *= info->timeFrom;
425  }
426  else
427  {
428  retval.MulByInvert (info->timeFrom);
429  }
430  return Time (retval);
431  }
442  inline int64_t ToInteger (enum Unit unit) const
443  {
444  struct Information *info = PeekInformation (unit);
445  int64_t v = m_data;
446  if (info->toMul)
447  {
448  v *= info->factor;
449  }
450  else
451  {
452  v /= info->factor;
453  }
454  return v;
455  }
456  inline double ToDouble (enum Unit unit) const
457  {
458  return To (unit).GetDouble ();
459  }
460  inline int64x64_t To (enum Unit unit) const
461  {
462  struct Information *info = PeekInformation (unit);
463  int64x64_t retval = int64x64_t (m_data);
464  if (info->toMul)
465  {
466  retval *= info->timeTo;
467  }
468  else
469  {
470  retval.MulByInvert (info->timeTo);
471  }
472  return retval;
473  }
478  inline operator int64x64_t () const
479  {
480  return int64x64_t (m_data);
481  }
482 
483 
497  TimeWithUnit As (const enum Unit unit) const;
498 
499 private:
501  struct Information
502  {
503  bool toMul;
504  bool fromMul;
505  int64_t factor;
508  };
510  struct Resolution
511  {
514  };
515 
521  static inline struct Resolution *PeekResolution (void)
522  {
523  static struct Time::Resolution resolution = SetDefaultNsResolution ();
524  return & resolution;
525  }
532  static inline struct Information *PeekInformation (enum Unit timeUnit)
533  {
534  return & (PeekResolution ()->info[timeUnit]);
535  }
536 
542  static struct Resolution SetDefaultNsResolution (void);
550  static void SetResolution (enum Unit unit, struct Resolution *resolution,
551  const bool convert = true);
552 
572  typedef std::set< Time * > MarkedTimes;
588 public:
594  static bool StaticInit ();
595 private:
596 
597  /* Friend the Simulator class so it can call the private function
598  ClearMarkedTimes ()
599  */
600  friend class Simulator;
607  static void ClearMarkedTimes ();
612  static void Mark (Time * const time);
617  static void Clear (Time * const time);
622  static void ConvertTimes (const enum Unit unit);
623 
631  friend bool operator == (const Time & lhs, const Time & rhs);
632  friend bool operator != (const Time & lhs, const Time & rhs);
633  friend bool operator <= (const Time & lhs, const Time & rhs);
634  friend bool operator >= (const Time & lhs, const Time & rhs);
635  friend bool operator < (const Time & lhs, const Time & rhs);
636  friend bool operator > (const Time & lhs, const Time & rhs);
637  friend Time operator + (const Time & lhs, const Time & rhs);
638  friend Time operator - (const Time & lhs, const Time & rhs);
639  friend Time operator * (const Time & lhs, const int64_t & rhs);
640  friend Time operator * (const int64_t & lhs, const Time & rhs);
641  friend int64_t operator / (const Time & lhs, const Time & rhs);
642  friend Time operator / (const Time & lhs, const int64_t & rhs);
643  friend Time & operator += (Time & lhs, const Time & rhs);
644  friend Time & operator -= (Time & lhs, const Time & rhs);
652  friend Time Abs (const Time & time);
659  friend Time Max (const Time & ta, const Time & tb);
666  friend Time Min (const Time & ta, const Time & tb);
667 
668  int64_t m_data;
669 
670 }; // class Time
671 
672 
674 static bool NS_UNUSED_GLOBAL (g_TimeStaticInit) = Time::StaticInit ();
675 
676 inline bool
677 operator == (const Time & lhs, const Time & rhs)
678 {
679  return lhs.m_data == rhs.m_data;
680 }
681 inline bool
682 operator != (const Time & lhs, const Time & rhs)
683 {
684  return lhs.m_data != rhs.m_data;
685 }
686 inline bool
687 operator <= (const Time & lhs, const Time & rhs)
688 {
689  return lhs.m_data <= rhs.m_data;
690 }
691 inline bool
692 operator >= (const Time & lhs, const Time & rhs)
693 {
694  return lhs.m_data >= rhs.m_data;
695 }
696 inline bool
697 operator < (const Time & lhs, const Time & rhs)
698 {
699  return lhs.m_data < rhs.m_data;
700 }
701 inline bool
702 operator > (const Time & lhs, const Time & rhs)
703 {
704  return lhs.m_data > rhs.m_data;
705 }
706 inline Time operator + (const Time & lhs, const Time & rhs)
707 {
708  return Time (lhs.m_data + rhs.m_data);
709 }
710 inline Time operator - (const Time & lhs, const Time & rhs)
711 {
712  return Time (lhs.m_data - rhs.m_data);
713 }
714 inline Time
715 operator * (const Time & lhs, const int64_t & rhs)
716 {
717  Time res = lhs;
718  res.m_data *= rhs;
719  return res;
720 }
721 inline Time
722 operator * (const int64_t & lhs, const Time & rhs)
723 {
724  Time res = rhs;
725  res.m_data *= lhs;
726  return res;
727 }
728 inline int64_t
729 operator / (const Time & lhs, const Time & rhs)
730 {
731  int64_t res = lhs.m_data / rhs.m_data;
732  return res;
733 }
734 inline Time
735 operator / (const Time & lhs, const int64_t & rhs)
736 {
737  Time res = lhs;
738  res.m_data /= rhs;
739  return res;
740 }
741 inline Time & operator += (Time & lhs, const Time & rhs)
742 {
743  lhs.m_data += rhs.m_data;
744  return lhs;
745 }
746 inline Time & operator -= (Time & lhs, const Time & rhs)
747 {
748  lhs.m_data -= rhs.m_data;
749  return lhs;
750 }
751 
752 
753 inline Time Abs (const Time & time)
754 {
755  return Time ((time.m_data < 0) ? -time.m_data : time.m_data);
756 }
757 inline Time Max (const Time & ta, const Time & tb)
758 {
759  return Time ((ta.m_data < tb.m_data) ? tb : ta);
760 }
761 inline Time Min (const Time & ta, const Time & tb)
762 {
763  return Time ((ta.m_data > tb.m_data) ? tb : ta);
764 }
765 
782 std::ostream & operator << (std::ostream & os, const Time & time);
793 std::istream & operator >> (std::istream & is, Time & time);
794 
813 inline Time Years (double value)
814 {
815  return Time::FromDouble (value, Time::Y);
816 }
817 inline Time Years (int64x64_t value)
818 {
819  return Time::From (value, Time::Y);
820 }
821 inline Time Days (double value)
822 {
823  return Time::FromDouble (value, Time::D);
824 }
825 inline Time Days (int64x64_t value)
826 {
827  return Time::From (value, Time::D);
828 }
829 inline Time Hours (double value)
830 {
831  return Time::FromDouble (value, Time::H);
832 }
833 inline Time Hours (int64x64_t value)
834 {
835  return Time::From (value, Time::H);
836 }
837 inline Time Minutes (double value)
838 {
839  return Time::FromDouble (value, Time::MIN);
840 }
841 inline Time Minutes (int64x64_t value)
842 {
843  return Time::From (value, Time::MIN);
844 }
845 inline Time Seconds (double value)
846 {
847  return Time::FromDouble (value, Time::S);
848 }
849 inline Time Seconds (int64x64_t value)
850 {
851  return Time::From (value, Time::S);
852 }
853 inline Time MilliSeconds (uint64_t value)
854 {
855  return Time::FromInteger (value, Time::MS);
856 }
858 {
859  return Time::From (value, Time::MS);
860 }
861 inline Time MicroSeconds (uint64_t value)
862 {
863  return Time::FromInteger (value, Time::US);
864 }
866 {
867  return Time::From (value, Time::US);
868 }
869 inline Time NanoSeconds (uint64_t value)
870 {
871  return Time::FromInteger (value, Time::NS);
872 }
874 {
875  return Time::From (value, Time::NS);
876 }
877 inline Time PicoSeconds (uint64_t value)
878 {
879  return Time::FromInteger (value, Time::PS);
880 }
882 {
883  return Time::From (value, Time::PS);
884 }
885 inline Time FemtoSeconds (uint64_t value)
886 {
887  return Time::FromInteger (value, Time::FS);
888 }
890 {
891  return Time::From (value, Time::FS);
892 }
902 inline Time TimeStep (uint64_t ts)
903 {
904  return Time (ts);
905 }
906 
913 
931 
938 inline
940 {
941  return MakeTimeChecker (Time::Min (), Time::Max ());
942 }
943 
951 inline
953 {
954  return MakeTimeChecker (min, Time::Max ());
955 }
956 
962 {
963 public:
970  TimeWithUnit (const Time time, const Time::Unit unit)
971  : m_time (time),
972  m_unit (unit)
973  { };
974 
975 private:
976  Time m_time;
978 
985  friend std::ostream & operator << (std::ostream & os, const TimeWithUnit & timeU);
986 
987 }; // class TimeWithUnit
988 
989 } // namespace ns3
990 
991 #endif /* TIME_H */
static struct Resolution * PeekResolution(void)
Get the current Resolution.
Definition: nstime.h:521
std::istream & operator>>(std::istream &is, Angles &a)
initialize a struct Angles from input
Definition: angles.cc:49
nanosecond
Definition: nstime.h:110
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:95
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:60
bool IsPositive(void) const
Definition: nstime.h:274
microsecond
Definition: nstime.h:109
Control the scheduling of simulation events.
Definition: simulator.h:63
int64x64_t operator+(const int64x64_t &lhs)
Unary plus operator.
Definition: int64x64-128.h:381
friend Time operator*(const Time &lhs, const int64_t &rhs)
Arithmetic operator.
Definition: nstime.h:715
int64x64_t timeFrom
Multiplier to convert from this unit.
Definition: nstime.h:507
static Time Min()
Minimum representable Time.
Definition: nstime.h:244
A Time with attached unit, to facilitate output in that unit.
Definition: nstime.h:961
int64_t ToInteger(enum Unit unit) const
Get the Time value expressed in a particular unit.
Definition: nstime.h:442
day, 24 hours
Definition: nstime.h:104
High precision numerical type, implementing Q64.64 fixed precision.
Definition: int64x64-128.h:20
bool IsZero(void) const
Definition: nstime.h:264
friend bool operator<(const Time &lhs, const Time &rhs)
Arithmetic operator.
Definition: nstime.h:697
friend bool operator!=(const Time &lhs, const Time &rhs)
Arithmetic operator.
Definition: nstime.h:682
minute, 60 seconds
Definition: nstime.h:106
int64x64_t operator-(const int64x64_t &lhs)
Unary negation operator (change sign operator)
Definition: int64x64-128.h:389
static Time From(const int64x64_t &value)
Create a Time in the current unit.
Definition: nstime.h:387
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:853
#define ATTRIBUTE_VALUE_DEFINE(Name)
Declare the attribute value class NameValue for the class Name
int64x64_t & operator+=(int64x64_t &lhs, const int64x64_t &rhs)
Compound addition operator.
Definition: int64x64-128.h:344
void MulByInvert(const int64x64_t &o)
Multiply this value by a Q0.128 value, presumably representing an inverse, completing a division oper...
hour, 60 minutes
Definition: nstime.h:105
int64_t GetFemtoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:342
double GetDouble(void) const
Get this value as a double.
Definition: int64x64-128.h:175
Time(unsigned long int v)
Construct from a numeric value.
Definition: nstime.h:195
Time(const int64x64_t &v)
Construct from a numeric value.
Definition: nstime.h:211
bool operator>=(const int64x64_t &lhs, const int64x64_t &rhs)
Greater or equal operator.
Definition: int64x64.h:154
int Compare(const Time &o) const
Compare this to another Time.
Definition: nstime.h:294
friend Time operator-(const Time &lhs, const Time &rhs)
Arithmetic operator.
Definition: nstime.h:710
int64x64_t To(enum Unit unit) const
Get the Time value expressed in a particular unit.
Definition: nstime.h:460
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:444
Time PicoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:877
struct Information info[LAST]
Conversion info from current unit.
Definition: nstime.h:512
static bool NS_UNUSED_GLOBAL(g_TimeStaticInit)
Force static initialization of Time.
friend Time operator+(const Time &lhs, const Time &rhs)
Arithmetic operator.
Definition: nstime.h:706
static Time Max()
Maximum representable Time.
Definition: nstime.h:249
friend Time Abs(const Time &time)
Absolute value function for Time.
Definition: nstime.h:753
bool operator<=(const int64x64_t &lhs, const int64x64_t &rhs)
Less or equal operator.
Definition: int64x64.h:146
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:322
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:194
Time(int v)
Construct from a numeric value.
Definition: nstime.h:163
Time Years(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:813
picosecond
Definition: nstime.h:111
year, 365 days
Definition: nstime.h:103
static enum Unit GetResolution(void)
Definition: time.cc:378
int64_t GetMicroSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:330
friend Time & operator-=(Time &lhs, const Time &rhs)
Arithmetic operator.
Definition: nstime.h:746
Time(long long int v)
Construct from a numeric value.
Definition: nstime.h:179
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:869
Current time unit, and conversion info.
Definition: nstime.h:510
static bool StaticInit()
Function to force static initialization of Time.
Definition: time.cc:61
bool IsStrictlyPositive(void) const
Definition: nstime.h:284
bool fromMul
Multiple when converting From, otherwise divide.
Definition: nstime.h:504
friend std::ostream & operator<<(std::ostream &os, const TimeWithUnit &timeU)
Output streamer.
Definition: time.cc:401
static Time From(const int64x64_t &value, enum Unit unit)
Create a Time equal to value in unit unit.
Definition: nstime.h:416
Ptr< SampleEmitter > s
double ToDouble(enum Unit unit) const
Get the Time value expressed in a particular unit.
Definition: nstime.h:456
Unit
The unit to use to interpret a number representing time.
Definition: nstime.h:101
int64x64_t Max(const int64x64_t &a, const int64x64_t &b)
Maximum.
Definition: int64x64.h:204
static void ConvertTimes(const enum Unit unit)
Convert existing Times to the new unit.
Definition: time.cc:341
friend bool operator>=(const Time &lhs, const Time &rhs)
Arithmetic operator.
Definition: nstime.h:692
ATTRIBUTE_ACCESSOR_DEFINE(Boolean)
Time(long int v)
Construct from a numeric value.
Definition: nstime.h:171
static struct Resolution SetDefaultNsResolution(void)
Set the default resolution.
Definition: time.cc:168
int64_t factor
Ratio of this unit / current unit.
Definition: nstime.h:505
bool operator<(const int64x64_t &lhs, const int64x64_t &rhs)
Less than operator.
Definition: int64x64-128.h:327
int64x64_t operator/(const int64x64_t &lhs, const int64x64_t &rhs)
Division operator.
Definition: int64x64.h:128
int64x64_t Abs(const int64x64_t &value)
Absolute value.
Definition: int64x64.h:183
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:43
Time(double v)
Construct from a numeric value.
Definition: nstime.h:155
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:1265
Time(unsigned long long int v)
Construct from a numeric value.
Definition: nstime.h:203
friend Time & operator+=(Time &lhs, const Time &rhs)
Arithmetic operator.
Definition: nstime.h:741
friend bool operator==(const Time &lhs, const Time &rhs)
Arithmetic operator.
Definition: nstime.h:677
bool IsNegative(void) const
Definition: nstime.h:269
int64_t GetTimeStep(void) const
Definition: nstime.h:352
friend int64_t operator/(const Time &lhs, const Time &rhs)
Arithmetic operator.
Definition: nstime.h:729
Time Hours(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:829
Time TimeStep(uint64_t ts)
Definition: nstime.h:902
double GetHours(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:314
Time()
Default constructor, with value 0.
Definition: nstime.h:127
int64_t GetInteger(void) const
Definition: nstime.h:360
~Time()
Destructor.
Definition: nstime.h:255
double GetDouble(void) const
Definition: nstime.h:356
static struct Information * PeekInformation(enum Unit timeUnit)
Get the Information record for timeUnit for the current Resolution.
Definition: nstime.h:532
Time Minutes(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:837
int64_t GetNanoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:334
static Time FromDouble(double value, enum Unit unit)
Create a Time equal to value in unit unit.
Definition: nstime.h:412
Time(unsigned int v)
Construct from a numeric value.
Definition: nstime.h:187
static void Mark(Time *const time)
Record a Time instance with the MarkedTimes.
Definition: time.cc:285
friend bool operator>(const Time &lhs, const Time &rhs)
Arithmetic operator.
Definition: nstime.h:702
int64_t GetPicoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:338
TimeWithUnit As(const enum Unit unit) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:386
How to convert between other units and the current unit.
Definition: nstime.h:501
static Time FromInteger(uint64_t value, enum Unit unit)
Create a Time equal to value in unit unit.
Definition: nstime.h:399
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:845
double GetDays(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:310
bool operator>(const int64x64_t &lhs, const int64x64_t &rhs)
Greater operator.
Definition: int64x64-128.h:335
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.cc:89
enum Time::Unit unit
Current time unit.
Definition: nstime.h:513
Time::Unit m_unit
The unit to use in output.
Definition: nstime.h:977
bool IsStrictlyNegative(void) const
Definition: nstime.h:279
static void SetResolution(enum Unit resolution)
Definition: time.cc:178
static void Clear(Time *const time)
Remove a Time instance from the MarkedTimes, called by ~Time().
Definition: time.cc:311
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:861
TimeWithUnit(const Time time, const Time::Unit unit)
Attach a unit to a Time.
Definition: nstime.h:970
second
Definition: nstime.h:107
std::set< Time * > MarkedTimes
Record all instances of Time, so we can rescale them when the resolution changes. ...
Definition: nstime.h:572
static MarkedTimes * g_markingTimes
Record of outstanding Time objects which will need conversion when the resolution is set...
Definition: nstime.h:587
Time Days(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:821
Time FemtoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:885
double GetYears(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:306
static void ClearMarkedTimes()
Remove all MarkedTimes.
Definition: time.cc:254
femtosecond
Definition: nstime.h:112
millisecond
Definition: nstime.h:108
friend bool operator<=(const Time &lhs, const Time &rhs)
Arithmetic operator.
Definition: nstime.h:687
int64_t GetMilliSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:326
double GetMinutes(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:318
Time & operator=(const Time &o)
Assignment operator.
Definition: nstime.h:121
Time m_time
The time.
Definition: nstime.h:973
int64x64_t timeTo
Multiplier to convert to this unit.
Definition: nstime.h:506
Time(const Time &o)
Copy constructor.
Definition: nstime.h:140
int64_t m_data
Virtual time value, in the current unit.
Definition: nstime.h:668
bool toMul
Multiply when converting To, otherwise divide.
Definition: nstime.h:503
int64x64_t & operator-=(int64x64_t &lhs, const int64x64_t &rhs)
Compound subtraction operator.
Definition: int64x64-128.h:353