17 #ifndef IGNITION_GAZEBO_ENTITYCOMPONENTMANAGER_HH_ 18 #define IGNITION_GAZEBO_ENTITYCOMPONENTMANAGER_HH_ 25 #include <type_traits> 28 #include <ignition/common/Console.hh> 29 #include <ignition/math/graph/Graph.hh> 31 #include "ignition/gazebo/Export.hh" 43 inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE {
70 public:
Entity CreateEntity();
74 public:
size_t EntityCount()
const;
87 public:
void RequestRemoveEntity(
const Entity _entity,
88 bool _recursive =
true);
93 public:
void RequestRemoveEntities();
98 public:
bool HasEntity(
const Entity _entity)
const;
116 public:
bool SetParentEntity(
const Entity _child,
const Entity _parent);
127 public:
bool EntityHasComponent(
const Entity _entity,
135 public:
bool EntityHasComponentType(
const Entity _entity,
142 public:
bool EntityMatches(
Entity _entity,
143 const std::set<ComponentTypeId> &_types)
const;
150 public:
bool RemoveComponent(
158 public:
bool RemoveComponent(
166 public:
template<
typename ComponentTypeT>
167 bool RemoveComponent(
Entity _entity);
171 public:
void RebuildViews();
179 public:
template<
typename ComponentTypeT>
181 const ComponentTypeT &_data);
188 public:
template<
typename ComponentTypeT>
189 const ComponentTypeT *Component(
const Entity _entity)
const;
196 public:
template<
typename ComponentTypeT>
197 ComponentTypeT *Component(
const Entity _entity);
203 public:
template<
typename ComponentTypeT>
204 const ComponentTypeT *Component(
const ComponentKey &_key)
const;
210 public:
template<
typename ComponentTypeT>
216 public:
template<
typename ComponentTypeT>
217 const ComponentTypeT *First()
const;
222 public:
template<
typename ComponentTypeT>
223 ComponentTypeT *First();
236 public:
template<
typename ...ComponentTypeTs>
237 Entity EntityByComponents(
238 const ComponentTypeTs &..._desiredComponents)
const;
255 public:
template<
typename ...ComponentTypeTs>
256 std::vector<Entity> ChildrenByComponents(
Entity _parent,
257 const ComponentTypeTs &..._desiredComponents)
const;
260 private:
template <
typename T>
275 public:
template<
typename ...ComponentTypeTs>
276 void EachNoCache(
typename identity<std::function<
277 bool(
const Entity &_entity,
278 const ComponentTypeTs *...)>>::type _f)
const;
292 public:
template<
typename ...ComponentTypeTs>
293 void EachNoCache(
typename identity<std::function<
294 bool(
const Entity &_entity,
295 ComponentTypeTs *...)>>::type _f);
309 public:
template<
typename ...ComponentTypeTs>
310 void Each(
typename identity<std::function<
311 bool(
const Entity &_entity,
312 const ComponentTypeTs *...)>>::type _f)
const;
326 public:
template<
typename ...ComponentTypeTs>
327 void Each(
typename identity<std::function<
328 bool(
const Entity &_entity,
329 ComponentTypeTs *...)>>::type _f);
335 public:
template <
class Function,
class... ComponentTypeTs>
336 static void ForEach(Function _f,
const ComponentTypeTs &... _components);
349 public:
template <
typename... ComponentTypeTs>
350 void EachNew(
typename identity<std::function<
351 bool(
const Entity &_entity,
352 ComponentTypeTs *...)>>::type _f);
365 public:
template <
typename... ComponentTypeTs>
366 void EachNew(
typename identity<std::function<
367 bool(
const Entity &_entity,
368 const ComponentTypeTs *...)>>::type _f)
const;
380 public:
template<
typename ...ComponentTypeTs>
381 void EachRemoved(
typename identity<std::function<
382 bool(
const Entity &_entity,
383 const ComponentTypeTs *...)>>::type _f)
const;
393 protected:
void ClearNewlyCreatedEntities();
398 protected:
void ProcessRemoveEntityRequests();
406 private:
bool IsNewEntity(
const Entity _entity)
const;
411 private:
bool IsMarkedForRemoval(
const Entity _entity)
const;
416 private:
bool RemoveEntity(
const Entity _entity);
472 private:
template<
typename FirstComponent,
473 typename ...RemainingComponents,
474 typename std::enable_if<
475 sizeof...(RemainingComponents) == 0,
int>::type = 0>
476 void AddComponentsToView(detail::View &_view,
477 const Entity _entity)
const;
484 private:
template<
typename FirstComponent,
485 typename ...RemainingComponents,
486 typename std::enable_if<
487 sizeof...(RemainingComponents) != 0,
int>::type = 0>
488 void AddComponentsToView(detail::View &_view,
489 const Entity _entity)
const;
495 private:
template<
typename ...ComponentTypeTs>
496 detail::View &FindView()
const;
504 private:
bool FindView(
const std::set<ComponentTypeId> &_types,
505 std::map<detail::ComponentTypeKey,
506 detail::View>::iterator &_iter)
const;
513 private: std::map<detail::ComponentTypeKey, detail::View>::iterator
514 AddView(
const std::set<ComponentTypeId> &_types,
515 detail::View &&_view)
const;
519 private:
void UpdateViews(
const Entity _entity);
525 private: std::unique_ptr<EntityComponentManagerPrivate> dataPtr;
530 friend class SimulationRunner;
534 friend class detail::View;
Component< Entity, class ParentEntityTag > ParentEntity
This component holds an entity's parent entity.
Definition: ParentEntity.hh:41
std::pair< ComponentTypeId, ComponentId > ComponentKey
A key that uniquely identifies, at the global scope, a component instance.
Definition: Types.hh:75
The EntityComponentManager constructs, deletes, and returns components and entities. A component can be of any class which inherits from components::BaseComponent.
Definition: EntityComponentManager.hh:60
math::graph::DirectedGraph< Entity, bool > EntityGraph
Type alias for the graph that holds entities. Each vertex is an entity, and the direction points from...
Definition: EntityComponentManager.hh:51
uint64_t ComponentTypeId
A unique identifier for a component type. A component type must be derived from components::BaseCompo...
Definition: Types.hh:71
class IGNITION_GAZEBO_HIDDEN EntityComponentManagerPrivate
Definition: EntityComponentManager.hh:45
int ComponentId
A unique identifier for a component instance. The uniqueness of a ComponentId is scoped to the compon...
Definition: Types.hh:66
This library is part of the Ignition Robotics project.
Definition: Altimeter.hh:25
uint64_t Entity
An Entity identifies a single object in simulation such as a model, link, or light. At its core, an Entity is just an identifier.
Definition: Entity.hh:59
Base class for all components.
Definition: Component.hh:195