Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Models / Table.cpp
diff options
context:
space:
mode:
Commita710a7ea125f294c41f51dfad4086faf8964fd03 (patch)
Author
 Syndamia <kamen@syndamia.com>
2022-06-14 09:24:01 +0300
Committer
 Syndamia <kamen@syndamia.com>
2022-06-14 09:24:01 +0300
Files5197ba2176834d4df32b7c2667bf32c25f6cf5aa /src/Models/Table.cpp
FMI-OOP-P2_Tables-a710a7ea125f294c41f51dfad4086faf8964fd03.tar
FMI-OOP-P2_Tables-a710a7ea125f294c41f51dfad4086faf8964fd03.tar.gz
FMI-OOP-P2_Tables-a710a7ea125f294c41f51dfad4086faf8964fd03.zip
Parent64b4c6222d46bb4316eedb367772e396a95a04dc (diff)
Autocommit at 14.06.2022 @ 09:24
1 files changed, 12 insertions, 6 deletions
-rw-r--r--src/Models/Table.cpp18
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';