diff options
Autocommit at 28.05.2022 @ 18:34
4 files changed, 9 insertions, 2 deletions
| -rw-r--r-- | src/Models/CellDouble.h | 1 | ||||
| -rw-r--r-- | src/Models/CellFormula.h | 1 | ||||
| -rw-r--r-- | src/Models/CellInt.h | 1 | ||||
| -rw-r--r-- | src/Models/Table.cpp | 8 |
diff --git a/src/Models/CellDouble.h b/src/Models/CellDouble.h index 736d77a..6396089 100644 --- a/src/Models/CellDouble.h +++ b/src/Models/CellDouble.h @@ -10,6 +10,7 @@ public: CellDouble() = default; CellDouble(double value); + double getNumeralValue() override; String getValueForPrint() override; void parseAndSetValue(const char* str) override; void readFromFile(std::ifstream& file) override; diff --git a/src/Models/CellFormula.h b/src/Models/CellFormula.h index 3074846..ea2be2b 100644 --- a/src/Models/CellFormula.h +++ b/src/Models/CellFormula.h @@ -21,6 +21,7 @@ class CellFormula : public Cell { double calculate(unsigned index = 0); + double getNumeralValue() override; public: CellFormula() = default; diff --git a/src/Models/CellInt.h b/src/Models/CellInt.h index ed336b9..137dc65 100644 --- a/src/Models/CellInt.h +++ b/src/Models/CellInt.h @@ -10,6 +10,7 @@ public: CellInt() = default; CellInt(int value); + double getNumeralValue() override; String getValueForPrint() override; void parseAndSetValue(const char* str) override; void readFromFile(std::ifstream& file) override; diff --git a/src/Models/Table.cpp b/src/Models/Table.cpp index 5d0c87f..af72875 100644 --- a/src/Models/Table.cpp +++ b/src/Models/Table.cpp @@ -19,14 +19,18 @@ bool containsNumber(const char*& str) { } void Table::putCell(unsigned row, unsigned col, const char* rawValue) { - Cell* newCell; + if (containsNumber(rawValue)) { unsigned intParse = atoi(rawValue); unsigned doubleParse = atof(rawValue); newCell = (doubleParse - intParse > 0.00001 && doubleParse > 0.00001) - ? new CellDouble(doubleParse) : new CellInt(intParse); + ? (Cell*)new CellDouble(doubleParse) : (Cell*)new CellInt(intParse); + } + else { + newCell = (*rawValue == '=') ? (Cell*)new CellFormula(rawValue) : (Cell*)new CellString(rawValue); } + cells[row][col] = newCell; } |
