Codechange: Use range-for iteration.

This commit is contained in:
Peter Nelson 2023-05-07 12:09:54 +01:00 committed by PeterN
parent cef3a2570d
commit e6740046ee
22 changed files with 169 additions and 193 deletions

View File

@ -124,9 +124,8 @@ public:
if (GetBlitters().size() == 0) return nullptr; if (GetBlitters().size() == 0) return nullptr;
const char *bname = name.empty() ? default_blitter : name.c_str(); const char *bname = name.empty() ? default_blitter : name.c_str();
Blitters::iterator it = GetBlitters().begin(); for (auto &it : GetBlitters()) {
for (; it != GetBlitters().end(); it++) { BlitterFactory *b = it.second;
BlitterFactory *b = (*it).second;
if (StrEqualsIgnoreCase(bname, b->name)) { if (StrEqualsIgnoreCase(bname, b->name)) {
return b->IsUsable() ? b : nullptr; return b->IsUsable() ? b : nullptr;
} }
@ -151,9 +150,8 @@ public:
static char *GetBlittersInfo(char *p, const char *last) static char *GetBlittersInfo(char *p, const char *last)
{ {
p += seprintf(p, last, "List of blitters:\n"); p += seprintf(p, last, "List of blitters:\n");
Blitters::iterator it = GetBlitters().begin(); for (auto &it : GetBlitters()) {
for (; it != GetBlitters().end(); it++) { BlitterFactory *b = it.second;
BlitterFactory *b = (*it).second;
p += seprintf(p, last, "%18s: %s\n", b->name.c_str(), b->GetDescription().c_str()); p += seprintf(p, last, "%18s: %s\n", b->name.c_str(), b->GetDescription().c_str());
} }
p += seprintf(p, last, "\n"); p += seprintf(p, last, "\n");

View File

@ -380,8 +380,7 @@ void VehicleCargoList::AddToMeta(const CargoPacket *cp, MoveToAction action)
*/ */
void VehicleCargoList::AgeCargo() void VehicleCargoList::AgeCargo()
{ {
for (ConstIterator it(this->packets.begin()); it != this->packets.end(); it++) { for (const auto &cp : this->packets) {
CargoPacket *cp = *it;
/* If we're at the maximum, then we can't increase no more. */ /* If we're at the maximum, then we can't increase no more. */
if (cp->days_in_transit == UINT16_MAX) continue; if (cp->days_in_transit == UINT16_MAX) continue;

View File

@ -105,9 +105,8 @@ bool DriverFactoryBase::SelectDriverImpl(const std::string &name, Driver::Type t
if (name.empty()) { if (name.empty()) {
/* Probe for this driver, but do not fall back to dedicated/null! */ /* Probe for this driver, but do not fall back to dedicated/null! */
for (int priority = 10; priority > 0; priority--) { for (int priority = 10; priority > 0; priority--) {
Drivers::iterator it = GetDrivers().begin(); for (auto &it : GetDrivers()) {
for (; it != GetDrivers().end(); ++it) { DriverFactoryBase *d = it.second;
DriverFactoryBase *d = (*it).second;
/* Check driver type */ /* Check driver type */
if (d->type != type) continue; if (d->type != type) continue;
@ -151,9 +150,8 @@ bool DriverFactoryBase::SelectDriverImpl(const std::string &name, Driver::Type t
} }
/* Find this driver */ /* Find this driver */
Drivers::iterator it = GetDrivers().begin(); for (auto &it : GetDrivers()) {
for (; it != GetDrivers().end(); ++it) { DriverFactoryBase *d = it.second;
DriverFactoryBase *d = (*it).second;
/* Check driver type */ /* Check driver type */
if (d->type != type) continue; if (d->type != type) continue;
@ -191,9 +189,8 @@ char *DriverFactoryBase::GetDriversInfo(char *p, const char *last)
p += seprintf(p, last, "List of %s drivers:\n", GetDriverTypeName(type)); p += seprintf(p, last, "List of %s drivers:\n", GetDriverTypeName(type));
for (int priority = 10; priority >= 0; priority--) { for (int priority = 10; priority >= 0; priority--) {
Drivers::iterator it = GetDrivers().begin(); for (auto &it : GetDrivers()) {
for (; it != GetDrivers().end(); it++) { DriverFactoryBase *d = it.second;
DriverFactoryBase *d = (*it).second;
if (d->type != type) continue; if (d->type != type) continue;
if (d->priority != priority) continue; if (d->priority != priority) continue;
p += seprintf(p, last, "%18s: %s\n", d->name, d->GetDescription()); p += seprintf(p, last, "%18s: %s\n", d->name, d->GetDescription());

View File

@ -1899,12 +1899,9 @@ void LoadUnloadStation(Station *st)
if (st->loading_vehicles.empty()) return; if (st->loading_vehicles.empty()) return;
Vehicle *last_loading = nullptr; Vehicle *last_loading = nullptr;
std::list<Vehicle *>::iterator iter;
/* Check if anything will be loaded at all. Otherwise we don't need to reserve either. */ /* Check if anything will be loaded at all. Otherwise we don't need to reserve either. */
for (iter = st->loading_vehicles.begin(); iter != st->loading_vehicles.end(); ++iter) { for (Vehicle *v : st->loading_vehicles) {
Vehicle *v = *iter;
if ((v->vehstatus & (VS_STOPPED | VS_CRASHED))) continue; if ((v->vehstatus & (VS_STOPPED | VS_CRASHED))) continue;
assert(v->load_unload_ticks != 0); assert(v->load_unload_ticks != 0);
@ -1920,8 +1917,7 @@ void LoadUnloadStation(Station *st)
*/ */
if (last_loading == nullptr) return; if (last_loading == nullptr) return;
for (iter = st->loading_vehicles.begin(); iter != st->loading_vehicles.end(); ++iter) { for (Vehicle *v : st->loading_vehicles) {
Vehicle *v = *iter;
if (!(v->vehstatus & (VS_STOPPED | VS_CRASHED))) LoadUnloadVehicle(v); if (!(v->vehstatus & (VS_STOPPED | VS_CRASHED))) LoadUnloadVehicle(v);
if (v == last_loading) break; if (v == last_loading) break;
} }

View File

@ -288,12 +288,12 @@ FILE *FioFOpenFile(const std::string &filename, const char *mode, Subdirectory s
} }
/* Resolve ONE directory link */ /* Resolve ONE directory link */
for (TarLinkList::iterator link = _tar_linklist[subdir].begin(); link != _tar_linklist[subdir].end(); link++) { for (const auto &link : _tar_linklist[subdir]) {
const std::string &src = link->first; const std::string &src = link.first;
size_t len = src.length(); size_t len = src.length();
if (resolved_name.length() >= len && resolved_name[len - 1] == PATHSEPCHAR && src.compare(0, len, resolved_name, 0, len) == 0) { if (resolved_name.length() >= len && resolved_name[len - 1] == PATHSEPCHAR && src.compare(0, len, resolved_name, 0, len) == 0) {
/* Apply link */ /* Apply link */
resolved_name.replace(0, len, link->second); resolved_name.replace(0, len, link.second);
break; // Only resolve one level break; // Only resolve one level
} }
} }
@ -666,10 +666,8 @@ bool TarScanner::AddFile(const std::string &filename, size_t basepath_length, co
* The destination path must NOT contain any links. * The destination path must NOT contain any links.
* The source path may contain one directory link. * The source path may contain one directory link.
*/ */
for (TarLinkList::iterator link = links.begin(); link != links.end(); link++) { for (auto &it : links) {
const std::string &src = link->first; TarAddLink(it.first, it.second, this->subdir);
const std::string &dest = link->second;
TarAddLink(src, dest, this->subdir);
} }
return true; return true;
@ -705,16 +703,16 @@ bool ExtractTar(const std::string &tar_filename, Subdirectory subdir)
Debug(misc, 8, "Extracting {} to directory {}", tar_filename, filename); Debug(misc, 8, "Extracting {} to directory {}", tar_filename, filename);
FioCreateDirectory(filename); FioCreateDirectory(filename);
for (TarFileList::iterator it2 = _tar_filelist[subdir].begin(); it2 != _tar_filelist[subdir].end(); it2++) { for (auto &it2 : _tar_filelist[subdir]) {
if (tar_filename != it2->second.tar_filename) continue; if (tar_filename != it2.second.tar_filename) continue;
filename.replace(p + 1, std::string::npos, it2->first); filename.replace(p + 1, std::string::npos, it2.first);
Debug(misc, 9, " extracting {}", filename); Debug(misc, 9, " extracting {}", filename);
/* First open the file in the .tar. */ /* First open the file in the .tar. */
size_t to_copy = 0; size_t to_copy = 0;
std::unique_ptr<FILE, FileDeleter> in(FioFOpenFileTar(it2->second, &to_copy)); std::unique_ptr<FILE, FileDeleter> in(FioFOpenFileTar(it2.second, &to_copy));
if (!in) { if (!in) {
Debug(misc, 6, "Extracting {} failed; could not open {}", filename, tar_filename); Debug(misc, 6, "Extracting {} failed; could not open {}", filename, tar_filename);
return false; return false;

View File

@ -51,8 +51,8 @@ void FlowMapper::Run(LinkGraphJob &job) const
* division by 0 if spawn date == last compression date. This matches * division by 0 if spawn date == last compression date. This matches
* LinkGraph::Monthly(). */ * LinkGraph::Monthly(). */
uint runtime = job.JoinDate() - job.Settings().recalc_time - job.LastCompression() + 1; uint runtime = job.JoinDate() - job.Settings().recalc_time - job.LastCompression() + 1;
for (FlowStatMap::iterator i = flows.begin(); i != flows.end(); ++i) { for (auto &it : flows) {
i->second.ScaleToMonthly(runtime); it.second.ScaleToMonthly(runtime);
} }
} }
/* Clear paths. */ /* Clear paths. */

View File

@ -273,14 +273,14 @@ void LinkGraphOverlay::Draw(const DrawPixelInfo *dpi)
void LinkGraphOverlay::DrawLinks(const DrawPixelInfo *dpi) const void LinkGraphOverlay::DrawLinks(const DrawPixelInfo *dpi) const
{ {
int width = ScaleGUITrad(this->scale); int width = ScaleGUITrad(this->scale);
for (LinkMap::const_iterator i(this->cached_links.begin()); i != this->cached_links.end(); ++i) { for (const auto &i : this->cached_links) {
if (!Station::IsValidID(i->first)) continue; if (!Station::IsValidID(i.first)) continue;
Point pta = this->GetStationMiddle(Station::Get(i->first)); Point pta = this->GetStationMiddle(Station::Get(i.first));
for (StationLinkMap::const_iterator j(i->second.begin()); j != i->second.end(); ++j) { for (const auto &j : i.second) {
if (!Station::IsValidID(j->first)) continue; if (!Station::IsValidID(j.first)) continue;
Point ptb = this->GetStationMiddle(Station::Get(j->first)); Point ptb = this->GetStationMiddle(Station::Get(j.first));
if (!this->IsLinkVisible(pta, ptb, dpi, width + 2)) continue; if (!this->IsLinkVisible(pta, ptb, dpi, width + 2)) continue;
this->DrawContent(pta, ptb, j->second); this->DrawContent(pta, ptb, j.second);
} }
} }
} }
@ -319,13 +319,13 @@ void LinkGraphOverlay::DrawContent(Point pta, Point ptb, const LinkProperties &c
void LinkGraphOverlay::DrawStationDots(const DrawPixelInfo *dpi) const void LinkGraphOverlay::DrawStationDots(const DrawPixelInfo *dpi) const
{ {
int width = ScaleGUITrad(this->scale); int width = ScaleGUITrad(this->scale);
for (StationSupplyList::const_iterator i(this->cached_stations.begin()); i != this->cached_stations.end(); ++i) { for (const auto &i : this->cached_stations) {
const Station *st = Station::GetIfValid(i->first); const Station *st = Station::GetIfValid(i.first);
if (st == nullptr) continue; if (st == nullptr) continue;
Point pt = this->GetStationMiddle(st); Point pt = this->GetStationMiddle(st);
if (!this->IsPointVisible(pt, dpi, 3 * width)) continue; if (!this->IsPointVisible(pt, dpi, 3 * width)) continue;
uint r = width * 2 + width * 2 * std::min(200U, i->second) / 200; uint r = width * 2 + width * 2 * std::min(200U, i.second) / 200;
LinkGraphOverlay::DrawVertex(pt.x, pt.y, r, LinkGraphOverlay::DrawVertex(pt.x, pt.y, r,
_colour_gradient[st->owner != OWNER_NONE ? _colour_gradient[st->owner != OWNER_NONE ?

View File

@ -110,8 +110,8 @@ void LinkGraphSchedule::JoinNext()
*/ */
void LinkGraphSchedule::SpawnAll() void LinkGraphSchedule::SpawnAll()
{ {
for (JobList::iterator i = this->running.begin(); i != this->running.end(); ++i) { for (auto &it : this->running) {
(*i)->SpawnThread(); it->SpawnThread();
} }
} }
@ -120,8 +120,8 @@ void LinkGraphSchedule::SpawnAll()
*/ */
/* static */ void LinkGraphSchedule::Clear() /* static */ void LinkGraphSchedule::Clear()
{ {
for (JobList::iterator i(instance.running.begin()); i != instance.running.end(); ++i) { for (auto &it : instance.running) {
(*i)->AbortJob(); it->AbortJob();
} }
instance.running.clear(); instance.running.clear();
instance.schedule.clear(); instance.schedule.clear();

View File

@ -144,10 +144,10 @@ bool LinkRefresher::HandleRefit(CargoID refit_cargo)
*/ */
void LinkRefresher::ResetRefit() void LinkRefresher::ResetRefit()
{ {
for (RefitList::iterator it(this->refit_capacities.begin()); it != this->refit_capacities.end(); ++it) { for (auto &it : this->refit_capacities) {
if (it->remaining == it->capacity) continue; if (it.remaining == it.capacity) continue;
this->capacities[it->cargo] += it->capacity - it->remaining; this->capacities[it.cargo] += it.capacity - it.remaining;
it->remaining = it->capacity; it.remaining = it.capacity;
} }
} }

View File

@ -413,9 +413,9 @@ void MusicSystem::SaveCustomPlaylist(PlaylistChoices pl)
size_t num = 0; size_t num = 0;
MemSetT(settings_pl, 0, NUM_SONGS_PLAYLIST); MemSetT(settings_pl, 0, NUM_SONGS_PLAYLIST);
for (Playlist::const_iterator song = this->standard_playlists[pl].begin(); song != this->standard_playlists[pl].end(); ++song) { for (const auto &song : this->standard_playlists[pl]) {
/* Music set indices in the settings playlist are 1-based, 0 means unused slot */ /* Music set indices in the settings playlist are 1-based, 0 means unused slot */
settings_pl[num++] = (byte)song->set_index + 1; settings_pl[num++] = (byte)song.set_index + 1;
} }
} }
@ -510,10 +510,10 @@ struct MusicTrackSelectionWindow : public Window {
case WID_MTS_LIST_LEFT: case WID_MTS_LIST_RIGHT: { case WID_MTS_LIST_LEFT: case WID_MTS_LIST_RIGHT: {
Dimension d = {0, 0}; Dimension d = {0, 0};
for (MusicSystem::Playlist::const_iterator song = _music.music_set.begin(); song != _music.music_set.end(); ++song) { for (const auto &song : _music.music_set) {
SetDParam(0, song->tracknr); SetDParam(0, song.tracknr);
SetDParam(1, 2); SetDParam(1, 2);
SetDParamStr(2, song->songname); SetDParamStr(2, song.songname);
Dimension d2 = GetStringBoundingBox(STR_PLAYLIST_TRACK_NAME); Dimension d2 = GetStringBoundingBox(STR_PLAYLIST_TRACK_NAME);
d.width = std::max(d.width, d2.width); d.width = std::max(d.width, d2.width);
d.height += d2.height; d.height += d2.height;
@ -533,10 +533,10 @@ struct MusicTrackSelectionWindow : public Window {
GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), PC_BLACK); GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), PC_BLACK);
Rect tr = r.Shrink(WidgetDimensions::scaled.framerect); Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
for (MusicSystem::Playlist::const_iterator song = _music.music_set.begin(); song != _music.music_set.end(); ++song) { for (const auto &song : _music.music_set) {
SetDParam(0, song->tracknr); SetDParam(0, song.tracknr);
SetDParam(1, 2); SetDParam(1, 2);
SetDParamStr(2, song->songname); SetDParamStr(2, song.songname);
DrawString(tr, STR_PLAYLIST_TRACK_NAME); DrawString(tr, STR_PLAYLIST_TRACK_NAME);
tr.top += FONT_HEIGHT_SMALL; tr.top += FONT_HEIGHT_SMALL;
} }
@ -547,10 +547,10 @@ struct MusicTrackSelectionWindow : public Window {
GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), PC_BLACK); GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), PC_BLACK);
Rect tr = r.Shrink(WidgetDimensions::scaled.framerect); Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
for (MusicSystem::Playlist::const_iterator song = _music.active_playlist.begin(); song != _music.active_playlist.end(); ++song) { for (const auto &song : _music.active_playlist) {
SetDParam(0, song->tracknr); SetDParam(0, song.tracknr);
SetDParam(1, 2); SetDParam(1, 2);
SetDParamStr(2, song->songname); SetDParamStr(2, song.songname);
DrawString(tr, STR_PLAYLIST_TRACK_NAME); DrawString(tr, STR_PLAYLIST_TRACK_NAME);
tr.top += FONT_HEIGHT_SMALL; tr.top += FONT_HEIGHT_SMALL;
} }
@ -698,8 +698,8 @@ struct MusicWindow : public Window {
case WID_M_TRACK_NAME: { case WID_M_TRACK_NAME: {
Dimension d = GetStringBoundingBox(STR_MUSIC_TITLE_NONE); Dimension d = GetStringBoundingBox(STR_MUSIC_TITLE_NONE);
for (MusicSystem::Playlist::const_iterator song = _music.music_set.begin(); song != _music.music_set.end(); ++song) { for (const auto &song : _music.music_set) {
SetDParamStr(0, song->songname); SetDParamStr(0, song.songname);
d = maxdim(d, GetStringBoundingBox(STR_MUSIC_TITLE_NAME)); d = maxdim(d, GetStringBoundingBox(STR_MUSIC_TITLE_NAME));
} }
d.width += padding.width; d.width += padding.width;

View File

@ -170,16 +170,16 @@ static uint16 GetGenericCallbackResult(uint8 feature, ResolverObject &object, ui
assert(feature < lengthof(_gcl)); assert(feature < lengthof(_gcl));
/* Test each feature callback sprite group. */ /* Test each feature callback sprite group. */
for (GenericCallbackList::const_iterator it = _gcl[feature].begin(); it != _gcl[feature].end(); ++it) { for (const auto &it : _gcl[feature]) {
object.grffile = it->file; object.grffile = it.file;
object.root_spritegroup = it->group; object.root_spritegroup = it.group;
/* Set callback param based on GRF version. */ /* Set callback param based on GRF version. */
object.callback_param1 = it->file->grf_version >= 8 ? param1_grfv8 : param1_grfv7; object.callback_param1 = it.file->grf_version >= 8 ? param1_grfv8 : param1_grfv7;
uint16 result = object.ResolveCallback(); uint16 result = object.ResolveCallback();
if (result == CALLBACK_FAILED) continue; if (result == CALLBACK_FAILED) continue;
/* Return NewGRF file if necessary */ /* Return NewGRF file if necessary */
if (file != nullptr) *file = it->file; if (file != nullptr) *file = it.file;
return result; return result;
} }

View File

@ -91,9 +91,9 @@ void AddChangedPersistentStorage(BasePersistentStorageArray *storage)
} }
/* Discard all temporary changes */ /* Discard all temporary changes */
for (std::set<BasePersistentStorageArray*>::iterator it = _changed_storage_arrays->begin(); it != _changed_storage_arrays->end(); it++) { for (auto &it : *_changed_storage_arrays) {
Debug(desync, 1, "Discarding persistent storage changes: Feature {}, GrfID {:08X}, Tile {}", (*it)->feature, BSWAP32((*it)->grfid), (*it)->tile); Debug(desync, 1, "Discarding persistent storage changes: Feature {}, GrfID {:08X}, Tile {}", it->feature, BSWAP32(it->grfid), it->tile);
(*it)->ClearChanges(); it->ClearChanges();
} }
_changed_storage_arrays->clear(); _changed_storage_arrays->clear();
} }

View File

@ -35,9 +35,8 @@
grfid = this->ro.grffile->grfid; grfid = this->ro.grffile->grfid;
} }
std::list<PersistentStorage *>::iterator iter; for (auto &it : this->t->psa_list) {
for (iter = this->t->psa_list.begin(); iter != this->t->psa_list.end(); iter++) { if (it->grfid == grfid) return it->GetValue(parameter);
if ((*iter)->grfid == grfid) return (*iter)->GetValue(parameter);
} }
return 0; return 0;
@ -133,10 +132,9 @@
if (grfid != this->ro.grffile->grfid) return; if (grfid != this->ro.grffile->grfid) return;
/* Check if the storage exists. */ /* Check if the storage exists. */
std::list<PersistentStorage *>::iterator iter; for (auto &it : t->psa_list) {
for (iter = t->psa_list.begin(); iter != t->psa_list.end(); iter++) { if (it->grfid == grfid) {
if ((*iter)->grfid == grfid) { it->StoreValue(pos, value);
(*iter)->StoreValue(pos, value);
return; return;
} }
} }

View File

@ -336,8 +336,8 @@ Vehicle *FindVehiclesInRoadStop(Vehicle *v, void *data)
if (rv->state < RVSB_IN_ROAD_STOP) return nullptr; if (rv->state < RVSB_IN_ROAD_STOP) return nullptr;
/* Do not add duplicates! */ /* Do not add duplicates! */
for (RVList::iterator it = rserh->vehicles.begin(); it != rserh->vehicles.end(); it++) { for (const auto &it : rserh->vehicles) {
if (rv == *it) return nullptr; if (rv == it) return nullptr;
} }
rserh->vehicles.push_back(rv); rserh->vehicles.push_back(rv);
@ -367,8 +367,8 @@ void RoadStop::Entry::Rebuild(const RoadStop *rs, int side)
} }
this->occupied = 0; this->occupied = 0;
for (RVList::iterator it = rserh.vehicles.begin(); it != rserh.vehicles.end(); it++) { for (const auto &it : rserh.vehicles) {
this->occupied += (*it)->gcache.cached_total_length; this->occupied += it->gcache.cached_total_length;
} }
} }

View File

@ -283,9 +283,9 @@ static void InitializeWindowsAndCaches()
} }
} }
for (Town *t : Town::Iterate()) { for (Town *t : Town::Iterate()) {
for (std::list<PersistentStorage *>::iterator it = t->psa_list.begin(); it != t->psa_list.end(); ++it) { for (auto &it : t->psa_list) {
(*it)->feature = GSF_FAKE_TOWNS; it->feature = GSF_FAKE_TOWNS;
(*it)->tile = t->xy; it->tile = t->xy;
} }
} }
for (RoadVehicle *rv : RoadVehicle::Iterate()) { for (RoadVehicle *rv : RoadVehicle::Iterate()) {
@ -2157,13 +2157,11 @@ bool AfterLoadGame()
* add cargopayment for the vehicles that don't have it. * add cargopayment for the vehicles that don't have it.
*/ */
for (Station *st : Station::Iterate()) { for (Station *st : Station::Iterate()) {
std::list<Vehicle *>::iterator iter; for (Vehicle *v : st->loading_vehicles) {
for (iter = st->loading_vehicles.begin(); iter != st->loading_vehicles.end(); ++iter) {
/* There are always as many CargoPayments as Vehicles. We need to make the /* There are always as many CargoPayments as Vehicles. We need to make the
* assert() in Pool::GetNew() happy by calling CanAllocateItem(). */ * assert() in Pool::GetNew() happy by calling CanAllocateItem(). */
static_assert(CargoPaymentPool::MAX_SIZE == VehiclePool::MAX_SIZE); static_assert(CargoPaymentPool::MAX_SIZE == VehiclePool::MAX_SIZE);
assert(CargoPayment::CanAllocateItem()); assert(CargoPayment::CanAllocateItem());
Vehicle *v = *iter;
if (v->cargo_payment == nullptr) v->cargo_payment = new CargoPayment(v); if (v->cargo_payment == nullptr) v->cargo_payment = new CargoPayment(v);
} }
} }

View File

@ -310,22 +310,22 @@ public:
void Save(GoodsEntry *ge) const override void Save(GoodsEntry *ge) const override
{ {
uint32 num_flows = 0; size_t num_flows = 0;
for (FlowStatMap::const_iterator it(ge->flows.begin()); it != ge->flows.end(); ++it) { for (const auto &it : ge->flows) {
num_flows += (uint32)it->second.GetShares()->size(); num_flows += it.second.GetShares()->size();
} }
SlSetStructListLength(num_flows); SlSetStructListLength(num_flows);
for (FlowStatMap::const_iterator outer_it(ge->flows.begin()); outer_it != ge->flows.end(); ++outer_it) { for (const auto &outer_it : ge->flows) {
const FlowStat::SharesMap *shares = outer_it->second.GetShares(); const FlowStat::SharesMap *shares = outer_it.second.GetShares();
uint32 sum_shares = 0; uint32 sum_shares = 0;
FlowSaveLoad flow; FlowSaveLoad flow;
flow.source = outer_it->first; flow.source = outer_it.first;
for (FlowStat::SharesMap::const_iterator inner_it(shares->begin()); inner_it != shares->end(); ++inner_it) { for (auto &inner_it : *shares) {
flow.via = inner_it->second; flow.via = inner_it.second;
flow.share = inner_it->first - sum_shares; flow.share = inner_it.first - sum_shares;
flow.restricted = inner_it->first > outer_it->second.GetUnrestricted(); flow.restricted = inner_it.first > outer_it.second.GetUnrestricted();
sum_shares = inner_it->first; sum_shares = inner_it.first;
assert(flow.share > 0); assert(flow.share > 0);
SlObject(&flow, this->GetDescription()); SlObject(&flow, this->GetDescription());
} }

View File

@ -564,9 +564,9 @@ void ScriptList::AddList(ScriptList *list)
this->modifications++; this->modifications++;
} else { } else {
ScriptListMap *list_items = &list->items; ScriptListMap *list_items = &list->items;
for (ScriptListMap::iterator iter = list_items->begin(); iter != list_items->end(); iter++) { for (auto &it : *list_items) {
this->AddItem((*iter).first); this->AddItem(it.first);
this->SetValue((*iter).first, (*iter).second); this->SetValue(it.first, it.second);
} }
} }
} }

View File

@ -1347,8 +1347,8 @@ void SettingEntry::DrawSetting(GameSettings *settings_ptr, int left, int right,
*/ */
void SettingsContainer::Init(byte level) void SettingsContainer::Init(byte level)
{ {
for (EntryVector::iterator it = this->entries.begin(); it != this->entries.end(); ++it) { for (auto &it : this->entries) {
(*it)->Init(level); it->Init(level);
} }
} }
@ -1363,16 +1363,16 @@ void SettingsContainer::ResetAll()
/** Recursively close all folds of sub-pages */ /** Recursively close all folds of sub-pages */
void SettingsContainer::FoldAll() void SettingsContainer::FoldAll()
{ {
for (EntryVector::iterator it = this->entries.begin(); it != this->entries.end(); ++it) { for (auto &it : this->entries) {
(*it)->FoldAll(); it->FoldAll();
} }
} }
/** Recursively open all folds of sub-pages */ /** Recursively open all folds of sub-pages */
void SettingsContainer::UnFoldAll() void SettingsContainer::UnFoldAll()
{ {
for (EntryVector::iterator it = this->entries.begin(); it != this->entries.end(); ++it) { for (auto &it : this->entries) {
(*it)->UnFoldAll(); it->UnFoldAll();
} }
} }
@ -1383,8 +1383,8 @@ void SettingsContainer::UnFoldAll()
*/ */
void SettingsContainer::GetFoldingState(bool &all_folded, bool &all_unfolded) const void SettingsContainer::GetFoldingState(bool &all_folded, bool &all_unfolded) const
{ {
for (EntryVector::const_iterator it = this->entries.begin(); it != this->entries.end(); ++it) { for (auto &it : this->entries) {
(*it)->GetFoldingState(all_folded, all_unfolded); it->GetFoldingState(all_folded, all_unfolded);
} }
} }
@ -1415,8 +1415,8 @@ bool SettingsContainer::UpdateFilterState(SettingFilter &filter, bool force_visi
*/ */
bool SettingsContainer::IsVisible(const BaseSettingEntry *item) const bool SettingsContainer::IsVisible(const BaseSettingEntry *item) const
{ {
for (EntryVector::const_iterator it = this->entries.begin(); it != this->entries.end(); ++it) { for (const auto &it : this->entries) {
if ((*it)->IsVisible(item)) return true; if (it->IsVisible(item)) return true;
} }
return false; return false;
} }
@ -1425,8 +1425,8 @@ bool SettingsContainer::IsVisible(const BaseSettingEntry *item) const
uint SettingsContainer::Length() const uint SettingsContainer::Length() const
{ {
uint length = 0; uint length = 0;
for (EntryVector::const_iterator it = this->entries.begin(); it != this->entries.end(); ++it) { for (const auto &it : this->entries) {
length += (*it)->Length(); length += it->Length();
} }
return length; return length;
} }
@ -1440,8 +1440,8 @@ uint SettingsContainer::Length() const
BaseSettingEntry *SettingsContainer::FindEntry(uint row_num, uint *cur_row) BaseSettingEntry *SettingsContainer::FindEntry(uint row_num, uint *cur_row)
{ {
BaseSettingEntry *pe = nullptr; BaseSettingEntry *pe = nullptr;
for (EntryVector::iterator it = this->entries.begin(); it != this->entries.end(); ++it) { for (const auto &it : this->entries) {
pe = (*it)->FindEntry(row_num, cur_row); pe = it->FindEntry(row_num, cur_row);
if (pe != nullptr) { if (pe != nullptr) {
break; break;
} }
@ -1457,8 +1457,8 @@ BaseSettingEntry *SettingsContainer::FindEntry(uint row_num, uint *cur_row)
uint SettingsContainer::GetMaxHelpHeight(int maxw) uint SettingsContainer::GetMaxHelpHeight(int maxw)
{ {
uint biggest = 0; uint biggest = 0;
for (EntryVector::const_iterator it = this->entries.begin(); it != this->entries.end(); ++it) { for (const auto &it : this->entries) {
biggest = std::max(biggest, (*it)->GetMaxHelpHeight(maxw)); biggest = std::max(biggest, it->GetMaxHelpHeight(maxw));
} }
return biggest; return biggest;
} }
@ -1480,11 +1480,9 @@ uint SettingsContainer::GetMaxHelpHeight(int maxw)
*/ */
uint SettingsContainer::Draw(GameSettings *settings_ptr, int left, int right, int y, uint first_row, uint max_row, BaseSettingEntry *selected, uint cur_row, uint parent_last) const uint SettingsContainer::Draw(GameSettings *settings_ptr, int left, int right, int y, uint first_row, uint max_row, BaseSettingEntry *selected, uint cur_row, uint parent_last) const
{ {
for (EntryVector::const_iterator it = this->entries.begin(); it != this->entries.end(); ++it) { for (const auto &it : this->entries) {
cur_row = (*it)->Draw(settings_ptr, left, right, y, first_row, max_row, selected, cur_row, parent_last); cur_row = it->Draw(settings_ptr, left, right, y, first_row, max_row, selected, cur_row, parent_last);
if (cur_row >= max_row) { if (cur_row >= max_row) break;
break;
}
} }
return cur_row; return cur_row;
} }

View File

@ -3781,10 +3781,10 @@ void RerouteCargo(Station *st, CargoID c, StationID avoid, StationID avoid2)
ge.cargo.Reroute(UINT_MAX, &ge.cargo, avoid, avoid2, &ge); ge.cargo.Reroute(UINT_MAX, &ge.cargo, avoid, avoid2, &ge);
/* Reroute cargo staged to be transferred. */ /* Reroute cargo staged to be transferred. */
for (std::list<Vehicle *>::iterator it(st->loading_vehicles.begin()); it != st->loading_vehicles.end(); ++it) { for (Vehicle *v : st->loading_vehicles) {
for (Vehicle *v = *it; v != nullptr; v = v->Next()) { for (Vehicle *u = v; u != nullptr; u = u->Next()) {
if (v->cargo_type != c) continue; if (u->cargo_type != c) continue;
v->cargo.Reroute(UINT_MAX, &v->cargo, avoid, avoid2, &ge); u->cargo.Reroute(UINT_MAX, &u->cargo, avoid, avoid2, &ge);
} }
} }
} }
@ -4531,11 +4531,11 @@ static CommandCost TerraformTile_Station(TileIndex tile, DoCommandFlag flags, in
uint FlowStat::GetShare(StationID st) const uint FlowStat::GetShare(StationID st) const
{ {
uint32 prev = 0; uint32 prev = 0;
for (SharesMap::const_iterator it = this->shares.begin(); it != this->shares.end(); ++it) { for (const auto &it : this->shares) {
if (it->second == st) { if (it.second == st) {
return it->first - prev; return it.first - prev;
} else { } else {
prev = it->first; prev = it.first;
} }
} }
return 0; return 0;
@ -4605,9 +4605,9 @@ void FlowStat::Invalidate()
assert(!this->shares.empty()); assert(!this->shares.empty());
SharesMap new_shares; SharesMap new_shares;
uint i = 0; uint i = 0;
for (SharesMap::iterator it(this->shares.begin()); it != this->shares.end(); ++it) { for (const auto &it : this->shares) {
new_shares[++i] = it->second; new_shares[++i] = it.second;
if (it->first == this->unrestricted) this->unrestricted = i; if (it.first == this->unrestricted) this->unrestricted = i;
} }
this->shares.swap(new_shares); this->shares.swap(new_shares);
assert(!this->shares.empty() && this->unrestricted <= (--this->shares.end())->first); assert(!this->shares.empty() && this->unrestricted <= (--this->shares.end())->first);
@ -4629,29 +4629,29 @@ void FlowStat::ChangeShare(StationID st, int flow)
uint added_shares = 0; uint added_shares = 0;
uint last_share = 0; uint last_share = 0;
SharesMap new_shares; SharesMap new_shares;
for (SharesMap::iterator it(this->shares.begin()); it != this->shares.end(); ++it) { for (const auto &it : this->shares) {
if (it->second == st) { if (it.second == st) {
if (flow < 0) { if (flow < 0) {
uint share = it->first - last_share; uint share = it.first - last_share;
if (flow == INT_MIN || (uint)(-flow) >= share) { if (flow == INT_MIN || (uint)(-flow) >= share) {
removed_shares += share; removed_shares += share;
if (it->first <= this->unrestricted) this->unrestricted -= share; if (it.first <= this->unrestricted) this->unrestricted -= share;
if (flow != INT_MIN) flow += share; if (flow != INT_MIN) flow += share;
last_share = it->first; last_share = it.first;
continue; // remove the whole share continue; // remove the whole share
} }
removed_shares += (uint)(-flow); removed_shares += (uint)(-flow);
} else { } else {
added_shares += (uint)(flow); added_shares += (uint)(flow);
} }
if (it->first <= this->unrestricted) this->unrestricted += flow; if (it.first <= this->unrestricted) this->unrestricted += flow;
/* If we don't continue above the whole flow has been added or /* If we don't continue above the whole flow has been added or
* removed. */ * removed. */
flow = 0; flow = 0;
} }
new_shares[it->first + added_shares - removed_shares] = it->second; new_shares[it.first + added_shares - removed_shares] = it.second;
last_share = it->first; last_share = it.first;
} }
if (flow > 0) { if (flow > 0) {
new_shares[last_share + (uint)flow] = st; new_shares[last_share + (uint)flow] = st;
@ -4675,19 +4675,19 @@ void FlowStat::RestrictShare(StationID st)
uint flow = 0; uint flow = 0;
uint last_share = 0; uint last_share = 0;
SharesMap new_shares; SharesMap new_shares;
for (SharesMap::iterator it(this->shares.begin()); it != this->shares.end(); ++it) { for (auto &it : this->shares) {
if (flow == 0) { if (flow == 0) {
if (it->first > this->unrestricted) return; // Not present or already restricted. if (it.first > this->unrestricted) return; // Not present or already restricted.
if (it->second == st) { if (it.second == st) {
flow = it->first - last_share; flow = it.first - last_share;
this->unrestricted -= flow; this->unrestricted -= flow;
} else { } else {
new_shares[it->first] = it->second; new_shares[it.first] = it.second;
} }
} else { } else {
new_shares[it->first - flow] = it->second; new_shares[it.first - flow] = it.second;
} }
last_share = it->first; last_share = it.first;
} }
if (flow == 0) return; if (flow == 0) return;
new_shares[last_share + flow] = st; new_shares[last_share + flow] = st;
@ -4742,10 +4742,10 @@ void FlowStat::ScaleToMonthly(uint runtime)
assert(runtime > 0); assert(runtime > 0);
SharesMap new_shares; SharesMap new_shares;
uint share = 0; uint share = 0;
for (SharesMap::iterator i = this->shares.begin(); i != this->shares.end(); ++i) { for (auto i : this->shares) {
share = std::max(share + 1, i->first * 30 / runtime); share = std::max(share + 1, i.first * 30 / runtime);
new_shares[share] = i->second; new_shares[share] = i.second;
if (this->unrestricted == i->first) this->unrestricted = share; if (this->unrestricted == i.first) this->unrestricted = share;
} }
this->shares.swap(new_shares); this->shares.swap(new_shares);
} }
@ -4795,8 +4795,8 @@ void FlowStatMap::PassOnFlow(StationID origin, StationID via, uint flow)
*/ */
void FlowStatMap::FinalizeLocalConsumption(StationID self) void FlowStatMap::FinalizeLocalConsumption(StationID self)
{ {
for (FlowStatMap::iterator i = this->begin(); i != this->end(); ++i) { for (auto &i : *this) {
FlowStat &fs = i->second; FlowStat &fs = i.second;
uint local = fs.GetShare(INVALID_STATION); uint local = fs.GetShare(INVALID_STATION);
if (local > INT_MAX) { // make sure it fits in an int if (local > INT_MAX) { // make sure it fits in an int
fs.ChangeShare(self, -INT_MAX); fs.ChangeShare(self, -INT_MAX);
@ -4840,8 +4840,8 @@ StationIDStack FlowStatMap::DeleteFlows(StationID via)
*/ */
void FlowStatMap::RestrictFlows(StationID via) void FlowStatMap::RestrictFlows(StationID via)
{ {
for (FlowStatMap::iterator it = this->begin(); it != this->end(); ++it) { for (auto &it : *this) {
it->second.RestrictShare(via); it.second.RestrictShare(via);
} }
} }
@ -4851,8 +4851,8 @@ void FlowStatMap::RestrictFlows(StationID via)
*/ */
void FlowStatMap::ReleaseFlows(StationID via) void FlowStatMap::ReleaseFlows(StationID via)
{ {
for (FlowStatMap::iterator it = this->begin(); it != this->end(); ++it) { for (auto &it : *this) {
it->second.ReleaseShare(via); it.second.ReleaseShare(via);
} }
} }
@ -4863,8 +4863,8 @@ void FlowStatMap::ReleaseFlows(StationID via)
uint FlowStatMap::GetFlow() const uint FlowStatMap::GetFlow() const
{ {
uint ret = 0; uint ret = 0;
for (FlowStatMap::const_iterator i = this->begin(); i != this->end(); ++i) { for (const auto &it : *this) {
ret += (--(i->second.GetShares()->end()))->first; ret += (--(it.second.GetShares()->end()))->first;
} }
return ret; return ret;
} }
@ -4877,8 +4877,8 @@ uint FlowStatMap::GetFlow() const
uint FlowStatMap::GetFlowVia(StationID via) const uint FlowStatMap::GetFlowVia(StationID via) const
{ {
uint ret = 0; uint ret = 0;
for (FlowStatMap::const_iterator i = this->begin(); i != this->end(); ++i) { for (const auto &it : *this) {
ret += i->second.GetShare(via); ret += it.second.GetShare(via);
} }
return ret; return ret;
} }

View File

@ -1058,9 +1058,9 @@ CargoDataEntry::~CargoDataEntry()
void CargoDataEntry::Clear() void CargoDataEntry::Clear()
{ {
if (this->children != nullptr) { if (this->children != nullptr) {
for (CargoDataSet::iterator i = this->children->begin(); i != this->children->end(); ++i) { for (auto &it : *this->children) {
assert(*i != this); assert(it != this);
delete *i; delete it;
} }
this->children->clear(); this->children->clear();
} }
@ -1464,21 +1464,19 @@ struct StationViewWindow : public Window {
CargoDataEntry *cargo_entry = cached_destinations.InsertOrRetrieve(i); CargoDataEntry *cargo_entry = cached_destinations.InsertOrRetrieve(i);
cargo_entry->Clear(); cargo_entry->Clear();
const FlowStatMap &flows = st->goods[i].flows; for (const auto &it : st->goods[i].flows) {
for (FlowStatMap::const_iterator it = flows.begin(); it != flows.end(); ++it) { StationID from = it.first;
StationID from = it->first;
CargoDataEntry *source_entry = cargo_entry->InsertOrRetrieve(from); CargoDataEntry *source_entry = cargo_entry->InsertOrRetrieve(from);
const FlowStat::SharesMap *shares = it->second.GetShares();
uint32 prev_count = 0; uint32 prev_count = 0;
for (FlowStat::SharesMap::const_iterator flow_it = shares->begin(); flow_it != shares->end(); ++flow_it) { for (const auto &flow_it : *it.second.GetShares()) {
StationID via = flow_it->second; StationID via = flow_it.second;
CargoDataEntry *via_entry = source_entry->InsertOrRetrieve(via); CargoDataEntry *via_entry = source_entry->InsertOrRetrieve(via);
if (via == this->window_number) { if (via == this->window_number) {
via_entry->InsertOrRetrieve(via)->Update(flow_it->first - prev_count); via_entry->InsertOrRetrieve(via)->Update(flow_it.first - prev_count);
} else { } else {
EstimateDestinations(i, from, via, flow_it->first - prev_count, via_entry); EstimateDestinations(i, from, via, flow_it.first - prev_count, via_entry);
} }
prev_count = flow_it->first; prev_count = flow_it.first;
} }
} }
} }

View File

@ -550,9 +550,8 @@ class NIHTown : public NIHelper {
{ {
Town *t = Town::Get(index); Town *t = Town::Get(index);
std::list<PersistentStorage *>::iterator iter; for (const auto &it : t->psa_list) {
for (iter = t->psa_list.begin(); iter != t->psa_list.end(); iter++) { if (it->grfid == grfid) return &it->storage[0];
if ((*iter)->grfid == grfid) return (int32 *)(&(*iter)->storage[0]);
} }
return nullptr; return nullptr;

View File

@ -222,9 +222,7 @@ std::tuple<CommandCost, Money, TileIndex> CmdTerraformLand(DoCommandFlag flags,
* Pass == 0: Collect tileareas which are caused to be auto-cleared. * Pass == 0: Collect tileareas which are caused to be auto-cleared.
* Pass == 1: Collect the actual cost. */ * Pass == 1: Collect the actual cost. */
for (int pass = 0; pass < 2; pass++) { for (int pass = 0; pass < 2; pass++) {
for (TileIndexSet::const_iterator it = ts.dirty_tiles.begin(); it != ts.dirty_tiles.end(); it++) { for (const auto &t : ts.dirty_tiles) {
TileIndex t = *it;
assert(t < Map::Size()); assert(t < Map::Size());
/* MP_VOID tiles can be terraformed but as tunnels and bridges /* MP_VOID tiles can be terraformed but as tunnels and bridges
* cannot go under / over these tiles they don't need checking. */ * cannot go under / over these tiles they don't need checking. */
@ -301,18 +299,17 @@ std::tuple<CommandCost, Money, TileIndex> CmdTerraformLand(DoCommandFlag flags,
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
/* Mark affected areas dirty. */ /* Mark affected areas dirty. */
for (TileIndexSet::const_iterator it = ts.dirty_tiles.begin(); it != ts.dirty_tiles.end(); it++) { for (const auto &t : ts.dirty_tiles) {
MarkTileDirtyByTile(*it); MarkTileDirtyByTile(t);
TileIndexToHeightMap::const_iterator new_height = ts.tile_to_new_height.find(*it); TileIndexToHeightMap::const_iterator new_height = ts.tile_to_new_height.find(t);
if (new_height == ts.tile_to_new_height.end()) continue; if (new_height == ts.tile_to_new_height.end()) continue;
MarkTileDirtyByTile(*it, 0, new_height->second); MarkTileDirtyByTile(t, 0, new_height->second);
} }
/* change the height */ /* change the height */
for (TileIndexToHeightMap::const_iterator it = ts.tile_to_new_height.begin(); for (const auto &it : ts.tile_to_new_height) {
it != ts.tile_to_new_height.end(); it++) { TileIndex t = it.first;
TileIndex t = it->first; int height = it.second;
int height = it->second;
SetTileHeight(t, (uint)height); SetTileHeight(t, (uint)height);
} }