Skip to content

Commit 1dbc513

Browse files
committed
added type feature
1 parent 6c8966b commit 1dbc513

3 files changed

Lines changed: 128 additions & 120 deletions

File tree

docs/documentation.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,9 @@ This will essentially return the VM brand as a `std::string`. The exact possible
165165
- `bhyve`
166166
- `QEMU`
167167
- `KVM`
168-
- `KVM Hyper-V Enlightenment`
169168
- `QEMU+KVM`
169+
- `KVM Hyper-V Enlightenment`
170+
- `QEMU+KVM Hyper-V Enlightenment`
170171
- `Virtual PC`
171172
- `Microsoft Hyper-V`
172173
- `Microsoft Virtual PC/Hyper-V`

src/cli.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ bhyve
213213
QEMU
214214
KVM
215215
KVM Hyper-V Enlightenment
216+
QEMU+KVM Hyper-V Enlightenment
216217
QEMU+KVM
217218
Virtual PC
218219
Microsoft Hyper-V
@@ -256,7 +257,7 @@ std::string type(const std::string &brand_str) {
256257
return "Unknown";
257258
}
258259

259-
const std::map<const char*, const char*> type_table {
260+
const std::map<std::string, std::string> type_table {
260261
{ "Xen HVM", "Hypervisor (type 1)" },
261262
{ "VMware ESX", "Hypervisor (type 1)" },
262263
{ "ACRN", "Hypervisor (type 1)" },
@@ -267,6 +268,7 @@ std::string type(const std::string &brand_str) {
267268
{ "KVM ", "Hypervisor (type 1)" },
268269
{ "bhyve", "Hypervisor (type 1)" },
269270
{ "KVM Hyper-V Enlightenment", "Hypervisor (type 1)" },
271+
{ "QEMU+KVM Hyper-V Enlightenment", "Hypervisor (type 1)" },
270272
{ "QEMU+KVM", "Hypervisor (type 1)" },
271273
{ "Intel HAXM", "Hypervisor (type 1)" },
272274
{ "Intel KGT (Trusty)", "Hypervisor (type 1)" },
@@ -306,7 +308,7 @@ std::string type(const std::string &brand_str) {
306308
{ "Apple VZ", "Unknown" }
307309
};
308310

309-
auto it = type_table.find(brand_str.c_str());
311+
auto it = type_table.find(brand_str);
310312

311313
if (it != type_table.end()) {
312314
return it->second;
@@ -608,15 +610,21 @@ void general() {
608610
ansi_exit <<
609611
"\n\n";
610612

611-
std::vector<const char*> brand_vector = VM::brand_vector();
613+
#if (MSVC)
614+
using brand_score_t = std::int32_t;
615+
#else
616+
using brand_score_t = std::uint8_t;
617+
#endif
618+
619+
std::map<const char*, brand_score_t> brand_map = VM::brand_map();
612620

613621
auto brand_vec = [&]() -> bool {
614622
bool is_hyperv_vpc_present = false;
615623

616-
for (const char* p_brand : brand_vector) {
624+
for (const auto p_brand : brand_map) {
617625
if (
618-
(std::strcmp(p_brand, "Microsoft Hyper-V") == 0) ||
619-
(std::strcmp(p_brand, "Virtual PC") == 0)
626+
(std::strcmp(p_brand.first, "Microsoft Hyper-V") == 0) ||
627+
(std::strcmp(p_brand.first, "Virtual PC") == 0)
620628
) {
621629
is_hyperv_vpc_present = true;
622630
}
@@ -630,10 +638,10 @@ void general() {
630638
bool is_vpc = false;
631639
bool is_other = false;
632640

633-
for (const auto p_brand : brand_vector) {
634-
if (std::strcmp(p_brand, "Microsoft Hyper-V") == 0) {
641+
for (const auto p_brand : brand_map) {
642+
if (std::strcmp(p_brand.first, "Microsoft Hyper-V") == 0) {
635643
is_hyperv = true;
636-
} else if (std::strcmp(p_brand, "Virtual PC") == 0) {
644+
} else if (std::strcmp(p_brand.first, "Virtual PC") == 0) {
637645
is_vpc = true;
638646
} else {
639647
is_other = true;

0 commit comments

Comments
 (0)