From 87943320f65c20f00e0e8cd7d1b033f65af88ef9 Mon Sep 17 00:00:00 2001 From: ColumbusTech Date: Thu, 22 Nov 2018 22:44:43 +0300 Subject: [PATCH] Delete ColumbusInfo.hpp --- ColumbusInfo.hpp | 147 ----------------------------------------------- 1 file changed, 147 deletions(-) delete mode 100644 ColumbusInfo.hpp diff --git a/ColumbusInfo.hpp b/ColumbusInfo.hpp deleted file mode 100644 index 2a1fd11..0000000 --- a/ColumbusInfo.hpp +++ /dev/null @@ -1,147 +0,0 @@ -#ifdef _WIN32 - #define COLUMBUS_PLATFORM_WINDOWS - #include -#endif - -#ifdef __linux - #define COLUMBUS_PLATFORM_LINUX - #include - #include -#endif - -#include -#include -#include -#include - -namespace Columbus -{ - - class Info - { - public: - static unsigned int getCPUCount(); - static unsigned int getCPUFrequency(); - - static unsigned long getRAMSize(); - static unsigned long getRAMFree(); - static int getRAMUsage(); - }; - - unsigned int Info::getCPUCount() - { - #ifdef COLUMBUS_PLATFORM_LINUX - return sysconf(_SC_NPROCESSORS_ONLN); - #endif - - #ifdef COLUMBUS_PLATFORM_WINDOWS - SYSTEM_INFO sysinfo; - GetSystemInfo(&sysinfo); - return sysinfo.dwNumberOfProcessors; - #endif - - return 0; - } - - unsigned int Info::getCPUFrequency() - { - #ifdef COLUMBUS_PLATFORM_LINUX - std::ifstream f("/proc/cpuinfo"); - if (!f.is_open()) return 0; - std::string line; - - while (getline(f, line)) - { - if (line.substr(0, 7) == "cpu MHz") - return atoi(line.substr(line.find(":") + 1).c_str()); - } - #endif - - #ifdef COLUMBUS_PLATFORM_WINDOWS - wchar_t Buffer[_MAX_PATH]; - DWORD BufSize = _MAX_PATH; - DWORD dwMHz = _MAX_PATH; - HKEY hKey; - - long lError = RegOpenKeyEx(HKEY_LOCAL_MACHINE, - L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", 0, KEY_READ, &hKey); - - if (lError != ERROR_SUCCESS) - { - FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, lError, 0, Buffer, _MAX_PATH, 0); - wprintf(Buffer); - return 0; - } - - RegQueryValueEx(hKey, L"~MHz", NULL, NULL, (LPBYTE)&dwMHz, &BufSize); - return dwMHz; - #endif - - return 0; - } - - unsigned long Info::getRAMSize() - { - #ifdef COLUMBUS_PLATFORM_LINUX - struct sysinfo info; - if (sysinfo(&info) == -1) return 0; - return info.totalram / (1024 * 1024); - #endif - - #ifdef COLUMBUS_PLATFORM_WINDOWS - MEMORYSTATUSEX memInfo; - memInfo.dwLength = sizeof(memInfo); - GlobalMemoryStatusEx(&memInfo); - return memInfo.ullTotalPhys / (1024 * 1024); - #endif - - return 0; - } - - unsigned long Info::getRAMFree() - { - #ifdef COLUMBUS_PLATFORM_LINUX - struct sysinfo info; - if (sysinfo(&info) == -1) return 0; - return info.freeram / (1024 * 1024); - #endif - - #ifdef COLUMBUS_PLATFORM_WINDOWS - MEMORYSTATUSEX memInfo; - memInfo.dwLength = sizeof(memInfo); - GlobalMemoryStatusEx(&memInfo); - return memInfo.ullAvailPhys / (1024 * 1024); - #endif - - return 0; - } - - int Info::getRAMUsage() - { - #ifdef COLUMBUS_PLATFORM_LINUX - struct sysinfo info; - if (sysinfo(&info) == -1) return 0; - float usage = static_cast(getRAMFree()) / static_cast(getRAMSize()); - return static_cast(100 - usage * 100); - #endif - - #ifdef COLUMBUS_PLATFORM_WINDOWS - MEMORYSTATUSEX memInfo; - memInfo.dwLength = sizeof(memInfo); - GlobalMemoryStatusEx(&memInfo); - return memInfo.dwMemoryLoad; - #endif - - return 0; - } - -} - - -#undef COLUMBUS_PLATFORM_WINDOWS -#undef COLUMBUS_PLATFORM_LINUX - - - - -