Basic class for an entity that contains other entities. More...
#include <composable_entity.h>
Public Member Functions | |
ENABLE_VTABLE () | |
CComposableEntity (CComposableEntity *pc_parent) | |
Class constructor. More... | |
CComposableEntity (CComposableEntity *pc_parent, const std::string &str_id) | |
Class constructor. More... | |
virtual | ~CComposableEntity () |
Class destructor. More... | |
virtual void | Reset () |
Resets the state of the entity to whatever it was after Init() or the standalone constructor was called. More... | |
virtual void | Update () |
Updates the status of this entity. More... | |
virtual std::string | GetTypeDescription () const |
Returns a string label for this class. More... | |
virtual void | SetEnabled (bool b_enabled) |
Enables or disables an entity. More... | |
virtual void | UpdateComponents () |
Calls the Update() method on all the components. More... | |
void | AddComponent (CEntity &c_component) |
Adds a component to this composable entity. More... | |
CEntity & | RemoveComponent (const std::string &str_component) |
Removes a component from this composable entity. More... | |
CEntity & | GetComponent (const std::string &str_component) |
Returns the component with the passed string label. More... | |
template<class E > | |
E & | GetComponent (const std::string &str_component) |
Returns the component with the passed string label. More... | |
bool | HasComponent (const std::string &str_component) |
Returns true if this composable entity has a component with the given string label. More... | |
CEntity::TMultiMap::iterator | FindComponent (const std::string &str_component) |
Searches for a component with the given string label. More... | |
CEntity::TMultiMap & | GetComponentMap () |
Returns the map of all the components. More... | |
CEntity::TVector & | GetComponentVector () |
Returns the vector of all the components. More... | |
Public Member Functions inherited from argos::CEntity | |
ENABLE_VTABLE () | |
CEntity (CComposableEntity *pc_parent) | |
Class constructor. More... | |
CEntity (CComposableEntity *pc_parent, const std::string &str_id) | |
Class constructor. More... | |
virtual | ~CEntity () |
Class destructor. More... | |
virtual void | Init (TConfigurationNode &t_tree) |
Initializes the state of the entity from the XML configuration tree. More... | |
virtual void | Destroy () |
Destroys the entity, undoing whatever was done by Init() or by the standalone constructor. More... | |
const std::string & | GetId () const |
Returns the id of this entity. More... | |
std::string | GetContext () const |
Returns the context of this entity. More... | |
bool | HasParent () const |
Returns true if this entity has a parent. More... | |
CEntity & | GetRootEntity () |
Returns the root entity containing this entity. More... | |
const CEntity & | GetRootEntity () const |
Returns the root entity containing this entity. More... | |
CComposableEntity & | GetParent () |
Returns this entity's parent. More... | |
const CComposableEntity & | GetParent () const |
Returns this entity's parent. More... | |
void | SetParent (CComposableEntity &c_parent) |
Sets this entity's parent. More... | |
ssize_t | GetIndex () const |
Returns the entity index. More... | |
void | SetIndex (ssize_t n_idx) |
Sets the entity index. More... | |
bool | IsEnabled () const |
Returns true if the entity is enabled. More... | |
void | Enable () |
Enables the entity. More... | |
void | Disable () |
Disables the entity. More... | |
TConfigurationNode * | GetConfigurationNode () |
Returns a pointer to the configuration node that was used to create this entity. More... | |
Public Member Functions inherited from argos::CBaseConfigurableResource | |
virtual | ~CBaseConfigurableResource () |
Class destructor. More... | |
Public Member Functions inherited from argos::EnableVTableFor< CEntity > | |
size_t | GetTagHelper (const DERIVED *) const |
Additional Inherited Members | |
Public Types inherited from argos::CEntity | |
typedef std::vector< CEntity * > | TVector |
A vector of entities. More... | |
typedef unordered_map< std::string, CEntity * > | TMap |
A map of entities. More... | |
typedef std::multimap< std::string, CEntity * > | TMultiMap |
A multi-map of entities. More... | |
Basic class for an entity that contains other entities.
Robots, as well as other complex objects, must extend this class. When you add robots, make sure to add the robot body (CEmbodiedEntity class) first, and its controllable component (CControllableEntity class) last.
Definition at line 32 of file composable_entity.h.
argos::CComposableEntity::CComposableEntity | ( | CComposableEntity * | pc_parent | ) |
Class constructor.
This constructor is meant to be used with the Init() method.
pc_parent | The parent of this entity. |
Definition at line 16 of file composable_entity.cpp.
argos::CComposableEntity::CComposableEntity | ( | CComposableEntity * | pc_parent, |
const std::string & | str_id | ||
) |
Class constructor.
This constructor is meant to be standalone. You should not call Init() after using this constructor, or memory leaks are likely to happen.
pc_parent | The parent of this entity. |
str_id | The id of this entity. |
Definition at line 22 of file composable_entity.cpp.
|
inlinevirtual |
Class destructor.
Definition at line 61 of file composable_entity.h.
void argos::CComposableEntity::AddComponent | ( | CEntity & | c_component | ) |
Adds a component to this composable entity.
c_component | The component to add. |
Definition at line 72 of file composable_entity.cpp.
argos::CComposableEntity::ENABLE_VTABLE | ( | ) |
CEntity::TMultiMap::iterator argos::CComposableEntity::FindComponent | ( | const std::string & | str_component | ) |
Searches for a component with the given string label.
The format of the label can be either label
or label[label_N]
to get the N+1
-th component with the wanted string label.
str_component | The string label of the component to find. |
CARGoSException | if the component was not found. |
Definition at line 185 of file composable_entity.cpp.
CEntity & argos::CComposableEntity::GetComponent | ( | const std::string & | str_component | ) |
Returns the component with the passed string label.
The format of the label can be either label
, label1.label2
or label1.label2[label2_N]
to get the N+1
-th component with the wanted string label. The dot syntax label1.label2
can be nested further, to create combinations such as label1.label2.label3[label3_N]
.
str_component | The string label of the component to return. |
CARGoSException | if the component was not found. |
Definition at line 109 of file composable_entity.cpp.
|
inline |
Returns the component with the passed string label.
This method internally performs a dynamic_cast
and returns directly the desired type instead of CEntity. The format of the label can be either label
, label1.label2
or label1.label2[label2_N]
to get the N+1
-th component with the wanted string label. The dot syntax label1.label2
can be nested further, to create combinations such as label1.label2.label3[label3_N]
.
str_component | The string label of the component to return. |
CARGoSException | if the component was not found or can't be cast to the target type. |
Definition at line 136 of file composable_entity.h.
|
inline |
Returns the map of all the components.
Definition at line 172 of file composable_entity.h.
|
inline |
Returns the vector of all the components.
The elements in this vector are stored in the same order as they were inserted.
Definition at line 181 of file composable_entity.h.
|
inlinevirtual |
Returns a string label for this class.
Reimplemented from argos::CEntity.
Reimplemented in argos::CTagEquippedEntity, argos::CRadioEquippedEntity, argos::CMagnetEquippedEntity, argos::CLEDEquippedEntity, argos::CDirectionalLEDEquippedEntity, argos::CCylinderEntity, argos::CBoxEntity, argos::CSpiriEntity, argos::CPrototypeLinkEquippedEntity, argos::CPrototypeJointEquippedEntity, argos::CPrototypeJointEntity, argos::CPrototypeEntity, argos::CMiniQuadrotorEntity, argos::CFootBotEntity, argos::CEyeBotEntity, and argos::CEPuckEntity.
Definition at line 77 of file composable_entity.h.
bool argos::CComposableEntity::HasComponent | ( | const std::string & | str_component | ) |
Returns true
if this composable entity has a component with the given string label.
The format of the label can be either label
, label1.label2
or label1.label2[label2_N]
to get the N+1
-th component with the wanted string label. The dot syntax label1.label2
can be nested further, to create combinations such as label1.label2.label3[label3_N]
.
str_component | The string label of the component to check. |
true
if this composable entity has a component with the given string label. Definition at line 150 of file composable_entity.cpp.
CEntity & argos::CComposableEntity::RemoveComponent | ( | const std::string & | str_component | ) |
Removes a component from this composable entity.
The format of the label can be either label
or label[label_N]
to get the N+1
-th component with the wanted string label.
str_component | The string label of the component to remove. |
CARGoSException | if the component was not found. |
Definition at line 83 of file composable_entity.cpp.
|
virtual |
Resets the state of the entity to whatever it was after Init() or the standalone constructor was called.
Internally calls Reset() for all the component entities.
Reimplemented from argos::CEntity.
Reimplemented in argos::CLEDEquippedEntity, argos::CCylinderEntity, argos::CBoxEntity, argos::CSpiriEntity, argos::CFootBotEntity, argos::CEyeBotEntity, and argos::CEPuckEntity.
Definition at line 29 of file composable_entity.cpp.
|
virtual |
Enables or disables an entity.
b_enabled | true if the entity is enabled, false otherwise |
Reimplemented from argos::CEntity.
Definition at line 47 of file composable_entity.cpp.
|
virtual |
Updates the status of this entity.
Internally calls UpdateComponents(). If you plan to overload this method, don't forget to call CComposableEntity::Update() or UpdateComponents() in your code.
Reimplemented from argos::CEntity.
Definition at line 40 of file composable_entity.cpp.
|
virtual |
Calls the Update() method on all the components.
Reimplemented in argos::CTagEquippedEntity, argos::CRadioEquippedEntity, argos::CMagnetEquippedEntity, argos::CLEDEquippedEntity, argos::CDirectionalLEDEquippedEntity, argos::CFootBotEntity, argos::CEyeBotEntity, and argos::CEPuckEntity.
Definition at line 59 of file composable_entity.cpp.