From 0718124de864ded5419986ba85bedf9f7cfe083d Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sat, 19 Jul 2025 10:32:09 +0100 Subject: [PATCH 1/2] Codechange: Allow SmallStack Titem type to be non-structural --- src/core/smallstack_type.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/smallstack_type.hpp b/src/core/smallstack_type.hpp index 1a88f0df1a..3b26951453 100644 --- a/src/core/smallstack_type.hpp +++ b/src/core/smallstack_type.hpp @@ -113,13 +113,14 @@ struct SmallStackItem { * index types of the same length. * @tparam Titem Value type to be used. * @tparam Tindex Index type to use for the pool. - * @tparam Tinvalid Invalid item to keep at the bottom of each stack. + * @tparam Tinvalid_value Value to construct invalid item to keep at the bottom of each stack. * @tparam Tgrowth_step Growth step for pool. * @tparam Tmax_size Maximum size for pool. */ -template +template class SmallStack : public SmallStackItem { public: + static constexpr Titem Tinvalid{Tinvalid_value}; typedef SmallStackItem Item; From 33dbebbbeeaab714ab63ca2c01a77e2fb10459ed Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sat, 19 Jul 2025 10:48:03 +0100 Subject: [PATCH 2/2] Codechange: Use StationID as StationIDStack Titem type --- src/cargopacket.cpp | 8 ++++---- src/cargopacket.h | 2 +- src/linkgraph/linkgraphjob.cpp | 2 +- src/order_cmd.cpp | 6 +++--- src/station_cmd.cpp | 2 +- src/station_type.h | 2 +- src/vehicle_base.h | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/cargopacket.cpp b/src/cargopacket.cpp index 5dfe57c873..38d9489490 100644 --- a/src/cargopacket.cpp +++ b/src/cargopacket.cpp @@ -410,7 +410,7 @@ void VehicleCargoList::AgeCargo() return (accepted && cp->first_station != current_station) ? MTA_DELIVER : MTA_KEEP; } else if (cargo_next == current_station) { return MTA_DELIVER; - } else if (next_station.Contains(cargo_next.base())) { + } else if (next_station.Contains(cargo_next)) { return MTA_KEEP; } else { return MTA_TRANSFER; @@ -470,7 +470,7 @@ bool VehicleCargoList::Stage(bool accepted, StationID current_station, StationID new_shares.ChangeShare(current_station, INT_MIN); StationIDStack excluded = next_station; while (!excluded.IsEmpty() && !new_shares.GetShares()->empty()) { - new_shares.ChangeShare(StationID{excluded.Pop()}, INT_MIN); + new_shares.ChangeShare(excluded.Pop(), INT_MIN); } if (new_shares.GetShares()->empty()) { cargo_next = StationID::Invalid(); @@ -743,7 +743,7 @@ uint StationCargoList::ShiftCargo(Taction action, StationIDStack next, bool incl { uint max_move = action.MaxMove(); while (!next.IsEmpty()) { - this->ShiftCargo(action, StationID{next.Pop()}); + this->ShiftCargo(action, next.Pop()); if (action.MaxMove() == 0) break; } if (include_invalid && action.MaxMove() > 0) { @@ -853,7 +853,7 @@ uint StationCargoList::Load(uint max_move, VehicleCargoList *dest, StationIDStac */ uint StationCargoList::Reroute(uint max_move, StationCargoList *dest, StationID avoid, StationID avoid2, const GoodsEntry *ge) { - return this->ShiftCargo(StationCargoReroute(this, dest, max_move, avoid, avoid2, ge), avoid.base(), false); + return this->ShiftCargo(StationCargoReroute(this, dest, max_move, avoid, avoid2, ge), avoid, false); } /* diff --git a/src/cargopacket.h b/src/cargopacket.h index f5017e2846..0078eb6480 100644 --- a/src/cargopacket.h +++ b/src/cargopacket.h @@ -555,7 +555,7 @@ public: inline bool HasCargoFor(StationIDStack next) const { while (!next.IsEmpty()) { - if (this->packets.find(StationID{next.Pop()}) != this->packets.end()) return true; + if (this->packets.find(next.Pop()) != this->packets.end()) return true; } /* Packets for StationID::Invalid() can go anywhere. */ return this->packets.find(StationID::Invalid()) != this->packets.end(); diff --git a/src/linkgraph/linkgraphjob.cpp b/src/linkgraph/linkgraphjob.cpp index 900e9ea453..48321b9124 100644 --- a/src/linkgraph/linkgraphjob.cpp +++ b/src/linkgraph/linkgraphjob.cpp @@ -136,7 +136,7 @@ LinkGraphJob::~LinkGraphJob() /* Delete old flows for source stations which have been deleted * from the new flows. This avoids flow cycles between old and * new flows. */ - while (!erased.IsEmpty()) geflows.erase(StationID{erased.Pop()}); + while (!erased.IsEmpty()) geflows.erase(erased.Pop()); } else if ((*lg)[node_id][dest_id].last_unrestricted_update == EconomyTime::INVALID_DATE) { /* Edge is fully restricted. */ flows.RestrictFlows(to); diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index 7b4b675d3c..251f3e848c 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -368,7 +368,7 @@ StationIDStack OrderList::GetNextStoppingStation(const Vehicle *v, VehicleOrderI next = v->cur_implicit_order_index; if (next >= this->GetNumOrders()) { next = this->GetFirstOrder(); - if (next == INVALID_VEH_ORDER_ID) return StationID::Invalid().base(); + if (next == INVALID_VEH_ORDER_ID) return StationID::Invalid(); } else { /* GetNext never returns INVALID_VEH_ORDER_ID if there is a valid station in the list. * As the given "next" is already valid and a station in the list, we @@ -404,11 +404,11 @@ StationIDStack OrderList::GetNextStoppingStation(const Vehicle *v, VehicleOrderI if (next == INVALID_VEH_ORDER_ID || ((orders[next].IsType(OT_GOTO_STATION) || orders[next].IsType(OT_IMPLICIT)) && orders[next].GetDestination() == v->last_station_visited && (orders[next].GetUnloadType() & (OUFB_TRANSFER | OUFB_UNLOAD)) != 0)) { - return StationID::Invalid().base(); + return StationID::Invalid(); } } while (orders[next].IsType(OT_GOTO_DEPOT) || orders[next].GetDestination() == v->last_station_visited); - return orders[next].GetDestination().ToStationID().base(); + return orders[next].GetDestination().ToStationID(); } /** diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 2fce47d5d2..78b73b16b3 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -5079,7 +5079,7 @@ StationIDStack FlowStatMap::DeleteFlows(StationID via) FlowStat &s_flows = f_it->second; s_flows.ChangeShare(via, INT_MIN); if (s_flows.GetShares()->empty()) { - ret.Push(f_it->first.base()); + ret.Push(f_it->first); this->erase(f_it++); } else { ++f_it; diff --git a/src/station_type.h b/src/station_type.h index 9641556213..07615dd7a1 100644 --- a/src/station_type.h +++ b/src/station_type.h @@ -26,7 +26,7 @@ struct RoadStop; struct StationSpec; struct Waypoint; -using StationIDStack = SmallStack; +using StationIDStack = SmallStack; /** Station types */ enum class StationType : uint8_t { diff --git a/src/vehicle_base.h b/src/vehicle_base.h index 58c311e804..2067f23ee6 100644 --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -741,7 +741,7 @@ public: */ inline StationIDStack GetNextStoppingStation() const { - return (this->orders == nullptr) ? StationID::Invalid().base() : this->orders->GetNextStoppingStation(this); + return (this->orders == nullptr) ? StationID::Invalid() : this->orders->GetNextStoppingStation(this); } void ResetRefitCaps();