Made parse function of csvFile struct return a vector<vector<string>> instead of being a template function

This commit is contained in:
iasonmanolas 2022-02-18 17:39:02 +02:00
parent 33facf05ab
commit 9e121beade
1 changed files with 9 additions and 14 deletions

View File

@ -65,10 +65,9 @@ class csvFile {
return write(val);
}
template<typename T>
static std::vector<std::vector<T>> parse(const std::filesystem::path &csvFilepath)
static std::vector<std::vector<std::string>> parse(const std::filesystem::path &csvFilepath)
{
std::vector<std::vector<T>> resultCSV;
std::vector<std::vector<std::string>> resultCSV;
if (!std::filesystem::exists(csvFilepath)) {
std::cerr << "The file does not exist:" << csvFilepath.string() << std::endl;
return resultCSV;
@ -79,21 +78,17 @@ class csvFile {
std::cerr << "Can't open file:" << csvFilepath.string() << std::endl;
return resultCSV;
}
std::vector<T> row;
std::vector<std::string> row;
std::string line;
using Tokenizer = boost::tokenizer<boost::escaped_list_separator<char>>;
while (std::getline(inputfile, line)) {
Tokenizer tokenizer(line);
row.resize(std::distance(tokenizer.begin(), tokenizer.end()));
std::transform(tokenizer.begin(), tokenizer.end(), row.begin(), [](const std::string &el) {
return boost::lexical_cast<T>(el);
});
// std::cout << std::endl;
// row.assign(tokenizer.begin(), tokenizer.end());
// for (const auto &el : row) {
// std::cout << el << " ";
// }
// std::cout << std::endl;
const int numOfCols = std::distance(tokenizer.begin(), tokenizer.end());
row.resize(numOfCols);
std::copy(tokenizer.begin(), tokenizer.end(), row.begin());
// std::transform(tokenizer.begin(), tokenizer.end(), row.begin(), [](const std::string &el) {
// return boost::lexical_cast<T>(el);
// });
resultCSV.push_back(row);
}