diff options
| Commit | a710a7ea125f294c41f51dfad4086faf8964fd03 (patch) | |
|---|---|---|
| Author | 2022-06-14 09:24:01 +0300 | |
| Committer | 2022-06-14 09:24:01 +0300 | |
| Files | 5197ba2176834d4df32b7c2667bf32c25f6cf5aa /src | |
| FMI-OOP-P2_Tables-a710a7ea125f294c41f51dfad4086faf8964fd03.tar FMI-OOP-P2_Tables-a710a7ea125f294c41f51dfad4086faf8964fd03.tar.gz FMI-OOP-P2_Tables-a710a7ea125f294c41f51dfad4086faf8964fd03.zip | ||
| Parent | 64b4c6222d46bb4316eedb367772e396a95a04dc (diff) | |
Autocommit at 14.06.2022 @ 09:24
2 files changed, 13 insertions, 8 deletions
| -rw-r--r-- | src/Models/Table.cpp | 18 | ||||
| -rw-r--r-- | src/test.table | 3 |
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<Cell*>()); while (inFile.peek() != EOF) { + if (cells.get_count() < row + 1) + cells.add(List<Cell*>()); + if (inFile.peek() == '\n') { row++; inFile.get(); - cells.add(List<Cell*>()); 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<String> Table::getAllCells() const { List<String> 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'; diff --git a/src/test.table b/src/test.table index a533889..22b8523 100644 --- a/src/test.table +++ b/src/test.table @@ -1,3 +1,2 @@ 8.6,3,"String","= 3 * R0C1 + R0C0 ^ R0C1 * 27 / R0C1 - 2 * 2.5 * 2 * 2 + R0C2 ^ R0C2","", -"","Bruh","","","", - +"HELLL YEAH BROTHER","Bruh","=R1C0 + R1C1",,, |
