Panda3D
Public Types | Public Member Functions | List of all members
PointerSlotStorage< T, SIZE > Class Template Reference

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

Detailed Description

template<typename T, int SIZE>
class PointerSlotStorage< T, SIZE >

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.

Template Parameters
T*Pointer-Type
SIZESize of the storage

Definition at line 61 of file pointerSlotStorage.h.

Constructor & Destructor Documentation

◆ PointerSlotStorage()

template<typename T, int SIZE>
PointerSlotStorage< T, SIZE >::PointerSlotStorage ( )
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.

Member Function Documentation

◆ begin()

template<typename T, int SIZE>
InternalContainer::iterator PointerSlotStorage< T, SIZE >::begin ( )
inline

Returns an iterator to the begin of the container.

This returns an iterator to the beginning of the container

Returns
Begin-Iterator

Definition at line 218 of file pointerSlotStorage.h.

◆ end()

template<typename T, int SIZE>
InternalContainer::iterator PointerSlotStorage< T, SIZE >::end ( )
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()

Returns
[description]

Definition at line 228 of file pointerSlotStorage.h.

◆ find_consecutive_slots()

template<typename T, int SIZE>
bool PointerSlotStorage< T, SIZE >::find_consecutive_slots ( size_t &  slot,
size_t  num_consecutive 
) const
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.

Parameters
slotOutput-Variable, index of the first slot of the consecutive slots will be stored there.
num_consecutiveAmount of consecutive slots to find, including the first slot.
Returns
true if consecutive slots were found, otherwise false.

Definition at line 137 of file pointerSlotStorage.h.

◆ find_slot()

template<typename T, int SIZE>
bool PointerSlotStorage< T, SIZE >::find_slot ( size_t &  slot) const
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.

Parameters
slotOutput-Variable, slot will be stored there
Returns
true if a slot was found, otherwise false

Definition at line 112 of file pointerSlotStorage.h.

◆ free_consecutive_slots()

template<typename T, int SIZE>
void PointerSlotStorage< T, SIZE >::free_consecutive_slots ( size_t  slot,
size_t  num_consecutive 
)
inline

Frees consecutive allocated slots.

This behaves like PointerSlotStorage::free_slot, but deletes consecutive slots.

Parameters
slotStart of the consecutive slots to free
num_consecutiveNumber of consecutive slots

Definition at line 186 of file pointerSlotStorage.h.

◆ free_slot()

template<typename T, int SIZE>
void PointerSlotStorage< T, SIZE >::free_slot ( size_t  slot)
inline

Frees an allocated slot.

This frees an allocated slot. If the slot was already freed before, this method throws an assertion.

Parameters
slotSlot to free

Definition at line 166 of file pointerSlotStorage.h.

◆ get_max_index()

template<typename T, int SIZE>
int PointerSlotStorage< T, SIZE >::get_max_index ( ) const
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.

Returns
Maximum index of the container

Definition at line 87 of file pointerSlotStorage.h.

◆ get_num_entries()

template<typename T, int SIZE>
size_t PointerSlotStorage< T, SIZE >::get_num_entries ( ) const
inline

Returns the amount of elements of the container.

This returns the amount of elements in the container which are no nullptr.

Returns
Amount of elements

Definition at line 97 of file pointerSlotStorage.h.

◆ reserve_slot()

template<typename T, int SIZE>
void PointerSlotStorage< T, SIZE >::reserve_slot ( size_t  slot,
ptr 
)
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.

Parameters
slotSlot to reserve
ptrPointer to store

Definition at line 202 of file pointerSlotStorage.h.


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