KarmaEngine
Game Engine for practical learning and research purposes
Loading...
Searching...
No Matches
KarmaVector< BuildingBlock > Class Template Reference

Karma's std::vector wrapper with additional functionalities. More...

#include <KarmaTypes.h>

Public Member Functions

 KarmaVector ()
 Constructor.
 ~KarmaVector ()
 Destructor.
uint32_t Remove (BuildingBlock aBlock)
 Removes an element from the vector.
void Add (BuildingBlock aBlock)
 Add an element to the vector.
void RangeCheck (uint32_t Index) const
 Sanity check for the index.
FORCEINLINE int32_t AddUnique (const BuildingBlock &Item)
int32_t Find (const BuildingBlock &Item) const
bool Contains (BuildingBlock aBlock) const
 Sees if the vector contains the specified element.
void RemoveAtSwap (int32_t Index)
 Removes an element at given location, swapping the last element into its place, and shrinking the array.
uint32_t RemoveSingleSwap (const BuildingBlock &Item)
 Removes a first appearence of single element from the array, swapping the last element into its place, and shrinking the array.
uint32_t Num () const
 Returns the total number of elements in a vector.
void Reset ()
 We just reset the vector. UE has the following implementation.
void Resize (uint32_t NewSize)
void SmartReset ()
 Just clear the elements.
void SetVectorElementByIndex (int32_t Index, BuildingBlock Value)
 Set the element of a vector using the vector index.
void Clear ()
 Clears the vector from all the elements.
const std::vector< BuildingBlock > & GetElements () const
 Getter for the elements of vector.
std::vector< BuildingBlock > & ModifyElements ()
 Getter for elements of vector for modification in appropriate way.
std::vector< BuildingBlock >::iterator begin ()
 Getter for first vector element.
std::vector< BuildingBlock >::iterator end ()
 Getter for the last vector element.
std::vector< BuildingBlock >::const_iterator begin () const
std::vector< BuildingBlock >::const_iterator end () const
FORCEINLINE BuildingBlock & IndexToObject (int32_t Index)
FORCEINLINE bool IsValidIndex (int32_t Index) const
FORCEINLINE BuildingBlock const * GetData () const
 Helper function to return typed pointer to the first entry of array.
BuildingBlock & operator[] (int32_t Index)
const BuildingBlock & operator[] (int32_t Index) const

Protected Attributes

std::vector< BuildingBlock > m_Elements

Detailed Description

template<typename BuildingBlock>
class KarmaVector< BuildingBlock >

Karma's std::vector wrapper with additional functionalities.

Since
Karma 1.0.0

Constructor & Destructor Documentation

◆ KarmaVector()

template<typename BuildingBlock>
KarmaVector< BuildingBlock >::KarmaVector ( )
inline

Constructor.

Since
Karma 1.0.0

◆ ~KarmaVector()

template<typename BuildingBlock>
KarmaVector< BuildingBlock >::~KarmaVector ( )
inline

Destructor.

Since
Karma 1.0.0

Member Function Documentation

◆ Add()

template<typename BuildingBlock>
void KarmaVector< BuildingBlock >::Add ( BuildingBlock aBlock)
inline

Add an element to the vector.

@aBlock The element to be added

Since
Karma 1.0.0

◆ AddUnique()

template<typename BuildingBlock>
FORCEINLINE int32_t KarmaVector< BuildingBlock >::AddUnique ( const BuildingBlock & Item)
inline

Adds unique element to array if the element doesn't exist.

Move semantics version.

Parameters
ItemItem to add
Returns
Index of the element in the array.
See also
Add, AddDefaulted, AddZeroed, Append, Insert
Since
Karma 1.0.0

◆ begin()

template<typename BuildingBlock>
std::vector< BuildingBlock >::iterator KarmaVector< BuildingBlock >::begin ( )
inline

Getter for first vector element.

Since
Karma 1.0.0

◆ Clear()

template<typename BuildingBlock>
void KarmaVector< BuildingBlock >::Clear ( )
inline

Clears the vector from all the elements.

Note
Duplicate of SmartReset
Since
Karma 1.0.0

◆ Contains()

template<typename BuildingBlock>
bool KarmaVector< BuildingBlock >::Contains ( BuildingBlock aBlock) const
inline

Sees if the vector contains the specified element.

Parameters
aBlockThe element to be see in the vector
Returns
true if the element exists in the vector
Since
Karam 1.0.0

◆ end()

template<typename BuildingBlock>
std::vector< BuildingBlock >::iterator KarmaVector< BuildingBlock >::end ( )
inline

Getter for the last vector element.

Since
Karma 1.0.0

◆ Find()

template<typename BuildingBlock>
int32_t KarmaVector< BuildingBlock >::Find ( const BuildingBlock & Item) const
inline

Finds first occurance of an element within the array.

Parameters
ItemItem to look for.
Returns
Index of the found element. INDEX_NONE otherwise.
See also
FindLast, FindLastByPredicate
https://www.techiedelight.com/find-index-element-vector-cpp/
Since
Karma 1.0.0

◆ GetData()

template<typename BuildingBlock>
FORCEINLINE BuildingBlock const * KarmaVector< BuildingBlock >::GetData ( ) const
inline

Helper function to return typed pointer to the first entry of array.

Since
Karma 1.0.0

◆ GetElements()

template<typename BuildingBlock>
const std::vector< BuildingBlock > & KarmaVector< BuildingBlock >::GetElements ( ) const
inline

Getter for the elements of vector.

Since
Karma 1.0.0

◆ IndexToObject()

template<typename BuildingBlock>
FORCEINLINE BuildingBlock & KarmaVector< BuildingBlock >::IndexToObject ( int32_t Index)
inline

Returns the UObject corresponding to index. Be advised this is only for very low level use.

Parameters
Indexindex of object to return
Returns
Object at this index
Since
Karma 1.0.0

◆ IsValidIndex()

template<typename BuildingBlock>
FORCEINLINE bool KarmaVector< BuildingBlock >::IsValidIndex ( int32_t Index) const
inline

Tests if index is valid, i.e. greater than or equal to zero, and less than the number of elements in the array.

Parameters
IndexIndex to test.
Returns
True if index is valid. False otherwise.
Since
Karma 1.0.0

◆ ModifyElements()

template<typename BuildingBlock>
std::vector< BuildingBlock > & KarmaVector< BuildingBlock >::ModifyElements ( )
inline

Getter for elements of vector for modification in appropriate way.

Remarks
A modifyable reference is returned
Since
Karma 1.0.0

◆ Num()

template<typename BuildingBlock>
uint32_t KarmaVector< BuildingBlock >::Num ( ) const
inline

Returns the total number of elements in a vector.

Since
Karma 1.0.0

◆ RangeCheck()

template<typename BuildingBlock>
void KarmaVector< BuildingBlock >::RangeCheck ( uint32_t Index) const
inline

Sanity check for the index.

Since
Karma 1.0.0

◆ Remove()

template<typename BuildingBlock>
uint32_t KarmaVector< BuildingBlock >::Remove ( BuildingBlock aBlock)
inline

Removes an element from the vector.

The function removes all occurrences of the specified element from the vector

Note
The vector size is reduced by the number of removed elements
Parameters
aBlockThe element to be removed
Since
Karma 1.0.0

◆ RemoveAtSwap()

template<typename BuildingBlock>
void KarmaVector< BuildingBlock >::RemoveAtSwap ( int32_t Index)
inline

Removes an element at given location, swapping the last element into its place, and shrinking the array.

Parameters
IndexThe index of the element to be removed
AllowShrinkingWhether to allow the array to shrink its allocation if possible
Note
This implementation is differenct from UE and here vector shrinks automatically
Since
Karma 1.0.0

◆ RemoveSingleSwap()

template<typename BuildingBlock>
uint32_t KarmaVector< BuildingBlock >::RemoveSingleSwap ( const BuildingBlock & Item)
inline

Removes a first appearence of single element from the array, swapping the last element into its place, and shrinking the array.

Parameters
ItemThe item to be removed
AllowShrinkingWhether to allow the array to shrink its allocation if possible
Returns
The number of elements removed (0 or 1)
Note
AllowShrinking is automatic different from UE
Since
Karma 1.0.0

◆ Reset()

template<typename BuildingBlock>
void KarmaVector< BuildingBlock >::Reset ( )
inline

We just reset the vector. UE has the following implementation.

Same as empty, but doesn't change memory allocations, unless the new size is larger than the current array. It calls the destructors on held items if needed and then zeros the ArrayNum.

Parameters
NewSizeThe expected usage size after calling this function.
Warning
Included deletion of possible UObjects. Hence needs rewriting once ShivaActor is functional
Since
Karma 1.0.0

◆ SetVectorElementByIndex()

template<typename BuildingBlock>
void KarmaVector< BuildingBlock >::SetVectorElementByIndex ( int32_t Index,
BuildingBlock Value )
inline

Set the element of a vector using the vector index.

Parameters
IndexThe index of the vector element to be set
ValueThe value to be assigned to the element
Since
Karma 1.0.0

◆ SmartReset()

template<typename BuildingBlock>
void KarmaVector< BuildingBlock >::SmartReset ( )
inline

Just clear the elements.

Remarks
Assuming the use of smart pointers
Warning
Still need to think deletion of UObjects
Since
Karma 1.0.0

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