Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Models / CellFormula.cpp
diff options
context:
space:
mode:
Commit2703f78c9a978321bc8f01dc695b6ce79d806ba7 (patch)
Author
 Syndamia <kamen@syndamia.com>
2022-06-14 15:04:42 +0300
Committer
 Syndamia <kamen@syndamia.com>
2022-06-14 15:04:42 +0300
Filesc432536e2212bc0fb17559abab11bfbd74ed5456 /src/Models/CellFormula.cpp
FMI-OOP-P2_Tables-2703f78c9a978321bc8f01dc695b6ce79d806ba7.tar
FMI-OOP-P2_Tables-2703f78c9a978321bc8f01dc695b6ce79d806ba7.tar.gz
FMI-OOP-P2_Tables-2703f78c9a978321bc8f01dc695b6ce79d806ba7.zip
Parent5a4dccf0f9a95cc14717d5337fd2b72cba22d9b6 (diff)
Autocommit at 14.06.2022 @ 15:04
1 files changed, 14 insertions, 1 deletions
-rw-r--r--src/Models/CellFormula.cpp15
diff --git a/src/Models/CellFormula.cpp b/src/Models/CellFormula.cpp
index fead01d..1cdf06a 100644
--- a/src/Models/CellFormula.cpp
+++ b/src/Models/CellFormula.cpp
@@ -29,8 +29,9 @@ double CellFormula::calculate(unsigned index) const {
const Cell* currCell = ptrByInd(formula[index].left);
double numVal = (currCell == nullptr) ? 0 : currCell->getNumeralValue();
+ // Handle prioritised operation
while (formula[index].right < 0) {
- switch (-formula[index++].right) {
+ switch (-formula[index++].right) { // Prioritized operations are stored as negative characters
case '+' : numVal += ptrByInd(formula[index].left)->getNumeralValue(); break;
case '*' : numVal *= ptrByInd(formula[index].left)->getNumeralValue(); break;
case '/' : if (ptrByInd(formula[index].left)->getNumeralValue() == 0) throw std::logic_error("Error: Divion by zero!");
@@ -59,6 +60,12 @@ CellFormula::CellFormula(const char* str, const List<List<Cell*>>* tableCells) :
#include <iostream>
+/*!
+ * Value is recalculated every time this function is called (in case a referenced cell is changed).
+ *
+ * \return 0 \if Calculation failed
+ * \return Calculated value \otherwise
+ */
double CellFormula::getNumeralValue() const {
try {
return calculate();
@@ -68,6 +75,12 @@ double CellFormula::getNumeralValue() const {
}
}
+/*!
+ * Value is recalculated every time this function is called (in case a referenced cell is changed).
+ *
+ * \return "Error" \if Calculation failed
+ * \return Calculated value as a String \otherwise
+ */
String CellFormula::getValueForPrint() const {
try {
return String() += calculate();