Website Summary Files Commits Branches @commit @diff @stats
path: root / src
diff options
context:
space:
mode:
3 files changed, 15 insertions, 10 deletions
-rw-r--r--src/Models/Table.cpp18
-rw-r--r--src/Models/Table.h2
-rw-r--r--src/UserInterface/UserInterface.cpp5
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());
}