Cogs.Foundation
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
Cogs::ComponentModel::Entity Class Reference

Container for components, providing composition of dynamic entities. More...

#include <Entity.h>

Public Member Functions

void addComponent (ComponentHandle component)
 
void removeComponent (ComponentHandle component)
 
template<typename T >
TgetComponent () const
 Get a pointer to the first component implementing the given type in the entity.
 
template<typename T >
void getComponents (ComponentCollection< T > &collection) const
 Get all the components implementing the templated type.
 
ComponentgetComponent (const Reflection::Name &typeName) const
 Get a pointer to the first component implementing the type with the given typeName in the entity. Note Component is movable object.
 
ComponentgetComponent (const Reflection::TypeId &id) const
 Get a pointer to the first component implementing the type with the given id in the entity. Note Component is movable object.
 
void getComponents (const Reflection::Name &typeName, ComponentCollectionBase &collection) const
 Get all the components implementing the type with the given typeName.
 
template<typename T >
TgetComponent (const Reflection::Type &type) const
 Get a pointer to the first component implementing the given type. Note T and type represented by type must match. Note Component is movable object.
 
ComponentgetComponentPtr (const Reflection::Type &type) const
 Get a pointer to the first component implementing the given type.
 
template<typename T >
ComponentHandle getComponentHandle () const
 Get a component handle to the first component implementing the given type.
 
ComponentHandle getComponentHandle (const Reflection::Name &componentName) const
 Get a component handle to the first component implementing the given type with the given componentName.
 
ComponentHandle getComponentHandle (const Reflection::Type &type) const
 Get a component handle to the first component implementing the given type.
 
ComponentHandle getComponentHandle (const Reflection::TypeId &id) const
 Get a component handle to the first component implementing the type with the given id.
 
constexpr size_t getId () const noexcept
 Get the unique identifier of this entity.
 
constexpr void setId (const size_t id) noexcept
 
const std::string & getName () const noexcept
 Get the name of this entity.
 
void setName (const StringView &name)
 
const ComponentCollectionBasegetComponents () const
 Get the collection of Component instances owned by this entity.
 
constexpr void setUserData (void *userData) noexcept
 
void setUserData (intptr_t userData)
 Deprecated use void*. Delete when Usage removed.
 
constexpr void * getUserData () const noexcept
 Get user data.
 

Static Public Member Functions

static void registerType ()
 Register the Entity type in the global type database.
 

Private Attributes

ComponentCollectionBase components
 Handles to components attached to this entity.
 
std::string name
 Name of the entity.
 
size_t id = static_cast<size_t>(-1)
 Unique identifier.
 
void * userData = nullptr
 User data storage.
 

Detailed Description

Container for components, providing composition of dynamic entities.

Member Function Documentation

◆ addComponent()

void Cogs::ComponentModel::Entity::addComponent ( ComponentHandle  component)

Add the component held by the given handle to the Entity, taking ownership of the Component instance. Internal: Use Cogs::Core::EntityStore.

References Cogs::ComponentModel::ComponentHandle::resolve().

◆ getComponent() [1/4]

template<typename T >
T * Cogs::ComponentModel::Entity::getComponent ( ) const
inline

Get a pointer to the first component implementing the given type in the entity.

Note Component is movable object.

References Cogs::T.

◆ getComponent() [2/4]

Cogs::ComponentModel::Component * Cogs::ComponentModel::Entity::getComponent ( const Reflection::Name typeName) const

Get a pointer to the first component implementing the type with the given typeName in the entity. Note Component is movable object.

References Cogs::Reflection::TypeDatabase::getType().

◆ getComponent() [3/4]

template<typename T >
T * Cogs::ComponentModel::Entity::getComponent ( const Reflection::Type type) const
inline

Get a pointer to the first component implementing the given type. Note T and type represented by type must match. Note Component is movable object.

References Cogs::T.

◆ getComponent() [4/4]

Cogs::ComponentModel::Component * Cogs::ComponentModel::Entity::getComponent ( const Reflection::TypeId id) const

Get a pointer to the first component implementing the type with the given id in the entity. Note Component is movable object.

◆ getComponentHandle() [1/4]

template<typename T >
ComponentHandle Cogs::ComponentModel::Entity::getComponentHandle ( ) const
inline

Get a component handle to the first component implementing the given type.

◆ getComponentHandle() [2/4]

Cogs::ComponentModel::ComponentHandle Cogs::ComponentModel::Entity::getComponentHandle ( const Reflection::Name componentName) const

