Add get_comp_by_name_optional.

This commit is contained in:
joevt 2023-12-18 01:17:41 -08:00 committed by dingusdev
parent 78020c4794
commit 23903a969d
2 changed files with 9 additions and 0 deletions

View File

@ -58,6 +58,14 @@ HWComponent* MachineBase::get_comp_by_name(std::string name) {
}
}
HWComponent* MachineBase::get_comp_by_name_optional(std::string name) {
if (this->device_map.count(name)) {
return this->device_map[name].get();
} else {
return nullptr;
}
}
HWComponent* MachineBase::get_comp_by_type(HWCompType type) {
std::string comp_name;
bool found = false;

View File

@ -41,6 +41,7 @@ public:
void add_device(std::string name, std::unique_ptr<HWComponent> dev_obj);
HWComponent* get_comp_by_name(std::string name);
HWComponent* get_comp_by_name_optional(std::string name);
HWComponent* get_comp_by_type(HWCompType type);
int postinit_devices();