IAggregatePool

Base class for pools of aggregate types (classes or structs). The items' index (required by the IPool base class) is implemented as a size_t member named 'object_pool_index', which is expected to exist in the type stored in the pool.

Note: certain methods are overridden and have asserts added to them to support the iteration. These asserts are deliberately not placed in an in contract, due to the way in contracts work -- in a class hierarchy only *one* of the class' in contracts must pass, *not* all. In this case, as the base class has no in contract, it would always pass, making any in contracts added here irrelevant.

Members

Aliases

Item
alias Item = IPool.Item

D2 compiler refuses to resolve Item type from IPool implicitly which may be a bug but is easily fixed by introducing explicit alias.

ItemType
alias ItemType = ItemType_!(T)

Pool item instance type alias.

Classes

AllItemsIterator
class AllItemsIterator

Provides safe 'foreach' iteration over all items in the pool.

BusyItemsIterator
class BusyItemsIterator

Provides safe 'foreach' iteration over the busy items in the pool.

IItemsIterator
class IItemsIterator

Base class for pool 'foreach' iterators. The constructor receives a slice of the items to be iterated over.

IdleItemsIterator
class IdleItemsIterator

Provides safe 'foreach' iteration over the idle items in the pool.

ReadOnlyAllItemsIterator
class ReadOnlyAllItemsIterator

Provides unsafe 'foreach' iteration over all items in the pool.

ReadOnlyBusyItemsIterator
class ReadOnlyBusyItemsIterator

Provides unsafe 'foreach' iteration over the busy items in the pool.

ReadOnlyIdleItemsIterator
class ReadOnlyIdleItemsIterator

Provides unsafe 'foreach' iteration over the idle items in the pool.

SafeItemsIterator
class SafeItemsIterator

Provides 'foreach' iteration over items[start .. end]. During iteration all methods of PoolCore may be called except limit_().

UnsafeItemsIterator
class UnsafeItemsIterator

Provides 'foreach' iteration over items[start .. end]. During iteration only read-only methods of PoolCore may be called.

Functions

clear
typeof(this) clear()

Recycles all items in the pool.

deleteItem
void deleteItem(Item item)

Deletes item and sets it to null.

fill
typeof(this) fill(size_t num, ItemType new_item)

Ensures that the pool contains at least the specified number of items. Useful to pre-allocate a pool of a certain size.

fill
typeof(this) fill(size_t num)

Ensures that the pool contains at least the specified number of items. Useful to pre-allocate a pool of a certain size.

get
ItemType get(ItemType new_item)

Takes an idle item from the pool or creates a new one if all item are busy or the pool is empty.

get
ItemType get()

Takes an idle item from the pool or creates a new one if all item are busy or the pool is empty.

getItemIndex
size_t getItemIndex(Item item)

Gets the object pool index of item.

get_
Item get_(Item new_item)

Takes an idle item from the pool or creates a new one if all item are busy or the pool is empty.

isNull
bool isNull(Item item)

Checks if item is null.

isSame
bool isSame(Item a, Item b)

Checks a and b for identity.

minimize
typeof(this) minimize(size_t num)

Minimizes the number of items in the pool, removing idle items in excess of the specified number. Only idle items will be removed, busy items are not affected. The reset() method (if existing) of any removed items is called before they are deleted.

opIndex
ItemType opIndex(size_t n)

Obtains the n-th pool item. n must be less than the value returned by length(). Caution: The item must not be recycled; while the item is in use, only opIndex(), opApply(), length() and limit() may be called.

recycle
void recycle(ItemType item)

Puts item back to the pool.

recycle_
void recycle_(Item item_in)

Puts item back to the pool.

resetItem
void resetItem(Item item)

Resets item.

setItemIndex
void setItemIndex(Item item, size_t n)

Sets the object pool index to item.

setLimit
size_t setLimit(size_t limit)

Sets the limit of number of items in pool or disables limitation for limit = unlimited.

Static functions

fromItem
ItemType fromItem(Item item)

Returns the member of the item union that is used by this instance.

toItem
Item toItem(ItemType item)

Sets the member of the item union that is used by this instance.

Static variables

_assignable
auto _assignable;
Undocumented in source.

Variables

iteration_items
Item[] iteration_items;

List of items (objects) in pool for safe iteration. items is copied into this array on safe iterator instantiation.

safe_iterator_open
bool safe_iterator_open;

true if a safe iterator instance exists currently, used for assertions to ensure that only a single safe iterator can exist at a time (as it uses the single buffer, iteration_items, above).

unsafe_iterators_open
size_t unsafe_iterators_open;

Count of unsafe iterator instances which exist currently, used for assertions to ensure that while an unsafe iterator exists the object pool may not be modified.

Inherited Members

From IPool

Item
union Item

Pool item union. The list of pool items is an array of Item; the subclass specifies which member is actually used.

limited
bool limited;

May be set to true at any time to limit the number of items in pool to the current number or to false to disable limitation.

items
Item[] items;

List of items (objects) in pool, busy items first

num_busy_
size_t num_busy_;

Number of busy items in pool

length
size_t length()

Returns the number of items in pool.

num_busy
size_t num_busy()

Returns the number of busy items in pool.

num_idle
size_t num_idle()

Returns the number of idle items in pool.

limit
size_t limit()

Returns the limit of number of items in pool or unlimited if currently unlimited.

is_limited
bool is_limited()
clear
typeof(this) clear()

Recycles all items in the pool.

setLimit
size_t setLimit(size_t limit)

Sets the limit of number of items in pool or disables limitation for limit = unlimited. When limiting the pool, any excess idle items are reset and deleted.

isBusy
bool isBusy(Item item)

Checks if item is currently busy.

fill_
typeof(this) fill_(size_t num, Item new_item)

Ensures that the pool contains at least the specified number of items. Useful to pre-allocate a pool of a certain size.

get_
Item get_(Item new_item)

Takes an idle item from the pool or creates a new one if all items are busy or the pool is empty.

opIndex_
Item opIndex_(size_t n)

Obtains the n-th pool item. n must be less than the value returned by length().

recycle_
void recycle_(Item item_in)

Puts item back to the pool.

setItemIndex
void setItemIndex(Item item, size_t n)

Sets the object pool index to item.

getItemIndex
size_t getItemIndex(Item item)

Gets the object pool index of item.

resetItem
void resetItem(Item item)

Resets item.

deleteItem
void deleteItem(Item item)

Deletes item and sets it to null.

isSame
bool isSame(Item a, Item b)

Checks a and b for identity.

isNull
bool isNull(Item item)

Checks if item is null.

truncate
void truncate(size_t remove)

Removes idle items from the pool. Excess idle items are reset and deleted.

Parameters

T

type stored in pool (must be a struct or a class)

Meta