Get a component handle to the first component implementing the given type with the given componentName.

References Cogs::Reflection::TypeDatabase::getType().

◆ getComponentHandle() [3/4]

Cogs::ComponentModel::ComponentHandle Cogs::ComponentModel::Entity::getComponentHandle ( const Reflection::Type type) const

Get a component handle to the first component implementing the given type.

Returns
A valid component handle, or ComponentHandle::Empty() if no matching component is found.

References Cogs::Reflection::Type::getTypeId().

◆ getComponentHandle() [4/4]

Cogs::ComponentModel::ComponentHandle Cogs::ComponentModel::Entity::getComponentHandle ( const Reflection::TypeId id) const

Get a component handle to the first component implementing the type with the given id.

Returns
A valid component handle, or ComponentHandle::Empty() if no matching component is found.

References Cogs::ComponentModel::ComponentHandle::Empty(), and Cogs::Reflection::TypeDatabase::getType().

◆ getComponentPtr()

Cogs::ComponentModel::Component * Cogs::ComponentModel::Entity::getComponentPtr ( const Reflection::Type type) const

Get a pointer to the first component implementing the given type.

Returns
Component pointer to the first implementing entity, nullptr if no matching component is found.

◆ getComponents() [1/3]

const ComponentCollectionBase & Cogs::ComponentModel::Entity::getComponents ( ) const
inline

Get the collection of Component instances owned by this entity.

◆ getComponents() [2/3]

template<typename T >
void Cogs::ComponentModel::Entity::getComponents ( ComponentCollection< T > &  collection) const
inline

Get all the components implementing the templated type.

The components are all stored in the given collection.

Parameters
collectionA component collection of the specified template type. Any existing content in the collection will be cleared.

◆ getComponents() [3/3]

void Cogs::ComponentModel::Entity::getComponents ( const Reflection::Name typeName,
ComponentCollectionBase collection 
) const

Get all the components implementing the type with the given typeName.

Parameters
typeNameName of the component type to retrieve. All components either of this type or deriving from this type will be included.
collectionComponent collection to store untyped component handles in. Any existing content in the collection will be cleared.

References Cogs::ComponentModel::ComponentCollectionBase::add(), Cogs::ComponentModel::ComponentCollectionBase::clear(), and Cogs::Reflection::TypeDatabase::getType().

◆ getId()

constexpr size_t Cogs::ComponentModel::Entity::getId ( ) const
inlineconstexprnoexcept

Get the unique identifier of this entity.

◆ getName()

const std::string & Cogs::ComponentModel::Entity::getName ( ) const
inlinenoexcept

Get the name of this entity.

◆ getUserData()

constexpr void * Cogs::ComponentModel::Entity::getUserData ( ) const
inlineconstexprnoexcept

Get user data.

◆ registerType()

void Cogs::ComponentModel::Entity::registerType ( )
static

Register the Entity type in the global type database.

References id.

◆ removeComponent()

void Cogs::ComponentModel::Entity::removeComponent ( ComponentHandle  component)

Remove the given component from the entity. Internal: Use Cogs::Core::EntityStore.

References Cogs::ComponentModel::ComponentHandle::resolve().

◆ setId()

constexpr void Cogs::ComponentModel::Entity::setId ( const size_t  id)
inlineconstexprnoexcept

Set the unique identifier of this entity. Internal: Use Cogs::Core::EntityStore.

◆ setName()

void Cogs::ComponentModel::Entity::setName ( const StringView name)

Set the name of this entity. Internal: Use Cogs::Core::EntityStore.

◆ setUserData() [1/2]

void Cogs::ComponentModel::Entity::setUserData ( intptr_t  userData)
inline

Deprecated use void*. Delete when Usage removed.

◆ setUserData() [2/2]

constexpr void Cogs::ComponentModel::Entity::setUserData ( void *  userData)
inlineconstexprnoexcept

Set user data. Can be used to e.g store a pointer to per-entity data. Internal: Owned by Cogs::Core::EntityStore

Member Data Documentation

◆ components

ComponentCollectionBase Cogs::ComponentModel::Entity::components
private

Handles to components attached to this entity.

◆ id

size_t Cogs::ComponentModel::Entity::id = static_cast<size_t>(-1)
private

Unique identifier.

Referenced by registerType().

◆ name

std::string Cogs::ComponentModel::Entity::name
private

Name of the entity.

◆ userData

void* Cogs::ComponentModel::Entity::userData = nullptr
private

User data storage.


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