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

@@ -311,8 +311,8 @@ namespace hex {
namespace impl {
void add(View *view);
std::map<std::string, View *> &getEntries();
void add(std::unique_ptr<View> &&view);
std::map<std::string, std::unique_ptr<View>> &getEntries();
}
@@ -324,7 +324,7 @@ namespace hex {
*/
template<std::derived_from<View> T, typename... Args>
void add(Args &&...args) {
return impl::add(new T(std::forward<Args>(args)...));
return impl::add(std::make_unique<T>(std::forward<Args>(args)...));
}
/**
@@ -332,7 +332,7 @@ namespace hex {
* @param unlocalizedName The unlocalized name of the view
* @return The view if it exists, nullptr otherwise
*/
View *getViewByName(const std::string &unlocalizedName);
View* getViewByName(const std::string &unlocalizedName);
}
/* Tools Registry. Allows adding new entries to the tools window */

View File

@@ -5,6 +5,7 @@
#include <functional>
#include <map>
#include <memory>
#include <set>
#include <string>
@@ -396,7 +397,7 @@ namespace hex {
* @param focused Whether the current view is focused
* @param keyCode The key code of the key that was pressed
*/
static void process(View *currentView, bool ctrl, bool alt, bool shift, bool super, bool focused, u32 keyCode);
static void process(const std::unique_ptr<View> &currentView, bool ctrl, bool alt, bool shift, bool super, bool focused, u32 keyCode);
/**
* @brief Process a key event. This should be called from the main loop.