Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Models / Table.cpp
diff options
context:
space:
mode:
Commitdfed677a8a8e6d0d75d14ed9626c16184ff4f066 (patch)
Author
 Syndamia <kamen@syndamia.com>
2022-05-30 21:28:44 +0300
Committer
 Syndamia <kamen@syndamia.com>
2022-05-30 21:28:44 +0300
Files162e30337bb34322e3c4d732182d68a66a4d13db /src/Models/Table.cpp
FMI-OOP-P2_Tables-dfed677a8a8e6d0d75d14ed9626c16184ff4f066.tar
FMI-OOP-P2_Tables-dfed677a8a8e6d0d75d14ed9626c16184ff4f066.tar.gz
FMI-OOP-P2_Tables-dfed677a8a8e6d0d75d14ed9626c16184ff4f066.zip
Parent00e2cff656eae2b7ce6f42132c413d2c324076eb (diff)
Autocommit at 30.05.2022 @ 21:28
1 files changed, 5 insertions, 2 deletions
-rw-r--r--src/Models/Table.cpp7
diff --git a/src/Models/Table.cpp b/src/Models/Table.cpp
index 506204a..75c5e70 100644
--- a/src/Models/Table.cpp
+++ b/src/Models/Table.cpp
@@ -32,6 +32,9 @@ bool containsNumber(const char*& str) {
#include <iostream>
void Table::readFromFile(std::ifstream& inFile) {
unsigned commaCount = countOfCommas(inFile);
+ if (commaCount == 0)
+ throw std::logic_error("Expected at least the first line to have data.");
+
unsigned colInd = 0;
cells.add(List<Cell*>(commaCount));
while (inFile.peek() != EOF) {
@@ -60,7 +63,7 @@ void Table::readFromFile(std::ifstream& inFile) {
}
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));
+ throw std::logic_error(fileLocationExceptionMsg("Error: Expected digit but got something else at row ", cells.get_count(), inFile.tellg() % commaCount));
// Parsing digits of whole number/whole part of floating point number
while (isDigit(inFile.peek())) {
@@ -76,7 +79,7 @@ void Table::readFromFile(std::ifstream& inFile) {
}
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));
+ throw std::logic_error(fileLocationExceptionMsg("Error: Expected space, comma or newline but got something else at row ", cells.get_count(), inFile.tellg() % commaCount));
if (exponent == 1)
cells[cells.get_count() - 1][colInd++] = new CellInt(whole);