Time.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00030
00034
00036
00037
00038 #ifndef __TIME_H_
00039 #define __TIME_H_
00040
00041
00042
00043
00044
00045 #include <stdio.h>
00046 #include <math.h>
00047 #include <vector>
00048 #include <iostream>
00049 #include <string>
00050 #include <sstream>
00051 #include <sys/time.h>
00052 #include <sys/select.h>
00053 #include <assert.h>
00054
00055 #ifdef FOUND_BOOST_SER
00056 #include <boost/serialization/vector.hpp>
00057 #include <boost/archive/text_iarchive.hpp>
00058 #include <boost/archive/text_oarchive.hpp>
00059 #endif
00060
00061 #include "Types.h"
00062
00063 using namespace std;
00064
00068
00070
00071
00072
00073 namespace MipBaselib {
00076 class Time{
00077 protected:
00078 #ifdef FOUND_BOOST_SER
00079 friend class boost::serialization::access;
00080 template<class Archive>
00081 void serialize(Archive & ar, const unsigned int version){
00082 ar & _sec;
00083 ar & _usec;
00084 }
00085 #endif
00086
00087 long int _sec;
00088 long int _usec;
00089 static const int TIME_RESOLUTION = 1000000;
00091 public:
00093 Time();
00094
00096 Time(long int s,long int u);
00097
00099 Time(Decimal t);
00100
00102 Time(const Time& t);
00103
00105 Time(stringstream& ss);
00106
00108 Time& operator=(const Time& t);
00109
00111 Time& operator+=(const Time& t);
00112
00114 Time& operator-=(const Time& t);
00115
00117 Time operator+(const Time &other) const;
00118
00120 Time operator-(const Time &other) const;
00121
00123 Time& operator*=(Decimal scalar);
00124
00126 Time& operator*(Decimal scalar);
00127
00129 bool operator==(const Time &other) const;
00130
00132 bool operator!=(const Time &other) const;
00133
00135 bool operator>(const Time &other) const;
00136
00138 bool operator<(const Time &other) const;
00139
00141 bool operator>=(const Time &other) const;
00142
00144 bool operator<=(const Time &other) const;
00145
00147 long int sec () const;
00148
00150 long int usec () const;
00151
00152
00154 void setTime(const Decimal &t);
00155
00157 void setTime(const long int &insec, const long int &inusec);
00158
00160 void setTime(const Time &time);
00161
00163 Decimal dCast();
00164
00166 Decimal freq();
00168 string print();
00170 string printFreq();
00171
00172 string printDCast();
00173
00174 string dateTime();
00175
00176 string exportAsString() const;
00177 };
00178
00179
00180
00183 class Timer{
00184 public:
00186 Timer();
00187
00189 Timer(Time alreadyElapsed);
00190
00192 Timer(const Timer& t);
00193
00195 Timer& operator=(const Timer& t);
00196
00198 void reset();
00199
00203 void pause();
00204
00206 void resume();
00207
00210 Time get();
00211
00213 string print();
00214
00216 Decimal freq();
00217
00219 string printFreq();
00220
00221 private:
00222 struct timeval current;
00223 Time _start;
00224 Time _accu;
00225 bool _pause;
00226 };
00227
00228
00229
00234 class TimeUtilities{
00235 private:
00236 public:
00240 static void sleep(Time t){
00241 struct timeval _t;
00242 _t.tv_sec = t.sec();
00243 _t.tv_usec = t.usec();
00244 select(0, NULL, NULL, NULL, &_t);
00245 };
00246
00247
00248
00249
00250
00251 };
00252
00253 };
00254
00255 #endif
00256
00257
00258
00259