OpenTTD Source 20241224-master-gf74b0cf984
|
Minimal stack that uses a pool to avoid pointers. More...
#include <smallstack_type.hpp>
Data Structures | |
struct | PooledSmallStack |
SmallStack item that can be kept in a pool. More... | |
Public Types | |
typedef SmallStackItem< Titem, Tindex > | Item |
typedef SimplePool< PooledSmallStack, Tindex, Tgrowth_step, Tmax_size > | SmallStackPool |
Public Member Functions | |
SmallStack (const Titem &value=Tinvalid) | |
Constructor for a stack with one or two items in it. | |
~SmallStack () | |
Remove the head of stack and all other items members that are unique to it. | |
SmallStack (const SmallStack &other) | |
Shallow copy the stack, marking the first item as branched. | |
SmallStack & | operator= (const SmallStack &other) |
Shallow copy the stack, marking the first item as branched. | |
void | Push (const Titem &item) |
Pushes a new item onto the stack if there is still space in the underlying pool. | |
Titem | Pop () |
Pop an item from the stack. | |
bool | IsEmpty () const |
Check if the stack is empty. | |
bool | Contains (const Titem &item) const |
Check if the given item is contained in the stack. | |
Public Member Functions inherited from SmallStackItem< Titem, Tindex > | |
SmallStackItem (const Titem &value, Tindex next) | |
Create a new item. | |
Protected Member Functions | |
void | Branch () |
Create a branch in the pool if necessary. | |
Static Protected Member Functions | |
static SmallStackPool & | GetPool () |
Additional Inherited Members | |
Data Fields inherited from SmallStackItem< Titem, Tindex > | |
Tindex | next |
Pool index of next item. | |
Titem | value |
Value of current item. | |
Minimal stack that uses a pool to avoid pointers.
It has some peculiar properties that make it useful for passing around lists of IDs but not much else:
Titem | Value type to be used. |
Tindex | Index type to use for the pool. |
Tinvalid | Invalid item to keep at the bottom of each stack. |
Tgrowth_step | Growth step for pool. |
Tmax_size | Maximum size for pool. |
Definition at line 135 of file smallstack_type.hpp.
typedef SmallStackItem<Titem, Tindex> SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::Item |
Definition at line 138 of file smallstack_type.hpp.
typedef SimplePool<PooledSmallStack, Tindex, Tgrowth_step, Tmax_size> SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::SmallStackPool |
Definition at line 147 of file smallstack_type.hpp.
|
inline |
Constructor for a stack with one or two items in it.
value | Initial item. If not missing or Tinvalid there will be Tinvalid below it. |
Definition at line 153 of file smallstack_type.hpp.
|
inline |
Remove the head of stack and all other items members that are unique to it.
Definition at line 158 of file smallstack_type.hpp.
References SmallStackItem< Titem, Tindex >::next, and SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::Pop().
|
inline |
Shallow copy the stack, marking the first item as branched.
other | Stack to copy from |
Definition at line 168 of file smallstack_type.hpp.
References SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::Branch().
|
inlineprotected |
Create a branch in the pool if necessary.
Definition at line 278 of file smallstack_type.hpp.
References SimplePool< Titem, Tindex, Tgrowth_step, Tmax_size >::Get(), lock, and SmallStackItem< Titem, Tindex >::next.
Referenced by SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::operator=(), and SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::SmallStack().
|
inline |
Check if the given item is contained in the stack.
item | Item to look for. |
Definition at line 253 of file smallstack_type.hpp.
References SimplePool< Titem, Tindex, Tgrowth_step, Tmax_size >::Get(), lock, SmallStackItem< Titem, Tindex >::next, and SmallStackItem< Titem, Tindex >::value.
Referenced by VehicleCargoList::ChooseAction().
|
inlinestaticprotected |
Definition at line 269 of file smallstack_type.hpp.
|
inline |
Check if the stack is empty.
Definition at line 243 of file smallstack_type.hpp.
References SmallStackItem< Titem, Tindex >::next, and SmallStackItem< Titem, Tindex >::value.
Referenced by OrderList::GetNextStoppingStation(), StationCargoList::HasCargoFor(), StationCargoList::ShiftCargo(), VehicleCargoList::Stage(), and LinkGraphJob::~LinkGraphJob().
|
inline |
Shallow copy the stack, marking the first item as branched.
other | Stack to copy from |
Definition at line 175 of file smallstack_type.hpp.
References SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::Branch(), SmallStackItem< Titem, Tindex >::next, SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::Pop(), and SmallStackItem< Titem, Tindex >::value.
|
inline |
Pop an item from the stack.
Definition at line 212 of file smallstack_type.hpp.
References SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::PooledSmallStack::branch_count, SimplePool< Titem, Tindex, Tgrowth_step, Tmax_size >::Destroy(), SimplePool< Titem, Tindex, Tgrowth_step, Tmax_size >::Get(), lock, SmallStackItem< Titem, Tindex >::next, and SmallStackItem< Titem, Tindex >::value.
Referenced by OrderList::GetNextStoppingStation(), StationCargoList::HasCargoFor(), SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::operator=(), StationCargoList::ShiftCargo(), VehicleCargoList::Stage(), LinkGraphJob::~LinkGraphJob(), and SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::~SmallStack().
|
inline |
Pushes a new item onto the stack if there is still space in the underlying pool.
Otherwise the topmost item's value gets overwritten.
item | Item to be pushed. |
Definition at line 192 of file smallstack_type.hpp.
References SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::PooledSmallStack::branch_count, SimplePool< Titem, Tindex, Tgrowth_step, Tmax_size >::Create(), SimplePool< Titem, Tindex, Tgrowth_step, Tmax_size >::Get(), lock, SmallStackItem< Titem, Tindex >::next, and SmallStackItem< Titem, Tindex >::value.
Referenced by FlowStatMap::DeleteFlows(), and OrderList::GetNextStoppingStation().