00001 /* 00002 * File: Timestamp.h 00003 * Author: Dorian Galvez-Lopez 00004 * Date: March 2009 00005 * Description: timestamping functions 00006 * 00007 * 00008 * This program is free software: you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License as published by 00010 * the Free Software Foundation, either version 3 of the License, or 00011 * any later version. 00012 * 00013 * This program is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public License 00019 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00020 * 00021 */ 00022 00023 #ifndef __D_TIMESTAMP__ 00024 #define __D_TIMESTAMP__ 00025 00026 #include <iostream> 00027 using namespace std; 00028 00029 namespace DUtils { 00030 00032 class Timestamp 00033 { 00034 public: 00035 00037 enum tOptions 00038 { 00039 NONE = 0, 00040 CURRENT_TIME = 0x1, 00041 ZERO = 0x2 00042 }; 00043 00044 public: 00045 00050 Timestamp(Timestamp::tOptions option = NONE); 00051 00055 virtual ~Timestamp(void); 00056 00062 bool empty() const; 00063 00067 void setToCurrentTime(); 00068 00074 inline void setTime(unsigned long secs, unsigned long usecs){ 00075 m_secs = secs; 00076 m_usecs = usecs; 00077 } 00078 00084 inline void getTime(unsigned long &secs, unsigned long &usecs) const 00085 { 00086 secs = m_secs; 00087 usecs = m_usecs; 00088 } 00089 00094 void setTime(const string &stime); 00095 00100 void setTime(double s); 00101 00105 double getFloatTime() const; 00106 00110 string getStringTime() const; 00111 00118 double operator- (const Timestamp &t) const; 00119 00125 Timestamp plus(unsigned long s, unsigned long us) const; 00126 00132 Timestamp minus(unsigned long s, unsigned long us) const; 00133 00139 Timestamp& operator+= (double s); 00140 00146 Timestamp& operator-= (double s); 00147 00152 Timestamp operator+ (double s) const; 00153 00158 Timestamp operator- (double s) const; 00159 00164 bool operator> (const Timestamp &t) const; 00165 00170 bool operator>= (const Timestamp &t) const; 00171 00176 bool operator== (const Timestamp &t) const; 00177 00182 bool operator< (const Timestamp &t) const; 00183 00188 bool operator<= (const Timestamp &t) const; 00189 00197 string Format(bool machine_friendly = false) const; 00198 00204 static string Format(double s); 00205 00206 00207 protected: 00209 unsigned long m_secs; // seconds 00211 unsigned long m_usecs; // microseconds 00212 }; 00213 00214 } 00215 00216 #endif 00217