/home/fwph/code/wurde/rde/core/Time.cpp

Go to the documentation of this file.
00001 
00027 #include <Time.H>
00028 
00029 //$Id: Time.cpp 63 2007-01-18 21:39:32Z fwph $
00030 
00031 using namespace WURDE;
00032 
00033 // Constructors and Destructor
00034 Time::Time(){
00035   gettimeofday(&m_tv,&m_tz);
00036 }
00037 
00038 Time::Time(const Time &m){
00039   m_tv=m.m_tv;
00040   m_tz=m.m_tz;
00041 }
00042 
00043 Time::Time(time_t value){
00044   Time();
00045 
00046   m_tv.tv_sec=value;
00047   m_tv.tv_usec=0;
00048 }
00049 
00050 Time::Time(struct timeval _tv){
00051   Time();
00052   
00053   m_tv=_tv;
00054 }
00055 
00056 Time::Time(struct timespec ts){
00057   Time();
00058   m_tv.tv_sec=ts.tv_sec;
00059   m_tv.tv_usec=ts.tv_nsec/1000;  
00060 
00061 }
00062 
00063 Time::~Time(){}
00064 
00065 
00066 // Operators with itself
00067 
00068 const Time &Time::operator=(const Time &right){
00069   m_tv=right.m_tv;
00070   m_tz=right.m_tz;
00071 
00072   return *this;
00073 }
00074 
00075 bool Time::operator==(const Time &right) const{
00076   if(m_tv.tv_sec==right.m_tv.tv_sec&&
00077      m_tv.tv_usec==right.m_tv.tv_usec){
00078     return true;
00079   }
00080 
00081   return false;
00082 }
00083 
00084 bool Time::operator!=(const Time &right) const{
00085   if(m_tv.tv_sec!=right.m_tv.tv_sec||
00086      m_tv.tv_usec!=right.m_tv.tv_usec){
00087     return true;
00088   }
00089 
00090   return false;
00091 }
00092 
00093 bool Time::operator<(const Time &right) const{
00094   if(m_tv.tv_sec<right.m_tv.tv_sec||
00095      (m_tv.tv_sec==right.m_tv.tv_sec&&
00096       m_tv.tv_usec<right.m_tv.tv_usec)){
00097     return true;
00098   }
00099 
00100   return false;
00101 }
00102 
00103 bool Time::operator>(const Time &right) const{
00104   if(m_tv.tv_sec>right.m_tv.tv_sec||
00105      (m_tv.tv_sec==right.m_tv.tv_sec&&
00106       m_tv.tv_usec>right.m_tv.tv_usec)){
00107     return true;
00108   }
00109 
00110   return false;
00111 }
00112 
00113 bool Time::operator<=(const Time &right) const{
00114   if(m_tv.tv_sec>right.m_tv.tv_sec||
00115      (m_tv.tv_sec==right.m_tv.tv_sec&&
00116       m_tv.tv_usec>right.m_tv.tv_usec)){
00117     return false;
00118   }
00119   return true;
00120 }
00121 
00122 bool Time::operator>=(const Time &right) const{
00123   if(m_tv.tv_sec<right.m_tv.tv_sec||
00124      (m_tv.tv_sec==right.m_tv.tv_sec&&
00125       m_tv.tv_usec<right.m_tv.tv_usec)){
00126     return false;
00127   }
00128   return true;
00129 }
00130 
00131 Time Time::operator+(const Time &right) const{
00132      Time temp;
00133      temp.m_tz=m_tz;
00134      temp.m_tv.tv_sec=m_tv.tv_sec+right.m_tv.tv_sec;
00135      temp.m_tv.tv_usec=m_tv.tv_usec+right.m_tv.tv_usec;
00136      return temp;
00137 }
00138 
00139 Time Time::operator-(const Time &right) const{
00140      Time temp;
00141      temp.m_tz=m_tz;
00142      temp.m_tv.tv_sec= m_tv.tv_sec-right.m_tv.tv_sec;
00143      temp.m_tv.tv_usec= m_tv.tv_usec-right.m_tv.tv_usec;
00144      return temp;
00145 }
00146 
00147 
00148 // Operators with timeval struct
00149 const Time &Time::operator=(const struct timeval &right){
00150   m_tv=right;
00151   return *this;
00152 }
00153 
00154 bool Time::operator==(const struct timeval &right) const{
00155   if(m_tv.tv_sec==right.tv_sec&&
00156      m_tv.tv_usec==right.tv_usec){
00157     return true;
00158   }
00159 
00160   return false;
00161 }
00162 
00163 bool Time::operator!=(const struct timeval &right) const{
00164   if(m_tv.tv_sec==right.tv_sec&&
00165      m_tv.tv_usec==right.tv_usec){
00166     return false;
00167   }
00168 
00169   return true;
00170 }
00171 
00172 
00173 bool Time::operator<(const struct timeval &right) const{
00174   if(m_tv.tv_sec<right.tv_sec||
00175      (m_tv.tv_sec==right.tv_sec&&
00176       m_tv.tv_usec<right.tv_usec)){
00177     return true;
00178   }
00179 
00180   return false;
00181 }
00182 
00183 
00184 bool Time::operator>(const struct timeval &right) const{
00185   if(m_tv.tv_sec>right.tv_sec||
00186      (m_tv.tv_sec==right.tv_sec&&
00187       m_tv.tv_usec>right.tv_usec)){
00188     return true;
00189   }
00190 
00191   return false;
00192 }
00193 
00194 bool Time::operator<=(const struct timeval &right) const{
00195   if(m_tv.tv_sec>right.tv_sec||
00196      (m_tv.tv_sec==right.tv_sec&&m_tv.tv_usec>right.tv_usec)){
00197     return false;
00198   }
00199   
00200   return true;
00201 }
00202 
00203 
00204 bool Time::operator>=(const struct timeval &right) const{
00205   if(m_tv.tv_sec<right.tv_sec||
00206      (m_tv.tv_sec==right.tv_sec&&m_tv.tv_usec<right.tv_usec)){
00207     return false;
00208   }
00209   
00210   return true;
00211 }
00212 
00213 
00214 Time Time::operator+(const struct timeval &right) const{
00215      Time temp;
00216      temp.m_tz=m_tz;
00217      temp.m_tv.tv_sec= m_tv.tv_sec+right.tv_sec;
00218      temp.m_tv.tv_usec= m_tv.tv_usec+right.tv_usec;
00219      
00220      return temp;
00221 }
00222 
00223 Time Time::operator-(const struct timeval &right) const{
00224      Time temp;
00225      temp.m_tz=m_tz;
00226      temp.m_tv.tv_sec= m_tv.tv_sec-right.tv_sec;
00227      temp.m_tv.tv_usec=m_tv.tv_usec-right.tv_usec;
00228      
00229      return temp;
00230 }
00231 
00232 // Operators with time_t
00233 const Time &Time::operator=(const time_t &right){
00234   m_tv.tv_usec=0;
00235   m_tv.tv_sec=right;
00236   
00237   return *this;
00238 }
00239 
00240 bool Time::operator==(const time_t &right) const{
00241   if(m_tv.tv_sec==right){
00242     return true;
00243   }
00244 
00245   return false;
00246 }
00247 
00248 bool Time::operator<(const time_t &right) const{
00249   if(m_tv.tv_sec<right){
00250     return true;
00251   }
00252 
00253   return false;
00254 }
00255 
00256 
00257 bool Time::operator>(const time_t &right) const{
00258   if(m_tv.tv_sec>right){
00259     return true;
00260   }
00261 
00262   return false;
00263 }
00264 
00265 bool Time::operator<=(const time_t &right) const{
00266   if(m_tv.tv_sec<=right){
00267     return true;
00268   }
00269 
00270   return false;
00271 }
00272 
00273 bool Time::operator>=(const time_t &right) const{
00274   if(m_tv.tv_sec>=right){
00275     return true;
00276   }
00277 
00278   return false;
00279 }
00280 
00281 Time Time::operator+(const time_t &right) const{
00282        Time temp;
00283        temp.m_tz=m_tz;
00284        temp.m_tv.tv_sec=m_tv.tv_sec+right;
00285        return temp;
00286 }
00287 
00288 Time Time::operator-(const time_t &right) const{
00289        Time temp;
00290        temp.m_tz=m_tz;
00291        temp.m_tv.tv_sec=m_tv.tv_sec-right;
00292 
00293        return temp;
00294 }
00295 
00296 // Operators with timespec struct
00297 const Time &Time::operator=(const struct timespec &right){
00298   m_tv.tv_sec=right.tv_sec;
00299   m_tv.tv_usec=right.tv_nsec/1000;
00300   return *this;
00301 }
00302 
00303 bool Time::operator==(const struct timespec &right) const{
00304   if(m_tv.tv_sec==right.tv_sec&&
00305      m_tv.tv_usec==right.tv_nsec/1000){
00306     return true;
00307   }
00308 
00309   return false;
00310 }
00311 
00312 bool Time::operator!=(const struct timespec &right) const{
00313   if(m_tv.tv_sec==right.tv_sec&&
00314      m_tv.tv_usec==right.tv_nsec/1000){
00315     return false;
00316   }
00317 
00318   return true;
00319 }
00320 
00321 
00322 bool Time::operator<(const struct timespec &right) const{
00323   if(m_tv.tv_sec<right.tv_sec||
00324      (m_tv.tv_sec==right.tv_sec&&
00325       m_tv.tv_usec<right.tv_nsec/1000)){
00326     return true;
00327   }
00328 
00329   return false;
00330 }
00331 
00332 
00333 bool Time::operator>(const struct timespec &right) const{
00334   if(m_tv.tv_sec>right.tv_sec||
00335      (m_tv.tv_sec==right.tv_sec&&
00336       m_tv.tv_usec>right.tv_nsec/1000)){
00337     return true;
00338   }
00339 
00340   return false;
00341 }
00342 
00343 bool Time::operator<=(const struct timespec &right) const{
00344   if(m_tv.tv_sec>right.tv_sec||
00345      (m_tv.tv_sec==right.tv_sec&&m_tv.tv_usec>right.tv_nsec/1000)){
00346     return false;
00347   }
00348   
00349   return true;
00350 }
00351 
00352 
00353 bool Time::operator>=(const struct timespec &right) const{
00354   if(m_tv.tv_sec<right.tv_sec||
00355      (m_tv.tv_sec==right.tv_sec&&m_tv.tv_usec<right.tv_nsec/1000)){
00356     return false;
00357   }
00358   
00359   return true;
00360 }
00361 
00362 
00363 Time Time::operator+(const struct timespec &right) const{
00364      Time temp;
00365      temp.m_tz=m_tz;
00366      temp.m_tv.tv_sec= m_tv.tv_sec+right.tv_sec;
00367      temp.m_tv.tv_usec= m_tv.tv_usec+(right.tv_nsec/1000);
00368      
00369      return temp;
00370 }
00371 
00372 Time Time::operator-(const struct timespec &right) const{
00373      Time temp;
00374      temp.m_tz=m_tz;
00375      temp.m_tv.tv_sec= m_tv.tv_sec-right.tv_sec;
00376      temp.m_tv.tv_usec=m_tv.tv_usec-(right.tv_nsec);
00377      
00378      return temp;
00379 }

Generated on Thu Feb 1 15:31:54 2007 for WURDE by  doxygen 1.5.1