diff options
| Commit | 7be7db4f51d2cba12e65ccf61c7ff5834a832e36 (patch) | |
|---|---|---|
| Author | 2022-05-30 20:48:31 +0300 | |
| Committer | 2022-05-30 20:48:31 +0300 | |
| Files | 5896cebc555a1e12d493f53f0f0fda05875dc39e /src | |
| FMI-OOP-P2_Tables-7be7db4f51d2cba12e65ccf61c7ff5834a832e36.tar FMI-OOP-P2_Tables-7be7db4f51d2cba12e65ccf61c7ff5834a832e36.tar.gz FMI-OOP-P2_Tables-7be7db4f51d2cba12e65ccf61c7ff5834a832e36.zip | ||
| Parent | c9839607652d8b762f4ba7cbd142e4a682ec567e (diff) | |
Autocommit at 30.05.2022 @ 20:48
3 files changed, 15 insertions, 10 deletions
| -rw-r--r-- | src/Models/Table.cpp | 18 | ||||
| -rw-r--r-- | src/Models/Table.h | 2 | ||||
| -rw-r--r-- | src/UserInterface/UserInterface.cpp | 5 |
diff --git a/src/Models/Table.cpp b/src/Models/Table.cpp index dd82b30..6ba20a4 100644 --- a/src/Models/Table.cpp +++ b/src/Models/Table.cpp @@ -100,23 +100,23 @@ void Table::readFromFile(std::ifstream& inFile) { throw std::logic_error(fileLocationExceptionMsg("Error: Could not determine type of value at row ", cells.get_count(), inFile.tellg() % cells.get_count() + 1)); } } - +#include <iostream> Table::Table(const char* filePath) { std::ifstream inFile(filePath); + std::cout << filePath << std::endl; if (inFile.is_open()) - throw std::logic_error("Could now open file!"); + throw std::logic_error("Could not open file!"); cells = List<List<Cell*>>(); readFromFile(inFile); inFile.close(); } -Table::Table(unsigned rows, unsigned cols) { - if (rows == 0 || cols == 0) - return; - - cells = List<List<Cell*>>(rows); - for (unsigned i = 0; i < rows; i++) - cells[i] = List<Cell*>(cols); +Table::~Table() { + for (unsigned i = 0; i < cells.get_length(); i++) { + for (unsigned j = 0; j < cells.get_length(); j++) { + delete cells[i][j]; + } + } } unsigned Table::get_rows() const { diff --git a/src/Models/Table.h b/src/Models/Table.h index eb62e2c..fb778e3 100644 --- a/src/Models/Table.h +++ b/src/Models/Table.h @@ -11,7 +11,7 @@ class Table { public: Table(const char* filePath); - Table(unsigned rows, unsigned cols); + ~Table(); unsigned get_rows() const; unsigned get_cols() const; diff --git a/src/UserInterface/UserInterface.cpp b/src/UserInterface/UserInterface.cpp index f64b1f2..6352381 100644 --- a/src/UserInterface/UserInterface.cpp +++ b/src/UserInterface/UserInterface.cpp @@ -73,6 +73,11 @@ void UserInterface::com_exit(const char* params) { } void UserInterface::com_print(const char* params) { + if (table == nullptr) { + printLine("You need to open a file!"); + return; + } + List<String> cells = table->getAllCells(); printTable(cells, table->get_cols()); } |
