From 869581eb238b820574d64cd8dabc9324cd7a0dd5 Mon Sep 17 00:00:00 2001 From: glx Date: Tue, 17 Dec 2019 19:14:42 +0100 Subject: [PATCH] Codechange: Replace FOR_ALL_SIGNS with range-based for loops --- src/economy.cpp | 3 +-- src/saveload/afterload.cpp | 3 +-- src/saveload/signs_sl.cpp | 4 +--- src/script/api/script_signlist.cpp | 3 +-- src/signs.cpp | 4 +--- src/signs_base.h | 3 --- src/signs_gui.cpp | 3 +-- src/viewport.cpp | 3 +-- 8 files changed, 7 insertions(+), 19 deletions(-) diff --git a/src/economy.cpp b/src/economy.cpp index a4e476537a..b4a7d68093 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -521,8 +521,7 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner) } } - Sign *si; - FOR_ALL_SIGNS(si) { + for (Sign *si : Sign::Iterate()) { if (si->owner == old_owner) si->owner = new_owner == INVALID_OWNER ? OWNER_NONE : new_owner; } diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index d175b612f7..f4e81b75bb 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -1990,8 +1990,7 @@ bool AfterLoadGame() UpdateNearestTownForRoadTiles(false); /* signs with invalid owner left from older savegames */ - Sign *si; - FOR_ALL_SIGNS(si) { + for (Sign *si : Sign::Iterate()) { if (si->owner != OWNER_NONE && !Company::IsValidID(si->owner)) si->owner = OWNER_NONE; } diff --git a/src/saveload/signs_sl.cpp b/src/saveload/signs_sl.cpp index 33be36d9c7..0be96e9821 100644 --- a/src/saveload/signs_sl.cpp +++ b/src/saveload/signs_sl.cpp @@ -32,9 +32,7 @@ static const SaveLoad _sign_desc[] = { /** Save all signs */ static void Save_SIGN() { - Sign *si; - - FOR_ALL_SIGNS(si) { + for (Sign *si : Sign::Iterate()) { SlSetArrayIndex(si->index); SlObject(si, _sign_desc); } diff --git a/src/script/api/script_signlist.cpp b/src/script/api/script_signlist.cpp index 7288d7568c..c64891a903 100644 --- a/src/script/api/script_signlist.cpp +++ b/src/script/api/script_signlist.cpp @@ -16,8 +16,7 @@ ScriptSignList::ScriptSignList() { - Sign *s; - FOR_ALL_SIGNS(s) { + for (const Sign *s : Sign::Iterate()) { if (ScriptSign::IsValidSign(s->index)) this->AddItem(s->index); } } diff --git a/src/signs.cpp b/src/signs.cpp index c42644269a..f477ab7641 100644 --- a/src/signs.cpp +++ b/src/signs.cpp @@ -59,9 +59,7 @@ void Sign::UpdateVirtCoord() /** Update the coordinates of all signs */ void UpdateAllSignVirtCoords() { - Sign *si; - - FOR_ALL_SIGNS(si) { + for (Sign *si : Sign::Iterate()) { si->UpdateVirtCoord(); } } diff --git a/src/signs_base.h b/src/signs_base.h index e92a05e2f6..6cc7dc6d80 100644 --- a/src/signs_base.h +++ b/src/signs_base.h @@ -32,7 +32,4 @@ struct Sign : SignPool::PoolItem<&_sign_pool> { void UpdateVirtCoord(); }; -#define FOR_ALL_SIGNS_FROM(var, start) FOR_ALL_ITEMS_FROM(Sign, sign_index, var, start) -#define FOR_ALL_SIGNS(var) FOR_ALL_SIGNS_FROM(var, 0) - #endif /* SIGNS_BASE_H */ diff --git a/src/signs_gui.cpp b/src/signs_gui.cpp index 9bd64b7d1b..ea3de70085 100644 --- a/src/signs_gui.cpp +++ b/src/signs_gui.cpp @@ -60,8 +60,7 @@ struct SignList { this->signs.clear(); - const Sign *si; - FOR_ALL_SIGNS(si) this->signs.push_back(si); + for (const Sign *si : Sign::Iterate()) this->signs.push_back(si); this->signs.SetFilterState(true); this->FilterSignList(); diff --git a/src/viewport.cpp b/src/viewport.cpp index 27bbdad517..fa590354b6 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -2260,8 +2260,7 @@ void RebuildViewportKdtree() if (town->cache.sign.kdtree_valid) items.push_back(ViewportSignKdtreeItem::MakeTown(town->index)); } - const Sign *sign; - FOR_ALL_SIGNS(sign) { + for (const Sign *sign : Sign::Iterate()) { if (sign->sign.kdtree_valid) items.push_back(ViewportSignKdtreeItem::MakeSign(sign->index)); }