diff options
| Commit | fa0cf9fa668a9fc2a034d9c4ba60a78d1e558482 (patch) | |
|---|---|---|
| Author | 2022-05-30 19:07:54 +0300 | |
| Committer | 2022-05-30 19:07:54 +0300 | |
| Files | f5ca78078cc4be2fe78cf41d61300247e3907bd9 /src | |
| FMI-OOP-P2_Tables-fa0cf9fa668a9fc2a034d9c4ba60a78d1e558482.tar FMI-OOP-P2_Tables-fa0cf9fa668a9fc2a034d9c4ba60a78d1e558482.tar.gz FMI-OOP-P2_Tables-fa0cf9fa668a9fc2a034d9c4ba60a78d1e558482.zip | ||
| Parent | 70a6737bafa88f57a5f038b8b2a306517060408d (diff) | |
Autocommit at 30.05.2022 @ 19:07
2 files changed, 16 insertions, 5 deletions
| -rw-r--r-- | src/Models/Table.cpp | 19 | ||||
| -rw-r--r-- | src/Models/Table.h | 2 |
diff --git a/src/Models/Table.cpp b/src/Models/Table.cpp index b29b075..2b4eb6c 100644 --- a/src/Models/Table.cpp +++ b/src/Models/Table.cpp @@ -6,16 +6,27 @@ #include <cstring> #include <fstream> #include <exception> +#include <stdexcept> -void Table::readFromFile(std::ifstream inFile) { - +unsigned countOfCommas(std::ifstream& file) { + unsigned commaCount = 0; + while (file.peek() != '\n') { + if (file.get() == ',') commaCount++; + } + return commaCount; +} + +void Table::readFromFile(std::ifstream& inFile) { + unsigned commaCount = countOfCommas(inFile); + cells = List<List<Cell*>>(commaCount + 1); } Table::Table(const char* filePath) { std::ifstream inFile(filePath); if (inFile.is_open()) - throw new std::logic_error("Could now open file!"); - cells = List<List<Cell*>>(); + throw std::logic_error("Could now open file!"); + readFromFile(inFile); + inFile.close(); } Table::Table(unsigned rows, unsigned cols) { diff --git a/src/Models/Table.h b/src/Models/Table.h index 4eb4265..ade25d9 100644 --- a/src/Models/Table.h +++ b/src/Models/Table.h @@ -7,7 +7,7 @@ class Table { List<List<Cell*>> cells; - void readFromFile(std::ifstream inFile); + void readFromFile(std::ifstream& inFile); public: Table(const char* filePath); |
