iterator related bugfix and cleanup.

This commit is contained in:
Martin Brodbeck 2023-01-03 12:07:19 +01:00
parent 825f490a90
commit 867ef315d3

View file

@ -13,7 +13,7 @@ std::vector<WasteDate> parseCsv(const std::string &csv) {
string line;
std::vector<WasteDate> dates;
// Get rid of the first line
// Get rid of the first line (header)
std::getline(stream, line);
while (std::getline(stream, line)) {
@ -23,7 +23,6 @@ std::vector<WasteDate> parseCsv(const std::string &csv) {
uint tokenPos = 0;
while ((pos = line.find(delimiter)) != std::string::npos) {
token = line.substr(0, pos);
// std::cout << token << std::endl;
if (token.length() > 0) {
istringstream liness(token);
@ -38,37 +37,31 @@ std::vector<WasteDate> parseCsv(const std::string &csv) {
std::chrono::day{(uint)day}};
std::vector<WasteDate>::iterator it;
WasteDate wd;
it = std::find_if(dates.begin(), dates.end(),
[&date](const WasteDate &x) { return date == x.date; });
if (it == dates.end()) {
WasteDate wd;
wd.date = date;
dates.push_back(wd);
wd = dates.back();
} else {
wd = *it;
it = std::prev(dates.end());
}
switch (tokenPos) {
case 0:
// printf("Gelber Sack: %s\n", token.c_str());
wd.wasteTypes.push_back(Waste::GelberSack);
it->wasteTypes.push_back(Waste::GelberSack);
break;
case 1:
// printf("Papiertonne: %s\n", token.c_str());
wd.wasteTypes.push_back(Waste::Papiertonne);
it->wasteTypes.push_back(Waste::Papiertonne);
break;
case 2:
// printf("Biotonne: %s\n", token.c_str());
wd.wasteTypes.push_back(Waste::Biotonne);
it->wasteTypes.push_back(Waste::Biotonne);
break;
case 3:
// printf("Restmüll: %s\n", token.c_str());
wd.wasteTypes.push_back(Waste::Restmuell);
it->wasteTypes.push_back(Waste::Restmuell);
break;
case 4:
// printf("Problemstoffmobil: %s\n", token.c_str());
wd.wasteTypes.push_back(Waste::Problemstoffmobil);
it->wasteTypes.push_back(Waste::Problemstoffmobil);
break;
default:
#ifdef DEBUG
@ -83,12 +76,6 @@ std::vector<WasteDate> parseCsv(const std::string &csv) {
}
}
// for(const auto& ymd: dates) {
// std::cout << "Current Year: " << static_cast<int>(ymd.date.year())
// << ", Month: " << static_cast<unsigned>(ymd.date.month())
// << ", Day: " << static_cast<unsigned>(ymd.date.day()) << '\n';
// }
return dates;
}