diff options
Autocommit at 28.05.2022 @ 18:44
4 files changed, 14 insertions, 3 deletions
| -rw-r--r-- | src/Models/CellFormula.cpp | 6 | ||||
| -rw-r--r-- | src/Models/CellFormula.h | 1 | ||||
| -rw-r--r-- | src/Models/CellString.cpp | 9 | ||||
| -rw-r--r-- | src/Models/CellString.h | 1 |
diff --git a/src/Models/CellFormula.cpp b/src/Models/CellFormula.cpp index 71e4e29..21de3ec 100644 --- a/src/Models/CellFormula.cpp +++ b/src/Models/CellFormula.cpp @@ -2,8 +2,12 @@ #include "CellDouble.h" #include <cstring> +CellFormula::CellFormula(const char* str) : referencedCells(), formula(), rawFormula() { + parseAndSetValue(str); +} + double CellFormula::calculate(unsigned index) { - double lval = CellDouble(formula[index].left->getValue()).getNumeralValue(); + double lval = formula[index].left->getNumeralValue(); switch(formula[index].right) { case plus: return lval + calculate(index++); diff --git a/src/Models/CellFormula.h b/src/Models/CellFormula.h index 5838b38..688f805 100644 --- a/src/Models/CellFormula.h +++ b/src/Models/CellFormula.h @@ -23,6 +23,7 @@ class CellFormula : public Cell { public: CellFormula() = default; + CellFormula(const char* str); double getNumeralValue() override; String getValueForPrint() override; diff --git a/src/Models/CellString.cpp b/src/Models/CellString.cpp index ffc760c..20eacf4 100644 --- a/src/Models/CellString.cpp +++ b/src/Models/CellString.cpp @@ -1,7 +1,12 @@ #include "CellString.h" +#include <cstring> -String CellString::getNumeralValue() { - return value; +CellString::CellString(const char* str) { + value = String(str); +} + +double CellString::getNumeralValue() { + return atof(value.get_cstr()); } String CellString::getValueForPrint() { diff --git a/src/Models/CellString.h b/src/Models/CellString.h index ee581e8..f15e904 100644 --- a/src/Models/CellString.h +++ b/src/Models/CellString.h @@ -8,6 +8,7 @@ class CellString : public Cell { public: CellString() = default; + CellString(const char* str); double getNumeralValue() override; String getValueForPrint() override; |
