Time.icpp
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_TIME_ICPP
2 #define GAUDIKERNEL_TIME_ICPP 1
3 
4 // Implementation of inline function for classes Gaudi::Time and Gaudi::TimeSpan
5 
6 namespace Gaudi {
7 
9  inline Time::Time (void): m_nsecs(0) {}
10 
13  inline Time::Time (ValueType nsecs): m_nsecs(nsecs) {
14  TimeAssert( m_nsecs >= 0, "cannot create a negative time");
15  }
16 
20  TimeAssert( m_nsecs >= 0, "cannot create a negative time");
21  }
22 
25  inline Time::Time (ValueType secs, int nsecs)
26  : m_nsecs(secs * Time::SEC_NSECS + nsecs) {
27  TimeAssert( m_nsecs >= 0, "cannot create a negative time");
28  }
29 
32  inline Time::ValueType Time::ns (void) const {
33  return m_nsecs;
34  }
35 
38  inline Time &Time::operator+= (const TimeSpan &x) {
39  TimeAssert( m_nsecs >= -x.m_nsecs, "time operation lead to negative time");
40  m_nsecs += x.m_nsecs;
41  return *this;
42  }
43 
46  inline Time &Time::operator-= (const TimeSpan &x) {
47  TimeAssert( m_nsecs >= x.m_nsecs, "time operation lead to negative time");
48  m_nsecs -= x.m_nsecs;
49  return *this;
50  }
51 
53  inline Time Time::epoch (void) {
54  return 0LL;
55  }
56 
58  inline Time Time::max (void) {
59  return 0x7fffffffffffffffLL;
60  }
61 
63  inline bool Time::isLeap (int year) {
64  return ((year % 4) == 0
65  && ((year % 100) != 0
66  || (year % 400) == 0));
67  }
68 
72 
73  inline TimeSpan::TimeSpan (void): m_nsecs(0) {}
74 
77 
79  inline TimeSpan::TimeSpan (ValueType nsecs): m_nsecs (nsecs) {}
80 
89  inline TimeSpan::TimeSpan (ValueType secs, int nsecs)
90  : m_nsecs(secs * Time::SEC_NSECS + nsecs) {}
91 
103  inline TimeSpan::TimeSpan (int days, int hours, int mins, int secs, int nsecs) {
104  m_nsecs = (secs + 60 * (mins + 60 * (hours + 24*days)))*Time::SEC_NSECS + nsecs;
105  }
106 
108  inline int TimeSpan::days (void) const {
110  }
111 
113  inline int TimeSpan::hours (void) const {
115  }
116 
118  inline int TimeSpan::minutes (void) const {
119  return int(m_nsecs / Time::SEC_NSECS / 60);
120  }
121 
124  return m_nsecs / Time::SEC_NSECS;
125  }
126 
128  inline TimeSpan::ValueType TimeSpan::ns (void) const {
129  return m_nsecs;
130  }
131 
134  inline int TimeSpan::lastHours (void) const {
135  return hours () - days () * 24;
136  }
137 
140  inline int TimeSpan::lastMinutes (void) const {
141  return minutes () - hours () * 60;
142  }
143 
146  inline int TimeSpan::lastSeconds (void) const {
147  return int(seconds() - ( (ValueType)minutes() * (ValueType)60 ));
148  }
149 
152  inline int TimeSpan::lastNSeconds (void) const {
153  return int(m_nsecs % Time::SEC_NSECS);
154  }
155 
158  m_nsecs += x.m_nsecs;
159  return *this;
160  }
161 
164  m_nsecs -= x.m_nsecs;
165  return *this;
166  }
167 
170  m_nsecs *= x.m_nsecs;
171  return *this;
172  }
173 
176  m_nsecs /= x.m_nsecs; return *this;
177  }
178 
181  m_nsecs %= x.m_nsecs; return *this;
182  }
183 
186  return out << Gaudi::TimeSpan(time).seconds() << '.' << time.nanoformat();
187  }
188 
191  return out << time.seconds() << '.' << Gaudi::Time(time).nanoformat();
192  }
193 }
194 
195 //<<<<<< INLINE PUBLIC FUNCTIONS >>>>>>
197  return Gaudi::Time (t.ns() + ts.ns());
198 }
199 
201  return Gaudi::Time (t.ns() + ts.ns());
202 }
203 
204 inline Gaudi::TimeSpan operator- (const Gaudi::Time &t1, const Gaudi::Time &t2) {
205  return Gaudi::TimeSpan (t1.ns() - t2.ns());
206 }
207 
209  return Gaudi::Time (t.ns() - ts.ns());
210 }
211 
212 //inline Gaudi::TimeSpan operator* (const Gaudi::Time &t, const Gaudi::TimeSpan &ts) {
213 // return Gaudi::TimeSpan (t.ns() * ts.ns());
214 //}
215 
216 //inline Gaudi::TimeSpan operator/ (const Gaudi::Time &t, const Gaudi::TimeSpan &ts) {
217 // return Gaudi::TimeSpan (t.ns() / ts.ns());
218 //}
219 
220 //inline Gaudi::TimeSpan operator% (const Gaudi::Time &t, const Gaudi::TimeSpan &ts) {
221 // return Gaudi::TimeSpan (t.ns() % ts.ns());
222 //}
223 
224 inline bool operator== (const Gaudi::Time &t1, const Gaudi::Time &t2) {
225  return t1.ns() == t2.ns();
226 }
227 
228 inline bool operator!= (const Gaudi::Time &t1, const Gaudi::Time &t2) {
229  return t1.ns() != t2.ns();
230 }
231 
232 inline bool operator< (const Gaudi::Time &t1, const Gaudi::Time &t2) {
233  return t1.ns() < t2.ns();
234 }
235 
236 inline bool operator<= (const Gaudi::Time &t1, const Gaudi::Time &t2) {
237  return t1.ns() <= t2.ns();
238 }
239 
240 inline bool operator> (const Gaudi::Time &t1, const Gaudi::Time &t2) {
241  return t1.ns() > t2.ns();
242 }
243 
244 inline bool operator>= (const Gaudi::Time &t1, const Gaudi::Time &t2) {
245  return t1.ns() >= t2.ns();
246 }
247 
248 inline bool operator! (const Gaudi::Time &t) {
249  return ! t.ns();
250 }
251 
255 
257  return ts;
258 }
259 
261  return Gaudi::TimeSpan (-ts.ns());
262 }
263 
265  return Gaudi::TimeSpan (ts1.ns() + ts2.ns());
266 }
267 
269  return Gaudi::TimeSpan (ts1.ns() - ts2.ns());
270 }
271 
272 //inline Gaudi::TimeSpan operator* (const Gaudi::TimeSpan &ts1, const Gaudi::TimeSpan &ts2) {
273 // return Gaudi::TimeSpan (ts1.ns() * ts2.ns());
274 //}
275 
276 //inline Gaudi::TimeSpan operator/ (const Gaudi::TimeSpan &ts1, const Gaudi::TimeSpan &ts2) {
277 // return Gaudi::TimeSpan (ts1.ns() / ts2.ns());
278 //}
279 
280 //inline Gaudi::TimeSpan operator% (const Gaudi::TimeSpan &ts1, const Gaudi::TimeSpan &ts2) {
281 // return Gaudi::TimeSpan (ts1.ns() % ts2.ns());
282 //}
283 
284 inline bool operator== (const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2) {
285  return t1.ns() == t2.ns();
286 }
287 
288 inline bool operator!= (const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2) {
289  return t1.ns() != t2.ns();
290 }
291 
292 inline bool operator< (const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2) {
293  return t1.ns() < t2.ns();
294 }
295 
296 inline bool operator<= (const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2) {
297  return t1.ns() <= t2.ns();
298 }
299 
300 inline bool operator> (const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2) {
301  return t1.ns() > t2.ns();
302 }
303 
304 inline bool operator>= (const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2) {
305  return t1.ns() >= t2.ns();
306 }
307 
308 inline bool operator! (const Gaudi::TimeSpan &ts) {
309  return ! ts.ns();
310 }
311 
312 // --- operators for serialization ---
313 
314 // Output serialization
316  return s << t.ns();
317 }
318 // Input serialization
321  s >> tmp;
322  t = Gaudi::Time(tmp);
323  return s;
324 }
325 
326 #endif
longlong ValueType
Definition: Time.h:216
ValueType seconds(void) const
Get the number of complete seconds in the span.
Definition: Time.icpp:123
ValueType ns(void) const
Return the time span as nanoseconds.
Definition: Time.icpp:128
GAUDI_API std::ostream & operator<<(std::ostream &o, const Gaudi::Histo1DDef &histo)
the streamer operator for class Gaudi::Histo1DDef
Definition: HistoDef.cpp:109
bool operator!=(const T &v, const Property< TP, V, H > &p)
delegate (value != property) to property operator!=
Definition: Property.h:633
static const int SECS_PER_HOUR
Seconds in one hour hour.
Definition: Time.h:238
bool operator==(const T &v, const Property< TP, V, H > &p)
delegate (value == property) to property operator==
Definition: Property.h:626
bool operator!(const Gaudi::Time &t)
Definition: Time.icpp:248
TimeSpan & operator/=(const TimeSpan &n)
Divide a time span.
Definition: Time.icpp:175
The stream buffer is a small object collecting object data.
Definition: StreamBuffer.h:41
int days(void) const
Get the number of complete days in the span.
Definition: Time.icpp:108
ValueType m_nsecs
Definition: Time.h:86
bool operator<=(const Gaudi::Time &t1, const Gaudi::Time &t2)
Definition: Time.icpp:236
int lastMinutes(void) const
Get the number of complete minutes in the last incomplete hour of the span.
Definition: Time.icpp:140
bool operator>=(const Gaudi::Time &t1, const Gaudi::Time &t2)
Definition: Time.icpp:244
int lastNSeconds(void) const
Get the number of nanoseconds in the last incomplete second of the span.
Definition: Time.icpp:152
Gaudi::TimeSpan operator-(const Gaudi::Time &t1, const Gaudi::Time &t2)
Definition: Time.icpp:204
void TimeAssert(bool cond, const std::string &msg="time assertion failed") const
Definition: Time.h:298
TimeSpan & operator*=(const TimeSpan &n)
Multiply a time span.
Definition: Time.icpp:169
int lastSeconds(void) const
Get the number of complete seconds in the last incomplete minute of the span.
Definition: Time.icpp:146
ValueType ns(void) const
Return the time as nanoseconds since 00:00:00 on January 1, 1970 in UTC.
Definition: Time.icpp:32
TimeSpan & operator+=(const TimeSpan &x)
Add to a time span.
Definition: Time.icpp:157
static const ValueType SEC_NSECS
Nanoseconds in one second.
Definition: Time.h:241
Based on seal::Time.
Definition: Time.h:213
TimeSpan & operator-=(const TimeSpan &x)
Subtract from a time span.
Definition: Time.icpp:163
bool operator>(const Gaudi::Time &t1, const Gaudi::Time &t2)
Definition: Time.icpp:240
int minutes(void) const
Get the number of complete minutes in the span.
Definition: Time.icpp:118
std::string nanoformat(size_t minwidth=1, size_t maxwidth=9) const
Format the nanosecond fractional part of the time as a string.
Definition: Time.cpp:322
TimeSpan & operator%=(const TimeSpan &n)
Compute a modulo of a time span.
Definition: Time.icpp:180
Time & operator+=(const TimeSpan &x)
Add the specified amount to the time.
Definition: Time.icpp:38
static bool isLeap(int year)
Check if the year is a leap-year.
Definition: Time.icpp:63
static Time epoch(void)
Returns the minimum time.
Definition: Time.icpp:53
ValueType m_nsecs
Definition: Time.h:296
int lastHours(void) const
Get the number of complete hours in the last incomplete day of the span.
Definition: Time.icpp:134
string s
Definition: gaudirun.py:245
static const int SECS_PER_DAY
Seconds in 24 hours.
Definition: Time.h:235
Time(void)
Initialize an empty (zero) time value.
Definition: Time.icpp:9
TimeSpan(void)
Initialize an empty (zero) time difference.
Definition: Time.icpp:73
StreamBuffer & operator>>(StreamBuffer &s, Gaudi::Time &t)
Definition: Time.icpp:319
bool operator<(const Gaudi::Time &t1, const Gaudi::Time &t2)
Definition: Time.icpp:232
Time & operator-=(const TimeSpan &x)
Subtract the specified amount from the time.
Definition: Time.icpp:46
int year(bool local) const
Get the year.
Definition: Time.cpp:175
Based on seal::TimeSpan.
Definition: Time.h:56
STL class.
static Time max(void)
Returns the maximum time.
Definition: Time.icpp:58
Helper functions to set/get the application return code.
Definition: __init__.py:1
decltype(std::declval< TP >()+std::declval< T >()) operator+(const T &v, const Property< TP, V, H > &p)
implemantation of (value + property)
Definition: Property.h:640
int hours(void) const
Get the number of complete hours in the span.
Definition: Time.icpp:113