3#include "ComponentCollection.h"
12 namespace ComponentModel
21 static void registerType();
37 static_assert(std::is_base_of<Component, T>::value,
"<T> not derived from Component");
40 return static_cast<T *
>(getComponent(typeId));
54 static_assert(std::is_base_of<Component, T>::value,
"<T> not derived from Component");
77 static_assert(std::is_base_of<Component, T>::value,
"<T> not derived from Component");
78 return static_cast<T *
>(getComponentPtr(type));
113 [[nodiscard]]
constexpr size_t getId() const noexcept {
return id; }
117 constexpr void setId(
const size_t id)
noexcept { this->
id = id; }
120 [[nodiscard]]
const std::string &
getName() const noexcept {
return name; }
131 constexpr void setUserData(
void* userData)
noexcept { this->userData = userData; }
134 [[deprecated]]
void setUserData(intptr_t userData) { this->userData =
reinterpret_cast<void*
>(userData); }
137 [[nodiscard]]
constexpr void*
getUserData() const noexcept {
return this->userData; }
147 size_t id =
static_cast<size_t>(-1);
150 void* userData =
nullptr;
155template<>
inline Cogs::StringView getName<Cogs::ComponentModel::Entity>() {
return "Entity"; }
A collection of components, held by component handles.
Typed collection of components.
Base class for Component instances.
Container for components, providing composition of dynamic entities.
T * getComponent() const
Get a pointer to the first component implementing the given type in the entity.
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...
constexpr size_t getId() const noexcept
Get the unique identifier of this entity.
ComponentCollectionBase components
Handles to components attached to this entity.
constexpr void setId(const size_t id) noexcept
std::string name
Name of the entity.
void getComponents(ComponentCollection< T > &collection) const
Get all the components implementing the templated type.
const std::string & getName() const noexcept
Get the name of this entity.
const ComponentCollectionBase & getComponents() const
Get the collection of Component instances owned by this entity.
constexpr void * getUserData() const noexcept
Get user data.
constexpr void setUserData(void *userData) noexcept
void setUserData(intptr_t userData)
Deprecated use void*. Delete when Usage removed.
ComponentHandle getComponentHandle() const
Get a component handle to the first component implementing the given type.
Represents a discrete type definition, describing a native type class.
Provides a weakly referenced view over the contents of a string.
uint16_t TypeId
Built in type used to uniquely identify a single type instance.
Contains all Cogs related functionality.
Handle to a Component instance.
Represents an unique name.