CargoList< Tinst > Class Template Reference

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,
  MTA_NO_ACTION
}
 

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.
virtual ~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 ListPackets () 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 StationID Source () const
 Returns source of the first cargo packet in this list.
FORCEINLINE 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, StationID st=INVALID_STATION, OrderID cur_order=INVALID_ORDER, CargoID cid=INVALID_CARGO, bool *did_transfer=NULL)
 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.
void RemoveFromCacheLocal (const CargoPacket *cp, uint amount)
virtual bool UpdateCargoNextHop (CargoPacket *cp, Station *st, CargoID cid)

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.

Friends

bool CargodestModeChanged (int32 p1)

Detailed Description

template<class Tinst>
class CargoList< Tinst >

Simple collection class for a list of cargo packets.

Template Parameters:
Tinst Actual instantation of this cargo list.

Definition at line 230 of file cargopacket.h.


Member Typedef Documentation

template<class Tinst>
typedef List::const_iterator CargoList< Tinst >::ConstIterator

The const iterator for our container.

Definition at line 237 of file cargopacket.h.

template<class Tinst>
typedef List::iterator CargoList< Tinst >::Iterator

The iterator for our container.

Definition at line 235 of file cargopacket.h.

template<class Tinst>
typedef std::list<CargoPacket *> CargoList< Tinst >::List

Container with cargo packets.

Definition at line 233 of file cargopacket.h.


Member Enumeration Documentation

template<class Tinst>
enum CargoList::MoveToAction

Kind of actions that could be done with packets on move.

Enumerator:
MTA_FINAL_DELIVERY 

"Deliver" the packet to the final destination, i.e. destroy the packet.

MTA_CARGO_LOAD 

Load the packet onto a vehicle, i.e. set the last loaded station ID.

MTA_TRANSFER 

The cargo is moved as part of a transfer.

MTA_UNLOAD 

The cargo is moved as part of a forced unload.

MTA_NO_ACTION 

The station doesn't accept the cargo, so do nothing (only applicable to cargo without destination).

Definition at line 240 of file cargopacket.h.


Constructor & Destructor Documentation

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

Create the cargo list.

Definition at line 269 of file cargopacket.h.


Member Function Documentation

template<class Tinst >
void CargoList< Tinst >::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, and StationCargoList.

Definition at line 219 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().

template<class Tinst >
void CargoList< Tinst >::Append ( CargoPacket cp  )  [inline]

Appends the given cargo packet.

Tries to merge it with another one in the packets list. If no fitting packet is found, appends it.

Warning:
After appending this packet may not exist anymore!
Note:
Do not use the cargo packet anymore after it has been appended to this CargoList!
Parameters:
cp Cargo packet to add.
Precondition:
cp != NULL

Definition at line 234 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().

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

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

Returns:
The before mentioned number.

Definition at line 315 of file cargopacket.h.

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

Invalidates the cached data and rebuilds it.

Reimplemented in VehicleCargoList, and StationCargoList.

Definition at line 461 of file cargopacket.cpp.

References CargoList< Tinst >::AddToCache(), CargoList< Tinst >::cargo_days_in_transit, CargoList< Tinst >::count, and CargoList< Tinst >::packets.

template<class Tinst >
template<class Tother_inst >
bool CargoList< Tinst >::MoveTo ( Tother_inst *  dest,
uint  max_move,
MoveToAction  mta,
CargoPayment payment,
StationID  st = INVALID_STATION,
OrderID  cur_order = INVALID_ORDER,
CargoID  cid = INVALID_CARGO,
bool *  did_transfer = NULL 
) [inline]

Moves the given amount of cargo to another list.

Depending on the value of mta the side effects of this function differ:

  • MTA_FINAL_DELIVERY: Destroys the packets that do not originate from a specific station.
  • MTA_CARGO_LOAD: Sets the loaded_at_xy value of the moved packets.
  • MTA_TRANSFER: Just move without side effects.
  • MTA_UNLOAD: Just move without side effects.
  • MTA_NO_ACTION: Does nothing for packets without destination, otherwise either like MTA_TRANSFER or MTA_FINAL_DELIVERY.
    Parameters:
    dest Destination to move the cargo to.
    max_move Amount of cargo entities to move.
    mta How to handle the moving (side effects).
    st Station ID where we are loading/unloading or STATION_INVALID for move from vehicle to vehicle.
    payment The payment helper.
    cur_order The current order of the loading vehicle.
    did_transfer Set to true if some cargo was transfered.
    Precondition:
    mta == MTA_FINAL_DELIVERY || dest != NULL
    mta == MTA_UNLOAD || mta == MTA_CARGO_LOAD || payment != NULL
    st != INVALID_STATION || (mta != MTA_CARGO_LOAD && payment == NULL)
    Returns:
    True if there are still packets that might be moved from this cargo list.

Definition at line 307 of file cargopacket.cpp.

References CargoPacket::count, CargoPacket::DestinationID(), CargoPacket::feeder_share, FindRouteLinkForCargo(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_routelink_pool >::Get(), SpecializedStation< Station, false >::Get(), RouteLink::GetOriginOrderId(), INVALID_ORDER, INVALID_SOURCE, CargoPacket::loaded_at_xy, CargoList< Tinst >::MTA_CARGO_LOAD, CargoList< Tinst >::MTA_FINAL_DELIVERY, CargoList< Tinst >::MTA_NO_ACTION, CargoList< Tinst >::MTA_TRANSFER, CargoList< Tinst >::MTA_UNLOAD, CargoPacket::next_order, CargoPacket::next_station, CargoPacket::NextHop(), CargoPacket::NextStation(), CargoList< Tinst >::packets, CargoPayment::PayFinalDelivery(), CargoPayment::PayTransfer(), CargoList< Tinst >::RemoveFromCache(), CargoPacket::source, and CargoPacket::Split().

Referenced by LoadUnloadVehicle().

template<class Tinst>
FORCEINLINE const List* CargoList< Tinst >::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 279 of file cargopacket.h.

Referenced by AddVehicleCargoDestSummary(), CargoPacket::AfterLoad(), StationViewWindow::FillCargodestList(), and StationViewWindow::OrderWaitingCargo().

template<class Tinst >
void CargoList< Tinst >::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, and StationCargoList.

Definition at line 207 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().

template<class Tinst>
FORCEINLINE StationID CargoList< Tinst >::Source (  )  const [inline]

Returns source of the first cargo packet in this list.

Returns:
The before mentioned source.

Definition at line 306 of file cargopacket.h.

Referenced by DrawRoadVehDetails(), DrawShipDetails(), and GetCargoSummaryOfArticulatedVehicle().

template<class Tinst >
void CargoList< Tinst >::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 257 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().


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

Generated on Mon May 9 05:19:41 2011 for OpenTTD by  doxygen 1.6.1