OpenTTD Source: CargoList< Tinst, Tcont > Class Template Reference

OpenTTD Source 15.3

Public Types | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes
CargoList< Tinst, Tcont > Class Template Reference

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

`#include <cargopacket.h>`

## Public Types
enum | MoveToAction : uint8_t { 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 | PeriodsInTransit () const
| Returns average number of cargo aging periods 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 = 0
| Cache for the number of cargo entities.
uint64_t | cargo_periods_in_transit = 0
| Cache for the sum of number of cargo aging periods 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 instantiation of this cargo list.

Definition at line 274 of file cargopacket.h.

## Member Typedef Documentation

## ◆ ConstIterator

template<class Tinst , class Tcont >

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

The const iterator for our container.

Definition at line 281 of file cargopacket.h.

## ◆ ConstReverseIterator

template<class Tinst , class Tcont >

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

The const reverse iterator for our container.

Definition at line 283 of file cargopacket.h.

## ◆ Iterator

template<class Tinst , class Tcont >

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

The iterator for our container.

Definition at line 277 of file cargopacket.h.

## ◆ ReverseIterator

template<class Tinst , class Tcont >

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

The reverse iterator for our container.

Definition at line 279 of file cargopacket.h.

## Member Enumeration Documentation

## ◆ MoveToAction

template<class Tinst , class Tcont >

enum CargoList::MoveToAction : uint8_t

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

Enumerator
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 286 of file cargopacket.h.

## Constructor & Destructor Documentation

## ◆ CargoList()

template<class Tinst , class Tcont >

CargoList< Tinst, Tcont >::CargoList | ( |  | ) |
| inline

Create the cargo list.

Definition at line 310 of file cargopacket.h.

## ◆ ~CargoList()

template<class Tinst , class Tcont >

CargoList< Tinst, Tcont >::~CargoList | ( |  | ) |

Destroy the cargolist ("frees" all cargo packets).

Definition at line 160 of file cargopacket.cpp.

## Member Function Documentation

## ◆ AddToCache()

template<class Tinst , class Tcont >

void CargoList< Tinst, Tcont >::AddToCache | ( | const CargoPacket * | cp | ) |
| protected

Update the cache to reflect adding of this packet.

Increases count and periods_in_transit.

Parameters

  cp | New packet to be inserted.

Definition at line 197 of file cargopacket.cpp.

References CargoPacket::count, and CargoPacket::periods_in_transit.

## ◆ InvalidateCache()

template<class Tinst , class Tcont >

void CargoList< Tinst, Tcont >::InvalidateCache | ( |  | ) |

Invalidates the cached data and rebuilds it.

Definition at line 205 of file cargopacket.cpp.

Referenced by CheckCaches().

## ◆ OnCleanPool()

template<class Tinst , class Tcont >

void CargoList< Tinst, Tcont >::OnCleanPool | ( |  | ) |

Empty the cargo list, but don't free the cargo packets; the cargo packets are cleaned by CargoPacket's CleanPool.

Definition at line 172 of file cargopacket.cpp.

## ◆ Packets()

template<class Tinst , class Tcont >

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 320 of file cargopacket.h.

References CargoList< Tinst, Tcont >::packets.

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

## ◆ PeriodsInTransit()

template<class Tinst , class Tcont >

uint CargoList< Tinst, Tcont >::PeriodsInTransit | ( |  | ) | const
| inline

Returns average number of cargo aging periods in transit for a cargo entity.

Returns
  The before mentioned number.

Definition at line 329 of file cargopacket.h.

References CargoList< Tinst, Tcont >::count.

Referenced by CheckCaches().

## ◆ RemoveFromCache()

template<class Tinst , class Tcont >

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 periods_in_transit.

Parameters

  cp | Packet to be removed from cache.
  count | Amount of cargo from the given packet to be removed.

Definition at line 184 of file cargopacket.cpp.

References CargoPacket::periods_in_transit.

Referenced by CargoLoad::operator()(), and CargoReservation::operator()().

## ◆ TryMerge()

template<class Tinst , class Tcont >

bool CargoList< Tinst, Tcont >::TryMerge | ( | CargoPacket * | icp,
|  | CargoPacket * | cp
| ) |  |
| staticprotected

Tries to merge the second packet into the first and return if that was successful.

Parameters

  icp | Packet to be merged into.
  cp | Packet to be eliminated.

Returns
  If the packets could be merged.

Definition at line 223 of file cargopacket.cpp.

References CargoPacket::count, CargoPacket::MAX_COUNT, and CargoPacket::Merge().

## Field Documentation

## ◆ cargo_periods_in_transit

template<class Tinst , class Tcont >

uint64_t CargoList< Tinst, Tcont >::cargo_periods_in_transit = 0
| protected

Cache for the sum of number of cargo aging periods in transit of each entity; comparable to man-hours.

Definition at line 298 of file cargopacket.h.

## ◆ count

template<class Tinst , class Tcont >

uint CargoList< Tinst, Tcont >::count = 0
| protected

Cache for the number of cargo entities.

Definition at line 297 of file cargopacket.h.

Referenced by CargoList< Tinst, Tcont >::PeriodsInTransit().

## ◆ packets

template<class Tinst , class Tcont >

Tcont CargoList< Tinst, Tcont >::packets {}
| protected

The cargo packets in this list.

Definition at line 300 of file cargopacket.h.

Referenced by CargoList< Tinst, Tcont >::Packets().

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

- src/cargopacket.h
- src/cargopacket.cpp