Simple collection class for a list of cargo packets. More...
#include <cargopacket.h>
Public Types | |
enum | MoveToAction { MTA_FINAL_DELIVERY, MTA_CARGO_LOAD, MTA_TRANSFER, MTA_UNLOAD } |
Kind of actions that could be done with packets on move. More... | |
typedef std::list< CargoPacket * > | List |
Container with cargo packets. | |
typedef List::iterator | Iterator |
The iterator for our container. | |
typedef List::const_iterator | ConstIterator |
The const 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. | |
const List * | Packets () const |
Returns a pointer to the cargo packet list (so you can iterate over it etc). | |
bool | Empty () const |
Checks whether this list is empty. | |
uint | Count () const |
Returns the number of cargo entities in this list. | |
StationID | Source () const |
Returns source of the first cargo packet in this list. | |
uint | DaysInTransit () const |
Returns average number of days in transit for a cargo entity. | |
void | Append (CargoPacket *cp) |
Appends the given cargo packet. | |
void | Truncate (uint max_remaining) |
Truncates the cargo in this list to the given amount. | |
template<class Tother_inst > | |
bool | MoveTo (Tother_inst *dest, uint count, MoveToAction mta, CargoPayment *payment, uint data=0) |
Moves the given amount of cargo to another list. | |
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. | |
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. | |
List | packets |
The cargo packets in this list. |
Simple collection class for a list of cargo packets.
Tinst | Actual instantiation of this cargo list. |
Definition at line 167 of file cargopacket.h.
typedef List::const_iterator CargoList< Tinst >::ConstIterator |
The const iterator for our container.
Definition at line 174 of file cargopacket.h.
The iterator for our container.
Definition at line 172 of file cargopacket.h.
typedef std::list<CargoPacket *> CargoList< Tinst >::List |
Container with cargo packets.
Definition at line 170 of file cargopacket.h.
enum CargoList::MoveToAction |
Kind of actions that could be done with packets on move.
Definition at line 177 of file cargopacket.h.
Create the cargo list.
Definition at line 196 of file cargopacket.h.
void CargoList< Tinst >::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 177 of file cargopacket.cpp.
References CargoList< Tinst >::cargo_days_in_transit, CargoPacket::count, CargoList< Tinst >::count, and CargoPacket::days_in_transit.
Referenced by CargoList< Tinst >::Append(), and CargoList< Tinst >::InvalidateCache().
void CargoList< Tinst >::Append | ( | CargoPacket * | cp | ) |
Appends the given cargo packet.
Tries to merge it with another one in the packets list. If no fitting packet is found, appends it.
cp | Cargo packet to add. |
Definition at line 192 of file cargopacket.cpp.
References CargoList< Tinst >::AddToCache(), CargoPacket::count, CargoPacket::MAX_COUNT, CargoPacket::Merge(), and CargoList< Tinst >::packets.
Referenced by Load_VEHS(), and LoadOldVehicle().
uint CargoList< Tinst >::Count | ( | ) | const [inline] |
Returns the number of cargo entities in this list.
Definition at line 224 of file cargopacket.h.
Referenced by AfterLoadGame(), CalcPercentVehicleFilled(), DrawRoadVehDetails(), DrawShipDetails(), CompanyStationsWindow::DrawWidget(), GetCargoSummaryOfArticulatedVehicle(), Train::GetImage(), RoadVehicle::GetImage(), Train::GetWeight(), RoadVehicle::GetWeight(), IsArticulatedVehicleEmpty(), LoadUnloadStation(), LoadUnloadVehicle(), StationViewWindow::OrderWaitingCargo(), StationResolverObject::ResolveReal(), VehicleResolverObject::ResolveReal(), and TransferCargo().
uint CargoList< Tinst >::DaysInTransit | ( | ) | const [inline] |
Returns average number of days in transit for a cargo entity.
Definition at line 242 of file cargopacket.h.
bool CargoList< Tinst >::Empty | ( | ) | const [inline] |
Checks whether this list is empty.
Definition at line 215 of file cargopacket.h.
Referenced by DrawRoadVehDetails(), DrawShipDetails(), StationViewWindow::DrawWaitingCargo(), CompanyStationsWindow::DrawWidget(), LoadUnloadVehicle(), StationViewWindow::OrderWaitingCargo(), CargoList< VehicleCargoList >::Source(), and TriggerStationRandomisation().
void CargoList< Tinst >::InvalidateCache | ( | ) |
Invalidates the cached data and rebuilds it.
Reimplemented in VehicleCargoList.
Definition at line 345 of file cargopacket.cpp.
References CargoList< Tinst >::AddToCache(), CargoList< Tinst >::cargo_days_in_transit, CargoList< Tinst >::count, and CargoList< Tinst >::packets.
Referenced by CargoPacket::AfterLoad(), and CheckCaches().
bool CargoList< Tinst >::MoveTo | ( | Tother_inst * | dest, | |
uint | max_move, | |||
MoveToAction | mta, | |||
CargoPayment * | payment, | |||
uint | data = 0 | |||
) |
Moves the given amount of cargo to another list.
Depending on the value of mta the side effects of this function differ:
dest | Destination to move the cargo to. | |
max_move | Amount of cargo entities to move. | |
mta | How to handle the moving (side effects). | |
data | Depending on mta the data of this variable differs:
| |
payment | The payment helper. |
Definition at line 264 of file cargopacket.cpp.
References CargoPacket::count, CargoPacket::feeder_share, CargoPacket::loaded_at_xy, CargoList< Tinst >::MTA_CARGO_LOAD, CargoList< Tinst >::MTA_FINAL_DELIVERY, CargoList< Tinst >::MTA_TRANSFER, CargoList< Tinst >::MTA_UNLOAD, CargoList< Tinst >::packets, CargoPayment::PayFinalDelivery(), CargoPayment::PayTransfer(), CargoList< Tinst >::RemoveFromCache(), CargoPacket::source, and CargoPacket::Split().
Referenced by LoadUnloadVehicle().
Returns a pointer to the cargo packet list (so you can iterate over it etc).
Definition at line 206 of file cargopacket.h.
Referenced by CargoPacket::AfterLoad(), and StationViewWindow::OrderWaitingCargo().
void CargoList< Tinst >::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 165 of file cargopacket.cpp.
References CargoList< Tinst >::cargo_days_in_transit, CargoPacket::count, CargoList< Tinst >::count, and CargoPacket::days_in_transit.
Referenced by CargoList< Tinst >::MoveTo(), and CargoList< Tinst >::Truncate().
StationID CargoList< Tinst >::Source | ( | ) | const [inline] |
Returns source of the first cargo packet in this list.
Definition at line 233 of file cargopacket.h.
Referenced by DrawRoadVehDetails(), DrawShipDetails(), and GetCargoSummaryOfArticulatedVehicle().
void CargoList< Tinst >::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 215 of file cargopacket.cpp.
References CargoList< Tinst >::cargo_days_in_transit, CargoList< Tinst >::count, CargoPacket::count, CargoPacket::days_in_transit, CargoList< Tinst >::packets, and CargoList< Tinst >::RemoveFromCache().
Referenced by CrashAirplane(), MaybeCrashAirplane(), Vehicle::PreDestructor(), RefitVehicle(), and Station::~Station().