Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Models
diff options
context:
space:
mode:
Commitf5cfef9dc1c0cc505d48c609a1c0511cd7ed166b (patch)
Author
 Syndamia <kamen@syndamia.com>
2022-05-28 16:44:11 +0300
Committer
 Syndamia <kamen@syndamia.com>
2022-05-28 16:44:11 +0300
Filesadba3eb02741f5a0f243c1993a1deef626308bd2 /src/Models
FMI-OOP-P2_Tables-f5cfef9dc1c0cc505d48c609a1c0511cd7ed166b.tar
FMI-OOP-P2_Tables-f5cfef9dc1c0cc505d48c609a1c0511cd7ed166b.tar.gz
FMI-OOP-P2_Tables-f5cfef9dc1c0cc505d48c609a1c0511cd7ed166b.zip
Parent827f0a8227b7db8ddf3f7ec0fa39bb945ea13bdb (diff)
Autocommit at 28.05.2022 @ 16:44
9 files changed, 26 insertions, 20 deletions
-rw-r--r--src/Models/Cell.h3
-rw-r--r--src/Models/CellDouble.cpp2
-rw-r--r--src/Models/CellDouble.h6
-rw-r--r--src/Models/CellFormula.cpp11
-rw-r--r--src/Models/CellInt.cpp2
-rw-r--r--src/Models/CellInt.h4
-rw-r--r--src/Models/CellString.cpp2
-rw-r--r--src/Models/CellString.h4
-rw-r--r--src/Models/Table.h12
diff --git a/src/Models/Cell.h b/src/Models/Cell.h
index f202945..73a6071 100644
--- a/src/Models/Cell.h
+++ b/src/Models/Cell.h
@@ -4,10 +4,9 @@
#include <fstream>
#include "../Generic/String/String.h"
-template <typename T>
class Cell {
public:
- virtual T getValue() = 0;
+ virtual double getNumeralValue() = 0;
virtual String getValueForPrint() = 0;
virtual void parseAndSetValue(const char* str) = 0;
virtual void readFromFile(std::ifstream& file) = 0;
diff --git a/src/Models/CellDouble.cpp b/src/Models/CellDouble.cpp
index 4673f9f..a823419 100644
--- a/src/Models/CellDouble.cpp
+++ b/src/Models/CellDouble.cpp
@@ -9,7 +9,7 @@ CellDouble::CellDouble(const String& str) {
value = atof(str.get_cstr());
}
-double CellDouble::getValue() {
+double CellDouble::getNumeralValue() {
return value;
}
diff --git a/src/Models/CellDouble.h b/src/Models/CellDouble.h
index 01500f8..24d4073 100644
--- a/src/Models/CellDouble.h
+++ b/src/Models/CellDouble.h
@@ -3,15 +3,13 @@
#include "Cell.h"
-class CellDouble : public Cell<double> {
+class CellDouble : public Cell {
double value;
public:
CellDouble() = default;
- CellDouble(int val);
- CellDouble(const String& str);
- double getValue() override;
+ double getNumeralValue() override;
String getValueForPrint() override;
void parseAndSetValue(const char* str) override;
void readFromFile(std::ifstream& file) override;
diff --git a/src/Models/CellFormula.cpp b/src/Models/CellFormula.cpp
index 1f5b766..71e4e29 100644
--- a/src/Models/CellFormula.cpp
+++ b/src/Models/CellFormula.cpp
@@ -3,26 +3,23 @@
#include <cstring>
double CellFormula::calculate(unsigned index) {
- double lval = CellDouble(formula[index].left->getValue()).getValue();
+ double lval = CellDouble(formula[index].left->getValue()).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: double rval = calculate(index++);
- if (rval == 0) throw std::overflow_error("Divide by zero exception");
- return lval / rval;
+ case div: return lval / calculate(index++);
default: return lval;
}
}
String CellFormula::getValueForPrint() {
- double result = calculate();
-
- return "";
+ return String() += calculate();
}
void CellFormula::parseAndSetValue(const char* str) {
+ //TODO
}
void CellFormula::readFromFile(std::ifstream& file) {
diff --git a/src/Models/CellInt.cpp b/src/Models/CellInt.cpp
index 189d515..67f763e 100644
--- a/src/Models/CellInt.cpp
+++ b/src/Models/CellInt.cpp
@@ -1,7 +1,7 @@
#include "CellInt.h"
#include <cstring>
-int CellInt::getValue() {
+int CellInt::getNumeralValue() {
return value;
}
diff --git a/src/Models/CellInt.h b/src/Models/CellInt.h
index a14c062..53ddda7 100644
--- a/src/Models/CellInt.h
+++ b/src/Models/CellInt.h
@@ -3,13 +3,13 @@
#include "Cell.h"
-class CellInt : public Cell<int> {
+class CellInt : public Cell {
int value;
public:
CellInt() = default;
- int getValue() override;
+ double getNumeralValue() override;
String getValueForPrint() override;
void parseAndSetValue(const char* str) override;
void readFromFile(std::ifstream& file) override;
diff --git a/src/Models/CellString.cpp b/src/Models/CellString.cpp
index e0c4f2d..ffc760c 100644
--- a/src/Models/CellString.cpp
+++ b/src/Models/CellString.cpp
@@ -1,6 +1,6 @@
#include "CellString.h"
-String CellString::getValue() {
+String CellString::getNumeralValue() {
return value;
}
diff --git a/src/Models/CellString.h b/src/Models/CellString.h
index daa8427..ee581e8 100644
--- a/src/Models/CellString.h
+++ b/src/Models/CellString.h
@@ -3,13 +3,13 @@
#include "Cell.h"
-class CellString : public Cell<String> {
+class CellString : public Cell {
String value;
public:
CellString() = default;
- String getValue() override;
+ double getNumeralValue() override;
String getValueForPrint() override;
void parseAndSetValue(const char* str) override;
void readFromFile(std::ifstream& file) override;
diff --git a/src/Models/Table.h b/src/Models/Table.h
new file mode 100644
index 0000000..d53ecbb
--- /dev/null
+++ b/src/Models/Table.h
@@ -0,0 +1,12 @@
+#ifndef MODELS_TABLE
+#define MODELS_TABLE
+
+#include "Cell.h"
+#include "../Generic/List/List.hpp"
+
+class Table {
+ List<List<Cell>> cells;
+ List<List<Cell>> constantsCells;
+};
+
+#endif