diff options
author | smatz <smatz@openttd.org> | 2009-05-22 14:23:36 +0000 |
---|---|---|
committer | smatz <smatz@openttd.org> | 2009-05-22 14:23:36 +0000 |
commit | 04723b240ebc7384954f73590be517ad2a47ce04 (patch) | |
tree | ac4bd41288d9d96a256ea0c702d1a75502bfecd9 | |
parent | b687ac51ee5e8628ed56319df573c903c0c86ef3 (diff) | |
download | openttd-04723b240ebc7384954f73590be517ad2a47ce04.tar.xz |
(svn r16377) -Codechange: unify FOR_ALL_* macros, use separate index variable instead of var->index
-rw-r--r-- | src/autoreplace_base.h | 4 | ||||
-rw-r--r-- | src/cargopacket.h | 8 | ||||
-rw-r--r-- | src/company_base.h | 4 | ||||
-rw-r--r-- | src/depot_base.h | 4 | ||||
-rw-r--r-- | src/engine_base.h | 4 | ||||
-rw-r--r-- | src/group.h | 4 | ||||
-rw-r--r-- | src/industry.h | 4 | ||||
-rw-r--r-- | src/network/core/tcp_game.h | 4 | ||||
-rw-r--r-- | src/network/network_base.h | 4 | ||||
-rw-r--r-- | src/oldpool.h | 6 | ||||
-rw-r--r-- | src/order_base.h | 8 | ||||
-rw-r--r-- | src/signs_base.h | 4 | ||||
-rw-r--r-- | src/station_base.h | 8 | ||||
-rw-r--r-- | src/town.h | 4 | ||||
-rw-r--r-- | src/vehicle_base.h | 5 | ||||
-rw-r--r-- | src/waypoint.h | 4 |
16 files changed, 42 insertions, 37 deletions
diff --git a/src/autoreplace_base.h b/src/autoreplace_base.h index 500f9595a..5037c16f0 100644 --- a/src/autoreplace_base.h +++ b/src/autoreplace_base.h @@ -34,7 +34,7 @@ struct EngineRenew : PoolItem<EngineRenew, EngineRenewID, &_EngineRenew_pool> { inline bool IsValid() const { return this->from != INVALID_ENGINE; } }; -#define FOR_ALL_ENGINE_RENEWS_FROM(er, start) for (er = EngineRenew::Get(start); er != NULL; er = (er->index + 1U < EngineRenew::GetPoolSize()) ? EngineRenew::Get(er->index + 1U) : NULL) if (er->IsValid()) -#define FOR_ALL_ENGINE_RENEWS(er) FOR_ALL_ENGINE_RENEWS_FROM(er, 0) +#define FOR_ALL_ENGINE_RENEWS_FROM(var, start) FOR_ALL_ITEMS_FROM(EngineRenew, enginerenew_index, var, start) +#define FOR_ALL_ENGINE_RENEWS(var) FOR_ALL_ENGINE_RENEWS_FROM(var, 0) #endif /* AUTOREPLACE_BASE_H */ diff --git a/src/cargopacket.h b/src/cargopacket.h index 74b9287b7..739e7f3ed 100644 --- a/src/cargopacket.h +++ b/src/cargopacket.h @@ -60,16 +60,16 @@ struct CargoPacket : PoolItem<CargoPacket, CargoPacketID, &_CargoPacket_pool> { /** * Iterate over all _valid_ cargo packets from the given start - * @param cp the variable used as "iterator" + * @param var the variable used as "iterator" * @param start the cargo packet ID of the first packet to iterate over */ -#define FOR_ALL_CARGOPACKETS_FROM(cp, start) for (cp = CargoPacket::Get(start); cp != NULL; cp = (cp->index + 1U < CargoPacket::GetPoolSize()) ? CargoPacket::Get(cp->index + 1U) : NULL) if (cp->IsValid()) +#define FOR_ALL_CARGOPACKETS_FROM(var, start) FOR_ALL_ITEMS_FROM(CargoPacket, cargopacket_index, var, start) /** * Iterate over all _valid_ cargo packets from the begin of the pool - * @param cp the variable used as "iterator" + * @param var the variable used as "iterator" */ -#define FOR_ALL_CARGOPACKETS(cp) FOR_ALL_CARGOPACKETS_FROM(cp, 0) +#define FOR_ALL_CARGOPACKETS(var) FOR_ALL_CARGOPACKETS_FROM(var, 0) extern const struct SaveLoad *GetGoodsDesc(); diff --git a/src/company_base.h b/src/company_base.h index ecfb61fef..bffe89b11 100644 --- a/src/company_base.h +++ b/src/company_base.h @@ -90,8 +90,8 @@ struct Company : PoolItem<Company, CompanyByte, &_Company_pool> { } }; -#define FOR_ALL_COMPANIES_FROM(d, start) for (d = Company::Get(start); d != NULL; d = (d->index + 1U < Company::GetPoolSize()) ? Company::Get(d->index + 1U) : NULL) if (d->IsValid()) -#define FOR_ALL_COMPANIES(d) FOR_ALL_COMPANIES_FROM(d, 0) +#define FOR_ALL_COMPANIES_FROM(var, start) FOR_ALL_ITEMS_FROM(Company, company_index, var, start) +#define FOR_ALL_COMPANIES(var) FOR_ALL_COMPANIES_FROM(var, 0) static inline byte ActiveCompanyCount() { diff --git a/src/depot_base.h b/src/depot_base.h index b22b7e50f..350eaee8f 100644 --- a/src/depot_base.h +++ b/src/depot_base.h @@ -24,7 +24,7 @@ struct Depot : PoolItem<Depot, DepotID, &_Depot_pool> { Depot *GetDepotByTile(TileIndex tile); -#define FOR_ALL_DEPOTS_FROM(d, start) for (d = Depot::Get(start); d != NULL; d = (d->index + 1U < Depot::GetPoolSize()) ? Depot::Get(d->index + 1U) : NULL) if (d->IsValid()) -#define FOR_ALL_DEPOTS(d) FOR_ALL_DEPOTS_FROM(d, 0) +#define FOR_ALL_DEPOTS_FROM(var, start) FOR_ALL_ITEMS_FROM(Depot, depot_index, var, start) +#define FOR_ALL_DEPOTS(var) FOR_ALL_DEPOTS_FROM(var, 0) #endif /* DEPOT_BASE_H */ diff --git a/src/engine_base.h b/src/engine_base.h index 8e71c573d..e3e055164 100644 --- a/src/engine_base.h +++ b/src/engine_base.h @@ -82,8 +82,8 @@ struct EngineOverrideManager : SmallVector<EngineIDMapping, 256> { extern EngineOverrideManager _engine_mngr; -#define FOR_ALL_ENGINES_FROM(e, start) for (e = Engine::Get(start); e != NULL; e = (e->index + 1U < Engine::GetPoolSize()) ? Engine::Get(e->index + 1U) : NULL) if (e->IsValid()) -#define FOR_ALL_ENGINES(e) FOR_ALL_ENGINES_FROM(e, 0) +#define FOR_ALL_ENGINES_FROM(var, start) FOR_ALL_ITEMS_FROM(Engine, engine_index, var, start) +#define FOR_ALL_ENGINES(var) FOR_ALL_ENGINES_FROM(var, 0) #define FOR_ALL_ENGINES_OF_TYPE(e, engine_type) FOR_ALL_ENGINES(e) if (e->type == engine_type) diff --git a/src/group.h b/src/group.h index 364514f56..193568ca0 100644 --- a/src/group.h +++ b/src/group.h @@ -45,8 +45,8 @@ static inline bool IsAllGroupID(GroupID id_g) return id_g == ALL_GROUP; } -#define FOR_ALL_GROUPS_FROM(g, start) for (g = Group::Get(start); g != NULL; g = (g->index + 1U < Group::GetPoolSize()) ? Group::Get(g->index + 1) : NULL) if (g->IsValid()) -#define FOR_ALL_GROUPS(g) FOR_ALL_GROUPS_FROM(g, 0) +#define FOR_ALL_GROUPS_FROM(var, start) FOR_ALL_ITEMS_FROM(Group, group_index, var, start) +#define FOR_ALL_GROUPS(var) FOR_ALL_GROUPS_FROM(var, 0) /** * Get the current size of the GroupPool diff --git a/src/industry.h b/src/industry.h index 988d6e0bb..a99e8fc09 100644 --- a/src/industry.h +++ b/src/industry.h @@ -334,8 +334,8 @@ static inline Industry *GetRandomIndustry() return Industry::Get(index); } -#define FOR_ALL_INDUSTRIES_FROM(i, start) for (i = Industry::Get(start); i != NULL; i = (i->index + 1U < Industry::GetPoolSize()) ? Industry::Get(i->index + 1U) : NULL) if (i->IsValid()) -#define FOR_ALL_INDUSTRIES(i) FOR_ALL_INDUSTRIES_FROM(i, 0) +#define FOR_ALL_INDUSTRIES_FROM(var, start) FOR_ALL_ITEMS_FROM(Industry, industry_index, var, start) +#define FOR_ALL_INDUSTRIES(var) FOR_ALL_INDUSTRIES_FROM(var, 0) static const uint8 IT_INVALID = 255; diff --git a/src/network/core/tcp_game.h b/src/network/core/tcp_game.h index 3bbb3ac0a..bfc82f17f 100644 --- a/src/network/core/tcp_game.h +++ b/src/network/core/tcp_game.h @@ -108,8 +108,8 @@ public: void Send_Command(Packet *p, const CommandPacket *cp); }; -#define FOR_ALL_CLIENT_SOCKETS_FROM(d, start) for (d = NetworkClientSocket::Get(start); d != NULL; d = (d->index + 1U < NetworkClientSocket::GetPoolSize()) ? NetworkClientSocket::Get(d->index + 1U) : NULL) if (d->IsValid()) -#define FOR_ALL_CLIENT_SOCKETS(d) FOR_ALL_CLIENT_SOCKETS_FROM(d, 0) +#define FOR_ALL_CLIENT_SOCKETS_FROM(var, start) FOR_ALL_ITEMS_FROM(NetworkClientSocket, clientsocket_index, var, start) +#define FOR_ALL_CLIENT_SOCKETS(var) FOR_ALL_CLIENT_SOCKETS_FROM(var, 0) #endif /* ENABLE_NETWORK */ diff --git a/src/network/network_base.h b/src/network/network_base.h index 929c4b7ba..700541b49 100644 --- a/src/network/network_base.h +++ b/src/network/network_base.h @@ -27,8 +27,8 @@ struct NetworkClientInfo : PoolItem<NetworkClientInfo, ClientIndex, &_NetworkCli inline bool IsValid() const { return client_id != INVALID_CLIENT_ID; } }; -#define FOR_ALL_CLIENT_INFOS_FROM(d, start) for (d = NetworkClientInfo::Get(start); d != NULL; d = (d->index + 1U < NetworkClientInfo::GetPoolSize()) ? NetworkClientInfo::Get(d->index + 1U) : NULL) if (d->IsValid()) -#define FOR_ALL_CLIENT_INFOS(d) FOR_ALL_CLIENT_INFOS_FROM(d, 0) +#define FOR_ALL_CLIENT_INFOS_FROM(var, start) FOR_ALL_ITEMS_FROM(NetworkClientInfo, clientinfo_index, var, start) +#define FOR_ALL_CLIENT_INFOS(var) FOR_ALL_CLIENT_INFOS_FROM(var, 0) #endif /* ENABLE_NETWORK */ #endif /* NETWORK_BASE_H */ diff --git a/src/oldpool.h b/src/oldpool.h index ab496d2c3..17b791ed7 100644 --- a/src/oldpool.h +++ b/src/oldpool.h @@ -376,4 +376,10 @@ public: template type *PoolItem<type, type##ID, &_##name##_pool>::AllocateSafeRaw(uint &first); \ template bool PoolItem<type, type##ID, &_##name##_pool>::CanAllocateItem(uint count); +#define FOR_ALL_ITEMS_FROM(type, iter, var, start) \ + for (size_t iter = start; var = NULL, iter < type::GetPoolSize(); iter++) \ + if ((var = type::Get(iter))->IsValid()) + +#define FOR_ALL_ITEMS(type, iter, var) FOR_ALL_ITEMS_FROM(type, iter, var, 0) + #endif /* OLDPOOL_H */ diff --git a/src/order_base.h b/src/order_base.h index f239fdff0..544c31b2d 100644 --- a/src/order_base.h +++ b/src/order_base.h @@ -406,14 +406,14 @@ public: void DebugCheckSanity() const; }; -#define FOR_ALL_ORDERS_FROM(order, start) for (order = Order::Get(start); order != NULL; order = (order->index + 1U < Order::GetPoolSize()) ? Order::Get(order->index + 1U) : NULL) if (order->IsValid()) -#define FOR_ALL_ORDERS(order) FOR_ALL_ORDERS_FROM(order, 0) +#define FOR_ALL_ORDERS_FROM(var, start) FOR_ALL_ITEMS_FROM(Order, order_index, var, start) +#define FOR_ALL_ORDERS(var) FOR_ALL_ORDERS_FROM(var, 0) #define FOR_VEHICLE_ORDERS(v, order) for (order = (v->orders.list == NULL) ? NULL : v->orders.list->GetFirstOrder(); order != NULL; order = order->next) -#define FOR_ALL_ORDER_LISTS_FROM(ol, start) for (ol = OrderList::Get(start); ol != NULL; ol = (ol->index + 1U < OrderList::GetPoolSize()) ? OrderList::Get(ol->index + 1U) : NULL) if (ol->IsValid()) -#define FOR_ALL_ORDER_LISTS(ol) FOR_ALL_ORDER_LISTS_FROM(ol, 0) +#define FOR_ALL_ORDER_LISTS_FROM(var, start) FOR_ALL_ITEMS_FROM(OrderList, orderlist_index, var, start) +#define FOR_ALL_ORDER_LISTS(var) FOR_ALL_ORDER_LISTS_FROM(var, 0) #endif /* ORDER_H */ diff --git a/src/signs_base.h b/src/signs_base.h index dd8d13bf0..e037fdc44 100644 --- a/src/signs_base.h +++ b/src/signs_base.h @@ -31,7 +31,7 @@ struct Sign : PoolItem<Sign, SignID, &_Sign_pool> { inline bool IsValid() const { return this->owner != INVALID_OWNER; } }; -#define FOR_ALL_SIGNS_FROM(ss, start) for (ss = Sign::Get(start); ss != NULL; ss = (ss->index + 1U < Sign::GetPoolSize()) ? Sign::Get(ss->index + 1U) : NULL) if (ss->IsValid()) -#define FOR_ALL_SIGNS(ss) FOR_ALL_SIGNS_FROM(ss, 0) +#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/station_base.h b/src/station_base.h index 2fa332a70..218f1aa9e 100644 --- a/src/station_base.h +++ b/src/station_base.h @@ -204,14 +204,14 @@ public: uint GetCatchmentRadius() const; }; -#define FOR_ALL_STATIONS_FROM(st, start) for (st = Station::Get(start); st != NULL; st = (st->index + 1U < Station::GetPoolSize()) ? Station::Get(st->index + 1U) : NULL) if (st->IsValid()) -#define FOR_ALL_STATIONS(st) FOR_ALL_STATIONS_FROM(st, 0) +#define FOR_ALL_STATIONS_FROM(var, start) FOR_ALL_ITEMS_FROM(Station, station_index, var, start) +#define FOR_ALL_STATIONS(var) FOR_ALL_STATIONS_FROM(var, 0) /* Stuff for ROADSTOPS */ -#define FOR_ALL_ROADSTOPS_FROM(rs, start) for (rs = RoadStop::Get(start); rs != NULL; rs = (rs->index + 1U < RoadStop::GetPoolSize()) ? RoadStop::Get(rs->index + 1U) : NULL) if (rs->IsValid()) -#define FOR_ALL_ROADSTOPS(rs) FOR_ALL_ROADSTOPS_FROM(rs, 0) +#define FOR_ALL_ROADSTOPS_FROM(var, start) FOR_ALL_ITEMS_FROM(RoadStop, roadstop_index, var, start) +#define FOR_ALL_ROADSTOPS(var) FOR_ALL_ROADSTOPS_FROM(var, 0) /* End of stuff for ROADSTOPS */ diff --git a/src/town.h b/src/town.h index d653fa59e..ead399d0c 100644 --- a/src/town.h +++ b/src/town.h @@ -326,8 +326,8 @@ static inline Town *GetRandomTown() Town *CalcClosestTownFromTile(TileIndex tile, uint threshold = UINT_MAX); -#define FOR_ALL_TOWNS_FROM(t, start) for (t = Town::Get(start); t != NULL; t = (t->index + 1U < Town::GetPoolSize()) ? Town::Get(t->index + 1U) : NULL) if (t->IsValid()) -#define FOR_ALL_TOWNS(t) FOR_ALL_TOWNS_FROM(t, 0) +#define FOR_ALL_TOWNS_FROM(var, start) FOR_ALL_ITEMS_FROM(Town, town_index, var, start) +#define FOR_ALL_TOWNS(var) FOR_ALL_TOWNS_FROM(var, 0) extern Town *_cleared_town; extern int _cleared_town_rating; diff --git a/src/vehicle_base.h b/src/vehicle_base.h index e602cc4ed..087833cb6 100644 --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -642,9 +642,8 @@ struct InvalidVehicle : public Vehicle { const char *GetTypeString() const { return "invalid vehicle"; } }; -#define FOR_ALL_VEHICLES_FROM(v, start) for (v = Vehicle::Get(start); v != NULL; v = (v->index + 1U < Vehicle::GetPoolSize()) ? Vehicle::Get(v->index + 1) : NULL) if (v->IsValid()) -#define FOR_ALL_VEHICLES(v) FOR_ALL_VEHICLES_FROM(v, 0) - +#define FOR_ALL_VEHICLES_FROM(var, start) FOR_ALL_ITEMS_FROM(Vehicle, vehicle_index, var, start) +#define FOR_ALL_VEHICLES(var) FOR_ALL_VEHICLES_FROM(var, 0) /** Generates sequence of free UnitID numbers */ struct FreeUnitIDGenerator { diff --git a/src/waypoint.h b/src/waypoint.h index eedef025b..7e6f9f12a 100644 --- a/src/waypoint.h +++ b/src/waypoint.h @@ -40,8 +40,8 @@ struct Waypoint : PoolItem<Waypoint, WaypointID, &_Waypoint_pool> { inline bool IsValid() const { return this->xy != INVALID_TILE; } }; -#define FOR_ALL_WAYPOINTS_FROM(wp, start) for (wp = Waypoint::Get(start); wp != NULL; wp = (wp->index + 1U < Waypoint::GetPoolSize()) ? Waypoint::Get(wp->index + 1U) : NULL) if (wp->IsValid()) -#define FOR_ALL_WAYPOINTS(wp) FOR_ALL_WAYPOINTS_FROM(wp, 0) +#define FOR_ALL_WAYPOINTS_FROM(var, start) FOR_ALL_ITEMS_FROM(Waypoint, waypoint_index, var, start) +#define FOR_ALL_WAYPOINTS(var) FOR_ALL_WAYPOINTS_FROM(var, 0) /** |