Simple collection class for a list of cargo packets. More...
#include <cargopacket.h>
Public Types | |
typedef Tcont::iterator | Iterator |
Iterator for our container. | |
typedef Tcont::const_iterator | ConstIterator |
Const iterator for our container. | |
typedef Tcont::reverse_iterator | ReverseIterator |
Reverse iterator for our container. | |
typedef Tcont::const_reverse_iterator | ConstReverseIterator |
Const reverse iterator for our container. | |
Public Member Functions | |
CargoList () | |
Create the cargo list. | |
~CargoList () | |
Destroy the cargolist ("frees" all cargo packets). | |
void | OnCleanPool () |
Empty the cargo list, but don't free the cargo packets; the cargo packets are cleaned by CargoPacket's CleanPool. | |
FORCEINLINE const Tcont * | Packets () const |
Returns a pointer to the cargo packet list (so you can iterate over it etc). | |
FORCEINLINE bool | Empty () const |
Checks whether this list is empty. | |
FORCEINLINE uint | Count () const |
Returns the number of cargo entities in this list. | |
FORCEINLINE uint | DaysInTransit () const |
Returns average number of days in transit for a cargo entity. | |
void | Truncate (uint max_remaining) |
Truncates the cargo in this list to the given amount. | |
void | InvalidateCache () |
Invalidates the cached data and rebuilds it. | |
Protected Member Functions | |
void | AddToCache (const CargoPacket *cp) |
Update the cache to reflect adding of this packet. | |
void | RemoveFromCache (const CargoPacket *cp) |
Update the cached values to reflect the removal of this packet. | |
CargoPacket * | RemovePacket (Iterator &it, uint cap, TileIndex load_place=INVALID_TILE) |
Remove a single packet or part of it from this list and increment the given iterator. | |
uint | MovePacket (StationCargoList *dest, StationID next, Iterator &it, uint cap) |
Move a single packet or part of it from this list to a station and increment the given iterator. | |
uint | MovePacket (VehicleCargoList *dest, Iterator &it, uint cap, TileIndex load_place=INVALID_TILE, bool reserved=false) |
Move a single packet or part of it from this list to a vehicle and increment the given iterator. | |
Protected Attributes | |
uint | count |
Cache for the number of cargo entities. | |
uint | cargo_days_in_transit |
Cache for the sum of number of days in transit of each entity; comparable to man-hours. | |
Tcont | packets |
The cargo packets in this list. |
Simple collection class for a list of cargo packets.
Tinst | Actual instantation of this cargo list. |
Definition at line 179 of file cargopacket.h.
typedef Tcont::const_iterator CargoList< Tinst, Tcont >::ConstIterator |
Const iterator for our container.
Definition at line 184 of file cargopacket.h.
typedef Tcont::const_reverse_iterator CargoList< Tinst, Tcont >::ConstReverseIterator |
Const reverse iterator for our container.
Definition at line 188 of file cargopacket.h.
Iterator for our container.
Definition at line 182 of file cargopacket.h.
typedef Tcont::reverse_iterator CargoList< Tinst, Tcont >::ReverseIterator |
Reverse iterator for our container.
Definition at line 186 of file cargopacket.h.
Create the cargo list.
Definition at line 208 of file cargopacket.h.
void CargoList< Tinst, Tcont >::AddToCache | ( | const CargoPacket * | cp | ) | [protected] |
Update the cache to reflect adding of this packet.
Increases count and days_in_transit.
cp | New packet to be inserted. |
Reimplemented in VehicleCargoList.
Definition at line 179 of file cargopacket.cpp.
References CargoList< Tinst, Tcont >::cargo_days_in_transit, CargoPacket::count, CargoList< Tinst, Tcont >::count, and CargoPacket::days_in_transit.
Referenced by CargoList< Tinst, Tcont >::InvalidateCache().
FORCEINLINE uint CargoList< Tinst, Tcont >::Count | ( | ) | const [inline] |
Returns the number of cargo entities in this list.
Definition at line 236 of file cargopacket.h.
Referenced by AfterLoadGame(), Vehicle::Crash(), DrawRoadVehDetails(), DrawShipDetails(), CompanyStationsWindow::DrawWidget(), GetCargoSummaryOfArticulatedVehicle(), Vehicle::GetConsistFreeCapacities(), Train::GetImage(), RoadVehicle::GetImage(), Train::GetWeight(), RoadVehicle::GetWeight(), IncreaseStats(), LoadUnloadVehicle(), and TransferCargo().
FORCEINLINE uint CargoList< Tinst, Tcont >::DaysInTransit | ( | ) | const [inline] |
Returns average number of days in transit for a cargo entity.
Definition at line 245 of file cargopacket.h.
FORCEINLINE bool CargoList< Tinst, Tcont >::Empty | ( | ) | const [inline] |
Checks whether this list is empty.
Definition at line 227 of file cargopacket.h.
Referenced by DrawRoadVehDetails(), DrawShipDetails(), CompanyStationsWindow::DrawWidget(), and LoadUnloadVehicle().
uint CargoList< Tinst, Tcont >::MovePacket | ( | StationCargoList< Tinst, Tcont > * | dest, | |
StationID | next, | |||
Iterator & | it, | |||
uint | cap | |||
) | [protected] |
Move a single packet or part of it from this list to a station and increment the given iterator.
dest | Station cargo list to move to. | |
next | Next station the packet will travel to. | |
it | Iterator pointing to the packet. | |
cap | Maximum amount of cargo to be moved. |
Definition at line 333 of file cargopacket.cpp.
References StationCargoList::Append(), CargoPacket::count, and CargoList< Tinst, Tcont >::RemovePacket().
uint CargoList< Tinst, Tcont >::MovePacket | ( | VehicleCargoList< Tinst, Tcont > * | dest, | |
Iterator & | it, | |||
uint | cap, | |||
TileIndex | load_place = INVALID_TILE , |
|||
bool | reserve = false | |||
) | [protected] |
Move a single packet or part of it from this list to a vehicle and increment the given iterator.
dest | Vehicle cargo list to move to. | |
it | Iterator pointing to the packet. | |
cap | Maximum amount of cargo to be moved. | |
load_place | New loaded_at for the packet. | |
reserve | If the packet should be loaded on or reserved for the vehicle. |
Definition at line 311 of file cargopacket.cpp.
References VehicleCargoList::Append(), CargoPacket::count, CargoList< Tinst, Tcont >::RemovePacket(), and VehicleCargoList::Reserve().
FORCEINLINE const Tcont* CargoList< Tinst, Tcont >::Packets | ( | ) | const [inline] |
Returns a pointer to the cargo packet list (so you can iterate over it etc).
Definition at line 218 of file cargopacket.h.
Referenced by CargoPacket::AfterLoad(), StationViewWindow::BuildCargoList(), OrderList::GetBestLoadableNext(), and SwapPackets().
void CargoList< Tinst, Tcont >::RemoveFromCache | ( | const CargoPacket * | cp | ) | [protected] |
Update the cached values to reflect the removal of this packet.
Decreases count and days_in_transit.
cp | Packet to be removed from cache. |
Reimplemented in VehicleCargoList.
Definition at line 167 of file cargopacket.cpp.
References CargoList< Tinst, Tcont >::cargo_days_in_transit, CargoPacket::count, CargoList< Tinst, Tcont >::count, and CargoPacket::days_in_transit.
Referenced by CargoList< Tinst, Tcont >::RemovePacket(), and CargoList< Tinst, Tcont >::Truncate().
CargoPacket * CargoList< Tinst, Tcont >::RemovePacket | ( | Iterator & | it, | |
uint | cap, | |||
TileIndex | load_place = INVALID_TILE | |||
) | [protected] |
Remove a single packet or part of it from this list and increment the given iterator.
it | Iterator pointing to the packet. | |
cap | Maximum amount of cargo to be moved. | |
load_place | New loaded_at for the packet or INVALID_TILE if the current one shall be kept. |
Definition at line 351 of file cargopacket.cpp.
References CargoList< Tinst, Tcont >::cargo_days_in_transit, CargoList< Tinst, Tcont >::count, CargoPacket::count, CargoPacket::days_in_transit, INVALID_TILE, CargoPacket::loaded_at_xy, CargoList< Tinst, Tcont >::packets, CargoList< Tinst, Tcont >::RemoveFromCache(), and CargoPacket::Split().
Referenced by CargoList< Tinst, Tcont >::MovePacket().
void CargoList< Tinst, Tcont >::Truncate | ( | uint | max_remaining | ) |
Truncates the cargo in this list to the given amount.
It leaves the first count cargo entities and removes the rest.
max_remaining | Maximum amount of entities to be in the list after the command. |
Definition at line 217 of file cargopacket.cpp.
References CargoList< Tinst, Tcont >::cargo_days_in_transit, CargoList< Tinst, Tcont >::count, CargoPacket::count, CargoPacket::days_in_transit, CargoList< Tinst, Tcont >::packets, and CargoList< Tinst, Tcont >::RemoveFromCache().
Referenced by CrashAirplane(), MaybeCrashAirplane(), Vehicle::PreDestructor(), RefitVehicle(), and Station::~Station().