Made parse function of csvFile struct return a vector<vector<string>> instead of being a template function
This commit is contained in:
parent
33facf05ab
commit
9e121beade
23
csvfile.hpp
23
csvfile.hpp
|
|
@ -65,10 +65,9 @@ class csvFile {
|
||||||
return write(val);
|
return write(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
static std::vector<std::vector<std::string>> parse(const std::filesystem::path &csvFilepath)
|
||||||
static std::vector<std::vector<T>> parse(const std::filesystem::path &csvFilepath)
|
|
||||||
{
|
{
|
||||||
std::vector<std::vector<T>> resultCSV;
|
std::vector<std::vector<std::string>> resultCSV;
|
||||||
if (!std::filesystem::exists(csvFilepath)) {
|
if (!std::filesystem::exists(csvFilepath)) {
|
||||||
std::cerr << "The file does not exist:" << csvFilepath.string() << std::endl;
|
std::cerr << "The file does not exist:" << csvFilepath.string() << std::endl;
|
||||||
return resultCSV;
|
return resultCSV;
|
||||||
|
|
@ -79,21 +78,17 @@ class csvFile {
|
||||||
std::cerr << "Can't open file:" << csvFilepath.string() << std::endl;
|
std::cerr << "Can't open file:" << csvFilepath.string() << std::endl;
|
||||||
return resultCSV;
|
return resultCSV;
|
||||||
}
|
}
|
||||||
std::vector<T> row;
|
std::vector<std::string> row;
|
||||||
std::string line;
|
std::string line;
|
||||||
using Tokenizer = boost::tokenizer<boost::escaped_list_separator<char>>;
|
using Tokenizer = boost::tokenizer<boost::escaped_list_separator<char>>;
|
||||||
while (std::getline(inputfile, line)) {
|
while (std::getline(inputfile, line)) {
|
||||||
Tokenizer tokenizer(line);
|
Tokenizer tokenizer(line);
|
||||||
row.resize(std::distance(tokenizer.begin(), tokenizer.end()));
|
const int numOfCols = std::distance(tokenizer.begin(), tokenizer.end());
|
||||||
std::transform(tokenizer.begin(), tokenizer.end(), row.begin(), [](const std::string &el) {
|
row.resize(numOfCols);
|
||||||
return boost::lexical_cast<T>(el);
|
std::copy(tokenizer.begin(), tokenizer.end(), row.begin());
|
||||||
});
|
// std::transform(tokenizer.begin(), tokenizer.end(), row.begin(), [](const std::string &el) {
|
||||||
// std::cout << std::endl;
|
// return boost::lexical_cast<T>(el);
|
||||||
// row.assign(tokenizer.begin(), tokenizer.end());
|
// });
|
||||||
// for (const auto &el : row) {
|
|
||||||
// std::cout << el << " ";
|
|
||||||
// }
|
|
||||||
// std::cout << std::endl;
|
|
||||||
resultCSV.push_back(row);
|
resultCSV.push_back(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue