The EntityComponentManager constructs, deletes, and returns components and entities. A component can be of any class which inherits from components::BaseComponent
.
More...
#include <ignition/gazebo/EntityComponentManager.hh>
Classes | |
struct | identity |
why is this required? More... | |
Public Member Functions | |
EntityComponentManager () | |
Constructor. More... | |
~EntityComponentManager () | |
Destructor. More... | |
template<typename ... ComponentTypeTs> | |
std::vector< Entity > | ChildrenByComponents (Entity _parent, const ComponentTypeTs &..._desiredComponents) const |
Get all entities which match the value of all the given components and are immediate children of a given parent entity. For example, the following will return a child of entity parent which has an int component equal to 123, and a string component equal to "name": More... | |
template<typename ComponentTypeT > | |
const ComponentTypeT * | Component (const Entity _entity) const |
Get a component assigned to an entity based on a component type. More... | |
template<typename ComponentTypeT > | |
ComponentTypeT * | Component (const Entity _entity) |
Get a mutable component assigned to an entity based on a component type. More... | |
template<typename ComponentTypeT > | |
const ComponentTypeT * | Component (const ComponentKey &_key) const |
Get a component based on a key. More... | |
template<typename ComponentTypeT > | |
ComponentTypeT * | Component (const ComponentKey &_key) |
Get a mutable component based on a key. More... | |
template<typename ComponentTypeT > | |
ComponentKey | CreateComponent (const Entity _entity, const ComponentTypeT &_data) |
Create a component of a particular type. This will copy the _data parameter. More... | |
Entity | CreateEntity () |
Creates a new Entity. More... | |
template<typename ... ComponentTypeTs> | |
void | Each (typename identity< std::function< bool(const Entity &_entity, const ComponentTypeTs *...)>>::type _f) const |
Get all entities which contain given component types, as well as the components. Note that an entity marked for removal (but not processed yet) will be included in the list of entities iterated by this call. More... | |
template<typename ... ComponentTypeTs> | |
void | Each (typename identity< std::function< bool(const Entity &_entity, ComponentTypeTs *...)>>::type _f) |
Get all entities which contain given component types, as well as the mutable components. Note that an entity marked for removal (but not processed yet) will be included in the list of entities iterated by this call. More... | |
template<typename... ComponentTypeTs> | |
void | EachNew (typename identity< std::function< bool(const Entity &_entity, ComponentTypeTs *...)>>::type _f) |
Get all newly created entities which contain given component types, as well as the components. This "newness" is cleared at the end of a simulation step. More... | |
template<typename... ComponentTypeTs> | |
void | EachNew (typename identity< std::function< bool(const Entity &_entity, const ComponentTypeTs *...)>>::type _f) const |
Get all newly created entities which contain given component types, as well as the components. This "newness" is cleared at the end of a simulation step. This is the const version. More... | |
template<typename ... ComponentTypeTs> | |
void | EachNoCache (typename identity< std::function< bool(const Entity &_entity, const ComponentTypeTs *...)>>::type _f) const |
A version of Each() that doesn't use a cache. The cached version, Each(), is preferred. Get all entities which contain given component types, as well as the components. More... | |
template<typename ... ComponentTypeTs> | |
void | EachNoCache (typename identity< std::function< bool(const Entity &_entity, ComponentTypeTs *...)>>::type _f) |
A version of Each() that doesn't use a cache. The cached version, Each(), is preferred. Get all entities which contain given component types, as well as the mutable components. More... | |
template<typename ... ComponentTypeTs> | |
void | EachRemoved (typename identity< std::function< bool(const Entity &_entity, const ComponentTypeTs *...)>>::type _f) const |
Get all entities which contain given component types and are about to be removed, as well as the components. More... | |
const EntityGraph & | Entities () const |
Get a graph with all the entities. Entities are vertices and edges point from parent to children. More... | |
template<typename ... ComponentTypeTs> | |
Entity | EntityByComponents (const ComponentTypeTs &..._desiredComponents) const |
Get an entity which matches the value of all the given components. For example, the following will return the entity which has an int component equal to 123, and a string component equal to "name": More... | |
size_t | EntityCount () const |
Get the number of entities on the server. More... | |
bool | EntityHasComponent (const Entity _entity, const ComponentKey &_key) const |
Check whether an entity has a specific component. More... | |
bool | EntityHasComponentType (const Entity _entity, const ComponentTypeId &_typeId) const |
Check whether an entity has a specific component type. More... | |
bool | EntityMatches (Entity _entity, const std::set< ComponentTypeId > &_types) const |
Get whether an entity has all the given component types. More... | |
template<typename ComponentTypeT > | |
const ComponentTypeT * | First () const |
The first component instance of the specified type. More... | |
template<typename ComponentTypeT > | |
ComponentTypeT * | First () |
The first component instance of the specified type. More... | |
bool | HasComponentType (const ComponentTypeId _typeId) const |
Get whether a component type has ever been created. More... | |
bool | HasEntity (const Entity _entity) const |
Get whether an Entity exists. More... | |
Entity | ParentEntity (const Entity _entity) const |
Get the first parent of the given entity. Entities are not expected to have multiple parents. TODO(louise) Either prevent multiple parents or provide full support for multiple parents. More... | |
void | RebuildViews () |
Rebuild all the views. This could be an expensive operation. More... | |
bool | RemoveComponent (const Entity _entity, const ComponentKey &_key) |
Remove a component from an entity based on a key. More... | |
bool | RemoveComponent (const Entity _entity, const ComponentTypeId &_typeId) |
Remove a component from an entity based on a type id. More... | |
template<typename ComponentTypeT > | |
bool | RemoveComponent (Entity _entity) |
Remove a component from an entity based on a type. More... | |
void | RequestRemoveEntities () |
Request to remove all entities. This will insert the request into a queue. The queue is processed toward the end of a simulation update step. More... | |
void | RequestRemoveEntity (const Entity _entity, bool _recursive=true) |
Request an entity deletion. This will insert the request into a queue. The queue is processed toward the end of a simulation update step. More... | |
bool | SetParentEntity (const Entity _child, const Entity _parent) |
Set the parent of an entity. More... | |
Static Public Member Functions | |
template<class Function , class... ComponentTypeTs> | |
static void | ForEach (Function _f, const ComponentTypeTs &... _components) |
Call a function for each parameter in a pack. More... | |
Protected Member Functions | |
void | ClearNewlyCreatedEntities () |
Clear the list of newly added entities so that a call to EachAdded after this will have no entities to iterate. This function is protected to facilitate testing. More... | |
void | ProcessRemoveEntityRequests () |
Process all entity remove requests. This will remove entities and their components. This function is protected to facilitate testing. More... | |
Detailed Description
The EntityComponentManager constructs, deletes, and returns components and entities. A component can be of any class which inherits from components::BaseComponent
.
Constructor & Destructor Documentation
◆ EntityComponentManager()
Constructor.
◆ ~EntityComponentManager()
Destructor.
Member Function Documentation
◆ ChildrenByComponents()
std::vector< Entity > ChildrenByComponents | ( | Entity | _parent, |
const ComponentTypeTs &... | _desiredComponents | ||
) | const |
Get all entities which match the value of all the given components and are immediate children of a given parent entity. For example, the following will return a child of entity parent
which has an int component equal to 123, and a string component equal to "name":
auto entity = ChildrenByComponents(parent, 123, std::string("name"));
Component type must have inequality operator.
- Parameters
-
[in] _parent Entity which should be an immediate parent of the returned entity. [in] _desiredComponents All the components which must match.
- Returns
- All matching entities, or an empty vector if no child entity has the exact components.
References EntityComponentManager::Component(), EntityComponentManager::Entities(), and EntityComponentManager::ForEach().
◆ ClearNewlyCreatedEntities()
|
protected |
Clear the list of newly added entities so that a call to EachAdded after this will have no entities to iterate. This function is protected to facilitate testing.
◆ Component() [1/4]
const ComponentTypeT * Component | ( | const Entity | _entity | ) | const |
Get a component assigned to an entity based on a component type.
- Parameters
-
[in] _entity The entity.
- Returns
- The component of the specified type assigned to specified Entity, or nullptr if the component could not be found.
Referenced by EntityComponentManager::ChildrenByComponents(), and EntityComponentManager::EntityByComponents().
◆ Component() [2/4]
ComponentTypeT * Component | ( | const Entity | _entity | ) |
Get a mutable component assigned to an entity based on a component type.
- Parameters
-
[in] _entity The entity.
- Returns
- The component of the specified type assigned to specified Entity, or nullptr if the component could not be found.
◆ Component() [3/4]
const ComponentTypeT * Component | ( | const ComponentKey & | _key | ) | const |
Get a component based on a key.
- Parameters
-
[in] _key A key that uniquely identifies a component.
- Returns
- The component associated with the key, or nullptr if the component could not be found.
◆ Component() [4/4]
ComponentTypeT * Component | ( | const ComponentKey & | _key | ) |
Get a mutable component based on a key.
- Parameters
-
[in] _key A key that uniquely identifies a component.
- Returns
- The component associated with the key, or nullptr if the component could not be found.
◆ CreateComponent()
ComponentKey CreateComponent | ( | const Entity | _entity, |
const ComponentTypeT & | _data | ||
) |
Create a component of a particular type. This will copy the _data parameter.
- Parameters
-
[in] _entity The entity that will be associated with the component. [in] _data Data used to construct the component.
- Returns
- Key that uniquely identifies the component.
◆ CreateEntity()
Entity CreateEntity | ( | ) |
Creates a new Entity.
- Returns
- An id for the Entity, or kNullEntity on failure.
◆ Each() [1/2]
void Each | ( | typename identity< std::function< bool(const Entity &_entity, const ComponentTypeTs *...)>>::type | _f | ) | const |
Get all entities which contain given component types, as well as the components. Note that an entity marked for removal (but not processed yet) will be included in the list of entities iterated by this call.
- Parameters
-
[in] _f Callback function to be called for each matching entity. The function parameter are all the desired component types, in the order they're listed on the template. The callback function can return false to stop subsequent calls to the callback, otherwise a true value should be returned.
- Template Parameters
-
ComponentTypeTs All the desired component types.
- Warning
- This function should not be called outside of System's PreUpdate, Update, or PostUpdate callbacks.
◆ Each() [2/2]
void Each | ( | typename identity< std::function< bool(const Entity &_entity, ComponentTypeTs *...)>>::type | _f | ) |
Get all entities which contain given component types, as well as the mutable components. Note that an entity marked for removal (but not processed yet) will be included in the list of entities iterated by this call.
- Parameters
-
[in] _f Callback function to be called for each matching entity. The function parameter are all the desired component types, in the order they're listed on the template. The callback function can return false to stop subsequent calls to the callback, otherwise a true value should be returned.
- Template Parameters
-
ComponentTypeTs All the desired mutable component types.
- Warning
- This function should not be called outside of System's PreUpdate, Update, or PostUpdate callbacks.
◆ EachNew() [1/2]
void EachNew | ( | typename identity< std::function< bool(const Entity &_entity, ComponentTypeTs *...)>>::type | _f | ) |
Get all newly created entities which contain given component types, as well as the components. This "newness" is cleared at the end of a simulation step.
- Parameters
-
[in] _f Callback function to be called for each matching entity. The function parameter are all the desired component types, in the order they're listed on the template. The callback function can return false to stop subsequent calls to the callback, otherwise a true value should be returned.
- Template Parameters
-
ComponentTypeTs All the desired component types.
- Warning
- This function should not be called outside of System's PreUpdate, callback. The result of call after PreUpdate is invalid
◆ EachNew() [2/2]
void EachNew | ( | typename identity< std::function< bool(const Entity &_entity, const ComponentTypeTs *...)>>::type | _f | ) | const |
Get all newly created entities which contain given component types, as well as the components. This "newness" is cleared at the end of a simulation step. This is the const version.
- Parameters
-
[in] _f Callback function to be called for each matching entity. The function parameter are all the desired component types, in the order they're listed on the template. The callback function can return false to stop subsequent calls to the callback, otherwise a true value should be returned.
- Template Parameters
-
ComponentTypeTs All the desired component types.
- Warning
- This function should not be called outside of System's PreUpdate, callback. The result of call after PreUpdate is invalid
◆ EachNoCache() [1/2]
void EachNoCache | ( | typename identity< std::function< bool(const Entity &_entity, const ComponentTypeTs *...)>>::type | _f | ) | const |
A version of Each() that doesn't use a cache. The cached version, Each(), is preferred. Get all entities which contain given component types, as well as the components.
- Parameters
-
[in] _f Callback function to be called for each matching entity. The function parameter are all the desired component types, in the order they're listed on the template. The callback function can return false to stop subsequent calls to the callback, otherwise a true value should be returned.
- Template Parameters
-
ComponentTypeTs All the desired component types.
- Warning
- This function should not be called outside of System's PreUpdate, Update, or PostUpdate callbacks.
References EntityComponentManager::Entities(), and EntityComponentManager::EntityMatches().
◆ EachNoCache() [2/2]
void EachNoCache | ( | typename identity< std::function< bool(const Entity &_entity, ComponentTypeTs *...)>>::type | _f | ) |
A version of Each() that doesn't use a cache. The cached version, Each(), is preferred. Get all entities which contain given component types, as well as the mutable components.
- Parameters
-
[in] _f Callback function to be called for each matching entity. The function parameter are all the desired component types, in the order they're listed on the template. The callback function can return false to stop subsequent calls to the callback, otherwise a true value should be returned.
- Template Parameters
-
ComponentTypeTs All the desired mutable component types.
- Warning
- This function should not be called outside of System's PreUpdate, Update, or PostUpdate callbacks.
References EntityComponentManager::Entities(), and EntityComponentManager::EntityMatches().
◆ EachRemoved()
void EachRemoved | ( | typename identity< std::function< bool(const Entity &_entity, const ComponentTypeTs *...)>>::type | _f | ) | const |
Get all entities which contain given component types and are about to be removed, as well as the components.
- Parameters
-
[in] _f Callback function to be called for each matching entity. The function parameter are all the desired component types, in the order they're listed on the template. The callback function can return false to stop subsequent calls to the callback, otherwise a true value should be returned.
- Template Parameters
-
ComponentTypeTs All the desired component types.
- Warning
- This function should not be called outside of System's PreUpdate, callback. The result of call after PreUpdate is invalid
References EntityComponentManager::Entities(), and EntityComponentManager::EntityMatches().
◆ Entities()
const EntityGraph& Entities | ( | ) | const |
Get a graph with all the entities. Entities are vertices and edges point from parent to children.
- Returns
- Entity graph.
Referenced by EntityComponentManager::ChildrenByComponents(), EntityComponentManager::EachNoCache(), and EntityComponentManager::EachRemoved().
◆ EntityByComponents()
Entity EntityByComponents | ( | const ComponentTypeTs &... | _desiredComponents | ) | const |
Get an entity which matches the value of all the given components. For example, the following will return the entity which has an int component equal to 123, and a string component equal to "name":
auto entity = EntityByComponents(123, std::string("name"));
Component type must have inequality operator.
- Parameters
-
[in] _desiredComponents All the components which must match.
- Returns
- Entity or kNullEntity if no entity has the exact components.
References EntityComponentManager::Component(), EntityComponentManager::ForEach(), and ignition::gazebo::kNullEntity.
◆ EntityCount()
size_t EntityCount | ( | ) | const |
Get the number of entities on the server.
- Returns
- Entity count.
◆ EntityHasComponent()
bool EntityHasComponent | ( | const Entity | _entity, |
const ComponentKey & | _key | ||
) | const |
Check whether an entity has a specific component.
- Parameters
-
[in] _entity The entity to check. [in] _key The component to check.
- Returns
- True if the component key belongs to the entity.
◆ EntityHasComponentType()
bool EntityHasComponentType | ( | const Entity | _entity, |
const ComponentTypeId & | _typeId | ||
) | const |
Check whether an entity has a specific component type.
- Parameters
-
[in] _entity The entity to check. [in] _typeId Component type id to check.
- Returns
- True if the entity exists and has at least one component with the provided type.
◆ EntityMatches()
bool EntityMatches | ( | Entity | _entity, |
const std::set< ComponentTypeId > & | _types | ||
) | const |
Get whether an entity has all the given component types.
- Parameters
-
[in] _entity The entity to check. [in] _types Component types to check that the Entity has.
- Returns
- True if the given entity has all the given types.
Referenced by EntityComponentManager::EachNoCache(), and EntityComponentManager::EachRemoved().
◆ First() [1/2]
const ComponentTypeT * First | ( | ) | const |
The first component instance of the specified type.
- Returns
- First component instance of the specified type, or nullptr if the type does not exist.
Referenced by EntityComponentManager::First().
◆ First() [2/2]
ComponentTypeT * First | ( | ) |
The first component instance of the specified type.
- Returns
- First component instance of the specified type, or nullptr if the type does not exist.
References EntityComponentManager::First().
◆ ForEach()
|
static |
Call a function for each parameter in a pack.
- Parameters
-
[in] _f Function to be called. [in] _components Parameters which should be passed to the function.
Referenced by EntityComponentManager::ChildrenByComponents(), and EntityComponentManager::EntityByComponents().
◆ HasComponentType()
bool HasComponentType | ( | const ComponentTypeId | _typeId | ) | const |
Get whether a component type has ever been created.
- Parameters
-
[in] _typeId ID of the component type to check.
- Returns
- True if the provided _typeId has been created.
◆ HasEntity()
bool HasEntity | ( | const Entity | _entity | ) | const |
Get whether an Entity exists.
- Parameters
-
[in] _entity Entity to confirm.
- Returns
- True if the Entity exists.
◆ ParentEntity()
Get the first parent of the given entity. Entities are not expected to have multiple parents. TODO(louise) Either prevent multiple parents or provide full support for multiple parents.
- Parameters
-
[in] _entity Entity.
- Returns
- The parent entity or kNullEntity if there's none.
◆ ProcessRemoveEntityRequests()
|
protected |
Process all entity remove requests. This will remove entities and their components. This function is protected to facilitate testing.
◆ RebuildViews()
void RebuildViews | ( | ) |
Rebuild all the views. This could be an expensive operation.
◆ RemoveComponent() [1/3]
bool RemoveComponent | ( | const Entity | _entity, |
const ComponentKey & | _key | ||
) |
Remove a component from an entity based on a key.
- Parameters
-
[in] _entity The entity. [in] _key A key that uniquely identifies a component.
- Returns
- True if the entity and component existed and the component was removed.
Referenced by EntityComponentManager::RemoveComponent().
◆ RemoveComponent() [2/3]
bool RemoveComponent | ( | const Entity | _entity, |
const ComponentTypeId & | _typeId | ||
) |
Remove a component from an entity based on a type id.
- Parameters
-
[in] _entity The entity. [in] _typeId Component's type Id.
- Returns
- True if the entity and component existed and the component was removed.
◆ RemoveComponent() [3/3]
bool RemoveComponent | ( | Entity | _entity | ) |
Remove a component from an entity based on a type.
- Parameters
-
[in] _entity The entity.
- Template Parameters
-
Component type.
- Returns
- True if the entity and component existed and the component was removed.
References EntityComponentManager::RemoveComponent().
◆ RequestRemoveEntities()
void RequestRemoveEntities | ( | ) |
Request to remove all entities. This will insert the request into a queue. The queue is processed toward the end of a simulation update step.
◆ RequestRemoveEntity()
void RequestRemoveEntity | ( | const Entity | _entity, |
bool | _recursive = true |
||
) |
Request an entity deletion. This will insert the request into a queue. The queue is processed toward the end of a simulation update step.
It is recommended that systems don't call this function directly, and instead use the gazebo::SdfEntityCreator
class to remove entities.
- Parameters
-
[in] _entity Entity to be removed. [in] _recursive Whether to recursively delete all child entities. True by default.
◆ SetParentEntity()
Set the parent of an entity.
It is recommended that systems don't call this function directly, and instead use the gazebo::SdfEntityCreator
class to create entities that have the correct parent-child relationship.
- Parameters
-
[in] _entity Entity or kNullEntity to remove current parent.
- Returns
- True if successful. Will fail if entities don't exist.
The documentation for this class was generated from the following file: