Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00045
00046
00047 #ifndef SIMPLETIME_H_
00048 #define SIMPLETIME_H_
00049
00050 #include "sdhlibrary_settings.h"
00051
00052
00053
00054
00055
00056 #if SDH_USE_VCC
00057 #include <sys/timeb.h>
00058 #include <time.h>
00059 #else
00060 # include <sys/time.h>
00061 #endif
00062
00063
00064
00065
00066
00067 #include "sdhexception.h"
00068
00069
00070
00071
00072
00073 NAMESPACE_SDH_START
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 #if SDH_USE_VCC
00091 typedef long tTimevalSec;
00092 typedef long tTimevalUSec;
00093 #else
00094 typedef time_t tTimevalSec;
00095 typedef suseconds_t tTimevalUSec;
00096 #endif
00097
00101 class VCC_EXPORT cSimpleTime
00102 {
00103 protected:
00104 #if SDH_USE_VCC
00105 struct _timeb timebuffer;
00106 #else
00107 struct timeval a_time;
00108 #endif
00109
00110 public:
00112 cSimpleTime()
00113 {
00114 StoreNow();
00115 }
00116
00117
00118
00120 void StoreNow(void)
00121 {
00122 #if SDH_USE_VCC
00123 _ftime64_s(&timebuffer);
00124
00125 #else
00126 gettimeofday(&a_time, NULL);
00127 #endif
00128 }
00129
00130
00132 double Elapsed(void) const
00133 {
00134 cSimpleTime now;
00135
00136 return Elapsed(now);
00137 }
00138
00139
00140
00142 long Elapsed_us(void) const
00143 {
00144 cSimpleTime now;
00145
00146 return Elapsed_us(now);
00147 }
00148
00149
00150
00151 #if SDH_USE_VCC
00152
00153 double Elapsed(cSimpleTime const& other) const
00154 {
00155 double seconds = double(other.timebuffer.time - timebuffer.time);
00156 double msec = double(other.timebuffer.millitm - timebuffer.millitm);
00157
00158 return seconds + msec / 1000.0;
00159 }
00160
00161
00163 long Elapsed_us(cSimpleTime const& other) const
00164 {
00165 long seconds = long(other.timebuffer.time - timebuffer.time);
00166 long msec = long(other.timebuffer.millitm - timebuffer.millitm);
00167
00168 return seconds * 1000000 + msec * 1000;
00169 }
00170
00171 #else
00172
00173 double Elapsed(cSimpleTime const& other) const
00174 {
00175 double seconds = double(other.a_time.tv_sec - a_time.tv_sec);
00176 double usec = double(other.a_time.tv_usec - a_time.tv_usec);
00177
00178 return seconds + usec / 1000000.0;
00179 }
00180
00181
00183 long Elapsed_us(cSimpleTime const& other) const
00184 {
00185 long seconds = other.a_time.tv_sec - a_time.tv_sec;
00186 long usec = other.a_time.tv_usec - a_time.tv_usec;
00187
00188 return seconds * 1000000 + usec;
00189 }
00190
00191
00192
00194 timeval Timeval(void)
00195 {
00196 return a_time;
00197 }
00198 #endif
00199 };
00200
00201
00202 NAMESPACE_SDH_END
00203
00204 #endif
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217