Skip to content

Commit f64bf73

Browse files
committed
Windows: fix compiling for GCC
1 parent 157be84 commit f64bf73

File tree

2 files changed

+122
-109
lines changed

2 files changed

+122
-109
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# 2.0.2
2+
3+
Fix compiling for MSYS2, no functional changes.
4+
5+
Bugfixes:
6+
* Workarund [a compiler bug of GCC](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85282) (Windows)
7+
18
# 2.0.1
29

310
First stable release of Fastfetch V2

src/util/windows/wmi.hpp

Lines changed: 115 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ extern "C" {
1414
#include <utility>
1515
#include <string_view>
1616
#include <cassert>
17+
#include <type_traits>
1718

1819
enum class FFWmiNamespace {
1920
CIMV2,
@@ -36,115 +37,120 @@ struct FFWmiVariant: VARIANT {
3637
return this->hasValue();
3738
}
3839

39-
template <typename T> T get();
40-
41-
// boolean
42-
template <> bool get<bool>() {
43-
assert(this->vt == VT_BOOL);
44-
return this->boolVal != VARIANT_FALSE;
45-
}
46-
47-
// signed
48-
template <> int8_t get() {
49-
assert(this->vt == VT_I1);
50-
return this->cVal;
51-
}
52-
template <> int16_t get() {
53-
assert(vt == VT_I2);
54-
return this->iVal;
55-
}
56-
template <> int32_t get() {
57-
assert(this->vt == VT_I4 || vt == VT_INT);
58-
return this->intVal;
59-
}
60-
template <> int64_t get() {
61-
assert(this->vt == VT_I8);
62-
return this->llVal;
63-
}
64-
65-
// unsigned
66-
template <> uint8_t get() {
67-
assert(this->vt == VT_UI1);
68-
return this->bVal;
69-
}
70-
template <> uint16_t get() {
71-
assert(this->vt == VT_UI2);
72-
return this->uiVal;
73-
}
74-
template <> uint32_t get() {
75-
assert(this->vt == VT_UI4 || vt == VT_UINT);
76-
return this->uintVal;
77-
}
78-
template <> uint64_t get() {
79-
assert(this->vt == VT_UI8);
80-
return this->ullVal;
81-
}
82-
83-
// decimal
84-
template <> float get() {
85-
assert(this->vt == VT_R4);
86-
return this->fltVal;
87-
}
88-
template <> double get() {
89-
assert(this->vt == VT_R8);
90-
return this->dblVal;
91-
}
92-
93-
// string
94-
template <> std::string_view get() {
95-
assert(this->vt == VT_LPSTR);
96-
return this->pcVal;
97-
}
98-
template <> std::wstring_view get() {
99-
assert(this->vt == VT_BSTR || this->vt == VT_LPWSTR);
100-
if (this->vt == VT_LPWSTR)
101-
return this->bstrVal;
102-
else
103-
return { this->bstrVal, SysStringLen(this->bstrVal) };
104-
}
105-
106-
// array signed
107-
template <> std::pair<const int8_t*, uint32_t> get() {
108-
assert(this->vt & VT_ARRAY);
109-
assert((this->vt & ~VT_ARRAY) == VT_I1);
110-
return std::make_pair((int8_t*)this->parray->pvData, this->parray->cDims);
111-
}
112-
template <> std::pair<const int16_t*, uint32_t> get() {
113-
assert(this->vt & VT_ARRAY);
114-
assert((this->vt & ~VT_ARRAY) == VT_I2);
115-
return std::make_pair((int16_t*)this->parray->pvData, this->parray->cDims);
116-
}
117-
template <> std::pair<const int32_t*, uint32_t> get() {
118-
assert(this->vt & VT_ARRAY);
119-
assert((this->vt & ~VT_ARRAY) == VT_I4);
120-
return std::make_pair((int32_t*)this->parray->pvData, this->parray->cDims);
121-
}
122-
template <> std::pair<const int64_t*, uint32_t> get() {
123-
assert(this->vt & VT_ARRAY);
124-
assert((this->vt & ~VT_ARRAY) == VT_I8);
125-
return std::make_pair((int64_t*)this->parray->pvData, this->parray->cDims);
126-
}
127-
128-
// array unsigned
129-
template <> std::pair<const uint8_t*, uint32_t> get() {
130-
assert(this->vt & VT_ARRAY);
131-
assert((this->vt & ~VT_ARRAY) == VT_UI1);
132-
return std::make_pair((uint8_t*)this->parray->pvData, this->parray->cDims);
133-
}
134-
template <> std::pair<const uint16_t*, uint32_t> get() {
135-
assert(this->vt & VT_ARRAY);
136-
assert((this->vt & ~VT_ARRAY) == VT_UI2);
137-
return std::make_pair((uint16_t*)this->parray->pvData, this->parray->cDims);
138-
}
139-
template <> std::pair<const uint32_t*, uint32_t> get() {
140-
assert(this->vt & VT_ARRAY);
141-
assert((this->vt & ~VT_ARRAY) == VT_UI4);
142-
return std::make_pair((uint32_t*)this->parray->pvData, this->parray->cDims);
143-
}
144-
template <> std::pair<const uint64_t*, uint32_t> get() {
145-
assert(this->vt & VT_ARRAY);
146-
assert((this->vt & ~VT_ARRAY) == VT_UI8);
147-
return std::make_pair((uint64_t*)this->parray->pvData, this->parray->cDims);
40+
template <typename T> T get()
41+
{
42+
// boolean
43+
if constexpr (std::is_same_v<T, bool>) {
44+
assert(this->vt == VT_BOOL);
45+
return this->boolVal != VARIANT_FALSE;
46+
}
47+
48+
// signed
49+
else if constexpr (std::is_same_v<T, int8_t>) {
50+
assert(this->vt == VT_I1);
51+
return this->cVal;
52+
}
53+
else if constexpr (std::is_same_v<T, int16_t>) {
54+
assert(vt == VT_I2);
55+
return this->iVal;
56+
}
57+
else if constexpr (std::is_same_v<T, int32_t>) {
58+
assert(this->vt == VT_I4 || vt == VT_INT);
59+
return this->intVal;
60+
}
61+
else if constexpr (std::is_same_v<T, int64_t>) {
62+
assert(this->vt == VT_I8);
63+
return this->llVal;
64+
}
65+
66+
// unsigned
67+
else if constexpr (std::is_same_v<T, uint8_t>) {
68+
assert(this->vt == VT_UI1);
69+
return this->bVal;
70+
}
71+
else if constexpr (std::is_same_v<T, uint16_t>) {
72+
assert(this->vt == VT_UI2);
73+
return this->uiVal;
74+
}
75+
else if constexpr (std::is_same_v<T, uint32_t>) {
76+
assert(this->vt == VT_UI4 || vt == VT_UINT);
77+
return this->uintVal;
78+
}
79+
else if constexpr (std::is_same_v<T, uint64_t>) {
80+
assert(this->vt == VT_UI8);
81+
return this->ullVal;
82+
}
83+
84+
// decimal
85+
else if constexpr (std::is_same_v<T, float>) {
86+
assert(this->vt == VT_R4);
87+
return this->fltVal;
88+
}
89+
else if constexpr (std::is_same_v<T, double>) {
90+
assert(this->vt == VT_R8);
91+
return this->dblVal;
92+
}
93+
94+
// string
95+
else if constexpr (std::is_same_v<T, std::string_view>) {
96+
assert(this->vt == VT_LPSTR);
97+
return this->pcVal;
98+
}
99+
else if constexpr (std::is_same_v<T, std::wstring_view>) {
100+
assert(this->vt == VT_BSTR || this->vt == VT_LPWSTR);
101+
if (this->vt == VT_LPWSTR)
102+
return this->bstrVal;
103+
else
104+
return { this->bstrVal, SysStringLen(this->bstrVal) };
105+
}
106+
107+
// array signed
108+
else if constexpr (std::is_same_v<T, std::pair<const int8_t*, uint32_t>>) {
109+
assert(this->vt & VT_ARRAY);
110+
assert((this->vt & ~VT_ARRAY) == VT_I1);
111+
return std::make_pair((int8_t*)this->parray->pvData, this->parray->cDims);
112+
}
113+
else if constexpr (std::is_same_v<T, std::pair<const int16_t*, uint32_t>>) {
114+
assert(this->vt & VT_ARRAY);
115+
assert((this->vt & ~VT_ARRAY) == VT_I2);
116+
return std::make_pair((int16_t*)this->parray->pvData, this->parray->cDims);
117+
}
118+
else if constexpr (std::is_same_v<T, std::pair<const int32_t*, uint32_t>>) {
119+
assert(this->vt & VT_ARRAY);
120+
assert((this->vt & ~VT_ARRAY) == VT_I4);
121+
return std::make_pair((int32_t*)this->parray->pvData, this->parray->cDims);
122+
}
123+
else if constexpr (std::is_same_v<T, std::pair<const int64_t*, uint32_t>>) {
124+
assert(this->vt & VT_ARRAY);
125+
assert((this->vt & ~VT_ARRAY) == VT_I8);
126+
return std::make_pair((int64_t*)this->parray->pvData, this->parray->cDims);
127+
}
128+
129+
// array unsigned
130+
else if constexpr (std::is_same_v<T, std::pair<const uint8_t*, uint32_t>>) {
131+
assert(this->vt & VT_ARRAY);
132+
assert((this->vt & ~VT_ARRAY) == VT_UI1);
133+
return std::make_pair((uint8_t*)this->parray->pvData, this->parray->cDims);
134+
}
135+
else if constexpr (std::is_same_v<T, std::pair<const uint16_t*, uint32_t>>) {
136+
assert(this->vt & VT_ARRAY);
137+
assert((this->vt & ~VT_ARRAY) == VT_UI2);
138+
return std::make_pair((uint16_t*)this->parray->pvData, this->parray->cDims);
139+
}
140+
else if constexpr (std::is_same_v<T, std::pair<const uint32_t*, uint32_t>>) {
141+
assert(this->vt & VT_ARRAY);
142+
assert((this->vt & ~VT_ARRAY) == VT_UI4);
143+
return std::make_pair((uint32_t*)this->parray->pvData, this->parray->cDims);
144+
}
145+
else if constexpr (std::is_same_v<T, std::pair<const uint64_t*, uint32_t>>) {
146+
assert(this->vt & VT_ARRAY);
147+
assert((this->vt & ~VT_ARRAY) == VT_UI8);
148+
return std::make_pair((uint64_t*)this->parray->pvData, this->parray->cDims);
149+
}
150+
else {
151+
assert(false && "unsupported type");
152+
__builtin_unreachable();
153+
}
148154
}
149155
};
150156

0 commit comments

Comments
 (0)