From 08abf46d43906b081a487373d6e75556cbb14a72 Mon Sep 17 00:00:00 2001 From: Henry Wilson Date: Sat, 30 Dec 2017 23:31:35 +0000 Subject: [PATCH 24/31] StationList ~> std::vector --- src/industry_cmd.cpp | 4 ++-- src/newgrf_house.cpp | 3 +-- src/script/api/script_industry.cpp | 2 +- src/station_cmd.cpp | 6 ++---- src/station_type.h | 2 +- 5 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index 9c98b120c..440be96fa 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -2391,7 +2391,7 @@ static int WhoCanServiceIndustry(Industry *ind) StationList stations; FindStationsAroundTiles(ind->location, &stations); - if (stations.Length() == 0) return 0; // No stations found at all => nobody services + if (stations.empty()) return 0; // No stations found at all => nobody services const Vehicle *v; int result = 0; @@ -2427,7 +2427,7 @@ static int WhoCanServiceIndustry(Industry *ind) /* Same cargo produced by industry is dropped here => not serviced by vehicle v */ if ((o->GetUnloadType() & OUFB_UNLOAD) && !c_accepts) break; - if (stations.Contains(st)) { + if (Contains(stations, st)) { if (v->owner == _local_company) return 2; // Company services industry result = 1; // Competitor services industry } diff --git a/src/newgrf_house.cpp b/src/newgrf_house.cpp index bcd83f2f1..23e721ddd 100644 --- a/src/newgrf_house.cpp +++ b/src/newgrf_house.cpp @@ -372,8 +372,7 @@ static uint32 GetDistanceFromNearbyHouse(uint8 parameter, TileIndex tile, HouseI /* Collect acceptance stats. */ uint32 res = 0; - for (Station * const * st_iter = sl->Begin(); st_iter != sl->End(); st_iter++) { - const Station *st = *st_iter; + for (const auto &st : *sl) { if (HasBit(st->goods[cid].status, GoodsEntry::GES_EVER_ACCEPTED)) SetBit(res, 0); if (HasBit(st->goods[cid].status, GoodsEntry::GES_LAST_MONTH)) SetBit(res, 1); if (HasBit(st->goods[cid].status, GoodsEntry::GES_CURRENT_MONTH)) SetBit(res, 2); diff --git a/src/script/api/script_industry.cpp b/src/script/api/script_industry.cpp index c536ec559..b9025307b 100644 --- a/src/script/api/script_industry.cpp +++ b/src/script/api/script_industry.cpp @@ -134,7 +134,7 @@ Industry *ind = ::Industry::Get(industry_id); StationList stations; ::FindStationsAroundTiles(ind->location, &stations); - return (int32)stations.Length(); + return (int32)stations.size(); } /* static */ int32 ScriptIndustry::GetDistanceManhattanToTile(IndustryID industry_id, TileIndex tile) diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 5fd865a0d..12d5c635d 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -3814,7 +3814,7 @@ void FindStationsAroundTiles(const TileArea &location, StationList *stations) /* Insert the station in the set. This will fail if it has * already been added. */ - stations->Include(st); + Include(*stations, st); } } } @@ -3842,9 +3842,7 @@ uint MoveGoodsToStation(CargoID type, uint amount, SourceType source_type, Sourc uint best_rating1 = 0; // rating of st1 uint best_rating2 = 0; // rating of st2 - for (Station * const *st_iter = all_stations->Begin(); st_iter != all_stations->End(); ++st_iter) { - Station *st = *st_iter; - + for (auto &st : *all_stations) { /* Is the station reserved exclusively for somebody else? */ if (st->town->exclusive_counter > 0 && st->town->exclusivity != st->owner) continue; diff --git a/src/station_type.h b/src/station_type.h index 952a683d7..759b395f9 100644 --- a/src/station_type.h +++ b/src/station_type.h @@ -95,7 +95,7 @@ static const uint MAX_LENGTH_STATION_NAME_CHARS = 32; ///< The maximum length of typedef std::list StationIDList; /** List of stations */ -typedef SmallVector StationList; +using StationList = std::vector; /** * Structure contains cached list of stations nearby. The list -- 2.14.1