TimeInterval.h
Go to the documentation of this file.
1 #ifndef _utl_TimeInterval_h_
2 #define _utl_TimeInterval_h_
3 
4 #include <iostream>
5 
6 
7 namespace utl {
8 
43  class TimeInterval {
44 
45  public:
46  TimeInterval(const double interval = 0)
47  : fInterval(interval) { }
48 
50  fInterval(ti.fInterval) { }
51 
53  { fInterval = ti.fInterval; return *this; }
54 
56  TimeInterval& operator=(const double& d)
57  { fInterval = d; return *this; }
58 
60 
62  long GetSecond() const;
63 
65 
66  double GetNanoSecond() const;
67 
69  double GetInterval() const { return fInterval; }
70 
72  operator double() const
73  { return fInterval; }
74 
77  { return TimeInterval(fInterval + ti.fInterval); }
78 
81  { return TimeInterval(fInterval - ti.fInterval); }
82 
84  TimeInterval operator*(const double& d) const
85  { return TimeInterval(fInterval * d); }
86 
88  friend TimeInterval operator*(const double& d, const TimeInterval& ti)
89  { return TimeInterval(d * ti.fInterval); }
90 
92  double operator/(const TimeInterval& ti) const
93  { return fInterval / ti.fInterval; }
94 
96  TimeInterval operator/(const double& d) const
97  { return TimeInterval(fInterval / d); }
98 
101  { fInterval += ti.fInterval; return *this; }
102 
105  { fInterval -= ti.fInterval; return *this; }
106 
108  TimeInterval& operator*=(const double& d)
109  { fInterval *= d; return *this; }
110 
112  TimeInterval& operator/=(const double& d)
113  { fInterval /= d; return *this; }
114 
117  { return TimeInterval(-fInterval); }
118 
119  bool operator>(const TimeInterval& ti) const
120  { return (fInterval > ti.fInterval); }
121 
122  bool operator>=(const TimeInterval& ti) const
123  { return (fInterval >= ti.fInterval); }
124 
125  bool operator<(const TimeInterval& ti) const
126  { return (fInterval < ti.fInterval); }
127 
128  bool operator<=(const TimeInterval& ti) const
129  { return (fInterval <= ti.fInterval); }
130 
131  bool operator==(const TimeInterval& ti) const
132  { return (fInterval == ti.fInterval); }
133 
134  bool operator!=(const TimeInterval& ti) const
135  { return (fInterval != ti.fInterval); }
136 
137  explicit operator bool() const { return fInterval; }
138 
140  friend std::ostream& operator<<(std::ostream& os, const TimeInterval& ti)
141  { return os << ti.fInterval; }
142 
143  // TODO double min/max?
144  static TimeInterval Min() { return -4.294967296e9; }
145  static TimeInterval Max() { return 4.294967296e9; }
146 
147  private:
151  double fInterval;
152 
153  };
154 
155 }
156 
157 
158 #endif
TimeInterval(const TimeInterval &ti)
Definition: TimeInterval.h:49
TimeInterval operator+=(const TimeInterval &ti)
[TimeInterval] += [TimeInterval] = [TimeInterval]
Definition: TimeInterval.h:100
friend std::ostream & operator<<(std::ostream &os, const TimeInterval &ti)
stream output
Definition: TimeInterval.h:140
bool operator<(const TimeInterval &ti) const
Definition: TimeInterval.h:125
long GetSecond() const
Get the seconds floor for the interval.
Definition: TimeInterval.cc:13
friend TimeInterval operator*(const double &d, const TimeInterval &ti)
[double] * [TimeInterval] = [TimeInterval]
Definition: TimeInterval.h:88
static TimeInterval Min()
Definition: TimeInterval.h:144
bool operator>=(const TimeInterval &ti) const
Definition: TimeInterval.h:122
TimeInterval operator-() const
unary sign reversal
Definition: TimeInterval.h:116
TimeInterval & operator-=(const TimeInterval &ti)
[TimeInterval] -= [TimeInterval] = [TimeInterval]
Definition: TimeInterval.h:104
double operator/(const TimeInterval &ti) const
[TimeInterval] / [TimeInterval] = [double]
Definition: TimeInterval.h:92
TimeInterval(const double interval=0)
Definition: TimeInterval.h:46
TimeInterval & operator/=(const double &d)
[TimeInterval] /= [double] = [TimeInterval]
Definition: TimeInterval.h:112
TimeInterval operator*(const double &d) const
[TimeInterval] * [double] = [TimeInterval]
Definition: TimeInterval.h:84
TimeInterval & operator=(const TimeInterval &ti)
Definition: TimeInterval.h:52
double GetInterval() const
Get the time interval as a double (in Auger base units)
Definition: TimeInterval.h:69
TimeInterval & operator*=(const double &d)
[TimeInterval] *= [TimeInterval] = [TimeInterval]
Definition: TimeInterval.h:108
TimeInterval operator/(const double &d) const
[TimeInterval] / [double] = [TimeInterval]
Definition: TimeInterval.h:96
bool operator!=(const TimeInterval &ti) const
Definition: TimeInterval.h:134
A TimeInterval is used to represent time elapsed between two events.
Definition: TimeInterval.h:43
bool operator==(const TimeInterval &ti) const
Definition: TimeInterval.h:131
bool operator<=(const TimeInterval &ti) const
Definition: TimeInterval.h:128
TimeInterval & operator=(const double &d)
[TimeInterval] = double
Definition: TimeInterval.h:56
bool operator>(const TimeInterval &ti) const
Definition: TimeInterval.h:119
TimeInterval operator-(const TimeInterval &ti) const
[TimeInterval] - [TimeInterval] = [TimeInterval]
Definition: TimeInterval.h:80
double GetNanoSecond() const
Get integer number of nanoseconds past seconds boundary.
Definition: TimeInterval.cc:25
TimeInterval operator+(const TimeInterval &ti) const
[TimeInterval] + [TimeInterval] = [TimeInterval]
Definition: TimeInterval.h:76
static TimeInterval Max()
Definition: TimeInterval.h:145

, generated on Tue Sep 26 2023.