00001 // ===================================================================== 00021 // ===================================================================== 00022 #ifndef __TSYSTEMTIMER_HH 00023 #define __TSYSTEMTIMER_HH 00024 00025 #include "Tglobals.h" 00026 00027 00047 class TSystemTimer 00048 { 00049 00050 private: 00051 enum { tUndefined = -1, tIdle, tReady, tRunning }; 00052 00053 private: 00054 Tint theStatus; 00055 Tstring theUnit; 00056 Tdouble theBeginOfRealTime; 00057 Tdouble theEndOfRealTime; 00058 Tdouble theBeginOfSystemTime; 00059 Tdouble theEndOfSystemTime; 00060 Tdouble theBeginOfUserTime; 00061 Tdouble theEndOfUserTime; 00062 Tdouble thePausedTime; 00063 Tdouble theRunningTime; 00064 Tdouble theIdlingTime; 00065 TdoubleList theRealLapTime; 00066 TdoubleList theSystemLapTime; 00067 TdoubleList theUserLapTime; 00068 00069 public: 00070 TSystemTimer( const Tstring& theUnit = Tsec ); 00071 TSystemTimer( const TSystemTimer& right ); 00072 ~TSystemTimer(); 00073 00074 public: 00075 Tint GetStatus() const; 00076 Tdouble GetBeginOfRealTime() const; 00077 Tdouble GetEndOfRealTime() const; 00078 Tdouble GetBeginOfSystemTime() const; 00079 Tdouble GetEndOfSystemTime() const; 00080 Tdouble GetBeginOfUserTime() const; 00081 Tdouble GetEndOfUserTime() const; 00082 Tdouble GetPausedTime() const; 00083 Tdouble GetRunningTime() const; 00084 Tdouble GetIdlingTime() const; 00085 const TdoubleList& GetRealLapTime() const; 00086 const TdoubleList& GetSystemLapTime() const; 00087 const TdoubleList& GetUserLapTime() const; 00088 const Tstring& GetUnit() const; 00089 Tint GetNumberOfLaps() const; 00090 Tstring WhatTimeIsItNow(); 00091 Tvoid SetUnit( const Tstring& unit ); 00092 00093 public: 00094 const TSystemTimer& operator=( const TSystemTimer& right ); 00095 friend Tostream& operator<<( Tostream& tos, const TSystemTimer& right ); 00096 00097 public: 00098 Tvoid Start(); 00099 Tvoid Pause(); 00100 Tvoid Stop(); 00101 Tvoid Lap(); 00102 Tvoid Restart(); 00103 00104 private: 00105 Tvoid initialize(); 00106 Tvoid clear(); 00107 Tvoid start(); 00108 Tvoid pause(); 00109 Tvoid stop(); 00110 Tvoid lap(); 00111 Tvoid restart(); 00112 Tvoid convertTimeScale( Tdouble factor ); 00113 00114 public: 00115 Tdouble GetRealElapsedTime(); 00116 Tdouble GetSystemElapsedTime(); 00117 Tdouble GetUserElapsedTime(); 00118 Tdouble GetTotalRunningTime(); 00119 Tdouble GetTotalIdlingTime(); 00120 00121 }; 00122 00123 inline Tint TSystemTimer::GetStatus() const 00124 { 00125 return theStatus; 00126 } 00127 00128 inline Tdouble TSystemTimer::GetBeginOfRealTime() const 00129 { 00130 return theBeginOfRealTime; 00131 } 00132 00133 inline Tdouble TSystemTimer::GetEndOfRealTime() const 00134 { 00135 return theEndOfRealTime; 00136 } 00137 00138 inline Tdouble TSystemTimer::GetBeginOfSystemTime() const 00139 { 00140 return theBeginOfSystemTime; 00141 } 00142 00143 inline Tdouble TSystemTimer::GetEndOfSystemTime() const 00144 { 00145 return theEndOfSystemTime; 00146 } 00147 00148 inline Tdouble TSystemTimer::GetBeginOfUserTime() const 00149 { 00150 return theBeginOfUserTime; 00151 } 00152 00153 inline Tdouble TSystemTimer::GetEndOfUserTime() const 00154 { 00155 return theEndOfUserTime; 00156 } 00157 00158 inline Tdouble TSystemTimer::GetPausedTime() const 00159 { 00160 return thePausedTime; 00161 } 00162 00163 inline Tdouble TSystemTimer::GetRunningTime() const 00164 { 00165 return theRunningTime; 00166 } 00167 00168 inline Tdouble TSystemTimer::GetIdlingTime() const 00169 { 00170 return theIdlingTime; 00171 } 00172 00173 inline const TdoubleList& TSystemTimer::GetRealLapTime() const 00174 { 00175 return theRealLapTime; 00176 } 00177 00178 inline const TdoubleList& TSystemTimer::GetSystemLapTime() const 00179 { 00180 return theSystemLapTime; 00181 } 00182 00183 inline const TdoubleList& TSystemTimer::GetUserLapTime() const 00184 { 00185 return theUserLapTime; 00186 } 00187 00188 inline const Tstring& TSystemTimer::GetUnit() const 00189 { 00190 return theUnit; 00191 } 00192 00193 inline Tint TSystemTimer::GetNumberOfLaps() const 00194 { 00195 return (Tint)theRealLapTime.size(); 00196 } 00197 00198 #endif