Gaudi Framework, version v24r2

Home   Generated: Wed Dec 4 2013
 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 {
110  return int(m_nsecs / Time::SEC_NSECS / Time::SECS_PER_DAY);
111  }
112 
114  inline int TimeSpan::hours (void) const {
115  return int(m_nsecs / Time::SEC_NSECS / Time::SECS_PER_HOUR);
116  }
117 
119  inline int TimeSpan::minutes (void) const {
120  return int(m_nsecs / Time::SEC_NSECS / 60);
121  }
122 
124  inline TimeSpan::ValueType TimeSpan::seconds (void) const {
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 
158  inline TimeSpan &TimeSpan::operator+= (const TimeSpan &x) {
159  m_nsecs += x.m_nsecs;
160  return *this;
161  }
162 
164  inline TimeSpan & TimeSpan::operator-= (const TimeSpan &x) {
165  m_nsecs -= x.m_nsecs;
166  return *this;
167  }
168 
170  inline TimeSpan & TimeSpan::operator*= (const TimeSpan &x) {
171  m_nsecs *= x.m_nsecs;
172  return *this;
173  }
174 
176  inline TimeSpan & TimeSpan::operator/= (const TimeSpan &x) {
177  m_nsecs /= x.m_nsecs; return *this;
178  }
179 
181  inline TimeSpan & TimeSpan::operator%= (const TimeSpan &x) {
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 >>>>>>
197 inline Gaudi::Time operator+ (const Gaudi::Time &t, const Gaudi::TimeSpan &ts) {
198  return Gaudi::Time (t.ns() + ts.ns());
199 }
200 
201 inline Gaudi::Time operator+ (const Gaudi::TimeSpan &ts, const Gaudi::Time &t) {
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 
209 inline Gaudi::Time operator- (const Gaudi::Time &t, const Gaudi::TimeSpan &ts) {
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 
257 inline Gaudi::TimeSpan operator+ (const Gaudi::TimeSpan &ts) {
258  return ts;
259 }
260 
261 inline Gaudi::TimeSpan operator- (const Gaudi::TimeSpan &ts) {
262  return Gaudi::TimeSpan (-ts.ns());
263 }
264 
265 inline Gaudi::TimeSpan operator+ (const Gaudi::TimeSpan &ts1, const Gaudi::TimeSpan &ts2) {
266  return Gaudi::TimeSpan (ts1.ns() + ts2.ns());
267 }
268 
269 inline Gaudi::TimeSpan operator- (const Gaudi::TimeSpan &ts1, const Gaudi::TimeSpan &ts2) {
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
316 inline StreamBuffer& operator<<(StreamBuffer &s, const Gaudi::Time &t) {
317  return s << t.ns();
318 }
319 // Input serialization
320 inline StreamBuffer& operator>>(StreamBuffer &s, Gaudi::Time &t) {
321  Gaudi::Time::ValueType tmp;
322  s >> tmp;
323  t = Gaudi::Time(tmp);
324  return s;
325 }
326 
327 #endif

Generated at Wed Dec 4 2013 14:33:09 for Gaudi Framework, version v24r2 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004