All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Time.icpp
Go to the documentation of this file.
1 // $Id: Time.icpp,v 1.1 2006/01/25 16:02:48 hmd Exp $
2 #ifndef GAUDIKERNEL_TIME_ICPP
3 #define GAUDIKERNEL_TIME_ICPP 1
4 
5 // Implementation of inline function for classes Gaudi::Time and Gaudi::TimeSpan
6 
7 namespace Gaudi {
8 
10  inline Time::Time (void): m_nsecs(0) {}
11 
14  inline Time::Time (ValueType nsecs): m_nsecs(nsecs) {
15  TimeAssert( m_nsecs >= 0, "cannot create a negative time");
16  }
17 
20  inline Time::Time (TimeSpan ts) : m_nsecs(ts.m_nsecs) {
21  TimeAssert( m_nsecs >= 0, "cannot create a negative time");
22  }
23 
26  inline Time::Time (ValueType secs, int nsecs)
27  : m_nsecs(secs * Time::SEC_NSECS + nsecs) {
28  TimeAssert( m_nsecs >= 0, "cannot create a negative time");
29  }
30 
33  inline Time::ValueType Time::ns (void) const {
34  return m_nsecs;
35  }
36 
39  inline Time &Time::operator+= (const TimeSpan &x) {
40  TimeAssert( m_nsecs >= -x.m_nsecs, "time operation lead to negative time");
41  m_nsecs += x.m_nsecs;
42  return *this;
43  }
44 
47  inline Time &Time::operator-= (const TimeSpan &x) {
48  TimeAssert( m_nsecs >= x.m_nsecs, "time operation lead to negative time");
49  m_nsecs -= x.m_nsecs;
50  return *this;
51  }
52 
54  inline Time Time::epoch (void) {
55  return 0LL;
56  }
57 
59  inline Time Time::max (void) {
60  return 0x7fffffffffffffffLL;
61  }
62 
64  inline bool Time::isLeap (int year) {
65  return ((year % 4) == 0
66  && ((year % 100) != 0
67  || (year % 400) == 0));
68  }
69 
73 
74  inline TimeSpan::TimeSpan (void): m_nsecs(0) {}
75 
77  inline TimeSpan::TimeSpan (Time t): m_nsecs (t.m_nsecs) {}
78 
80  inline TimeSpan::TimeSpan (ValueType nsecs): m_nsecs (nsecs) {}
81 
90  inline TimeSpan::TimeSpan (ValueType secs, int nsecs)
91  : m_nsecs(secs * Time::SEC_NSECS + nsecs) {}
92 
104  inline TimeSpan::TimeSpan (int days, int hours, int mins, int secs, int nsecs) {
105  m_nsecs = (secs + 60 * (mins + 60 * (hours + 24*days)))*Time::SEC_NSECS + nsecs;
106  }
107 
109  inline int TimeSpan::days (void) const {
111  }
112 
114  inline int TimeSpan::hours (void) const {
116  }
117 
119  inline int TimeSpan::minutes (void) const {
120  return int(m_nsecs / Time::SEC_NSECS / 60);
121  }
122 
125  return m_nsecs / Time::SEC_NSECS;
126  }
127 
129  inline TimeSpan::ValueType TimeSpan::ns (void) const {
130  return m_nsecs;
131  }
132 
135  inline int TimeSpan::lastHours (void) const {
136  return hours () - days () * 24;
137  }
138 
141  inline int TimeSpan::lastMinutes (void) const {
142  return minutes () - hours () * 60;
143  }
144 
147  inline int TimeSpan::lastSeconds (void) const {
148  return int(seconds() - ( (ValueType)minutes() * (ValueType)60 ));
149  }
150 
153  inline int TimeSpan::lastNSeconds (void) const {
154  return int(m_nsecs % Time::SEC_NSECS);
155  }
156 
159  m_nsecs += x.m_nsecs;
160  return *this;
161  }
162 
165  m_nsecs -= x.m_nsecs;
166  return *this;
167  }
168 
171  m_nsecs *= x.m_nsecs;
172  return *this;
173  }
174 
177  m_nsecs /= x.m_nsecs; return *this;
178  }
179 
182  m_nsecs %= x.m_nsecs; return *this;
183  }
184 
186  inline std::ostream& operator<< (std::ostream &out, const Gaudi::Time &time) {
187  return out << Gaudi::TimeSpan(time).seconds() << '.' << time.nanoformat();
188  }
189 
191  inline std::ostream& operator<< (std::ostream &out, const Gaudi::TimeSpan &time) {
192  return out << time.seconds() << '.' << Gaudi::Time(time).nanoformat();
193  }
194 }
195 
196 //<<<<<< INLINE PUBLIC FUNCTIONS >>>>>>
198  return Gaudi::Time (t.ns() + ts.ns());
199 }
200 
202  return Gaudi::Time (t.ns() + ts.ns());
203 }
204 
205 inline Gaudi::TimeSpan operator- (const Gaudi::Time &t1, const Gaudi::Time &t2) {
206  return Gaudi::TimeSpan (t1.ns() - t2.ns());
207 }
208 
210  return Gaudi::Time (t.ns() - ts.ns());
211 }
212 
213 //inline Gaudi::TimeSpan operator* (const Gaudi::Time &t, const Gaudi::TimeSpan &ts) {
214 // return Gaudi::TimeSpan (t.ns() * ts.ns());
215 //}
216 
217 //inline Gaudi::TimeSpan operator/ (const Gaudi::Time &t, const Gaudi::TimeSpan &ts) {
218 // return Gaudi::TimeSpan (t.ns() / ts.ns());
219 //}
220 
221 //inline Gaudi::TimeSpan operator% (const Gaudi::Time &t, const Gaudi::TimeSpan &ts) {
222 // return Gaudi::TimeSpan (t.ns() % ts.ns());
223 //}
224 
225 inline bool operator== (const Gaudi::Time &t1, const Gaudi::Time &t2) {
226  return t1.ns() == t2.ns();
227 }
228 
229 inline bool operator!= (const Gaudi::Time &t1, const Gaudi::Time &t2) {
230  return t1.ns() != t2.ns();
231 }
232 
233 inline bool operator< (const Gaudi::Time &t1, const Gaudi::Time &t2) {
234  return t1.ns() < t2.ns();
235 }
236 
237 inline bool operator<= (const Gaudi::Time &t1, const Gaudi::Time &t2) {
238  return t1.ns() <= t2.ns();
239 }
240 
241 inline bool operator> (const Gaudi::Time &t1, const Gaudi::Time &t2) {
242  return t1.ns() > t2.ns();
243 }
244 
245 inline bool operator>= (const Gaudi::Time &t1, const Gaudi::Time &t2) {
246  return t1.ns() >= t2.ns();
247 }
248 
249 inline bool operator! (const Gaudi::Time &t) {
250  return ! t.ns();
251 }
252 
256 
258  return ts;
259 }
260 
262  return Gaudi::TimeSpan (-ts.ns());
263 }
264 
266  return Gaudi::TimeSpan (ts1.ns() + ts2.ns());
267 }
268 
270  return Gaudi::TimeSpan (ts1.ns() - ts2.ns());
271 }
272 
273 //inline Gaudi::TimeSpan operator* (const Gaudi::TimeSpan &ts1, const Gaudi::TimeSpan &ts2) {
274 // return Gaudi::TimeSpan (ts1.ns() * ts2.ns());
275 //}
276 
277 //inline Gaudi::TimeSpan operator/ (const Gaudi::TimeSpan &ts1, const Gaudi::TimeSpan &ts2) {
278 // return Gaudi::TimeSpan (ts1.ns() / ts2.ns());
279 //}
280 
281 //inline Gaudi::TimeSpan operator% (const Gaudi::TimeSpan &ts1, const Gaudi::TimeSpan &ts2) {
282 // return Gaudi::TimeSpan (ts1.ns() % ts2.ns());
283 //}
284 
285 inline bool operator== (const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2) {
286  return t1.ns() == t2.ns();
287 }
288 
289 inline bool operator!= (const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2) {
290  return t1.ns() != t2.ns();
291 }
292 
293 inline bool operator< (const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2) {
294  return t1.ns() < t2.ns();
295 }
296 
297 inline bool operator<= (const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2) {
298  return t1.ns() <= t2.ns();
299 }
300 
301 inline bool operator> (const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2) {
302  return t1.ns() > t2.ns();
303 }
304 
305 inline bool operator>= (const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2) {
306  return t1.ns() >= t2.ns();
307 }
308 
309 inline bool operator! (const Gaudi::TimeSpan &ts) {
310  return ! ts.ns();
311 }
312 
313 // --- operators for serialization ---
314 
315 // Output serialization
317  return s << t.ns();
318 }
319 // Input serialization
322  s >> tmp;
323  t = Gaudi::Time(tmp);
324  return s;
325 }
326 
327 #endif
longlong ValueType
Definition: Time.h:217
ValueType seconds(void) const
Get the number of complete seconds in the span.
Definition: Time.icpp:124
ValueType ns(void) const
Return the time span as nanoseconds.
Definition: Time.icpp:129
GAUDI_API std::ostream & operator<<(std::ostream &o, const Gaudi::Histo1DDef &histo)
the streamer operator for class Gaudi::Histo1DDef
Definition: HistoDef.cpp:114
static const int SECS_PER_HOUR
Seconds in one hour hour.
Definition: Time.h:239
bool operator!(const Gaudi::Time &t)
Definition: Time.icpp:249
TimeSpan & operator/=(const TimeSpan &n)
Divide a time span.
Definition: Time.icpp:176
The stream buffer is a small object collecting object data.
Definition: StreamBuffer.h:40
int days(void) const
Get the number of complete days in the span.
Definition: Time.icpp:109
ValueType m_nsecs
Definition: Time.h:87
Gaudi::Time operator+(const Gaudi::Time &t, const Gaudi::TimeSpan &ts)
Definition: Time.icpp:197
bool operator<=(const Gaudi::Time &t1, const Gaudi::Time &t2)
Definition: Time.icpp:237
int lastMinutes(void) const
Get the number of complete minutes in the last incomplete hour of the span.
Definition: Time.icpp:141
bool operator>=(const Gaudi::Time &t1, const Gaudi::Time &t2)
Definition: Time.icpp:245
int lastNSeconds(void) const
Get the number of nanoseconds in the last incomplete second of the span.
Definition: Time.icpp:153
Gaudi::TimeSpan operator-(const Gaudi::Time &t1, const Gaudi::Time &t2)
Definition: Time.icpp:205
void TimeAssert(bool cond, const std::string &msg="time assertion failed") const
Definition: Time.h:299
TimeSpan & operator*=(const TimeSpan &n)
Multiply a time span.
Definition: Time.icpp:170
int lastSeconds(void) const
Get the number of complete seconds in the last incomplete minute of the span.
Definition: Time.icpp:147
ValueType ns(void) const
Return the time as nanoseconds since 00:00:00 on January 1, 1970 in UTC.
Definition: Time.icpp:33
TimeSpan & operator+=(const TimeSpan &x)
Add to a time span.
Definition: Time.icpp:158
static const ValueType SEC_NSECS
Nanoseconds in one second.
Definition: Time.h:242
bool operator!=(const Gaudi::Time &t1, const Gaudi::Time &t2)
Definition: Time.icpp:229
Based on seal::Time.
Definition: Time.h:214
TimeSpan & operator-=(const TimeSpan &x)
Subtract from a time span.
Definition: Time.icpp:164
bool operator>(const Gaudi::Time &t1, const Gaudi::Time &t2)
Definition: Time.icpp:241
int minutes(void) const
Get the number of complete minutes in the span.
Definition: Time.icpp:119
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:323
TimeSpan & operator%=(const TimeSpan &n)
Compute a modulo of a time span.
Definition: Time.icpp:181
Time & operator+=(const TimeSpan &x)
Add the specified amount to the time.
Definition: Time.icpp:39
static bool isLeap(int year)
Check if the year is a leap-year.
Definition: Time.icpp:64
static Time epoch(void)
Returns the minimum time.
Definition: Time.icpp:54
ValueType m_nsecs
Definition: Time.h:297
int lastHours(void) const
Get the number of complete hours in the last incomplete day of the span.
Definition: Time.icpp:135
string s
Definition: gaudirun.py:210
static const int SECS_PER_DAY
Seconds in 24 hours.
Definition: Time.h:236
Time(void)
Initialize an empty (zero) time value.
Definition: Time.icpp:10
TimeSpan(void)
Initialize an empty (zero) time difference.
Definition: Time.icpp:74
This is a number of static methods for bootstrapping the Gaudi framework.
Definition: Bootstrap.h:15
StreamBuffer & operator>>(StreamBuffer &s, Gaudi::Time &t)
Definition: Time.icpp:320
bool operator<(const Gaudi::Time &t1, const Gaudi::Time &t2)
Definition: Time.icpp:233
StreamBuffer & operator<<(StreamBuffer &s, const Gaudi::Time &t)
Definition: Time.icpp:316
Time & operator-=(const TimeSpan &x)
Subtract the specified amount from the time.
Definition: Time.icpp:47
Based on seal::TimeSpan.
Definition: Time.h:57
static Time max(void)
Returns the maximum time.
Definition: Time.icpp:59
bool operator==(const Gaudi::Time &t1, const Gaudi::Time &t2)
Definition: Time.icpp:225
int hours(void) const
Get the number of complete hours in the span.
Definition: Time.icpp:114