Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Models
diff options
context:
space:
mode:
Commitb07bd9dfb73e5a63520a0a30533841dc8ceff567 (patch)
Author
 Syndamia <kamen@syndamia.com>
2022-05-28 18:34:29 +0300
Committer
 Syndamia <kamen@syndamia.com>
2022-05-28 18:34:29 +0300
Filesbc3e4db314781b9d8940faa49c2c1a4a319734fa /src/Models
FMI-OOP-P2_Tables-b07bd9dfb73e5a63520a0a30533841dc8ceff567.tar
FMI-OOP-P2_Tables-b07bd9dfb73e5a63520a0a30533841dc8ceff567.tar.gz
FMI-OOP-P2_Tables-b07bd9dfb73e5a63520a0a30533841dc8ceff567.zip
Parent68f6b62e49916a59442f4ae69fc0554bf1d84f3a (diff)
Autocommit at 28.05.2022 @ 18:34
4 files changed, 9 insertions, 2 deletions
-rw-r--r--src/Models/CellDouble.h1
-rw-r--r--src/Models/CellFormula.h1
-rw-r--r--src/Models/CellInt.h1
-rw-r--r--src/Models/Table.cpp8
diff --git a/src/Models/CellDouble.h b/src/Models/CellDouble.h
index 736d77a..6396089 100644
--- a/src/Models/CellDouble.h
+++ b/src/Models/CellDouble.h
@@ -10,6 +10,7 @@ public:
CellDouble() = default;
CellDouble(double value);
+ double getNumeralValue() override;
String getValueForPrint() override;
void parseAndSetValue(const char* str) override;
void readFromFile(std::ifstream& file) override;
diff --git a/src/Models/CellFormula.h b/src/Models/CellFormula.h
index 3074846..ea2be2b 100644
--- a/src/Models/CellFormula.h
+++ b/src/Models/CellFormula.h
@@ -21,6 +21,7 @@ class CellFormula : public Cell {
double calculate(unsigned index = 0);
+ double getNumeralValue() override;
public:
CellFormula() = default;
diff --git a/src/Models/CellInt.h b/src/Models/CellInt.h
index ed336b9..137dc65 100644
--- a/src/Models/CellInt.h
+++ b/src/Models/CellInt.h
@@ -10,6 +10,7 @@ public:
CellInt() = default;
CellInt(int value);
+ double getNumeralValue() override;
String getValueForPrint() override;
void parseAndSetValue(const char* str) override;
void readFromFile(std::ifstream& file) override;
diff --git a/src/Models/Table.cpp b/src/Models/Table.cpp
index 5d0c87f..af72875 100644
--- a/src/Models/Table.cpp
+++ b/src/Models/Table.cpp
@@ -19,14 +19,18 @@ bool containsNumber(const char*& str) {
}
void Table::putCell(unsigned row, unsigned col, const char* rawValue) {
-
Cell* newCell;
+
if (containsNumber(rawValue)) {
unsigned intParse = atoi(rawValue);
unsigned doubleParse = atof(rawValue);
newCell = (doubleParse - intParse > 0.00001 && doubleParse > 0.00001)
- ? new CellDouble(doubleParse) : new CellInt(intParse);
+ ? (Cell*)new CellDouble(doubleParse) : (Cell*)new CellInt(intParse);
+ }
+ else {
+ newCell = (*rawValue == '=') ? (Cell*)new CellFormula(rawValue) : (Cell*)new CellString(rawValue);
}
+ cells[row][col] = newCell;
}