Cogs.Core
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 >
T * getComponent () 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 >
T * getComponent (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.

Definition at line 17 of file Entity.h.

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.

Definition at line 18 of file Entity.cpp.

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

Referenced by Cogs::Core::EntityStore::addComponent(), and Cogs::Core::AddComponentCommand::apply().

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

Definition at line 35 of file Entity.h.

Referenced by Cogs::Core::EntityStore::addChild(), Cogs::Core::TranslateCommand::apply(), Cogs::Core::RotateCommand::apply(), Cogs::Core::ScaleCommand::apply(), Cogs::Core::ScaleToUnitCubeCommand::apply(), Cogs::Core::ExportCommand::apply(), Cogs::Core::SetFieldCommand< T >::apply(), Cogs::Core::RemapMaterialCommand::apply(), Cogs::Core::MergeMaterialCommand::apply(), Cogs::Core::applyFieldValues(), Cogs::Core::applyRecursiveFieldChange(), Cogs::Core::EntityStore::dumpHierarchy(), Cogs::Core::EntityStore::findEntity(), Cogs::Core::findHierarchyWithMatch(), Cogs::Core::Image360::Bounds::getBounds(), Cogs::Core::VectorField::VectorFieldBounds::getBounds(), Cogs::Core::OGC3DTilesBounds::getBounds(), Cogs::Core::PotreeBounds::getBounds(), Cogs::Core::SeaCurrentsBounds::getBounds(), Cogs::Core::AssetBounds::getBounds(), Cogs::Core::InstancedMeshRenderBounds::getBounds(), Cogs::Core::EntityStore::getEntityParent(), Cogs::Core::Editor::getLayerVisibility(), Cogs::Core::Editor::isStandardEntity(), Cogs::Core::EchoSounder::UniformGridSystem::preUpdate(), Cogs::Core::EntityStore::removeChild(), Cogs::Core::EntityStore::removeChildren(), Cogs::Core::Editor::selectFurthestAway(), Cogs::Core::Editor::showAll(), Cogs::Core::Editor::showHide(), Cogs::Core::AssetSystem::update(), Cogs::Core::AdaptivePlanarGridSystem::update(), Cogs::Core::EditorState::updateSelectedInfo(), and Cogs::Core::writeEntity().

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

Definition at line 67 of file Entity.cpp.

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.

Definition at line 75 of file Entity.h.

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

Definition at line 72 of file Entity.cpp.

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

Definition at line 90 of file Entity.h.

Referenced by Cogs::Core::applyFieldValues().

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

Definition at line 93 of file Entity.cpp.

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.

Definition at line 45 of file Entity.cpp.

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.

Definition at line 50 of file Entity.cpp.

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.

Definition at line 38 of file Entity.cpp.

◆ getComponents() [1/3]

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

Get the collection of Component instances owned by this entity.

Definition at line 127 of file Entity.h.

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

Definition at line 52 of file Entity.h.

Referenced by Cogs::Core::applyRecursiveFieldChange(), Cogs::Core::EntityStore::dumpHierarchy(), Cogs::Core::findHierarchyWithMatch(), and Cogs::Core::writeEntity().

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

Definition at line 79 of file Entity.cpp.

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

◆ getId()

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

◆ getName()

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

◆ getUserData()

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

◆ registerType()

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

Register the Entity type in the global type database.

Definition at line 9 of file Entity.cpp.

References id.

◆ removeComponent()

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

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

Definition at line 29 of file Entity.cpp.

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.

Definition at line 117 of file Entity.h.

Referenced by Cogs::Core::EntityStore::createEntities(), and Cogs::Core::EntityStore::createEntity().

◆ setName()

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

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

Definition at line 98 of file Entity.cpp.

Referenced by Cogs::Core::EntityStore::renameEntity().

◆ setUserData() [1/2]

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

Deprecated use void*. Delete when Usage removed.

Definition at line 134 of file Entity.h.

◆ 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

Definition at line 131 of file Entity.h.

Member Data Documentation

◆ components

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

Handles to components attached to this entity.

Definition at line 141 of file Entity.h.

◆ id

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

Unique identifier.

Definition at line 147 of file Entity.h.

Referenced by registerType().

◆ name

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

Name of the entity.

Definition at line 144 of file Entity.h.

◆ userData

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

User data storage.

Definition at line 150 of file Entity.h.


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