• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

src/Time.cpp

00001 #include <stdlib.h>
00002 #include "FCam/Time.h"
00003 #include "Debug.h"
00004 
00005 
00006 namespace FCam {
00007 
00008 Time Time::now() {
00009     Time t2;
00010     gettimeofday(&t2.t, NULL);   
00011     return t2;
00012 }
00013 
00014 int Time::operator-(const Time &other) const {
00015     return (((int)(s()) - (int)(other.s()))*1000000 + 
00016             ((int)(us()) - (int)(other.us())));
00017 }
00018 
00019 bool Time::operator<(const Time &other) const {
00020     return (s() < other.s() ||
00021             (s() == other.s() && us() < other.us()));
00022 }
00023 
00024 bool Time::operator>(const Time &other) const {
00025     return (s() > other.s() ||
00026             (s() == other.s() && us() > other.us()));
00027 }
00028 
00029 bool Time::operator>=(const Time &other) const {
00030     return (s() > other.s() ||
00031             (s() == other.s() && us() >= other.us()));
00032 }
00033 
00034 bool Time::operator<=(const Time &other) const {
00035     return (s() < other.s() ||
00036             (s() == other.s() && us() <= other.us()));
00037 }
00038 
00039 bool Time::operator==(const Time &other) const {
00040     return (s() == other.s() &&
00041             us() == other.us());
00042 }
00043 
00044 bool Time::operator!=(const Time &other) const {
00045     return (us() != other.us() ||
00046             s() != other.s());
00047 }
00048 
00049 
00050 Time Time::operator+=(int usecs) {
00051     int newUsecs = us() + usecs;
00052     int dSec = 0;
00053     while (newUsecs < 0) {
00054         dSec--;
00055         newUsecs += 1000000;
00056     }
00057     while (newUsecs > 1000000) {
00058         dSec++;
00059         newUsecs -= 1000000;            
00060     }
00061     t.tv_usec = newUsecs;
00062     t.tv_sec += dSec;    
00063     return *this;
00064 }
00065 
00066 Time Time::operator+(int usecs) const {
00067     Time t2 = *this;
00068     t2 += usecs;
00069     return t2;
00070 }
00071 
00072 Time::operator timeval() {
00073     return t;
00074 }
00075 
00076 Time::operator struct timespec() {
00077     struct timespec t_;
00078     t_.tv_sec = t.tv_sec;
00079     t_.tv_nsec = t.tv_usec*1000;
00080     return t_;
00081 }
00082 
00083 }
00084  

Generated on Mon Aug 16 2010 14:25:45 for FCam by  doxygen 1.7.1