Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

/home/pauldt/projects/IDEA/IDEA-ALL/IDEA-DEV/Core/Utilities/Includes/TimeBasics.hh

Go to the documentation of this file.
00001 #ifndef TIME_BASICS_HEADER_FILE
00002 #define TIME_BASICS_HEADER_FILE
00003 
00004 #include <ctime>
00005 #include <iostream>
00006 
00007 
00011 #define ONE_SECOND_IN_DECI_SECS   10L
00012 
00015 #define ONE_SECOND_IN_CENTI_SECS   100L
00016 
00019 #define ONE_SECOND_IN_MILLI_SECS   1000L
00020 
00024 #define ONE_SECOND_IN_MSECS   1000L
00025 
00028 #define ONE_SECOND_IN_MICRO_SECS   1000000L
00029 
00032 #define ONE_SECOND_IN_NANO_SECS   1000000000L
00033 
00037 #define ONE_SECOND_IN_NSECS   1000000000L
00038 
00039 
00040 namespace IDEA
00041 {
00047   typedef enum 
00048     {
00049       SECONDS = 0,   
00050       DECI_SECONDS = 1,  
00051       CENTI_SECONDS = 2, 
00052       MILLI_SECONDS = 3, 
00053       MICRO_SECONDS = 6, 
00054       NANO_SECONDS = 9   
00055     } Granularity;
00056 
00057   std::ostream& operator<<( std::ostream& os, const Granularity& g );
00058 
00066   class Time
00067   {
00068     friend Time operator+ (const Time& tv1, const Time& tv2);
00069     friend Time operator- (const Time& tv1, const Time& tv2);
00070     friend bool operator< (const Time& tv1, const Time& tv2);
00071     friend bool operator> (const Time &tv1, const Time &tv2);
00072     friend bool operator<= (const Time &tv1, const Time &tv2);
00073     friend bool operator>= (const Time &tv1, const Time &tv2);
00074     friend bool operator== (const Time &tv1, const Time &tv2);
00075     friend bool operator!= (const Time &tv1, const Time &tv2);
00076     friend Time operator * (double d, const Time &tv);
00077     friend Time operator * (const Time &tv, double d);
00078     friend std::ostream& operator<<(std::ostream& os, const Time& t);
00079   public:
00083     static const Time& getZero();
00087     static const Time& getSecond();
00091     static const Time& getMinute();
00095     static const Time& getHour();
00099     static const Time& getDay();
00103     static const Time& getWeek();
00107     static const Time& getYear();
00111     Time();
00115     Time(long sec, long nsec );
00119     Time(const timespec &t);
00123     Time(const Time& t);
00127     void set(long sec, long nsec);
00131     void set(double d);
00135     void set (const timespec &t);
00139     operator timespec() const;
00143     long getSeconds() const;
00147     void setSeconds(long sec);
00151     long getNanoSeconds() const;
00155     void setNanoSeconds(long nsec);
00159     Time& operator+= (const Time& tv);
00163     Time& operator-=(const Time &tv);
00167     Time& operator *= (double d);
00171     Time& operator++(void);
00175     Time& operator--(void);
00180     static Time convert( int units, const Granularity& g );
00184     static int convert( const Time& t, const Granularity& g );
00185   private:
00186     static const Time s_Zero;
00187     static const Time s_Second;
00188     static const Time s_Minute;
00189     static const Time s_Hour;
00190     static const Time s_Day;
00191     static const Time s_Week;
00192     static const Time s_Month;
00193     static const Time s_Year;
00200     void normalize();
00201 
00202     timespec m_TimeImpl;
00203   };
00204 
00208   Time operator+ (const Time& tv1, const Time& tv2);
00212   Time operator- (const Time& tv1, const Time& tv2);
00216   bool  operator< (const Time& tv1, const Time& tv2);
00220   bool  operator> (const Time &tv1, const Time &tv2);
00224   bool  operator<= (const Time &tv1, const Time &tv2);
00228   bool  operator>= (const Time &tv1, const Time &tv2);
00232   bool  operator== (const Time &tv1, const Time &tv2);
00236   bool  operator!= (const Time &tv1, const Time &tv2);
00240   Time  operator * (double d, const Time &tv);
00244   Time  operator * (const Time &tv, double d);
00245 
00246   std::ostream& operator<<(std::ostream& os, const Time& t);
00247 }
00248 
00249 #endif //TIME_BASICS_HEADER_FILE

Contact information
© IDEA
Generated on Fri Feb 3 17:09:41 2006 for IDEA.