6 Commits

  1. 6
      .gitignore
  2. 8
      CMakeLists.txt
  3. 47
      src/InputManager/InputManager.cpp
  4. 17
      src/InputManager/InputManager.h
  5. 31
      src/StorageEditor/StorageEditor.cpp
  6. 27
      src/StorageEditor/StorageEditor.h
  7. 8
      src/Ware/Ware.cpp
  8. 2
      src/Ware/Ware.h
  9. 4
      src/WarenStorage/WarenStorage.cpp
  10. 8
      src/WarenStorage/WarenStorage.h
  11. 26
      src/header-files/StorageEditor.h
  12. 6
      src/main.cpp
  13. 0
      src/pch.h
  14. 30
      src/source-files/StorageEditor.cpp

6
.gitignore

@ -1 +1,7 @@
.vimspector.json
CMakeFiles
CMakeCache.txt
cmake_install.cmake
CMakeLists.txt
kaufland
Makefile

8
CMakeLists.txt

@ -2,10 +2,10 @@ project(kaufland)
set (CMAKE_CXX_STANDARD 14)
set(SOURCES
src/source-files/Ware.cpp
src/source-files/WarenStorage.cpp
src/source-files/StorageEditor.cpp
src/source-files/InputManager.cpp
src/Ware/Ware.cpp
src/WarenStorage/WarenStorage.cpp
src/StorageEditor/StorageEditor.cpp
src/InputManager/InputManager.cpp
)
set(COMBINED_SOURCES ${SOURCES} src/main.cpp)

47
src/source-files/InputManager.cpp → src/InputManager/InputManager.cpp

