Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Models / Table.cpp
diff options
context:
space:
mode:
Commite55eec22a7356ceef3f422ef64b986f88d95501a (patch)
Author
 Syndamia <kamen@syndamia.com>
2022-06-14 07:28:28 +0300
Committer
 Syndamia <kamen@syndamia.com>
2022-06-14 07:28:28 +0300
Fileseb3c9fb45d0dbab1e92559a0ad48acc2fb987e29 /src/Models/Table.cpp
FMI-OOP-P2_Tables-e55eec22a7356ceef3f422ef64b986f88d95501a.tar
FMI-OOP-P2_Tables-e55eec22a7356ceef3f422ef64b986f88d95501a.tar.gz
FMI-OOP-P2_Tables-e55eec22a7356ceef3f422ef64b986f88d95501a.zip
Parent2c961228ea05472cb86eab289f5f7859f492190b (diff)
Autocommit at 14.06.2022 @ 07:28
1 files changed, 7 insertions, 3 deletions
-rw-r--r--src/Models/Table.cpp10
diff --git a/src/Models/Table.cpp b/src/Models/Table.cpp
index 787652a..fe84115 100644
--- a/src/Models/Table.cpp
+++ b/src/Models/Table.cpp
@@ -51,7 +51,7 @@ void Table::readFromFile(std::ifstream& inFile) {
cells.add(List<Cell*>());
while (inFile.peek() != EOF) {
- if (inFile.peek() == '\0') {
+ if (inFile.peek() == '\n') {
row++;
inFile.get();
cells.add(List<Cell*>());
@@ -121,6 +121,9 @@ unsigned Table::get_cols() const {
return cells[0].get_length();
}
+#define abs(a) ((a < 0) ? -a : a)
+#define FLOATING_POINT_PRECISION 0.0001f
+
void Table::putCell(unsigned row, unsigned col, const char* rawValue) {
Cell* newCell;
@@ -132,12 +135,13 @@ void Table::putCell(unsigned row, unsigned col, const char* rawValue) {
? (Cell*)new CellFormula(rawValue, &cells)
: (Cell*)new CellString(rawValue);
}
- if (containsNumber(rawValue)) {
+ else if ((*rawValue == '+' || *rawValue == '-') || (*rawValue >= '0' && *rawValue <= '9')) {
double doubleParse = atof(rawValue);
unsigned intPart = abs(doubleParse);
newCell = (abs(doubleParse) - intPart > FLOATING_POINT_PRECISION)
- ? (Cell*)new CellDouble(doubleParse) : (Cell*)new CellInt(intPart);
+ ? (Cell*)new CellDouble(doubleParse)
+ : (Cell*)new CellInt(intPart);
}
else