Gaudi Framework, version v23r2

Home   Generated: Thu Jun 28 2012

Time.icpp

Go to the documentation of this file.
00001 // $Id: Time.icpp,v 1.1 2006/01/25 16:02:48 hmd Exp $
00002 #ifndef GAUDIKERNEL_TIME_ICPP
00003 #define GAUDIKERNEL_TIME_ICPP 1
00004 
00005 // Implementation of inline function for classes Gaudi::Time and Gaudi::TimeSpan
00006 
00007 namespace Gaudi {
00008 
00010   inline Time::Time (void): m_nsecs(0) {}
00011 
00014   inline Time::Time (ValueType nsecs): m_nsecs(nsecs) {
00015     TimeAssert( m_nsecs >= 0, "cannot create a negative time");
00016   }
00017 
00020   inline Time::Time (TimeSpan ts) : m_nsecs(ts.m_nsecs) {
00021     TimeAssert( m_nsecs >= 0, "cannot create a negative time");
00022   }
00023 
00026   inline Time::Time (ValueType secs, int nsecs)
00027     : m_nsecs(secs * Time::SEC_NSECS + nsecs) {
00028     TimeAssert( m_nsecs >= 0, "cannot create a negative time");
00029   }
00030 
00033   inline Time::ValueType Time::ns (void) const {
00034     return m_nsecs;
00035   }
00036 
00039   inline Time &Time::operator+= (const TimeSpan &x) {
00040     TimeAssert( m_nsecs >= -x.m_nsecs, "time operation lead to negative time");
00041     m_nsecs += x.m_nsecs;
00042     return *this;
00043   }
00044 
00047   inline Time &Time::operator-= (const TimeSpan &x) {
00048     TimeAssert( m_nsecs >= x.m_nsecs, "time operation lead to negative time");
00049     m_nsecs -= x.m_nsecs;
00050     return *this;
00051   }
00052 
00054   inline Time Time::epoch (void) {
00055     return 0LL;
00056   }
00057 
00059   inline Time Time::max (void) {
00060     return 0x7fffffffffffffffLL;
00061   }
00062 
00064   inline bool Time::isLeap (int year) {
00065     return ((year % 4) == 0
00066             && ((year % 100) != 0
00067                 || (year % 400) == 0));
00068   }
00069 
00073 
00074   inline TimeSpan::TimeSpan (void): m_nsecs(0) {}
00075 
00077   inline TimeSpan::TimeSpan (Time t): m_nsecs (t.m_nsecs) {}
00078 
00080   inline TimeSpan::TimeSpan (ValueType nsecs): m_nsecs (nsecs) {}
00081 
00090   inline TimeSpan::TimeSpan (ValueType secs, int nsecs)
00091     : m_nsecs(secs * Time::SEC_NSECS + nsecs) {}
00092 
00104   inline TimeSpan::TimeSpan (int days, int hours, int mins, int secs, int nsecs) {
00105     m_nsecs = (secs + 60 * (mins + 60 * (hours + 24*days)))*Time::SEC_NSECS + nsecs;
00106   }
00107 
00109   inline int TimeSpan::days (void) const {
00110     return int(m_nsecs / Time::SEC_NSECS / Time::SECS_PER_DAY);
00111   }
00112 
00114   inline int TimeSpan::hours (void) const {
00115     return int(m_nsecs / Time::SEC_NSECS / Time::SECS_PER_HOUR);
00116   }
00117 
00119   inline int TimeSpan::minutes (void) const {
00120     return int(m_nsecs / Time::SEC_NSECS / 60);
00121   }
00122 
00124   inline TimeSpan::ValueType TimeSpan::seconds (void) const {
00125     return m_nsecs / Time::SEC_NSECS;
00126   }
00127 
00129   inline TimeSpan::ValueType TimeSpan::ns (void) const {
00130     return m_nsecs;
00131   }
00132 
00135   inline int TimeSpan::lastHours (void) const {
00136     return hours () - days () * 24;
00137   }
00138 
00141   inline int TimeSpan::lastMinutes (void) const {
00142     return minutes () - hours () * 60;
00143   }
00144 
00147   inline int TimeSpan::lastSeconds (void) const {
00148     return int(seconds() - ( (ValueType)minutes() * (ValueType)60 ));
00149   }
00150 
00153   inline int TimeSpan::lastNSeconds (void) const {
00154     return int(m_nsecs % Time::SEC_NSECS);
00155   }
00156 
00158   inline TimeSpan &TimeSpan::operator+= (const TimeSpan &x) {
00159     m_nsecs += x.m_nsecs;
00160     return *this;
00161   }
00162 
00164   inline TimeSpan & TimeSpan::operator-= (const TimeSpan &x) {
00165     m_nsecs -= x.m_nsecs;
00166     return *this;
00167   }
00168 
00170   inline TimeSpan & TimeSpan::operator*= (const TimeSpan &x) {
00171     m_nsecs *= x.m_nsecs;
00172     return *this;
00173   }
00174 
00176   inline TimeSpan & TimeSpan::operator/= (const TimeSpan &x) {
00177     m_nsecs /= x.m_nsecs; return *this;
00178   }
00179 
00181   inline TimeSpan & TimeSpan::operator%= (const TimeSpan &x) {
00182     m_nsecs %= x.m_nsecs; return *this;
00183   }
00184 
00186   inline std::ostream& operator<< (std::ostream &out, const Gaudi::Time &time) {
00187     return out << Gaudi::TimeSpan(time).seconds() << '.' << time.nanoformat();
00188   }
00189 
00191   inline std::ostream& operator<< (std::ostream &out, const Gaudi::TimeSpan &time) {
00192     return out << time.seconds() << '.' << Gaudi::Time(time).nanoformat();
00193   }
00194 }
00195 
00196 //<<<<<< INLINE PUBLIC FUNCTIONS                                        >>>>>>
00197 inline Gaudi::Time operator+ (const Gaudi::Time &t, const Gaudi::TimeSpan &ts) {
00198   return Gaudi::Time (t.ns() + ts.ns());
00199 }
00200 
00201 inline Gaudi::Time operator+ (const Gaudi::TimeSpan &ts, const Gaudi::Time &t) {
00202   return Gaudi::Time (t.ns() + ts.ns());
00203 }
00204 
00205 inline Gaudi::TimeSpan operator- (const Gaudi::Time &t1, const Gaudi::Time &t2) {
00206   return Gaudi::TimeSpan (t1.ns() - t2.ns());
00207 }
00208 
00209 inline Gaudi::Time operator- (const Gaudi::Time &t, const Gaudi::TimeSpan &ts) {
00210   return Gaudi::Time (t.ns() - ts.ns());
00211 }
00212 
00213 //inline Gaudi::TimeSpan operator* (const Gaudi::Time &t, const Gaudi::TimeSpan &ts) {
00214 //  return Gaudi::TimeSpan (t.ns() * ts.ns());
00215 //}
00216 
00217 //inline Gaudi::TimeSpan operator/ (const Gaudi::Time &t, const Gaudi::TimeSpan &ts) {
00218 //  return Gaudi::TimeSpan (t.ns() / ts.ns());
00219 //}
00220 
00221 //inline Gaudi::TimeSpan operator% (const Gaudi::Time &t, const Gaudi::TimeSpan &ts) {
00222 //  return Gaudi::TimeSpan (t.ns() % ts.ns());
00223 //}
00224 
00225 inline bool operator== (const Gaudi::Time &t1, const Gaudi::Time &t2) {
00226   return t1.ns() == t2.ns();
00227 }
00228 
00229 inline bool operator!= (const Gaudi::Time &t1, const Gaudi::Time &t2) {
00230   return t1.ns() != t2.ns();
00231 }
00232 
00233 inline bool operator< (const Gaudi::Time &t1, const Gaudi::Time &t2) {
00234   return t1.ns() < t2.ns();
00235 }
00236 
00237 inline bool operator<= (const Gaudi::Time &t1, const Gaudi::Time &t2) {
00238   return t1.ns() <= t2.ns();
00239 }
00240 
00241 inline bool operator> (const Gaudi::Time &t1, const Gaudi::Time &t2) {
00242   return t1.ns() > t2.ns();
00243 }
00244 
00245 inline bool operator>= (const Gaudi::Time &t1, const Gaudi::Time &t2) {
00246   return t1.ns() >= t2.ns();
00247 }
00248 
00249 inline bool operator! (const Gaudi::Time &t) {
00250   return ! t.ns();
00251 }
00252 
00256 
00257 inline Gaudi::TimeSpan operator+ (const Gaudi::TimeSpan &ts) {
00258   return ts;
00259 }
00260 
00261 inline Gaudi::TimeSpan operator- (const Gaudi::TimeSpan &ts) {
00262   return Gaudi::TimeSpan (-ts.ns());
00263 }
00264 
00265 inline Gaudi::TimeSpan operator+ (const Gaudi::TimeSpan &ts1, const Gaudi::TimeSpan &ts2) {
00266   return Gaudi::TimeSpan (ts1.ns() + ts2.ns());
00267 }
00268 
00269 inline Gaudi::TimeSpan operator- (const Gaudi::TimeSpan &ts1, const Gaudi::TimeSpan &ts2) {
00270   return Gaudi::TimeSpan (ts1.ns() - ts2.ns());
00271 }
00272 
00273 //inline Gaudi::TimeSpan operator* (const Gaudi::TimeSpan &ts1, const Gaudi::TimeSpan &ts2) {
00274 //  return Gaudi::TimeSpan (ts1.ns() * ts2.ns());
00275 //}
00276 
00277 //inline Gaudi::TimeSpan operator/ (const Gaudi::TimeSpan &ts1, const Gaudi::TimeSpan &ts2) {
00278 //  return Gaudi::TimeSpan (ts1.ns() / ts2.ns());
00279 //}
00280 
00281 //inline Gaudi::TimeSpan operator% (const Gaudi::TimeSpan &ts1, const Gaudi::TimeSpan &ts2) {
00282 //  return Gaudi::TimeSpan (ts1.ns() % ts2.ns());
00283 //}
00284 
00285 inline bool operator== (const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2) {
00286   return t1.ns() == t2.ns();
00287 }
00288 
00289 inline bool operator!= (const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2) {
00290   return t1.ns() != t2.ns();
00291 }
00292 
00293 inline bool operator< (const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2) {
00294   return t1.ns() < t2.ns();
00295 }
00296 
00297 inline bool operator<= (const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2) {
00298   return t1.ns() <= t2.ns();
00299 }
00300 
00301 inline bool operator> (const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2) {
00302   return t1.ns() > t2.ns();
00303 }
00304 
00305 inline bool operator>= (const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2) {
00306   return t1.ns() >= t2.ns();
00307 }
00308 
00309 inline bool operator! (const Gaudi::TimeSpan &ts) {
00310   return ! ts.ns();
00311 }
00312 
00313 // --- operators for serialization ---
00314 
00315 // Output serialization
00316 inline StreamBuffer& operator<<(StreamBuffer &s, const Gaudi::Time &t)  {
00317   return s << t.ns();
00318 }
00319 // Input serialization
00320 inline StreamBuffer& operator>>(StreamBuffer &s, Gaudi::Time &t)  {
00321   Gaudi::Time::ValueType tmp;
00322   s >> tmp;
00323   t = Gaudi::Time(tmp);
00324   return s;
00325 }
00326 
00327 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Thu Jun 28 2012 23:27:23 for Gaudi Framework, version v23r2 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004