-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.cpccHardware.h
97 lines (72 loc) · 2.63 KB
/
core.cpccHardware.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* *****************************************
* File: core.hardware.h
* Purpose: Portable (cross-platform), light-weight functions
* *****************************************
* Library: Cross Platform C++ Classes (cpcc)
* Copyright: 2019 StarMessage software.
* License: Free for opensource projects.
* Commercial license exists for closed source projects.
* Web: http://www.StarMessageSoftware.com/cpcclibrary
* Download: https://github.com/starmessage/cpcc
* email: sales -at- starmessage.info
* *****************************************
*/
#pragma once
#include <vector>
#include <thread> // for number of CPU cores
#include "cpccUnicodeSupport.h"
// about retina display:
// HiDPI and DPI (high dots-per-inch) and
// PPI (pixels per inch) as the technical terms used for Retina Display on non-Apple platforms
struct cpccMonitorInfoT { int left=0, top=0, right=0, bottom=0; bool isRetina=false; };
typedef std::vector<cpccMonitorInfoT> cpccMonitorList;
// /////////////////////////////////////////
//
// cpccHardware
//
// /////////////////////////////////////////
class cpccHardware
{
public:
static bool hasRetinaDisplay(void); // todo: rename to hasAtLeastOneRetinaDisplay. But would this function be useful?
static size_t getListOfMonitors(cpccMonitorList &list);
static std::basic_string<TCHAR> getAllMonitorResolutionAsText(void);
static long getRamMemoryTotal_inMb(void);
static long getRamMemoryFree_inMb(void);
static int getCPUcores(void);
static std::basic_string<TCHAR> getCPUmodel(void);
};
// /////////////////////////////////////////
//
// cpccHardware implementation
//
// /////////////////////////////////////////
inline int cpccHardware::getCPUcores(void)
{
/*
// for macOS:
int mib[] = { CTL_HW, HW_NCPU };
int nCPUs = 0;
size_t length = sizeof(nCPUs);
sysctl(mib, 2, &nCPUs, &length, NULL, 0);
return nCPUs;
*/
return std::thread::hardware_concurrency();
}
inline std::basic_string<TCHAR> cpccHardware::getAllMonitorResolutionAsText(void)
{
cpcc_string result, separatorText;
cpccMonitorList list;
getListOfMonitors(list);
for (const auto &monitor : list)
{
result += separatorText + cpcc_to_string(monitor.right - monitor.left) + _T("x") + cpcc_to_string(monitor.bottom - monitor.top);
if (monitor.isRetina)
result += _T(" HiDPI");
separatorText = _T(", ");
}
return result;
}
#ifdef _WIN32
inline bool cpccHardware::hasRetinaDisplay(void) { return false; }
#endif