Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Models / Table.cpp
diff options
context:
space:
mode:
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';