CargoList< Tinst, Tcont > Class Template Reference

Simple collection class for a list of cargo packets. More...

#include <cargopacket.h>

Inheritance diagram for CargoList< Tinst, Tcont >:
VehicleCargoList

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.
CargoPacketRemovePacket (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.

Detailed Description

template<class Tinst, class Tcont>
class CargoList< Tinst, Tcont >

Simple collection class for a list of cargo packets.

Template Parameters:
Tinst Actual instantation of this cargo list.

Definition at line 179 of file cargopacket.h.


Member Typedef Documentation

template<class Tinst, class Tcont>
typedef Tcont::const_iterator CargoList< Tinst, Tcont >::ConstIterator

Const iterator for our container.

Definition at line 184 of file cargopacket.h.

template<class Tinst, class Tcont>
typedef Tcont::const_reverse_iterator CargoList< Tinst, Tcont >::ConstReverseIterator

Const reverse iterator for our container.

Definition at line 188 of file cargopacket.h.

template<class Tinst, class Tcont>
typedef Tcont::iterator CargoList< Tinst, Tcont >::Iterator

Iterator for our container.

Definition at line 182 of file cargopacket.h.

template<class Tinst, class Tcont>
typedef Tcont::reverse_iterator CargoList< Tinst, Tcont >::ReverseIterator

Reverse iterator for our container.

Definition at line 186 of file cargopacket.h.


Constructor & Destructor Documentation

template<class Tinst, class Tcont>
CargoList< Tinst, Tcont >::CargoList (  )  [inline]

Create the cargo list.

Definition at line 208 of file cargopacket.h.


Member Function Documentation

template<class Tinst , class Tcont >
void CargoList< Tinst, Tcont >::AddToCache ( const CargoPacket cp  )  [inline, protected]

Update the cache to reflect adding of this packet.

Increases count and days_in_transit.

Parameters:
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 VehicleCargoList::AddToCache(), and CargoList< Tinst, Tcont >::InvalidateCache().

template<class Tinst, class Tcont>
FORCEINLINE uint CargoList< Tinst, Tcont >::Count (  )  const [inline]
template<class Tinst, class Tcont>
FORCEINLINE uint CargoList< Tinst, Tcont >::DaysInTransit (  )  const [inline]

Returns average number of days in transit for a cargo entity.

Returns:
The before mentioned number.

Definition at line 245 of file cargopacket.h.

template<class Tinst, class Tcont>
FORCEINLINE bool CargoList< Tinst, Tcont >::Empty (  )  const [inline]

Checks whether this list is empty.

Returns:
True if and only if the list is empty.

Definition at line 227 of file cargopacket.h.

Referenced by DrawRoadVehDetails(), DrawShipDetails(), CompanyStationsWindow::DrawWidget(), LoadUnloadVehicle(), and VehicleCargoList::Source().

template<class Tinst , class Tcont >
uint CargoList< Tinst, Tcont >::MovePacket ( VehicleCargoList< Tinst, Tcont > *  dest,
Iterator it,
uint  cap,
TileIndex  load_place = INVALID_TILE,
bool  reserve = false 
) [inline, protected]

Move a single packet or part of it from this list to a vehicle and increment the given iterator.

Parameters:
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.
Returns:
Actual amount of cargo which has been moved.

Definition at line 311 of file cargopacket.cpp.

References VehicleCargoList::Append(), CargoPacket::count, CargoList< Tinst, Tcont >::RemovePacket(), and VehicleCargoList::Reserve().

template<class Tinst , class Tcont >
uint CargoList< Tinst, Tcont >::MovePacket ( StationCargoList< Tinst, Tcont > *  dest,
StationID  next,
Iterator it,
uint  cap 
) [inline, protected]

Move a single packet or part of it from this list to a station and increment the given iterator.

Parameters:
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.
Returns:
Actual amount of cargo which has been moved.

Definition at line 333 of file cargopacket.cpp.

References StationCargoList::Append(), CargoPacket::count, and CargoList< Tinst, Tcont >::RemovePacket().

Referenced by VehicleCargoList::MoveTo().

template<class Tinst, class Tcont>
FORCEINLINE const Tcont* CargoList< Tinst, Tcont >::Packets (  )  const [inline]

Returns a pointer to the cargo packet list (so you can iterate over it etc).

Returns:
Pointer to the packet list.

Definition at line 218 of file cargopacket.h.

Referenced by CargoPacket::AfterLoad(), StationViewWindow::BuildCargoList(), OrderList::GetBestLoadableNext(), and SwapPackets().

template<class Tinst , class Tcont >
void CargoList< Tinst, Tcont >::RemoveFromCache ( const CargoPacket cp  )  [inline, protected]

Update the cached values to reflect the removal of this packet.

Decreases count and days_in_transit.

Parameters:
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 VehicleCargoList::RemoveFromCache(), CargoList< Tinst, Tcont >::RemovePacket(), and CargoList< Tinst, Tcont >::Truncate().

template<class Tinst , class Tcont >
CargoPacket * CargoList< Tinst, Tcont >::RemovePacket ( Iterator it,
uint  cap,
TileIndex  load_place = INVALID_TILE 
) [inline, protected]

Remove a single packet or part of it from this list and increment the given iterator.

Parameters:
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.
Returns:
Removed packet.

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(), and VehicleCargoList::TransferPacket().

template<class Tinst , class Tcont >
void CargoList< Tinst, Tcont >::Truncate ( uint  max_remaining  )  [inline]

Truncates the cargo in this list to the given amount.

It leaves the first count cargo entities and removes the rest.

Parameters:
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().


The documentation for this class was generated from the following files:

Generated on Sun Jun 5 04:20:48 2011 for OpenTTD by  doxygen 1.6.1