Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Models / Table.cpp
diff options
context:
space:
mode:
Commitfff7dbb2b1cb19f47d6a642b13a4980e58c2deb1 (patch)
Author
 Syndamia <kamen@syndamia.com>
2022-05-30 19:48:09 +0300
Committer
 Syndamia <kamen@syndamia.com>
2022-05-30 19:48:09 +0300
Files3296fa41e8ea50cccfd15aacd92c6f0d2869800d /src/Models/Table.cpp
FMI-OOP-P2_Tables-fff7dbb2b1cb19f47d6a642b13a4980e58c2deb1.tar
FMI-OOP-P2_Tables-fff7dbb2b1cb19f47d6a642b13a4980e58c2deb1.tar.gz
FMI-OOP-P2_Tables-fff7dbb2b1cb19f47d6a642b13a4980e58c2deb1.zip
Parent5f793307d00b33b1a424206da14b6492b2690f9e (diff)
Autocommit at 30.05.2022 @ 19:48
1 files changed, 20 insertions, 7 deletions
-rw-r--r--src/Models/Table.cpp27
diff --git a/src/Models/Table.cpp b/src/Models/Table.cpp
index e8f954b..5f5862f 100644
--- a/src/Models/Table.cpp
+++ b/src/Models/Table.cpp
@@ -45,22 +45,35 @@ void Table::readFromFile(std::ifstream& inFile) {
inFile.get();
}
else if (inFile.peek() == '-' || inFile.peek() == '+' || isDigit(inFile.peek())) {
- double number = 0;
+ int whole = 0;
+ unsigned exponent = 1;
+
+ if (inFile.peek() == '-' || inFile.peek() == '+') {
+ inFile.get();
+ if (inFile.peek() == '-') whole *= -1;
+ }
- if (inFile.peek() == '-' || inFile.peek() == '+') inFile.get();
if (isDigit(inFile.peek()))
throw std::logic_error(fileLocationExceptionMsg("Error: Expected digit but got something else at row ", cells.get_count(), inFile.tellg() % cells.get_count() + 1));
- while (isDigit(inFile.peek())) inFile.get();
+
+ while (isDigit(inFile.peek())) {
+ (whole *= 10) += inFile.get() - '0';
+ }
if (inFile.peek() != '.') {
inFile.get();
- while (isDigit(inFile.peek())) inFile.get();
+ while (isDigit(inFile.peek())) {
+ inFile.get();
+ exponent *= 10;
+ }
}
+
if (inFile.peek() != ' ' && inFile.peek() != ',' && inFile.peek() != '\n')
throw std::logic_error(fileLocationExceptionMsg("Error: Expected space, comma or newline but got something else at row ", cells.get_count(), inFile.tellg() % cells.get_count() + 1));
- unsigned numberEnd = inFile.tellg();
- inFile.seekg(numberStart, std::ios::beg);
- cells[cells.get_count() - 1].add();
+ if (exponent == 1)
+ cells[cells.get_count() - 1].add(new CellInt(whole));
+ else
+ cells[cells.get_count() - 1].add(new CellDouble((double)whole / exponent));
}
}
}