impr: Use smart pointers to allocate Views

This commit is contained in:
WerWolv
2023-04-08 12:08:45 +02:00
parent dfca7e923c
commit 21f38974a8
6 changed files with 22 additions and 27 deletions

View File

@@ -354,25 +354,25 @@ namespace hex {
namespace impl {
std::map<std::string, View *> &getEntries() {
static std::map<std::string, View *> views;
std::map<std::string, std::unique_ptr<View>> &getEntries() {
static std::map<std::string, std::unique_ptr<View>> views;
return views;
}
}
void impl::add(View *view) {
void impl::add(std::unique_ptr<View> &&view) {
log::debug("Registered new view: {}", view->getUnlocalizedName());
impl::getEntries().insert({ view->getUnlocalizedName(), view });
impl::getEntries().insert({ view->getUnlocalizedName(), std::move(view) });
}
View *getViewByName(const std::string &unlocalizedName) {
View* getViewByName(const std::string &unlocalizedName) {
auto &views = impl::getEntries();
if (views.contains(unlocalizedName))
return views[unlocalizedName];
return views[unlocalizedName].get();
else
return nullptr;
}

View File

@@ -32,7 +32,7 @@ namespace hex {
return pressedShortcut;
}
void ShortcutManager::process(View *currentView, bool ctrl, bool alt, bool shift, bool super, bool focused, u32 keyCode) {
void ShortcutManager::process(const std::unique_ptr<View> &currentView, bool ctrl, bool alt, bool shift, bool super, bool focused, u32 keyCode) {
Shortcut pressedShortcut = getShortcut(ctrl, alt, shift, super, keyCode);
if (focused && currentView->m_shortcuts.contains(pressedShortcut))