diff options
| Commit | 64b4c6222d46bb4316eedb367772e396a95a04dc (patch) | |
|---|---|---|
| Author | 2022-06-14 09:18:59 +0300 | |
| Committer | 2022-06-14 09:18:59 +0300 | |
| Files | 7f412b371e576d4d9c9e707a927100cd7c0365a5 /src | |
| FMI-OOP-P2_Tables-64b4c6222d46bb4316eedb367772e396a95a04dc.tar FMI-OOP-P2_Tables-64b4c6222d46bb4316eedb367772e396a95a04dc.tar.gz FMI-OOP-P2_Tables-64b4c6222d46bb4316eedb367772e396a95a04dc.zip | ||
| Parent | c396eec30d0db694d665275b625d04627c401317 (diff) | |
Autocommit at 14.06.2022 @ 09:18
2 files changed, 11 insertions, 13 deletions
| -rw-r--r-- | src/Models/Table.cpp | 21 | ||||
| -rw-r--r-- | src/test.table | 3 |
diff --git a/src/Models/Table.cpp b/src/Models/Table.cpp index 552cd61..b0e3656 100644 --- a/src/Models/Table.cpp +++ b/src/Models/Table.cpp @@ -48,7 +48,7 @@ void throwException(std::ifstream& inFile, unsigned row) { } void Table::readFromFile(std::ifstream& inFile) { - unsigned row = 0; + unsigned row = longestRow = 0; cells.add(List<Cell*>()); while (inFile.peek() != EOF) { @@ -62,7 +62,7 @@ void Table::readFromFile(std::ifstream& inFile) { List<char> buffer; W(inFile); - if (inFile.peek() == '"') { + if (inFile.peek() == '"') { // W"=A"S | W"A"S inFile.get(); A(inFile, buffer); buffer.add('\0'); @@ -77,11 +77,11 @@ void Table::readFromFile(std::ifstream& inFile) { ? (Cell*)new CellFormula(buffer.raw_data(), &cells) : (Cell*)new CellString(buffer.raw_data())); } - else if (inFile.peek() == ',') { + else if (inFile.peek() == ',') { // epsilon inFile.get(); cells[row].add((Cell*)new CellString("")); } - else { + else { // WPDS | WPD.DS P(inFile, buffer); D(inFile, buffer); if (inFile.peek() == '.') { @@ -123,9 +123,8 @@ Table::Table(const char* filePath) { Table::~Table() { for (unsigned i = 0; i < cells.get_count(); i++) { - for (unsigned j = 0; j < cells[i].get_count(); j++) { + for (unsigned j = 0; j < cells[i].get_count(); j++) delete cells[i][j]; - } } } @@ -159,7 +158,6 @@ void Table::putCell(unsigned row, unsigned col, const char* rawValue) { ? (Cell*)new CellDouble(doubleParse) : (Cell*)new CellInt(intPart); } - else throw std::logic_error("Error: Could not determine data type."); @@ -177,10 +175,8 @@ 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++) { - std::cout <<cells[i][j]->getValueForPrint() << std::endl; + for (unsigned j = 0; j < cells[i].get_count(); j++) toRet.add(cells[i][j]->getValueForPrint()); - } } return toRet; } @@ -191,9 +187,8 @@ void Table::saveToFile(const char* filePath) const { throw std::logic_error("Could not open file!"); for (unsigned i = 0; i < cells.get_count(); i++) { - for (unsigned j = 0; j < cells.get_count(); j++) { - if (cells[i][j] != nullptr) - cells[i][j]->writeToFile(outFile); + for (unsigned j = 0; j < cells[i].get_count(); j++) { + cells[i][j]->writeToFile(outFile); outFile << ','; } outFile << '\n'; diff --git a/src/test.table b/src/test.table index e69de29..a533889 100644 --- a/src/test.table +++ b/src/test.table @@ -0,0 +1,3 @@ +8.6,3,"String","= 3 * R0C1 + R0C0 ^ R0C1 * 27 / R0C1 - 2 * 2.5 * 2 * 2 + R0C2 ^ R0C2","", +"","Bruh","","","", + |
