CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::AbstractComponentStore Class Referenceabstract

The component store class is responsible for managing and organizing component data storage in memory. More...

#include <CeresEngine/Entity/ComponentStore.hpp>

Inheritance diagram for CeresEngine::AbstractComponentStore:
CeresEngine::ComponentStore< C >

Public Member Functions

 AbstractComponentStore (const size_t chunkSize, const size_t elementSize)
 
virtual ~AbstractComponentStore () noexcept
 Defaulted virtual destructor.
 
virtual AbstractComponentcreate (EntityIndex entityIndex)=0
 Creates a new component at entityIndex position.
 
virtual void destroy (EntityIndex entityIndex)=0
 Destroys the component located at entityIndex.
 
virtual void copy (EntityIndex sourceEntityIndex, EntityIndex targetEntityIndex)=0
 Copies the component located at entityIndex
 
virtual AbstractComponentget (EntityIndex entityIndex)=0
 Gets the component at entityIndex position.
 
virtual const AbstractComponentget (EntityIndex entityIndex) const =0
 Gets the component at entityIndex position.
 
size_t getSize () const noexcept
 
size_t getCapacity () const noexcept
 
size_t getChunkSize () const noexcept
 
size_t getChunkCount () const noexcept
 

Protected Member Functions

voidgetRawPointer (const EntityIndex index) noexcept
 Gets a pointer to the the component stored at index.
 
const voidgetRawPointer (const EntityIndex index) const noexcept
 Gets a pointer to the the component stored at index.
 
void ensureMinimumSize (std::size_t size)
 Ensures that the store size is at least size bytes.
 
void ensureMinimumCapacity (size_t minCapacity)
 Ensures that the store capacity is at least minCapacity bytes.
 

Protected Attributes

size_t mSize = 0
 The current store size (in bytes)
 
size_t mCapacity = 0
 The current store capacity (in bytes)
 
size_t mChunkSize
 The size to be used for each memory chunk (in bytes)
 
size_t mElementSize
 The amount of bytes allocated for each element in the store.
 
Vector< char * > mChunks
 A vector of all allocated memory chunks.
 

Detailed Description

The component store class is responsible for managing and organizing component data storage in memory.

Constructor & Destructor Documentation

◆ AbstractComponentStore()

CeresEngine::AbstractComponentStore::AbstractComponentStore ( const size_t  chunkSize,
const size_t  elementSize 
)
inline

◆ ~AbstractComponentStore()

virtual CeresEngine::AbstractComponentStore::~AbstractComponentStore ( )
virtualnoexcept

Defaulted virtual destructor.

Member Function Documentation

◆ copy()

virtual void CeresEngine::AbstractComponentStore::copy ( EntityIndex  sourceEntityIndex,
EntityIndex  targetEntityIndex 
)
pure virtual

Copies the component located at entityIndex

Parameters
sourceEntityIndexThe index of the component to copy from
targetEntityIndexThe index of the component to copy to

Implemented in CeresEngine::ComponentStore< C >.

◆ create()

virtual AbstractComponent & CeresEngine::AbstractComponentStore::create ( EntityIndex  entityIndex)
pure virtual

Creates a new component at entityIndex position.

Note
Calling create() on a already created index could lead to a memory leak! The previously constructed component destructor will not be called. The user must manually call `destroy()ยด before calling create on the same index.
Parameters
entityIndexThe component position
Returns
A reference to the created component

Implemented in CeresEngine::ComponentStore< C >.

◆ destroy()

virtual void CeresEngine::AbstractComponentStore::destroy ( EntityIndex  entityIndex)
pure virtual

Destroys the component located at entityIndex.

Parameters
entityIndexThe index of the component to be destroyed

Implemented in CeresEngine::ComponentStore< C >.

◆ ensureMinimumCapacity()

void CeresEngine::AbstractComponentStore::ensureMinimumCapacity ( size_t  minCapacity)
protected

Ensures that the store capacity is at least minCapacity bytes.

If the store is not large enough, more memory will be allocated.

Parameters
minCapacityThe minimum capacity to ensure

◆ ensureMinimumSize()

void CeresEngine::AbstractComponentStore::ensureMinimumSize ( std::size_t  size)
protected

Ensures that the store size is at least size bytes.

If the store is not large enough, the store capacity will be adjusted as needed.

Parameters
sizeThe minimum size to ensure

◆ get() [1/2]

virtual const AbstractComponent & CeresEngine::AbstractComponentStore::get ( EntityIndex  entityIndex) const
pure virtual

Gets the component at entityIndex position.

Note
Calling get() on a not allocated/created position will cause a crash. The user must make sure that the component being retrieved has been previously created with a call to create().
Parameters
entityIndexThe component position
Returns
A reference to the stored component

Implemented in CeresEngine::ComponentStore< C >.

◆ get() [2/2]

virtual AbstractComponent & CeresEngine::AbstractComponentStore::get ( EntityIndex  entityIndex)
pure virtual

Gets the component at entityIndex position.

Note
Calling get() on a not allocated/created position will cause a crash. The user must make sure that the component being retrieved has been previously created with a call to create().
Parameters
entityIndexThe component position
Returns
A reference to the stored component

Implemented in CeresEngine::ComponentStore< C >.

◆ getCapacity()

size_t CeresEngine::AbstractComponentStore::getCapacity ( ) const
inlinenoexcept
Returns
The current store capacity (in bytes)

◆ getChunkCount()

size_t CeresEngine::AbstractComponentStore::getChunkCount ( ) const
inlinenoexcept
Returns
The number of allocated memory chunks

◆ getChunkSize()

size_t CeresEngine::AbstractComponentStore::getChunkSize ( ) const
inlinenoexcept
Returns
The size to be used for each memory chunk (in bytes)

◆ getRawPointer() [1/2]

const void * CeresEngine::AbstractComponentStore::getRawPointer ( const EntityIndex  index) const
inlineprotectednoexcept

Gets a pointer to the the component stored at index.

Parameters
indexThe component position
Returns
A pointer to the the component stored at index.

◆ getRawPointer() [2/2]

void * CeresEngine::AbstractComponentStore::getRawPointer ( const EntityIndex  index)
inlineprotectednoexcept

Gets a pointer to the the component stored at index.

Parameters
indexThe component position
Returns
A pointer to the the component stored at index.

◆ getSize()

size_t CeresEngine::AbstractComponentStore::getSize ( ) const
inlinenoexcept
Returns
The current store size (in bytes)

Member Data Documentation

◆ mCapacity

size_t CeresEngine::AbstractComponentStore::mCapacity = 0
protected

The current store capacity (in bytes)

◆ mChunks

Vector<char*> CeresEngine::AbstractComponentStore::mChunks
protected

A vector of all allocated memory chunks.

◆ mChunkSize

size_t CeresEngine::AbstractComponentStore::mChunkSize
protected

The size to be used for each memory chunk (in bytes)

◆ mElementSize

size_t CeresEngine::AbstractComponentStore::mElementSize
protected

The amount of bytes allocated for each element in the store.

◆ mSize

size_t CeresEngine::AbstractComponentStore::mSize = 0
protected

The current store size (in bytes)


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