@ -1,8 +1,8 @@
#include "../header-files/InputManager.h"
#include "InputManager.h"
#include <exception>
#include <sstream>
InputManager::InputManager(StorageEditor storageEditor) {
InputManager::InputManager(std::shared_ptr<StorageEditor> storageEditor) {
this->editor = storageEditor;
}
@ -14,15 +14,16 @@ void InputManager::setSelectedOption(MenuOption option) {
this->selectedOption = option;
}
InputManager::MenuOption InputManager::askMenuOption(std::string question, std::vector<std::string> answers) {
InputManager::MenuOption InputManager::askMenuOption(const std::string& question, const std::vector<std::string>& answers) {
this->displayDialog(question, answers);
int input;
std::cin >> input;
return input;
}
void InputManager::displayDialog(std::string question, std::vector<std::string> answers) {
void InputManager::displayDialog(const std::string& question, const std::vector<std::string>& answers) {
std::cout << question << std::endl;
std::cout << "-------------------------------" << std::endl;
int counter = 0;
@ -34,16 +35,11 @@ void InputManager::displayDialog(std::string question, std::vector<std::string>
}
InputManager::WareAndAmount InputManager::displayAddWareDialog() {
std::string name;
bool hasCooling;
double width, height;
int amount;
name = getInput<std::string>("Enter Ware Name:");
hasCooling = getNeedsCooling();
width = getInput<double>("Enter Ware width:");
height = getInput<double>("Enter Ware height:");
amount = getInput<int>("Enter Ware amount:");
std::string name = getInput<std::string>("Enter Ware Name:");
bool hasCooling = getNeedsCooling();
double width = getInput<double>("Enter Ware width:");
double height = getInput<double>("Enter Ware height:");
int amount = getInput<int>("Enter Ware amount:");
InputManager::WareAndAmount wareAndAmount;
wareAndAmount.ware = Ware(name, hasCooling, width, height);
@ -53,11 +49,8 @@ InputManager::WareAndAmount InputManager::displayAddWareDialog() {
}
InputManager::WareAndAmount InputManager::displayRemoveWareDialog() {
std::string name;
int amount;
name = getInput<std::string>("Enter Name of the Ware you want to remove:");
amount = getInput<int>("Enter amount you want to remove:");
std::string name = getInput<std::string>("Enter Name of the Ware you want to remove:");
int amount = getInput<int>("Enter amount you want to remove:");
InputManager::WareAndAmount wareAndAmount;
@ -91,16 +84,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<Ware> waren = this->editor.getWarenStorage().getAllWaren();
std::vector<Ware> waren = this->editor->getWarenStorage()->getAllWaren();
displayWaren(waren);
break;
}
@ -108,13 +101,17 @@ void InputManager::displayMainMenu() {
return;
break;
}
default: {
return;
break;
}
}
displayMainMenu();
}
// if no more initialization needed --> refactor to setStorageEditor
void InputManager::displayWaren(const std::vector<Ware> waren) {
void InputManager::displayWaren(const std::vector<Ware>& waren) {
std::cout << "Liste der sich im Lager befindlichen Waren:" << std::endl;
std::vector<InputManager::WareAndAmount> sortedWarenList = sortAndGroupWaren(waren);
@ -222,7 +219,7 @@ std::vector<InputManager::WareAndAmount> InputManager::sortAndGroupWaren(const s
bool InputManager::getNeedsCooling() {
std::string input;
bool hasCooling;
bool hasCooling = false;
std::cout << "Does Ware need Cooling? (y/n)" << std::endl;
try {
@ -247,7 +244,7 @@ bool InputManager::getNeedsCooling() {
//std::istream
template <typename T>
T InputManager::getInput(std::string message) const {
T InputManager::getInput(const std::string& message) const {
std::cout << message << std::endl;
T val;
try {

17
src/header-files/InputManager.h → src/InputManager/InputManager.h

@ -1,5 +1,6 @@
#include "pch.h"
#include "StorageEditor.h"
#include "../pch.h"
#include "../StorageEditor/StorageEditor.h"
#include <memory>
class InputManager {
@ -7,13 +8,13 @@ class InputManager {
typedef int MenuOption;
private:
StorageEditor editor;
std::shared_ptr<StorageEditor> editor;
MenuOption selectedOption;
MenuOption askMenuOption(std::string question, std::vector<std::string> answers);
MenuOption askMenuOption(const std::string& question, const std::vector<std::string>& answers);
void displayDialog(std::string question, std::vector<std::string> answers);
void displayDialog(const std::string& question, const std::vector<std::string>& answers);
struct WareAndAmount {
Ware ware;
@ -22,11 +23,11 @@ class InputManager {
public:
InputManager(StorageEditor storageEditor);
InputManager(std::shared_ptr<StorageEditor> storageEditor);
void displayMainMenu();
void displayWaren(const std::vector<Ware> waren);
void displayWaren(const std::vector<Ware>& waren);
WareAndAmount displayAddWareDialog();
@ -38,7 +39,7 @@ class InputManager {
void setSelectedOption(MenuOption option);
template <typename T>
T getInput(std::string message) const;
T getInput(const std::string& message) const;
bool getNeedsCooling();

31
src/StorageEditor/StorageEditor.cpp

@ -0,0 +1,31 @@
#include "StorageEditor.h"
StorageEditor::StorageEditor() { }
StorageEditor::StorageEditor(std::shared_ptr<WarenStorage> storage) {
this->storage = storage;
}
std::shared_ptr<WarenStorage> StorageEditor::getWarenStorage() const {
return storage;
}
void StorageEditor::setWarenStorage(const WarenStorage storage) {
//move might be unnecessary here
this->storage = std::make_shared<WarenStorage>(std::move(storage));
}
void StorageEditor::addWaren(const Ware ware, int amount) {
for(auto i = 0; i < amount; i++) {
storage->addWareAndGenerateId(ware);
}
}
void StorageEditor::removeWaren(const std::string& name, const int amount) {
for(auto i = 0; i < amount; i++) {
storage->removeWare(name);
}
}

27
src/StorageEditor/StorageEditor.h

@ -0,0 +1,27 @@
#include "../pch.h"
#include <memory>
#include "../WarenStorage/WarenStorage.h"
class StorageEditor {
private:
std::shared_ptr<WarenStorage> storage;
public:
StorageEditor();
StorageEditor(std::shared_ptr<WarenStorage> storage);
std::shared_ptr<WarenStorage> getWarenStorage() const;
void setWarenStorage(const WarenStorage storage);
void addWareAndGenerateId(Ware ware);
void addWaren(const Ware ware, int amount);
void removeWare(const std::string& name);
void removeWaren(const std::string& name, int amount);
};

8
src/source-files/Ware.cpp → src/Ware/Ware.cpp

@ -1,4 +1,4 @@
#include "../header-files/data-classes/Ware.h"
#include "Ware.h"
Ware::Ware(){ ++count; }
Ware::~Ware() { --count; }
@ -9,11 +9,11 @@ Ware::Ware(std::string name, bool hasCooling, double width, double height) {
this->size = { width, height };
if(hasCooling) {
this->type = CoolingWare;
this->type = WareType::CoolingWare;
} else if(isLargeWare(this->size)) {
this->type = LargeWare;
this->type = WareType::LargeWare;
} else {
this->type = DefaultWare;
this->type = WareType::DefaultWare;
}
count++;
this->id = this->generateId();

2
src/header-files/data-classes/Ware.h → src/Ware/Ware.h

@ -7,7 +7,7 @@ class Ware {
double height;
};
enum WareType {
enum class WareType {
DefaultWare,
CoolingWare,
LargeWare

4
src/source-files/WarenStorage.cpp → src/WarenStorage/WarenStorage.cpp

@ -1,4 +1,4 @@
#include "../header-files/data-classes/WarenStorage.h"
#include "WarenStorage.h"
WarenStorage::WarenStorage() { }
@ -63,7 +63,7 @@ void WarenStorage::addWareAndGenerateId(Ware ware) {
}
}
void WarenStorage::removeWare(const std::string name) {
void WarenStorage::removeWare(const std::string& name) {
std::vector<Ware> allWaren = getAllWaren();
for(size_t i = 0; i < allWaren.size(); i++) {
if(allWaren[i].getName() == name) {

8
src/header-files/data-classes/WarenStorage.h → src/WarenStorage/WarenStorage.h

@ -1,5 +1,5 @@
#include "../pch.h"
#include "Ware.h"
#include "../Ware/Ware.h"
class WarenStorage {
public:
@ -39,9 +39,5 @@ class WarenStorage {
void addWareAndGenerateId(Ware ware);
void removeWare(const std::string name);
//const frage:
//
//wie kann ich die get...Waren() getter wieder als const definieren, ohne dass ich damit StorageEditor die möglichkeit nehme sie zu Editieren.
void removeWare(const std::string& name);
};

26
src/header-files/StorageEditor.h

@ -1,26 +0,0 @@
#include "pch.h"
#include "data-classes/WarenStorage.h"
class StorageEditor {
private:
WarenStorage storage;
public:
StorageEditor();
StorageEditor(WarenStorage storage);
WarenStorage getWarenStorage() const;
void setWarenStorage(const WarenStorage storage);
void addWareAndGenerateId(Ware ware);
void addWaren(const Ware ware, int amount);
void removeWare(std::string name);
void removeWaren(std::string name, int amount);
};

6
src/main.cpp

@ -1,12 +1,12 @@
#include "header-files/pch.h"
#include "header-files/InputManager.h"
#include "pch.h"
#include "InputManager/InputManager.h"
int Ware::count;
int main () {
std::cout << "Kaufland:" << std::endl;
StorageEditor editor;
std::shared_ptr<StorageEditor> editor;
InputManager inputManager(editor);
inputManager.displayMainMenu();

0
src/header-files/pch.h → src/pch.h

30
src/source-files/StorageEditor.cpp

@ -1,30 +0,0 @@
#include "../header-files/StorageEditor.h"
StorageEditor::StorageEditor() { }
StorageEditor::StorageEditor(const WarenStorage storage) {
this->storage = storage;
}
WarenStorage StorageEditor::getWarenStorage() const {
return storage;
}
void StorageEditor::setWarenStorage(const WarenStorage storage) {
this->storage = storage;
}
void StorageEditor::addWaren(const Ware ware, int amount) {
for(auto i = 0; i < amount; i++) {
storage.addWareAndGenerateId(ware);
}
}
void StorageEditor::removeWaren(std::string name, const int amount) {
for(auto i = 0; i < amount; i++) {
storage.removeWare(name);
}
}
Loading…
Cancel
Save