iterator related bugfix and cleanup.
This commit is contained in:
parent
825f490a90
commit
867ef315d3
1 changed files with 9 additions and 22 deletions
|
@ -13,7 +13,7 @@ std::vector<WasteDate> parseCsv(const std::string &csv) {
|
||||||
string line;
|
string line;
|
||||||
std::vector<WasteDate> dates;
|
std::vector<WasteDate> dates;
|
||||||
|
|
||||||
// Get rid of the first line
|
// Get rid of the first line (header)
|
||||||
std::getline(stream, line);
|
std::getline(stream, line);
|
||||||
|
|
||||||
while (std::getline(stream, line)) {
|
while (std::getline(stream, line)) {
|
||||||
|
@ -23,7 +23,6 @@ std::vector<WasteDate> parseCsv(const std::string &csv) {
|
||||||
uint tokenPos = 0;
|
uint tokenPos = 0;
|
||||||
while ((pos = line.find(delimiter)) != std::string::npos) {
|
while ((pos = line.find(delimiter)) != std::string::npos) {
|
||||||
token = line.substr(0, pos);
|
token = line.substr(0, pos);
|
||||||
// std::cout << token << std::endl;
|
|
||||||
|
|
||||||
if (token.length() > 0) {
|
if (token.length() > 0) {
|
||||||
istringstream liness(token);
|
istringstream liness(token);
|
||||||
|
@ -38,37 +37,31 @@ std::vector<WasteDate> parseCsv(const std::string &csv) {
|
||||||
std::chrono::day{(uint)day}};
|
std::chrono::day{(uint)day}};
|
||||||
|
|
||||||
std::vector<WasteDate>::iterator it;
|
std::vector<WasteDate>::iterator it;
|
||||||
WasteDate wd;
|
|
||||||
it = std::find_if(dates.begin(), dates.end(),
|
it = std::find_if(dates.begin(), dates.end(),
|
||||||
[&date](const WasteDate &x) { return date == x.date; });
|
[&date](const WasteDate &x) { return date == x.date; });
|
||||||
if (it == dates.end()) {
|
if (it == dates.end()) {
|
||||||
|
WasteDate wd;
|
||||||
wd.date = date;
|
wd.date = date;
|
||||||
dates.push_back(wd);
|
dates.push_back(wd);
|
||||||
wd = dates.back();
|
it = std::prev(dates.end());
|
||||||
} else {
|
|
||||||
wd = *it;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (tokenPos) {
|
switch (tokenPos) {
|
||||||
case 0:
|
case 0:
|
||||||
// printf("Gelber Sack: %s\n", token.c_str());
|
it->wasteTypes.push_back(Waste::GelberSack);
|
||||||
wd.wasteTypes.push_back(Waste::GelberSack);
|
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
// printf("Papiertonne: %s\n", token.c_str());
|
it->wasteTypes.push_back(Waste::Papiertonne);
|
||||||
wd.wasteTypes.push_back(Waste::Papiertonne);
|
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
// printf("Biotonne: %s\n", token.c_str());
|
it->wasteTypes.push_back(Waste::Biotonne);
|
||||||
wd.wasteTypes.push_back(Waste::Biotonne);
|
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
// printf("Restmüll: %s\n", token.c_str());
|
it->wasteTypes.push_back(Waste::Restmuell);
|
||||||
wd.wasteTypes.push_back(Waste::Restmuell);
|
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
// printf("Problemstoffmobil: %s\n", token.c_str());
|
it->wasteTypes.push_back(Waste::Problemstoffmobil);
|
||||||
wd.wasteTypes.push_back(Waste::Problemstoffmobil);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
#ifdef DEBUG
|
#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;
|
return dates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue