GizmoBase

gzTime.h

Go to the documentation of this file.
00001 // *****************************************************************************
00002 // File         : gzTime.h
00003 // Module       : gzBase
00004 // Description  : Class definition of time management utilties
00005 // Author       : Anders Modén      
00006 // Product      : GizmoBase 2.1.1
00007 //      
00008 // Copyright © 2003- Saab Training Systems AB, Sweden
00009 //          
00010 // NOTE:    GizmoBase is a platform abstraction utility layer for C++. It contains 
00011 //          design patterns and C++ solutions for the advanced programmer.
00012 //
00013 //
00014 // Revision History...                          
00015 //                                  
00016 // Who  Date    Description                     
00017 //                                  
00018 // AMO  040301  Created file 
00019 //
00020 // ******************************************************************************
00021 
00022 #ifndef __GZ_TIME_H__
00023 #define __GZ_TIME_H__
00024 
00029 #include "gzBase.h"
00030 
00031 //******************************************************************************
00032 // Class    : gzTime
00033 //                                  
00034 // Purpose  : Time management
00035 //                                  
00036 // Notes    : - 
00037 //                                  
00038 // Revision History...                          
00039 //                                  
00040 // Who  Date    Description                     
00041 //                                  
00042 // AMO  980820  Created 
00043 //                                  
00044 //******************************************************************************
00045 
00051 class  GZ_BASE_EXPORT gzTime 
00052 {
00053 public:
00054 
00055     gzTime();
00056 
00057     gzTime( gzDouble seconds );
00058 
00059     gzTime( gzULong year ,  gzUByte month , gzUByte day , gzDouble dayseconds=0 );
00060 
00061     gzTime( gzULong year ,  gzUByte month , gzUByte day , gzDouble hour , gzDouble minute , gzDouble second);
00062 
00063     gzDouble seconds() const;
00064 
00065     gzULong year() const;
00066 
00067     gzUByte month() const;
00068 
00069     gzUByte day() const;
00070 
00071     gzDouble daySeconds() const;
00072 
00073     gzUByte hour() const;
00074 
00075     gzUByte minute() const;
00076 
00077     gzDouble hourSeconds() const;
00078 
00079     gzString asString(const gzString &format="%4d-%02d-%02d %02d:%02d:%02d") const;
00080 
00082     static gzTime now(gzBool localTime=FALSE);
00083 
00084     static gzVoid setTime(gzDouble time,gzBool localTime=FALSE);
00085 
00086     static gzDouble systemSeconds(gzULong threadID=0);
00087 
00088     static gzDouble getLocalTimeOffset();
00089 
00090     static gzUShort daysPerYear(gzULong year);
00091 
00092     static gzUByte daysPerMonth(gzUByte month,gzULong year);
00093 
00094     static gzVoid   useCPUSpeedCheck(gzBool on=FALSE,gzULong threadID=0);
00095     static gzVoid   useHighSpeedClock(gzBool on=FALSE,gzULong threadID=0);
00096 
00097     static gzVoid   clearThreadData(gzULong threadID=0);
00098 
00099     gzDouble operator -(const gzTime &time) const;
00100     gzDouble operator +(const gzTime &time) const;
00101     gzDouble operator -(const gzDouble &sec) const;
00102     gzDouble operator +(const gzDouble &sec) const;
00103 
00104     gzBool operator<(const gzTime &time) const;
00105     gzBool operator<=(const gzTime &time) const;
00106     gzBool operator>(const gzTime &time) const;
00107     gzBool operator>=(const gzTime &time) const;
00108     gzBool operator!=(const gzTime &time) const;
00109     gzBool operator==(const gzTime &time) const;
00110 
00111 private:
00112     
00113     gzDouble        m_seconds;
00114     gzBool          m_hasDayseconds;
00115     gzDouble        m_daySeconds;
00116 
00117     static gzDouble s_systemTimeOffset;
00118 };
00119 
00120 //******************************************************************************
00121 // Class    : gzTimer
00122 //                                  
00123 // Purpose  : Timer measuring
00124 //                                  
00125 // Notes    : - 
00126 //                                  
00127 // Revision History...                          
00128 //                                  
00129 // Who  Date    Description                     
00130 //                                  
00131 // AMO  040301  Created 
00132 //                                  
00133 //******************************************************************************
00136 class  gzTimer : public gzNameInterface
00137 {
00138 public:
00139 
00140     GZ_BASE_EXPORT gzTimer(const gzString &name=GZ_EMPTY_STRING):gzNameInterface(name)      
00141     { 
00142         m_resetTime=gzTime::systemSeconds();            
00143     }
00144 
00145     GZ_BASE_EXPORT gzVoid   reset()     
00146     { 
00147         m_resetTime=gzTime::systemSeconds();            
00148     }
00149 
00150     GZ_BASE_EXPORT gzDouble getTime()   
00151     { 
00152         return gzTime::systemSeconds()-m_resetTime; 
00153     }
00154 
00155     GZ_BASE_EXPORT gzVoid notifyTime(const gzDouble &minTime=0.0)
00156     {
00157         gzDouble diff(gzTime::systemSeconds()-m_resetTime);
00158 
00159         if(diff>=minTime)
00160             GZMESSAGE(GZ_MESSAGE_DEBUG,"--- GZ_TIMER '%s' Time: %g Freq: %g ---",(const char *)getName(),diff,1.0/(diff));
00161     }
00162 
00163 private:
00164     gzDouble    m_resetTime;
00165 };
00166 #endif // __GZ_TIME_H__
00167 

Documentation for GizmoBase generated at Wed Feb 20 11:57:55 2008 by   Saab Training Systems AB, ¸ (c) 2003-and beyond