OpenTTD Source 20250205-master-gfd85ab1e2c
CargoDataEntry Class Reference

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

Public Member Functions

CargoDataEntryInsertOrRetrieve (StationID station)
 Insert a new child or retrieve an existing child using a station ID as ID.
 
CargoDataEntryInsertOrRetrieve (CargoType cargo)
 Insert a new child or retrieve an existing child using a cargo type 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 (CargoType cargo)
 Remove a child associated with the given cargo.
 
CargoDataEntryRetrieve (StationID station) const
 Retrieve a child for the given station.
 
CargoDataEntryRetrieve (CargoType 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.
 
CargoType GetCargo () const
 Get the cargo type 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.
 
bool HasTransfers () const
 Has this entry transfers.
 
void SetTransfers (bool value)
 Set the transfers state.
 
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 (CargoType car, uint c, CargoDataEntry *p)
 
 CargoDataEntry (StationID st)
 
 CargoDataEntry (CargoType car)
 
CargoDataEntryRetrieve (CargoDataSet::iterator i) const
 
template<class Tid >
CargoDataEntryInsertOrRetrieve (Tid 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. More...
 
   struct { 
 
      CargoType   cargo 
 ID of the cargo this entry is associated with. More...
 
      bool   transfers 
 If there are transfers for this cargo. More...
 
   }  
 
};  
 
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 918 of file station_gui.cpp.

Constructor & Destructor Documentation

◆ CargoDataEntry() [1/5]

CargoDataEntry::CargoDataEntry ( )

Definition at line 1063 of file station_gui.cpp.

◆ ~CargoDataEntry()

CargoDataEntry::~CargoDataEntry ( )

Definition at line 1103 of file station_gui.cpp.

◆ CargoDataEntry() [2/5]

CargoDataEntry::CargoDataEntry ( StationID  st,
uint  c,
CargoDataEntry p 
)
private

Definition at line 1079 of file station_gui.cpp.

◆ CargoDataEntry() [3/5]

CargoDataEntry::CargoDataEntry ( CargoType  car,
uint  c,
CargoDataEntry p 
)
private

Definition at line 1071 of file station_gui.cpp.

◆ CargoDataEntry() [4/5]

CargoDataEntry::CargoDataEntry ( StationID  st)
private

Definition at line 1087 of file station_gui.cpp.

◆ CargoDataEntry() [5/5]

CargoDataEntry::CargoDataEntry ( CargoType  car)
private

Definition at line 1095 of file station_gui.cpp.

Member Function Documentation

◆ Begin()

CargoDataSet::iterator CargoDataEntry::Begin ( ) const
inline

Get an iterator pointing to the begin of the set of children.

Definition at line 1017 of file station_gui.cpp.

References children.

◆ Clear()

void CargoDataEntry::Clear ( )

Delete all subentries, reset count and num_children and adapt parent's count.

Definition at line 1112 of file station_gui.cpp.

References children, count, num_children, and parent.

Referenced by StationViewWindow::RecalcDestinations().

◆ End()

CargoDataSet::iterator CargoDataEntry::End ( ) const
inline

Get an iterator pointing to the end of the set of children.

Definition at line 1022 of file station_gui.cpp.

References children.

◆ GetCargo()

CargoType CargoDataEntry::GetCargo ( ) const
inline

Get the cargo type for this entry.

Definition at line 997 of file station_gui.cpp.

References cargo.

Referenced by StationViewWindow::DrawEntries(), and StationViewWindow::SetDisplayedRow().

◆ GetCount()

uint CargoDataEntry::GetCount ( ) const
inline

Get the cargo count for this entry.

Definition at line 1002 of file station_gui.cpp.

References count.

Referenced by StationViewWindow::EstimateDestinations().

◆ GetNumChildren()

uint CargoDataEntry::GetNumChildren ( ) const
inline

Get the number of children for this entry.

Definition at line 1012 of file station_gui.cpp.

References num_children.

Referenced by StationViewWindow::OnPaint().

◆ GetParent()

CargoDataEntry * CargoDataEntry::GetParent ( ) const
inline

Get the parent entry for this entry.

Definition at line 1007 of file station_gui.cpp.

References parent.

Referenced by StationViewWindow::SetDisplayedRow().

◆ GetStation()

StationID CargoDataEntry::GetStation ( ) const
inline

◆ HasTransfers()

bool CargoDataEntry::HasTransfers ( ) const
inline

Has this entry transfers.

Definition at line 1027 of file station_gui.cpp.

References transfers.

◆ IncrementSize()

void CargoDataEntry::IncrementSize ( )
private

Increment.

Definition at line 1176 of file station_gui.cpp.

References IncrementSize(), num_children, and parent.

Referenced by IncrementSize(), and InsertOrRetrieve().

◆ InsertOrRetrieve() [1/3]

CargoDataEntry * CargoDataEntry::InsertOrRetrieve ( CargoType  cargo)
inline

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

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

Definition at line 938 of file station_gui.cpp.

References cargo.

◆ InsertOrRetrieve() [2/3]

CargoDataEntry * CargoDataEntry::InsertOrRetrieve ( StationID  station)
inline

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

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

Definition at line 928 of file station_gui.cpp.

References station.

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

◆ InsertOrRetrieve() [3/3]

template<class Tid >
CargoDataEntry * CargoDataEntry::InsertOrRetrieve ( Tid  child_id)
private

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

Template Parameters
IDtype of ID: either StationID or CargoType
Parameters
child_idID of the child to be inserted or retrieved.
Returns
the new or retrieved subentry

Definition at line 1148 of file station_gui.cpp.

References children, Count, and IncrementSize().

◆ Remove() [1/3]

void CargoDataEntry::Remove ( CargoDataEntry child)
private

Remove a subentry from this one and delete it.

Parameters
childthe 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 1132 of file station_gui.cpp.

References children.

◆ Remove() [2/3]

void CargoDataEntry::Remove ( CargoType  cargo)
inline

Remove a child associated with the given cargo.

Parameters
cargotype of the cargo for which the child should be removed.

Definition at line 959 of file station_gui.cpp.

References cargo, and Remove().

◆ Remove() [3/3]

void CargoDataEntry::Remove ( StationID  station)
inline

Remove a child associated with the given station.

Parameters
stationID of the station for which the child should be removed.

Definition at line 949 of file station_gui.cpp.

References Remove(), and station.

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

◆ Resort()

void CargoDataEntry::Resort ( CargoSortType  type,
SortOrder  order 
)

Definition at line 1182 of file station_gui.cpp.

◆ Retrieve() [1/3]

CargoDataEntry * CargoDataEntry::Retrieve ( CargoDataSet::iterator  i) const
private

Definition at line 1189 of file station_gui.cpp.

◆ Retrieve() [2/3]

CargoDataEntry * CargoDataEntry::Retrieve ( CargoType  cargo) const
inline

Retrieve a child for the given cargo.

Return nullptr if it doesn't exist.

Parameters
cargotype of the cargo the child we're looking for is associated with.
Returns
a child entry for the given cargo or nullptr.

Definition at line 981 of file station_gui.cpp.

References cargo, children, and Retrieve().

◆ Retrieve() [3/3]

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

Retrieve a child for the given station.

Return nullptr if it doesn't exist.

Parameters
stationID of the station the child we're looking for is associated with.
Returns
a child entry for the given station or nullptr.

Definition at line 970 of file station_gui.cpp.

References children, Retrieve(), and station.

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

◆ SetTransfers()

void CargoDataEntry::SetTransfers ( bool  value)
inline

Set the transfers state.

Definition at line 1032 of file station_gui.cpp.

References transfers.

Referenced by StationViewWindow::ShowCargo().

◆ Update()

void CargoDataEntry::Update ( uint  count)

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

Parameters
countthe amount to be added to this entry

Definition at line 1167 of file station_gui.cpp.

References count, parent, and Update().

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

Field Documentation

◆ cargo

CargoType CargoDataEntry::cargo

ID of the cargo this entry is associated with.

Definition at line 1054 of file station_gui.cpp.

Referenced by GetCargo(), InsertOrRetrieve(), Remove(), and Retrieve().

◆ children

CargoDataSet* CargoDataEntry::children
private

the children of this entry.

Definition at line 1060 of file station_gui.cpp.

Referenced by Begin(), Clear(), End(), InsertOrRetrieve(), Remove(), Retrieve(), and Retrieve().

◆ count

uint CargoDataEntry::count
private

sum of counts of all children or amount of cargo for this entry.

Definition at line 1059 of file station_gui.cpp.

Referenced by Clear(), GetCount(), and Update().

◆ num_children

uint CargoDataEntry::num_children
private

the number of subentries belonging to this entry.

Definition at line 1058 of file station_gui.cpp.

Referenced by Clear(), GetNumChildren(), and IncrementSize().

◆ parent

CargoDataEntry* CargoDataEntry::parent
private

the parent of this entry.

Definition at line 1050 of file station_gui.cpp.

Referenced by Clear(), GetParent(), IncrementSize(), and Update().

◆ station

StationID CargoDataEntry::station

ID of the station this entry is associated with.

Definition at line 1052 of file station_gui.cpp.

Referenced by GetStation(), InsertOrRetrieve(), Remove(), and Retrieve().

◆ transfers

bool CargoDataEntry::transfers

If there are transfers for this cargo.

Definition at line 1055 of file station_gui.cpp.

Referenced by HasTransfers(), and SetTransfers().


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