Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Models
diff options
context:
space:
mode:
Commit272f317bb0817ec46ecfae9696457ec84b8ec55c (patch)
Author
 Syndamia <kamen@syndamia.com>
2022-05-30 17:57:35 +0300
Committer
 Syndamia <kamen@syndamia.com>
2022-05-30 17:57:35 +0300
Filesf43dad6728fe83c8c60ffb97200ad445b4eeb3bd /src/Models
FMI-OOP-P2_Tables-272f317bb0817ec46ecfae9696457ec84b8ec55c.tar
FMI-OOP-P2_Tables-272f317bb0817ec46ecfae9696457ec84b8ec55c.tar.gz
FMI-OOP-P2_Tables-272f317bb0817ec46ecfae9696457ec84b8ec55c.zip
Parent3f16ffd43bbff7684c1a572c688bbd6990daf616 (diff)
Autocommit at 30.05.2022 @ 17:57
2 files changed, 13 insertions, 11 deletions
-rw-r--r--src/Models/CellFormula.cpp11
-rw-r--r--src/Models/CellFormula.h13
diff --git a/src/Models/CellFormula.cpp b/src/Models/CellFormula.cpp
index 4990ee4..915c38d 100644
--- a/src/Models/CellFormula.cpp
+++ b/src/Models/CellFormula.cpp
@@ -3,6 +3,11 @@
#include <cstring>
#include <iostream>
#include <stdexcept>
+
+const Cell* CellFormula::ptrByInd(int firstInd, int secondInd) const {
+ return (firstInd < 0) ? &localCells[secondInd] : (*tableCells)[firstInd][secondInd];
+}
+
double pow(double x, unsigned y) {
if (y == 0) return 1;
@@ -13,7 +18,7 @@ double pow(double x, unsigned y) {
}
double CellFormula::calculate(unsigned index) {
- CellLoc& c = formula[index].left;
+ Cell* currCell = ptrByInd(formula[index].left);
double lval = (c.firstInd == -1) ? localCells[c.secondInd].getNumeralValue() : (*tableCells)[c.firstInd][c.secondInd]->getNumeralValue();
while (formula[index].right < 0) {
@@ -47,7 +52,7 @@ CellFormula::CellFormula(const char* str, const List<List<Cell*>>* tableCells) :
#include <iostream>
-double CellFormula::getNumeralValue() {
+double CellFormula::getNumeralValue() const {
try {
return calculate();
}
@@ -56,7 +61,7 @@ double CellFormula::getNumeralValue() {
}
}
-String CellFormula::getValueForPrint() {
+String CellFormula::getValueForPrint() const {
try {
return String() += calculate();
}
diff --git a/src/Models/CellFormula.h b/src/Models/CellFormula.h
index 3387c4a..9fd07a5 100644
--- a/src/Models/CellFormula.h
+++ b/src/Models/CellFormula.h
@@ -7,24 +7,21 @@
#include "../Generic/Pair/Pair.hpp"
class CellFormula : public Cell {
- struct CellLoc {
- int firstInd;
- int secondInd;
- };
const List<List<Cell*>>* tableCells;
List<CellDouble> localCells;
- List<Pair<CellLoc, char>> formula;
+ List<Pair<Pair<int, int>, char>> formula;
String rawFormula;
- double calculate(unsigned index = 0);
+ const Cell* ptrByInd(int firstInd, int secondInd) const;
+ double calculate(unsigned index = 0) const;
public:
CellFormula() = default;
CellFormula(const char* str, const List<List<Cell*>>* tableCells);
- double getNumeralValue() override;
- String getValueForPrint() override;
+ double getNumeralValue() const override;
+ String getValueForPrint() const override;
void parseAndSetValue(const char* str) override;
void readFromFile(std::ifstream& file) override;
void writeToFile(std::ofstream& file) override;