CMS 3D CMS Logo

Tm.h

Go to the documentation of this file.
00001 // $Id: Tm.h,v 1.2 2006/06/19 14:43:14 egeland Exp $
00002 
00003 #ifndef TM_HH
00004 #define TM_HH
00005 
00006 #include <stdexcept>
00007 #include <string>
00008 #include <iostream>
00009 #include <time.h>
00010 #include <stdint.h>
00011 
00012 // Wrapper class for time.h tm struct
00013 class Tm {
00014   static const uint64_t NEG_INF_MICROS = 0;
00015   static const uint64_t PLUS_INF_MICROS = (uint64_t)-1;
00016 
00017  public:
00018   // Default constructor makes a null Tm
00019   Tm();
00020 
00021   // Initialized constructor
00022   Tm(struct tm * initTm);
00023 
00024   Tm(uint64_t micros);
00025 
00026   // Destructor
00027   virtual ~Tm();
00028 
00029   /*
00030    *  Return a pointer to the tm data structure.
00031    */
00032   struct tm c_tm() const;
00033 
00034   /*
00035    *  Returns true if this Tm is null
00036    */
00037   int isNull() const;
00038 
00039   /*
00040    *  Sets this Tm to null
00041    */
00042   void setNull();
00043 
00044 
00045   static Tm plusInfinity()
00046     {
00047       return Tm(PLUS_INF_MICROS);
00048     };
00049 
00050 
00051   static Tm negInfinity()
00052     {
00053       return Tm(NEG_INF_MICROS);
00054     };
00055 
00056   /*
00057    *  String representation of Tm in YYYY-MM-DD hh:mm:ss format
00058    */
00059   std::string str() const;
00060 
00061   /*
00062    *  return number of microseconds since Jan 1 1970
00063    */
00064   uint64_t microsTime() const;
00065 
00066   /*
00067    *  Set self to current time
00068    */
00069   void setToCurrentLocalTime();
00070   void setToCurrentGMTime();
00071 
00072   /*
00073    *  Set using time_t
00074    */
00075   void setToLocalTime( time_t t);
00076   void setToGMTime( time_t t );
00077 
00078   /*
00079    *  Set using microseconds
00080    */
00081   void setToMicrosTime(uint64_t micros);
00082 
00083   /*
00084    *  Set to string of format YYYY-MM-DD HH:MM:SS
00085    */
00086   void setToString(const std::string s) throw(std::runtime_error);
00087 
00088   void dumpTm();
00089 
00090   inline bool operator==(const Tm &t) const
00091     {   return (m_tm.tm_hour  == t.m_tm.tm_hour &&
00092                 m_tm.tm_isdst == t.m_tm.tm_isdst &&
00093                 m_tm.tm_mday  == t.m_tm.tm_mday &&
00094                 m_tm.tm_min   == t.m_tm.tm_min &&
00095                 m_tm.tm_mon   == t.m_tm.tm_mon &&
00096                 m_tm.tm_sec   == t.m_tm.tm_sec &&
00097                 m_tm.tm_wday  == t.m_tm.tm_wday &&
00098                 m_tm.tm_yday  == t.m_tm.tm_yday &&
00099                 m_tm.tm_year  == t.m_tm.tm_year); 
00100     }
00101                                     
00102   inline bool operator!=(const Tm &t) const { return !(t == *this); }
00103 
00104  private:
00105   struct tm m_tm;
00106 };
00107 
00108 #endif

Generated on Tue Jun 9 17:40:47 2009 for CMSSW by  doxygen 1.5.4