From 7b702aa1f7ef28fb5c716a358f0a9226feb18f9c Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 29 Mar 2022 00:26:23 +0200 Subject: [PATCH] make input manager use shared_pointer of storage editor instead of copy --- src/InputManager/InputManager.cpp | 8 ++++---- src/InputManager/InputManager.h | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/InputManager/InputManager.cpp b/src/InputManager/InputManager.cpp index fafd6fc..98cced5 100644 --- a/src/InputManager/InputManager.cpp +++ b/src/InputManager/InputManager.cpp @@ -2,7 +2,7 @@ #include #include -InputManager::InputManager(StorageEditor storageEditor) { +InputManager::InputManager(std::shared_ptr storageEditor) { this->editor = storageEditor; } @@ -91,16 +91,16 @@ void InputManager::displayMainMenu() { switch(selectedOption) { case 1: { InputManager::WareAndAmount x = displayAddWareDialog(); - editor.addWaren(x.ware, x.amount); + editor->addWaren(x.ware, x.amount); break; } case 2: { InputManager::WareAndAmount x = displayRemoveWareDialog(); - editor.removeWaren(x.ware.getName(), x.amount); + editor->removeWaren(x.ware.getName(), x.amount); break; } case 3: { - std::vector waren = this->editor.getWarenStorage().getAllWaren(); + std::vector waren = this->editor->getWarenStorage().getAllWaren(); displayWaren(waren); break; } diff --git a/src/InputManager/InputManager.h b/src/InputManager/InputManager.h index 6db4fdc..24ecc10 100644 --- a/src/InputManager/InputManager.h +++ b/src/InputManager/InputManager.h @@ -1,5 +1,6 @@ #include "../pch.h" #include "../StorageEditor/StorageEditor.h" +#include class InputManager { @@ -7,7 +8,7 @@ class InputManager { typedef int MenuOption; private: - StorageEditor editor; + std::shared_ptr editor; MenuOption selectedOption; @@ -22,7 +23,7 @@ class InputManager { public: - InputManager(StorageEditor storageEditor); + InputManager(std::shared_ptr storageEditor); void displayMainMenu();