4#include "../Reflection/Field.h"
5#include "../Reflection/TypeDatabase.h"
15 Reflection::TypeDatabase::createAbstractType<Entity>().setFields(fields);
20 if (
auto * component = handle.
resolve(); component) {
21 this->components.add(handle);
22 component->setContainer(
this);
31 if(
auto * component = handle.
resolve(); component) {
32 component->setContainer(
nullptr);
35 this->components.remove(handle);
40 auto handle = getComponentHandle(type);
42 return handle.resolve();
47 return getComponentHandle(type.
getTypeId());
52 for (
const auto & c : components) {
53 if (c.typeId ==
id)
return c;
56 for (
const auto & c : components) {
59 if (componentType.canCastTo(
id)) {
74 auto handle = getComponentHandle(
id);
76 return handle.resolve();
85 for (
const auto & c : components) {
87 if (type.canCastTo(componentType)) {
100 this->name = std::string(name);
A collection of components, held by component handles.
COGSFOUNDATION_API void add(ComponentHandle component)
Adds the given component handle to the collection.
COGSFOUNDATION_API void clear()
Clears the contents of the collection.
Base class for Component instances.
void removeComponent(ComponentHandle component)
T * getComponent() const
Get a pointer to the first component implementing the given type in the entity.
Component * getComponentPtr(const Reflection::Type &type) const
Get a pointer to the first component implementing the given type.
static void registerType()
Register the Entity type in the global type database.
const ComponentCollectionBase & getComponents() const
Get the collection of Component instances owned by this entity.
void addComponent(ComponentHandle component)
size_t id
Unique identifier.
ComponentHandle getComponentHandle() const
Get a component handle to the first component implementing the given type.
void setName(const StringView &name)
Field definition describing a single data member of a data structure.
static const Type & getType()
Get the Type of the given template argument.
Represents a discrete type definition, describing a native type class.
constexpr TypeId getTypeId() const
Get the unique Reflection::TypeId of this instance.
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.
Handle to a Component instance.
COGSFOUNDATION_API class Component * resolve() const
Resolve the handle, returning a pointer to the held Component instance.
static ComponentHandle Empty()
Returns an empty, invalid handle. Will evaluate to false if tested against using operator bool().
Represents an unique name.