Platform_Win32_Time.cpp
Go to the documentation of this file.00001 //*** Platform_Win32_Time *** 00002 00003 #include "Platform_Win32_Time.h" 00004 00005 00006 #define WIN32_LEAN_AND_MEAN 00007 #define VC_EXTRALEAN 00008 #include <windows.h> 00009 #include <time.h> 00010 00011 //*** Constructor *** 00012 00013 Platform_Win32_Time::Platform_Win32_Time() 00014 { 00015 // Store the performance counter frequency 00016 LARGE_INTEGER f; 00017 QueryPerformanceFrequency(&f); 00018 performanceFrequency_=(double)f.QuadPart; 00019 00020 // Store the initial value of the performance counter, so that 00021 // the time we returned is always measured from when the 00022 // application was started, instead of from when the computer 00023 // was last rebooted. 00024 LARGE_INTEGER c; 00025 QueryPerformanceCounter(&c); 00026 initialValue_=(double)c.QuadPart; 00027 } 00028 00029 00030 //*** GetTime *** 00031 00032 float Platform_Win32_Time::GetTime() 00033 { 00034 // Retrieve the current performance counter value 00035 LARGE_INTEGER c; 00036 QueryPerformanceCounter(&c); 00037 double performanceCount=(double)c.QuadPart; 00038 00039 // Compensate for initial value (this will also improve precision of the float we return) 00040 performanceCount-=initialValue_; 00041 00042 // Calculate the number of millisecons 00043 float result=(float)(performanceCount/performanceFrequency_); 00044 00045 // And return it 00046 return result; 00047 } 00048 00049 00050 //*** GetSystemTime *** 00051 00052 Platform_Time::SystemTime Platform_Win32_Time::GetSystemTime(bool utcTime) 00053 { 00054 SYSTEMTIME sysTime; 00055 if (utcTime) 00056 { 00057 ::GetSystemTime(&sysTime); 00058 } 00059 else 00060 { 00061 GetLocalTime(&sysTime); 00062 } 00063 00064 SystemTime result; 00065 result.year=(short)sysTime.wYear; 00066 result.month=(char)sysTime.wMonth; 00067 result.day=(char)sysTime.wDay; 00068 result.dayOfWeek=(char)sysTime.wDayOfWeek; 00069 result.hour=(char)sysTime.wHour; 00070 result.minute=(char)sysTime.wMinute; 00071 result.second=(char)sysTime.wSecond; 00072 00073 return result; 00074 }
Reproduction/republishing of any material on this site without permission is strictly prohibited.
