From 1a926be1b7c1102495d6ac36faa69e2da52d6640 Mon Sep 17 00:00:00 2001 From: Robin Dietzel Date: Thu, 26 Jan 2023 14:17:58 +0100 Subject: [PATCH] FIX: use raw pointer here --- Middlewares/floatpump/Inc/Menu.h | 7 +++++-- Middlewares/floatpump/Src/Menu.cpp | 6 +++--- Middlewares/floatpump/Src/Menu_Controller.cpp | 16 ++++++++-------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Middlewares/floatpump/Inc/Menu.h b/Middlewares/floatpump/Inc/Menu.h index ff64f0a..b695208 100644 --- a/Middlewares/floatpump/Inc/Menu.h +++ b/Middlewares/floatpump/Inc/Menu.h @@ -9,7 +9,6 @@ #include #include #include -#include namespace floatpump { namespace menu { @@ -125,6 +124,10 @@ namespace floatpump { public: explicit Menu(const std::string &m_name) : m_name(m_name) {} + enum class Error { + invalid_index + }; + template auto addEntry(As &&...args) -> void { m_entries.push_back(std::make_unique(std::forward(args)...)); @@ -148,7 +151,7 @@ namespace floatpump { auto getSubmenu(int index) -> Menu *; - auto getEntry(int index) -> std::optional>; + auto getEntry(int index) -> IMenuEntry* ; auto getParent() -> Menu * { return m_parent; diff --git a/Middlewares/floatpump/Src/Menu.cpp b/Middlewares/floatpump/Src/Menu.cpp index 36559e8..477ae73 100644 --- a/Middlewares/floatpump/Src/Menu.cpp +++ b/Middlewares/floatpump/Src/Menu.cpp @@ -104,11 +104,11 @@ namespace floatpump::menu { } } - auto Menu::getEntry(int index) -> std::optional> { + auto Menu::getEntry(int index) -> IMenuEntry* { if (index >= m_submenus.size() && index < m_entries.size() + m_submenus.size()) { - return *m_entries[index - m_submenus.size()]; + return m_entries[index - m_submenus.size()].get(); } else { - return std::nullopt; + return nullptr; } } diff --git a/Middlewares/floatpump/Src/Menu_Controller.cpp b/Middlewares/floatpump/Src/Menu_Controller.cpp index 6276060..3b6ea44 100644 --- a/Middlewares/floatpump/Src/Menu_Controller.cpp +++ b/Middlewares/floatpump/Src/Menu_Controller.cpp @@ -70,8 +70,8 @@ namespace floatpump::menu { m_menu = m->getSubmenu(m_current_index); m_current_index = 0; //Forward press action if entry is entry - } else if (m->getEntry(m_current_index) != std::nullopt) { - m->getEntry(m_current_index)->get().u_press(); + } else if (m->getEntry(m_current_index) != nullptr) { + m->getEntry(m_current_index)->u_press(); //If we are on the Go-Back-Entry and have a parent: replace menu with parent menu } else if (m_menu->getParent() != nullptr) { m_menu = m_menu->getParent(); @@ -81,10 +81,10 @@ namespace floatpump::menu { void Menu_Controller::increase(Menu *m) { if (m_current_index < m->getAllEntriesNum()) { - if (m->getEntry(m_current_index) != std::nullopt) { + if (m->getEntry(m_current_index) != nullptr) { //Forward increase action to entry if we have an entered entry - if (m->getEntry(m_current_index)->get().is_entered()) { - m->getEntry(m_current_index)->get().u_increase(); + if (m->getEntry(m_current_index)->is_entered()) { + m->getEntry(m_current_index)->u_increase(); } else if (m_current_index < m->getAllEntriesNum() - 1) { m_current_index++; } @@ -98,10 +98,10 @@ namespace floatpump::menu { void Menu_Controller::decrease(Menu *m) { if (m_current_index > 0) { - if (m->getEntry(m_current_index) != std::nullopt) { + if (m->getEntry(m_current_index) != nullptr) { //Forward decrease action to entry if we have an entered entry - if (m->getEntry(m_current_index)->get().is_entered()) { - m->getEntry(m_current_index)->get().u_decrease(); + if (m->getEntry(m_current_index)->is_entered()) { + m->getEntry(m_current_index)->u_decrease(); } else { m_current_index--; }