Browse Source

make input manager use shared_pointer of storage editor instead of copy

master
leo 3 years ago
parent
commit
7b702aa1f7
  1. 8
      src/InputManager/InputManager.cpp
  2. 5
      src/InputManager/InputManager.h

8
src/InputManager/InputManager.cpp

@ -2,7 +2,7 @@
#include <exception> #include <exception>
#include <sstream> #include <sstream>
InputManager::InputManager(StorageEditor storageEditor) {
InputManager::InputManager(std::shared_ptr<StorageEditor> storageEditor) {
this->editor = storageEditor; this->editor = storageEditor;
} }
@ -91,16 +91,16 @@ void InputManager::displayMainMenu() {
switch(selectedOption) { switch(selectedOption) {
case 1: { case 1: {
InputManager::WareAndAmount x = displayAddWareDialog(); InputManager::WareAndAmount x = displayAddWareDialog();
editor.addWaren(x.ware, x.amount);
editor->addWaren(x.ware, x.amount);
break; break;
} }
case 2: { case 2: {
InputManager::WareAndAmount x = displayRemoveWareDialog(); InputManager::WareAndAmount x = displayRemoveWareDialog();
editor.removeWaren(x.ware.getName(), x.amount);
editor->removeWaren(x.ware.getName(), x.amount);
break; break;
} }
case 3: { case 3: {
std::vector<Ware> waren = this->editor.getWarenStorage().getAllWaren();
std::vector<Ware> waren = this->editor->getWarenStorage().getAllWaren();
displayWaren(waren); displayWaren(waren);
break; break;
} }

5
src/InputManager/InputManager.h

@ -1,5 +1,6 @@
#include "../pch.h" #include "../pch.h"
#include "../StorageEditor/StorageEditor.h" #include "../StorageEditor/StorageEditor.h"
#include <memory>
class InputManager { class InputManager {
@ -7,7 +8,7 @@ class InputManager {
typedef int MenuOption; typedef int MenuOption;
private: private:
StorageEditor editor;
std::shared_ptr<StorageEditor> editor;
MenuOption selectedOption; MenuOption selectedOption;
@ -22,7 +23,7 @@ class InputManager {
public: public:
InputManager(StorageEditor storageEditor);
InputManager(std::shared_ptr<StorageEditor> storageEditor);
void displayMainMenu(); void displayMainMenu();

Loading…
Cancel
Save