diff options
| Commit | e55eec22a7356ceef3f422ef64b986f88d95501a (patch) | |
|---|---|---|
| Author | 2022-06-14 07:28:28 +0300 | |
| Committer | 2022-06-14 07:28:28 +0300 | |
| Files | eb3c9fb45d0dbab1e92559a0ad48acc2fb987e29 /src | |
| FMI-OOP-P2_Tables-e55eec22a7356ceef3f422ef64b986f88d95501a.tar FMI-OOP-P2_Tables-e55eec22a7356ceef3f422ef64b986f88d95501a.tar.gz FMI-OOP-P2_Tables-e55eec22a7356ceef3f422ef64b986f88d95501a.zip | ||
| Parent | 2c961228ea05472cb86eab289f5f7859f492190b (diff) | |
Autocommit at 14.06.2022 @ 07:28
2 files changed, 12 insertions, 3 deletions
| -rw-r--r-- | src/Generic/List/List.hpp | 5 | ||||
| -rw-r--r-- | src/Models/Table.cpp | 10 |
diff --git a/src/Generic/List/List.hpp b/src/Generic/List/List.hpp index ba4851c..f26e7d1 100644 --- a/src/Generic/List/List.hpp +++ b/src/Generic/List/List.hpp @@ -204,6 +204,11 @@ const T& List<T>::operator[](unsigned index) const { } template <typename T> +const T* List<T>::raw_data() const { + return elements; +} + +template <typename T> List<T>& List<T>::operator+=(const List<T> other) { for (unsigned i = 0; i < other.length; i++) add(other[i]); 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 |
