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

include/FCam/Time.h

Go to the documentation of this file.
00001 #ifndef FCAM_TIME_H
00002 #define FCAM_TIME_H
00003 
00006 
00007 #include <time.h>
00008 #include <sys/time.h>
00009 #include <string>
00010 
00011 namespace FCam {
00012 
00020     class Time {
00021     public:
00022 
00024         static Time now();
00025         
00027         Time(int s, int us) {t.tv_sec = s; t.tv_usec = us;}
00028 
00030         Time(timeval t_) : t(t_) {};
00031            
00033         Time(struct timespec t_) {
00034             t.tv_sec = t_.tv_sec;
00035             t.tv_usec = t_.tv_nsec/1000;
00036         }
00037 
00038         Time()  {t.tv_sec = 0; t.tv_usec = 0;}
00039         
00041         int s() const {return t.tv_sec;}
00042 
00044         int us() const {return t.tv_usec;}
00045 
00046         std::string toString() const {
00047             time_t tim = t.tv_sec;
00048             struct tm *local = localtime(&tim);
00049             char buf[32];
00050             // From most significant to least significant
00051             snprintf(buf, 23, "%04d.%02d.%02d_%02d.%02d.%02d.%02d", 
00052                      local->tm_year + 1900,
00053                      local->tm_mon+1,
00054                      local->tm_mday,
00055                      local->tm_hour,
00056                      local->tm_min,
00057                      local->tm_sec,
00058                      (int)(t.tv_usec/10000));
00059             return std::string(buf);
00060         }
00061         
00069         Time operator+(int usecs) const;
00070         Time operator+=(int usecs);
00071         Time operator-(int usecs) const {return (*this) + (-usecs);}
00072         Time operator-=(int usecs) {return (*this) += (-usecs);}
00073         int operator-(const Time &other) const;
00075 
00081         bool operator<(const Time &other) const; 
00082         bool operator>(const Time &other) const;
00083         bool operator>=(const Time &other) const;
00084         bool operator<=(const Time &other) const;
00085         bool operator==(const Time &other) const;
00086         bool operator!=(const Time &other) const;
00088 
00095         operator timeval();
00096         operator struct timespec(); 
00098 
00099     private:
00100         timeval t;
00101     };
00102     
00103 }
00104 
00105 #endif

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