argos::CComposableEntity Class Reference

Basic class for an entity that contains other entities. More...

#include <composable_entity.h>

Inheritance diagram for argos::CComposableEntity:
Collaboration diagram for argos::CComposableEntity:

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...
 
CEntityRemoveComponent (const std::string &str_component)
 Removes a component from this composable entity. More...
 
CEntityGetComponent (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::TMultiMapGetComponentMap ()
 Returns the map of all the components. More...
 
CEntity::TVectorGetComponentVector ()
 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...
 
CEntityGetRootEntity ()
 Returns the root entity containing this entity. More...
 
const CEntityGetRootEntity () const
 Returns the root entity containing this entity. More...
 
CComposableEntityGetParent ()
 Returns this entity's parent. More...
 
const CComposableEntityGetParent () 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...
 
TConfigurationNodeGetConfigurationNode ()
 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...
 

Detailed Description

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.

See also
CEntity

Definition at line 32 of file composable_entity.h.

Constructor & Destructor Documentation

◆ CComposableEntity() [1/2]

argos::CComposableEntity::CComposableEntity ( CComposableEntity pc_parent)

Class constructor.

This constructor is meant to be used with the Init() method.

Parameters
pc_parentThe parent of this entity.

Definition at line 16 of file composable_entity.cpp.

◆ CComposableEntity() [2/2]

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.

Parameters
pc_parentThe parent of this entity.
str_idThe id of this entity.

Definition at line 22 of file composable_entity.cpp.

◆ ~CComposableEntity()

virtual argos::CComposableEntity::~CComposableEntity ( )
inlinevirtual

Class destructor.

Definition at line 61 of file composable_entity.h.

Member Function Documentation

◆ AddComponent()

void argos::CComposableEntity::AddComponent ( CEntity c_component)

Adds a component to this composable entity.

Parameters
c_componentThe component to add.

Definition at line 72 of file composable_entity.cpp.

◆ ENABLE_VTABLE()

argos::CComposableEntity::ENABLE_VTABLE ( )

◆ FindComponent()

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.

Parameters
str_componentThe string label of the component to find.
Returns
An iterator to the component found.
Exceptions
CARGoSExceptionif the component was not found.

Definition at line 185 of file composable_entity.cpp.

◆ GetComponent() [1/2]

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].

Parameters
str_componentThe string label of the component to return.
See also
GetTypeDescription()
Exceptions
CARGoSExceptionif the component was not found.

Definition at line 109 of file composable_entity.cpp.

◆ GetComponent() [2/2]

template<class E >
E& argos::CComposableEntity::GetComponent ( const std::string &  str_component)
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].

Parameters
str_componentThe string label of the component to return.
See also
GetTypeDescription()
Exceptions
CARGoSExceptionif the component was not found or can't be cast to the target type.

Definition at line 136 of file composable_entity.h.

◆ GetComponentMap()

CEntity::TMultiMap& argos::CComposableEntity::GetComponentMap ( )
inline

Returns the map of all the components.

Returns
The map of all the components.

Definition at line 172 of file composable_entity.h.

◆ GetComponentVector()

CEntity::TVector& argos::CComposableEntity::GetComponentVector ( )
inline

Returns the vector of all the components.

The elements in this vector are stored in the same order as they were inserted.

Returns
The vector of all the components.

Definition at line 181 of file composable_entity.h.

◆ GetTypeDescription()

◆ HasComponent()

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].

Parameters
str_componentThe string label of the component to check.
Returns
true if this composable entity has a component with the given string label.
See also
GetTypeDescription()

Definition at line 150 of file composable_entity.cpp.

◆ RemoveComponent()

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.

Parameters
str_componentThe string label of the component to remove.
See also
GetTypeDescription()
Exceptions
CARGoSExceptionif the component was not found.

Definition at line 83 of file composable_entity.cpp.

◆ Reset()

void argos::CComposableEntity::Reset ( )
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.

◆ SetEnabled()

void argos::CComposableEntity::SetEnabled ( bool  b_enabled)
virtual

Enables or disables an entity.

Parameters
b_enabledtrue if the entity is enabled, false otherwise
See also
CEntity::m_bEnabled
CEntity::m_bCanBeEnabledIfDisabled

Reimplemented from argos::CEntity.

Definition at line 47 of file composable_entity.cpp.

◆ Update()

void argos::CComposableEntity::Update ( )
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.

See also
UpdateComponents()

Reimplemented from argos::CEntity.

Definition at line 40 of file composable_entity.cpp.

◆ UpdateComponents()

void argos::CComposableEntity::UpdateComponents ( )
virtual