Simple collection class for a list of cargo packets. More...
#include <cargopacket.h>
Public Types | |
enum | MoveToAction { MTA_BEGIN = 0, MTA_TRANSFER = 0, MTA_DELIVER, MTA_KEEP, MTA_LOAD, MTA_END, NUM_MOVE_TO_ACTION = MTA_END } |
Kind of actions that could be done with packets on move. More... | |
typedef Tcont::iterator | Iterator |
The iterator for our container. | |
typedef Tcont::reverse_iterator | ReverseIterator |
The reverse iterator for our container. | |
typedef Tcont::const_iterator | ConstIterator |
The const iterator for our container. | |
typedef Tcont::const_reverse_iterator | ConstReverseIterator |
The 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. | |
const Tcont * | Packets () const |
Returns a pointer to the cargo packet list (so you can iterate over it etc). | |
uint | DaysInTransit () const |
Returns average number of days in transit for a cargo entity. | |
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, uint count) |
Update the cached values to reflect the removal of this packet or part of it. | |
Static Protected Member Functions | |
static bool | TryMerge (CargoPacket *cp, CargoPacket *icp) |
Tries to merge the second packet into the first and return if that was successful. | |
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 instantiation of this cargo list. |
Definition at line 207 of file cargopacket.h.
typedef Tcont::const_iterator CargoList< Tinst, Tcont >::ConstIterator |
The const iterator for our container.
Definition at line 214 of file cargopacket.h.
typedef Tcont::const_reverse_iterator CargoList< Tinst, Tcont >::ConstReverseIterator |
The const reverse iterator for our container.
Definition at line 216 of file cargopacket.h.
The iterator for our container.
Definition at line 210 of file cargopacket.h.
typedef Tcont::reverse_iterator CargoList< Tinst, Tcont >::ReverseIterator |
The reverse iterator for our container.
Definition at line 212 of file cargopacket.h.
enum CargoList::MoveToAction |
Kind of actions that could be done with packets on move.
MTA_TRANSFER |
Transfer the cargo to the station. |
MTA_DELIVER |
Deliver the cargo to some town or industry. |
MTA_KEEP |
Keep the cargo in the vehicle. |
MTA_LOAD |
Load the cargo from the station. |
Definition at line 219 of file cargopacket.h.
Create the cargo list.
Definition at line 243 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 194 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(), and CargoReroute::operator()().
uint CargoList< Tinst, Tcont >::DaysInTransit | ( | ) | const [inline] |
Returns average number of days in transit for a cargo entity.
Definition at line 262 of file cargopacket.h.
void CargoList< Tinst, Tcont >::InvalidateCache | ( | ) |
Invalidates the cached data and rebuilds it.
Reimplemented in VehicleCargoList.
Definition at line 202 of file cargopacket.cpp.
References CargoList< Tinst, Tcont >::AddToCache(), CargoList< Tinst, Tcont >::cargo_days_in_transit, CargoList< Tinst, Tcont >::count, and CargoList< Tinst, Tcont >::packets.
Referenced by CargoPacket::AfterLoad(), and CheckCaches().
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 253 of file cargopacket.h.
Referenced by CargoPacket::AfterLoad(), StationViewWindow::BuildCargoList(), DeleteStaleLinks(), OrderList::GetBestLoadableNext(), and SwapPackets().
void CargoList< Tinst, Tcont >::RemoveFromCache | ( | const CargoPacket * | cp, | |
uint | count | |||
) | [protected] |
Update the cached values to reflect the removal of this packet or part of it.
Decreases count and days_in_transit.
cp | Packet to be removed from cache. | |
count | Amount of cargo from the given packet to be removed. |
Reimplemented in VehicleCargoList.
Definition at line 181 of file cargopacket.cpp.
References CargoList< Tinst, Tcont >::cargo_days_in_transit, and CargoPacket::days_in_transit.
Referenced by CargoReroute::operator()(), CargoReservation::operator()(), and CargoLoad::operator()().
bool CargoList< Tinst, Tcont >::TryMerge | ( | CargoPacket * | icp, | |
CargoPacket * | cp | |||
) | [static, protected] |
Tries to merge the second packet into the first and return if that was successful.
Definition at line 220 of file cargopacket.cpp.
References CargoPacket::count, CargoPacket::MAX_COUNT, and CargoPacket::Merge().