The Joe Engine
Joe's engine programming playground
JoeEngine::PackedArray< T > Class Template Reference

The PackedArray class. More...

#include <PackedArray.h>

Public Member Functions

 PackedArray ()
 Constructor. More...
 
 ~PackedArray ()=default
 Destructor (default). More...
 
std::vector< T >::iterator begin () noexcept
 Get non-const interator to beginning. More...
 
std::vector< T >::iterator end () noexcept
 Get non-const interator to end. More...
 
std::vector< T >::const_iterator begin () const noexcept
 Get const interator to beginning. More...
 
std::vector< T >::const_iterator end () const noexcept
 Get const interator to end. More...
 
uint32_t Size () const
 Get size. More...
 
const std::vector< T > & GetData () const
 Get const reference to data. More...
 
std::vector< T > & GetData ()
 Get non-const reference to data. More...
 
void AddElement (uint32_t index, T element)
 Add index-element pair. More...
 
void RemoveElement (uint32_t index)
 Remove element at index. More...
 
T & operator[] (int i)
 Get non-const element at index. More...
 
const T & operator[] (int i) const
 Get const element at index. More...
 

Detailed Description

template<typename T>
class JoeEngine::PackedArray< T >

The PackedArray class.

Data structure class that stores a densely-packed list of data with a variety of helper functions for easy insertion and removal.

See also
JEEngineInstance

Constructor & Destructor Documentation

◆ PackedArray()

template<typename T>
JoeEngine::PackedArray< T >::PackedArray ( )
inline

Constructor.

No interesting behavior.

◆ ~PackedArray()

template<typename T>
JoeEngine::PackedArray< T >::~PackedArray ( )
default

Destructor (default).

Member Function Documentation

◆ AddElement()

template<typename T>
void JoeEngine::PackedArray< T >::AddElement ( uint32_t  index,
element 
)
inline

Add index-element pair.

Adds the specified data element to the densely-packed data list. Will re-use a previously invalid entry if one is available to avoid unnecessary allocations. The indirection map and data indices lists are updated to reflect this addition. Now, using the []-operator with the specified index will return the specified element.

Parameters
indexthe index to insert the element at
elementthe specified data element

◆ begin() [1/2]

template<typename T>
std::vector<T>::const_iterator JoeEngine::PackedArray< T >::begin ( ) const
inlinenoexcept

Get const interator to beginning.

Returns a const iterator to the front of the underlying data list. This is useful, for example, when using a for-each loop to read from each element of the array.

Returns
iterator to the front of the data list.
See also
ComponentManager, RotatorComponent

◆ begin() [2/2]

template<typename T>
std::vector<T>::iterator JoeEngine::PackedArray< T >::begin ( )
inlinenoexcept

Get non-const interator to beginning.

Returns a non-const iterator to the front of the underlying data list. This is useful, for example, when using a for-each loop to, say, update each element of the array. This is common with various Component types.

Returns
iterator to the front of the data list.
See also
ComponentManager, RotatorComponent

◆ end() [1/2]

template<typename T>
std::vector<T>::const_iterator JoeEngine::PackedArray< T >::end ( ) const
inlinenoexcept

Get const interator to end.

Returns a const iterator to the ednd of the underlying data list. This is useful, for example, when using a for-each loop to read from each element of the array.

Returns
iterator to the end of the data list.
See also
ComponentManager, RotatorComponent

◆ end() [2/2]

template<typename T>
std::vector<T>::iterator JoeEngine::PackedArray< T >::end ( )
inlinenoexcept

Get non-const interator to end.

Returns a non-const iterator to the end of the underlying data list. This is useful, for example, when using a for-each loop to, say, update each element of the array. This is common with various Component types.

Returns
iterator to the end of the data list.
See also
ComponentManager, RotatorComponent

◆ GetData() [1/2]

template<typename T>
std::vector<T>& JoeEngine::PackedArray< T >::GetData ( )
inline

Get non-const reference to data.

Returns a non-const reference to the data list.

Returns
non-const reference to the data list

◆ GetData() [2/2]

template<typename T>
const std::vector<T>& JoeEngine::PackedArray< T >::GetData ( ) const
inline

Get const reference to data.

Returns a const reference to the data list.

Returns
const reference to the data list

◆ operator[]() [1/2]

template<typename T>
T& JoeEngine::PackedArray< T >::operator[] ( int  i)
inline

Get non-const element at index.

Accesses the element at the specified index (e.g. an entity ID) via the indirection map. Catches invalid indices and throws an error in those cases. This []-operator is for non-const accesses, which is most likely writing.

Parameters
ithe specified index,
Returns
a non-const reference to the data element.

◆ operator[]() [2/2]

template<typename T>
const T& JoeEngine::PackedArray< T >::operator[] ( int  i) const
inline

Get const element at index.

Accesses the element at the specified index (e.g. an entity ID) via the indirection map. Catches invalid indices and throws an error in those cases. This []-operator is for const accesses, meaning reading.

Parameters
ithe specified index,
Returns
a const reference to the data element.

◆ RemoveElement()

template<typename T>
void JoeEngine::PackedArray< T >::RemoveElement ( uint32_t  index)
inline

Remove element at index.

Removes the element at the specified index. The indirection map entry for this index will now be marked as invalid, and future attempts to read the data from this index via the []-operator will throw an error.

Parameters
indexthe index whose element to remove

◆ Size()

template<typename T>
uint32_t JoeEngine::PackedArray< T >::Size ( ) const
inline

Get size.

Returns the number of data elements stored by this class in the densely-packed data list.

Returns
the number of elements

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