Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Models / CellFormula.cpp
blob: be50ef716853b386426468506c69343991c0ba6d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "CellFormula.h"
#include "CellDouble.h"
#include <cstring>

CellFormula::CellFormula(const char* str) : referencedCells(), formula(), rawFormula() {
	parseAndSetValue(str);
}

double CellFormula::calculate(unsigned index) {
	double lval = formula[index].left->getNumeralValue();

	switch(formula[index].right) {
		case plus:  return lval + calculate(index++);
		case minus: return lval - calculate(index++);
		case mult:  return lval * calculate(index++);
		case div:   return lval / calculate(index++);
		case pow:
		case none:
		default:    return lval;
	}
}

String CellFormula::getValueForPrint() {
	return String() += calculate();
}

void CellFormula::parseAndSetValue(const char* str) {
	
}

void CellFormula::readFromFile(std::ifstream& file) {
	file >> rawFormula;
}

void CellFormula::writeToFile(std::ofstream& file) {
	file << rawFormula;
}