Class to keep a list of pointers and nullpointers. More...
#include "pointerSlotStorage.h"
Public Types | |
typedef array< T, SIZE > | InternalContainer |
Public Member Functions | |
PointerSlotStorage () | |
Constructs a new PointerSlotStorage. More... | |
InternalContainer::iterator | begin () |
Returns an iterator to the begin of the container. More... | |
InternalContainer::iterator | end () |
Returns an iterator to the end of the container. More... | |
bool | find_consecutive_slots (size_t &slot, size_t num_consecutive) const |
Finds free consecutive slots. More... | |
bool | find_slot (size_t &slot) const |
Finds a free slot. More... | |
void | free_consecutive_slots (size_t slot, size_t num_consecutive) |
Frees consecutive allocated slots. More... | |
void | free_slot (size_t slot) |
Frees an allocated slot. More... | |
int | get_max_index () const |
Returns the maximum index of the container. More... | |
size_t | get_num_entries () const |
Returns the amount of elements of the container. More... | |
void | reserve_slot (size_t slot, T ptr) |
Reserves a slot. More... | |
Class to keep a list of pointers and nullpointers.
This class stores a fixed size list of pointers, whereas pointers may be a nullptr as well. It provides functionality to find free slots, and also to find free consecutive slots, as well as taking care of reserving slots.
T* | Pointer-Type |
SIZE | Size of the storage |
Definition at line 61 of file pointerSlotStorage.h.
|
inline |
Constructs a new PointerSlotStorage.
This constructs a new PointerSlotStorage, with all slots initialized to a nullptr.
Definition at line 68 of file pointerSlotStorage.h.
|
inline |
Returns an iterator to the begin of the container.
This returns an iterator to the beginning of the container
Definition at line 218 of file pointerSlotStorage.h.
|
inline |
Returns an iterator to the end of the container.
This returns an iterator to the end of the iterator. This only iterates to PointerSlotStorage::get_max_index()
Definition at line 228 of file pointerSlotStorage.h.
|
inline |
Finds free consecutive slots.
This behaves like find_slot, but it tries to find a slot after which <num_consecutive-1> free slots follow as well.
When no slot found was found, slot will be undefined, and false will be returned.
slot | Output-Variable, index of the first slot of the consecutive slots will be stored there. |
num_consecutive | Amount of consecutive slots to find, including the first slot. |
Definition at line 137 of file pointerSlotStorage.h.
|
inline |
Finds a free slot.
This finds the first slot which is a nullptr and returns it. This is most likely useful in combination with reserve_slot.
When no slot found was found, slot will be undefined, and false will be returned.
slot | Output-Variable, slot will be stored there |
Definition at line 112 of file pointerSlotStorage.h.
|
inline |
Frees consecutive allocated slots.
This behaves like PointerSlotStorage::free_slot, but deletes consecutive slots.
slot | Start of the consecutive slots to free |
num_consecutive | Number of consecutive slots |
Definition at line 186 of file pointerSlotStorage.h.
|
inline |
Frees an allocated slot.
This frees an allocated slot. If the slot was already freed before, this method throws an assertion.
slot | Slot to free |
Definition at line 166 of file pointerSlotStorage.h.
|
inline |
Returns the maximum index of the container.
This returns the greatest index of any element which is not zero. This can be useful for iterating the container, since all elements coming after the returned index are guaranteed to be a nullptr.
If no elements are in this container, -1 is returned.
Definition at line 87 of file pointerSlotStorage.h.
|
inline |
Returns the amount of elements of the container.
This returns the amount of elements in the container which are no nullptr.
Definition at line 97 of file pointerSlotStorage.h.
|
inline |
Reserves a slot.
This reserves a slot by storing a pointer in it. If the slot was already taken, throws an assertion. If the ptr is a nullptr, also throws an assertion. If the slot was out of bounds, also throws an assertion.
slot | Slot to reserve |
ptr | Pointer to store |
Definition at line 202 of file pointerSlotStorage.h.