blob: 1f5b7661ae5dcf2bd6d34a04e0882c1696cc5c31 (
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
|
#include "CellFormula.h"
#include "CellDouble.h"
#include <cstring>
double CellFormula::calculate(unsigned index) {
double lval = CellDouble(formula[index].left->getValue()).getValue();
switch(formula[index].right) {
case plus: return lval + calculate(index++);
case minus: return lval - calculate(index++);
case mult: return lval * calculate(index++);
case div: double rval = calculate(index++);
if (rval == 0) throw std::overflow_error("Divide by zero exception");
return lval / rval;
default: return lval;
}
}
String CellFormula::getValueForPrint() {
double result = calculate();
return "";
}
void CellFormula::parseAndSetValue(const char* str) {
}
void CellFormula::readFromFile(std::ifstream& file) {
file >> rawFormula;
}
void CellFormula::writeToFile(std::ofstream& file) {
file << rawFormula;
}
|