13 #ifndef COMPOSABLE_ENTITY_H
14 #define COMPOSABLE_ENTITY_H
17 class CComposableEntity;
20 #include <argos3/core/simulator/entity/entity.h>
21 #include <argos3/core/simulator/space/space.h>
56 const std::string& str_id);
137 E* pcComponent =
dynamic_cast<E*
>(&
GetComponent(str_component));
138 if(pcComponent != NULL) {
166 CEntity::TMultiMap::iterator
FindComponent(
const std::string& str_component);
173 return m_mapComponents;
182 return m_vecComponents;
195 #define SPACE_OPERATION_ADD_COMPOSABLE_ENTITY(ENTITY) \
196 class CSpaceOperationAdd ## ENTITY : public CSpaceOperationAddEntity { \
198 void ApplyTo(CSpace& c_space, ENTITY& c_entity) { \
199 c_space.AddEntity(c_entity); \
200 for(size_t i = 0; i < c_entity.GetComponentVector().size(); ++i) { \
201 CallEntityOperation<CSpaceOperationAddEntity, CSpace, void>(c_space, *(c_entity.GetComponentVector()[i])); \
206 #define SPACE_OPERATION_REMOVE_COMPOSABLE_ENTITY(ENTITY) \
207 class CSpaceOperationRemove ## ENTITY : public CSpaceOperationRemoveEntity { \
209 void ApplyTo(CSpace& c_space, ENTITY& c_entity) { \
210 CEntity* pcToRemove; \
211 while(!c_entity.GetComponentVector().empty()) { \
212 pcToRemove = c_entity.GetComponentVector().back(); \
213 c_entity.RemoveComponent(pcToRemove->GetTypeDescription() + "[" + pcToRemove->GetId() + "]"); \
214 CallEntityOperation<CSpaceOperationRemoveEntity, CSpace, void>(c_space, *pcToRemove); \
216 c_space.RemoveEntity(c_entity); \
220 #define REGISTER_STANDARD_SPACE_OPERATION_ADD_COMPOSABLE(ENTITY) \
221 SPACE_OPERATION_ADD_COMPOSABLE_ENTITY(ENTITY) \
222 REGISTER_SPACE_OPERATION(CSpaceOperationAddEntity, \
223 CSpaceOperationAdd ## ENTITY, \
226 #define REGISTER_STANDARD_SPACE_OPERATION_REMOVE_COMPOSABLE(ENTITY) \
227 SPACE_OPERATION_REMOVE_COMPOSABLE_ENTITY(ENTITY) \
228 REGISTER_SPACE_OPERATION(CSpaceOperationRemoveEntity, \
229 CSpaceOperationRemove ## ENTITY, \
232 #define REGISTER_STANDARD_SPACE_OPERATIONS_ON_COMPOSABLE(ENTITY) \
233 REGISTER_STANDARD_SPACE_OPERATION_ADD_COMPOSABLE(ENTITY) \
234 REGISTER_STANDARD_SPACE_OPERATION_REMOVE_COMPOSABLE(ENTITY)
CEntity::TMultiMap & GetComponentMap()
Returns the map of all the components.
std::vector< CEntity * > TVector
A vector of entities.
virtual ~CComposableEntity()
Class destructor.
#define THROW_ARGOSEXCEPTION(message)
This macro throws an ARGoS exception with the passed message.
virtual void SetEnabled(bool b_enabled)
Enables or disables an entity.
virtual std::string GetTypeDescription() const
Returns a string label for this class.
E & GetComponent(const std::string &str_component)
Returns the component with the passed string label.
Basic class for an entity that contains other entities.
std::multimap< std::string, CEntity * > TMultiMap
A multi-map of entities.
CEntity::TVector & GetComponentVector()
Returns the vector of all the components.
void AddComponent(CEntity &c_component)
Adds a component to this composable entity.
CComposableEntity(CComposableEntity *pc_parent)
Class constructor.
bool HasComponent(const std::string &str_component)
Returns true if this composable entity has a component with the given string label.
const std::string & GetId() const
Returns the id of this entity.
The namespace containing all the ARGoS related code.
CEntity::TMultiMap::iterator FindComponent(const std::string &str_component)
Searches for a component with the given string label.
virtual void UpdateComponents()
Calls the Update() method on all the components.
virtual void Update()
Updates the status of this entity.
virtual void Reset()
Resets the state of the entity to whatever it was after Init() or the standalone constructor was call...
CEntity & GetComponent(const std::string &str_component)
Returns the component with the passed string label.
CEntity & RemoveComponent(const std::string &str_component)
Removes a component from this composable entity.