00001 // -*- Mode: C++; tab-width: 2; -*- 00002 // vi: set ts=2: 00003 // 00004 // -------------------------------------------------------------------------- 00005 // OpenMS Mass Spectrometry Framework 00006 // -------------------------------------------------------------------------- 00007 // Copyright (C) 2003-2008 -- Oliver Kohlbacher, Knut Reinert 00008 // 00009 // This library is free software; you can redistribute it and/or 00010 // modify it under the terms of the GNU Lesser General Public 00011 // License as published by the Free Software Foundation; either 00012 // version 2.1 of the License, or (at your option) any later version. 00013 // 00014 // This library is distributed in the hope that it will be useful, 00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 // Lesser General Public License for more details. 00018 // 00019 // You should have received a copy of the GNU Lesser General Public 00020 // License along with this library; if not, write to the Free Software 00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 // 00023 // -------------------------------------------------------------------------- 00024 // $Maintainer: Oliver Kohlbacher $ 00025 // -------------------------------------------------------------------------- 00026 00027 #ifndef OPENMS_CONCEPT_TIMESTAMP_H 00028 #define OPENMS_CONCEPT_TIMESTAMP_H 00029 00030 #include <OpenMS/config.h> 00031 00032 #include <iostream> 00033 #ifdef OPENMS_HAS_WINDOWS_PERFORMANCE_COUNTER 00034 #include <windows.h> 00035 #include <sys/timeb.h> 00036 #endif 00037 00038 namespace OpenMS 00039 { 00040 00048 class PreciseTime 00049 { 00050 00051 public: 00052 00056 00060 PreciseTime() 00061 throw(); 00062 00065 PreciseTime(const PreciseTime& time) 00066 throw(); 00067 00070 PreciseTime(long secs, long usecs) 00071 throw(); 00072 00075 virtual ~PreciseTime() 00076 throw(); 00077 00079 00082 00085 static const PreciseTime ZERO; 00086 00088 00091 00094 void set(long secs, long usecs) 00095 throw(); 00096 00099 void set(const PreciseTime& time) 00100 throw(); 00101 00104 const PreciseTime& operator = (const PreciseTime& time) 00105 throw(); 00106 00109 virtual void clear() 00110 throw(); 00111 00113 00116 00119 bool operator < (const PreciseTime& time) const 00120 throw(); 00121 00124 bool operator > (const PreciseTime& time) const 00125 throw(); 00126 00129 bool operator == (const PreciseTime& time) const 00130 throw(); 00131 00133 00136 00139 long getSeconds() const 00140 throw(); 00141 00144 long getMicroSeconds() const 00145 throw(); 00146 00150 static PreciseTime now() 00151 throw(); 00152 00154 00155 protected: 00156 00157 long secs_; 00158 long usecs_; 00159 00160 #ifdef OPENMS_HAS_WINDOWS_PERFORMANCE_COUNTER 00161 static long ticks_; 00162 #endif 00163 }; 00164 00173 class TimeStamp 00174 { 00175 public: 00176 00180 00183 TimeStamp() 00184 throw(); 00185 00188 virtual ~TimeStamp() 00189 throw(); 00190 00192 00195 00198 bool isNewerThan(const PreciseTime& time) const 00199 throw(); 00200 00203 bool isOlderThan(const PreciseTime& time) const 00204 throw(); 00205 00208 bool isNewerThan(const TimeStamp& stamp) const 00209 throw(); 00210 00213 bool isOlderThan(const TimeStamp& stamp) const 00214 throw(); 00215 00218 bool operator == (const TimeStamp& stamp) const 00219 throw(); 00220 00223 bool operator < (const TimeStamp& stamp) const 00224 throw(); 00225 00228 bool operator > (const TimeStamp& stamp) const 00229 throw(); 00230 00231 00233 00236 00243 virtual void stamp(const PreciseTime& time = PreciseTime::ZERO) 00244 throw(); 00245 00249 const PreciseTime& getTime() const 00250 throw(); 00251 00253 00256 00259 const PreciseTime& operator = (const PreciseTime& time) 00260 throw(); 00261 00264 virtual void clear() 00265 throw(); 00266 00268 00269 protected: 00270 00273 PreciseTime time_; 00274 }; 00275 00279 00282 std::ostream& operator << (std::ostream& os, const PreciseTime& time) 00283 throw(); 00284 00287 std::ostream& operator << (std::ostream& os, const TimeStamp& stamp) 00288 throw(); 00289 00291 00292 inline 00293 PreciseTime::PreciseTime(long secs, long usecs) 00294 throw() 00295 : secs_(secs), 00296 usecs_(usecs) 00297 { 00298 } 00299 00300 inline 00301 PreciseTime::~PreciseTime() 00302 throw() 00303 { 00304 } 00305 00306 inline 00307 void PreciseTime::set(const PreciseTime& time) 00308 throw() 00309 { 00310 secs_ = time.secs_; 00311 usecs_ = time.usecs_; 00312 } 00313 00314 inline 00315 void PreciseTime::set(long secs, long usecs) 00316 throw() 00317 { 00318 secs_ = secs; 00319 usecs_ = usecs; 00320 } 00321 00322 inline 00323 const PreciseTime& PreciseTime::operator = (const PreciseTime& time) 00324 throw() 00325 { 00326 set(time); 00327 return *this; 00328 } 00329 00330 inline 00331 void PreciseTime::clear() 00332 throw() 00333 { 00334 secs_ = 0; 00335 usecs_ = 0; 00336 } 00337 00338 inline 00339 bool PreciseTime::operator < (const PreciseTime& time) const 00340 throw() 00341 { 00342 return ((secs_ < time.secs_) || ((secs_ == time.secs_) && (usecs_ < time.usecs_))); 00343 } 00344 00345 inline 00346 bool PreciseTime::operator > (const PreciseTime& time) const 00347 throw() 00348 { 00349 return ((secs_ > time.secs_) || ((secs_ == time.secs_) && (usecs_ > time.usecs_))); 00350 } 00351 00352 inline 00353 bool PreciseTime::operator == (const PreciseTime& time) const 00354 throw() 00355 { 00356 return ((secs_ == time.secs_) && (usecs_ == time.usecs_)); 00357 } 00358 00359 inline 00360 long PreciseTime::getSeconds() const 00361 throw() 00362 { 00363 return secs_; 00364 } 00365 00366 inline 00367 long PreciseTime::getMicroSeconds() const 00368 throw() 00369 { 00370 return usecs_; 00371 } 00372 00373 inline 00374 bool TimeStamp::isOlderThan(const PreciseTime& time) const 00375 throw() 00376 { 00377 return (time_ < time); 00378 } 00379 00380 inline 00381 bool TimeStamp::isNewerThan(const PreciseTime& time) const 00382 throw() 00383 { 00384 return (time_ > time); 00385 } 00386 00387 inline 00388 bool TimeStamp::isOlderThan(const TimeStamp& stamp) const 00389 throw() 00390 { 00391 return (time_ < stamp.time_); 00392 } 00393 00394 inline 00395 bool TimeStamp::isNewerThan(const TimeStamp& stamp) const 00396 throw() 00397 { 00398 return (time_ > stamp.time_); 00399 } 00400 00401 inline 00402 void TimeStamp::clear() 00403 throw() 00404 { 00405 time_.clear(); 00406 } 00407 00408 inline 00409 TimeStamp::~TimeStamp() 00410 throw() 00411 { 00412 clear(); 00413 } 00414 00415 inline 00416 void TimeStamp::stamp(const PreciseTime& time) 00417 throw () 00418 { 00419 // in the default case, stamp with the current 00420 // time 00421 if (time == PreciseTime::ZERO) 00422 { 00423 time_ = PreciseTime::now(); 00424 } 00425 else 00426 { 00427 time_ = time; 00428 } 00429 } 00430 00431 inline 00432 const PreciseTime& TimeStamp::getTime() const 00433 throw() 00434 { 00435 return time_; 00436 } 00437 00438 inline 00439 bool TimeStamp::operator == (const TimeStamp& stamp) const 00440 throw() 00441 { 00442 return time_ == stamp.time_; 00443 } 00444 00445 inline 00446 bool TimeStamp::operator < (const TimeStamp& stamp) const 00447 throw() 00448 { 00449 return time_ < stamp.time_; 00450 } 00451 00452 inline 00453 bool TimeStamp::operator > (const TimeStamp& stamp) const 00454 throw() 00455 { 00456 return time_ > stamp.time_; 00457 } 00458 00459 } // namespace OpenMS 00460 00461 #endif // OPENMS_CONCEPT_TIMESTAMP_H
Generated Tue Apr 1 15:36:38 2008 -- using doxygen 1.5.4 | OpenMS / TOPP 1.1 |