From a710a7ea125f294c41f51dfad4086faf8964fd03 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Tue, 14 Jun 2022 09:24:01 +0300 Subject: Autocommit at 14.06.2022 @ 09:24 --- src/Models/Table.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src/Models/Table.cpp') diff --git a/src/Models/Table.cpp b/src/Models/Table.cpp index b0e3656..a1063f5 100644 --- a/src/Models/Table.cpp +++ b/src/Models/Table.cpp @@ -49,13 +49,14 @@ void throwException(std::ifstream& inFile, unsigned row) { void Table::readFromFile(std::ifstream& inFile) { unsigned row = longestRow = 0; - cells.add(List()); while (inFile.peek() != EOF) { + if (cells.get_count() < row + 1) + cells.add(List()); + if (inFile.peek() == '\n') { row++; inFile.get(); - cells.add(List()); continue; } @@ -79,7 +80,7 @@ void Table::readFromFile(std::ifstream& inFile) { } else if (inFile.peek() == ',') { // epsilon inFile.get(); - cells[row].add((Cell*)new CellString("")); + cells[row].add(nullptr); } else { // WPDS | WPD.DS P(inFile, buffer); @@ -175,8 +176,12 @@ void Table::putCell(unsigned row, unsigned col, const char* rawValue) { List Table::getAllCells() const { List toRet; for (unsigned i = 0; i < cells.get_count(); i++) { - for (unsigned j = 0; j < cells[i].get_count(); j++) - toRet.add(cells[i][j]->getValueForPrint()); + for (unsigned j = 0; j < cells[i].get_count(); j++) { + if (cells[i][j] != nullptr) + toRet.add(cells[i][j]->getValueForPrint()); + else + toRet.add(""); + } } return toRet; } @@ -188,7 +193,8 @@ void Table::saveToFile(const char* filePath) const { for (unsigned i = 0; i < cells.get_count(); i++) { for (unsigned j = 0; j < cells[i].get_count(); j++) { - cells[i][j]->writeToFile(outFile); + if (cells[i][j] != nullptr) + cells[i][j]->writeToFile(outFile); outFile << ','; } outFile << '\n'; -- cgit v1.3.1-23-gd82d