Public Member Functions | Private Member Functions | Private Attributes

CargoDataEntry Class Reference

A cargo data entry representing one possible row in the station view window's top part. More...

#include <station_gui.h>

Public Member Functions

CargoDataEntryInsertOrRetrieve (StationID station)
 Insert a new child or retrieve an existing child using a station ID as ID.
CargoDataEntryInsertOrRetrieve (CargoID cargo)
 Insert a new child or retrieve an existing child using a cargo ID as ID.
void Update (uint count)
 Update the count for this entry and propagate the change to the parent entry if there is one.
void Remove (StationID station)
 Remove a child associated with the given station.
void Remove (CargoID cargo)
 Remove a child associated with the given cargo.
CargoDataEntryRetrieve (StationID station) const
 Retrieve a child for the given station.
CargoDataEntryRetrieve (CargoID cargo) const
 Retrieve a child for the given cargo.
void Resort (CargoSortType type, SortOrder order)
StationID GetStation () const
 Get the station ID for this entry.
CargoID GetCargo () const
 Get the cargo ID for this entry.
uint GetCount () const
 Get the cargo count for this entry.
CargoDataEntryGetParent () const
 Get the parent entry for this entry.
uint GetNumChildren () const
 Get the number of children for this entry.
CargoDataSet::iterator Begin () const
 Get an iterator pointing to the begin of the set of children.
CargoDataSet::iterator End () const
 Get an iterator pointing to the end of the set of children.
void Clear ()
 Delete all subentries, reset count and num_children and adapt parent's count.

Private Member Functions

 CargoDataEntry (StationID st, uint c, CargoDataEntry *p)
 CargoDataEntry (CargoID car, uint c, CargoDataEntry *p)
 CargoDataEntry (StationID st)
 CargoDataEntry (CargoID car)
CargoDataEntryRetrieve (CargoDataSet::iterator i) const
template<class ID >
CargoDataEntryInsertOrRetrieve (ID s)
 Retrieve a subentry or insert it if it doesn't exist, yet.
void Remove (CargoDataEntry *comp)
 Remove a subentry from this one and delete it.
void IncrementSize ()
 Increment.

Private Attributes

CargoDataEntryparent
 the parent of this entry
union {
   StationID   station
 ID of the station this entry is associated with.
   CargoID   cargo
 ID of the cargo this entry is associated with.
}; 
uint num_children
 the number of subentries belonging to this entry
uint count
 sum of counts of all children or amount of cargo for this entry
CargoDataSet * children
 the children of this entry

Detailed Description

A cargo data entry representing one possible row in the station view window's top part.

Cargo data entries form a tree where each entry can have several children. Parents keep track of the sums of their childrens' cargo counts.

Definition at line 74 of file station_gui.h.


Member Function Documentation

CargoDataEntry* CargoDataEntry::InsertOrRetrieve ( CargoID  cargo  )  [inline]

Insert a new child or retrieve an existing child using a cargo ID as ID.

Parameters:
cargo ID of the cargo for which an entry shall be created or retrieved
Returns:
a child entry associated with the given cargo.

Definition at line 91 of file station_gui.h.

template<class ID >
CargoDataEntry * CargoDataEntry::InsertOrRetrieve ( ID  child_id  )  [private]

Retrieve a subentry or insert it if it doesn't exist, yet.

Template Parameters:
ID type of ID: either StationID or CargoID
Parameters:
child_id ID of the child to be inserted or retrieved.
Returns:
the new or retrieved subentry

Definition at line 899 of file station_gui.cpp.

References children, and IncrementSize().

CargoDataEntry* CargoDataEntry::InsertOrRetrieve ( StationID  station  )  [inline]

Insert a new child or retrieve an existing child using a station ID as ID.

Parameters:
station ID of the station for which an entry shall be created or retrieved
Returns:
a child entry associated with the given station.

Definition at line 84 of file station_gui.h.

Referenced by StationViewWindow::EstimateDestinations(), StationViewWindow::HandleCargoWaitingClick(), StationViewWindow::RecalcDestinations(), and StationViewWindow::ShowCargo().

void CargoDataEntry::Remove ( CargoID  cargo  )  [inline]

Remove a child associated with the given cargo.

Parameters:
cargo ID of the cargo for which the child should be removed.

Definition at line 105 of file station_gui.h.

References Remove().

Referenced by Remove().

void CargoDataEntry::Remove ( CargoDataEntry child  )  [private]

Remove a subentry from this one and delete it.

Parameters:
child the entry to be removed. This may also be a synthetic entry which only contains the ID of the entry to be removed. In this case child is not deleted.

Definition at line 883 of file station_gui.cpp.

References children.

void CargoDataEntry::Remove ( StationID  station  )  [inline]

Remove a child associated with the given station.

Parameters:
station ID of the station for which the child should be removed.

Definition at line 99 of file station_gui.h.

References Remove().

Referenced by StationViewWindow::HandleCargoWaitingClick(), StationViewWindow::OnInvalidateData(), and Remove().

CargoDataEntry* CargoDataEntry::Retrieve ( CargoID  cargo  )  const [inline]

Retrieve a child for the given cargo.

Return NULL if it doesn't exist.

Parameters:
cargo ID of the cargo the child we're looking for is associated with.
Returns:
a child entry for the given cargo or NULL.

Definition at line 119 of file station_gui.h.

References children, and Retrieve().

Referenced by Retrieve().

CargoDataEntry* CargoDataEntry::Retrieve ( StationID  station  )  const [inline]

Retrieve a child for the given station.

Return NULL if it doesn't exist.

Parameters:
station ID of the station the child we're looking for is associated with.
Returns:
a child entry for the given station or NULL.

Definition at line 112 of file station_gui.h.

References children, and Retrieve().

Referenced by StationViewWindow::BuildCargoList(), StationViewWindow::BuildFlowList(), StationViewWindow::HandleCargoWaitingClick(), Retrieve(), StationViewWindow::SetDisplayedRow(), and StationViewWindow::ShowCargo().

void CargoDataEntry::Update ( uint  count  ) 

Update the count for this entry and propagate the change to the parent entry if there is one.

Parameters:
count the amount to be added to this entry

Definition at line 918 of file station_gui.cpp.

References parent, and Update().

Referenced by StationViewWindow::EstimateDestinations(), StationViewWindow::RecalcDestinations(), StationViewWindow::ShowCargo(), and Update().


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