22#include <argos3/core/utility/datatypes/any.h>
23#include <argos3/core/simulator/medium/medium.h>
24#include <argos3/core/simulator/entity/embodied_entity.h>
25#include <argos3/core/simulator/entity/controllable_entity.h>
56 typedef std::map <std::string, CAny, std::less <std::string> >
TMapPerType;
79 typedef std::map <std::string, TMapPerType, std::less <std::string> >
TMapPerTypePerId;
116 virtual void Reset();
163 return *(it->second);
166 "\" when requesting entity from space.");
178 const std::string& str_pattern);
227 return GetEntitiesByTypeImpl(str_type);
231 return GetEntitiesByTypeImpl(str_type);
273 template <
typename ENTITY>
275 std::string strEntityQualifiedName = c_entity.GetContext() + c_entity.GetId();
279 c_entity.GetTypeDescription() <<
280 " entity with id \"" <<
281 strEntityQualifiedName <<
282 "\". An entity with that id already exists.");
285 if(!c_entity.HasParent()) {
296 c_entity.SetIndex(unIdx);
306 template <
typename ENTITY>
308 std::string strEntityQualifiedName = c_entity.GetContext() + c_entity.GetId();
313 TMapPerType::iterator itMapPerTypePerId = itMapPerType->second.find(strEntityQualifiedName);
314 if(itMapPerTypePerId != itMapPerType->second.end()) {
316 CEntity::TVector::iterator itVec = find(
m_vecEntities.begin(),
321 itMapPerType->second.erase(itMapPerTypePerId);
323 if(!c_entity.HasParent()) {
336 strEntityQualifiedName <<
337 "\" has not been found in the indexes.");
506 TMapPerType& GetEntitiesByTypeImpl(
const std::string& str_type)
const;
513 template <
typename ACTION>
533#define SPACE_OPERATION_ADD_ENTITY(ENTITY) \
534 class CSpaceOperationAdd ## ENTITY : public CSpaceOperationAddEntity { \
536 void ApplyTo(CSpace& c_space, ENTITY& c_entity) { \
537 c_space.AddEntity(c_entity); \
541#define SPACE_OPERATION_REMOVE_ENTITY(ENTITY) \
542 class CSpaceOperationRemove ## ENTITY : public CSpaceOperationRemoveEntity { \
544 void ApplyTo(CSpace& c_space, ENTITY& c_entity) { \
545 c_space.RemoveEntity(c_entity); \
549#define REGISTER_SPACE_OPERATION(ACTION, OPERATION, ENTITY) \
550 REGISTER_ENTITY_OPERATION(ACTION, CSpace, OPERATION, void, ENTITY);
552#define REGISTER_STANDARD_SPACE_OPERATION_ADD_ENTITY(ENTITY) \
553 SPACE_OPERATION_ADD_ENTITY(ENTITY) \
554 REGISTER_SPACE_OPERATION(CSpaceOperationAddEntity, \
555 CSpaceOperationAdd ## ENTITY, \
558#define REGISTER_STANDARD_SPACE_OPERATION_REMOVE_ENTITY(ENTITY) \
559 SPACE_OPERATION_REMOVE_ENTITY(ENTITY) \
560 REGISTER_SPACE_OPERATION(CSpaceOperationRemoveEntity, \
561 CSpaceOperationRemove ## ENTITY, \
564#define REGISTER_STANDARD_SPACE_OPERATIONS_ON_ENTITY(ENTITY) \
565 REGISTER_STANDARD_SPACE_OPERATION_ADD_ENTITY(ENTITY) \
566 REGISTER_STANDARD_SPACE_OPERATION_REMOVE_ENTITY(ENTITY)
unsigned int UInt32
32-bit unsigned integer.
#define THROW_ARGOSEXCEPTION(message)
This macro throws an ARGoS exception with the passed message.
The namespace containing all the ARGoS related code.
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
An entity that contains a pointer to the user-defined controller.
std::vector< CControllableEntity * > TVector
A vector of controllable entities.
This entity is a link to a body in the physics engine.
std::vector< CEntity * > TVector
A vector of entities.
unordered_map< std::string, CEntity * > TMap
A map of entities.
The basic operation to be stored in the vtable.
std::vector< CMedium * > TVector
std::vector< CPhysicsEngine * > TVector
void Distribute(TConfigurationNode &t_tree)
CControllableEntity::TVector m_vecControllableEntities
A vector of controllable entities.
virtual void Init(TConfigurationNode &t_tree)
Initializes the space using the <arena> section of the XML configuration file.
virtual void Destroy()
Destroys the space and all its entities.
const CVector3 & GetArenaCenter() const
Returns the arena center.
const CRange< CVector3 > & GetArenaLimits() const
Returns the arena limits.
virtual void Reset()
Reset the space and all its entities.
void AddBoxStrip(TConfigurationNode &t_tree)
bool ControllableEntityIterationEnabled() const
CRange< CVector3 > m_cArenaLimits
Arena limits.
friend class CSpaceOperationRemoveControllableEntity
UInt32 GetNumberEntities() const
Returns the number of entities contained in the space.
virtual void UpdatePhysics()=0
const CVector3 & GetArenaSize() const
Returns the arena size.
virtual void Update()
Updates the space.
virtual ~CSpace()
Class destructor.
std::map< std::string, CAny, std::less< std::string > > TMapPerType
A map of entities indexed by type description.
CFloorEntity & GetFloorEntity()
Returns the floor entity.
CSpace()
Class constructor.
CPhysicsEngine::TVector * m_ptPhysicsEngines
A pointer to the list of physics engines.
void SetArenaCenter(const CVector3 &c_center)
Sets the arena center.
CEntity::TMap m_mapEntitiesPerId
A map of entities.
void SetFloorEntity(CFloorEntity &c_floor_entity)
Sets the floor entity.
UInt32 m_unSimulationClock
The current simulation clock.
std::function< void(CControllableEntity *)> TControllableEntityIterCBType
The callback type for iteration over controllable entities within the PreStep() and/or PostStep() par...
void GetEntitiesMatching(CEntity::TVector &t_buffer, const std::string &str_pattern)
Returns the entities matching a given pattern.
TControllableEntityIterCBType m_cbControllableEntityIter
Callback for iterating over entities from within the loop functions.
TMapPerTypePerId m_mapEntitiesPerTypePerId
A map of maps of all the simulated entities.
CEntity::TVector & GetEntityVector()
Returns a vector of all the entities in the space.
CMedium::TVector * m_ptMedia
A pointer to the list of media.
void SetSimulationClock(UInt32 un_simulation_clock)
Sets a new value for the simulation clock.
CEntity & GetEntity(const std::string &str_id)
Returns the entity with the given id.
virtual void ControllableEntityIterationWaitAbort()
If the loop functions do not perform entity iteration in either of the PreStep() or PostStep() functi...
virtual void IterateOverControllableEntities(const TControllableEntityIterCBType &c_cb)=0
Given a callback specified in the loop functions, iterate over all controllable entities currently pr...
virtual void UpdateControllableEntitiesAct()=0
void AddEntity(ENTITY &c_entity)
Adds an entity of the given type.
void IncreaseSimulationClock(UInt32 un_increase=1)
Increases the simulation clock by the wanted value.
UInt32 GetSimulationClock() const
Returns the current value of the simulation clock.
CVector3 m_cArenaSize
Arena size.
CVector3 m_cArenaCenter
Arena center.
CEntity::TMap & GetEntityMapPerId()
Returns a map of all entities ordered by id.
const TMapPerType & GetEntitiesByType(const std::string &str_type) const
TMapPerTypePerId & GetEntityMapPerTypePerId()
Returns a nested map of entities, ordered by type and by id.
friend class CSpaceOperationAddEmbodiedEntity
CEntity::TVector m_vecRootEntities
A vector of all the entities without a parent.
CFloorEntity * m_pcFloorEntity
The floor entity.
virtual void UpdateMedia()=0
virtual void AddEntityToPhysicsEngine(CEmbodiedEntity &c_entity)
void SetArenaSize(const CVector3 &c_size)
Sets the arena size.
virtual void AddControllableEntity(CControllableEntity &c_entity)
TMapPerType & GetEntitiesByType(const std::string &str_type)
Returns a map containing all the objects of a given type.
CSimulator & m_cSimulator
CEntity::TVector m_vecEntities
A vector of entities.
virtual void UpdateControllableEntitiesSenseStep()=0
std::map< std::string, TMapPerType, std::less< std::string > > TMapPerTypePerId
A map of entities indexed by type description and by id.
virtual void RemoveControllableEntity(CControllableEntity &c_entity)
CEntity::TVector & GetRootEntityVector()
Returns a vector of all the root entities in the space.
void RemoveEntity(ENTITY &c_entity)
Removes an entity of the given type.
friend class CSpaceOperationAddControllableEntity
virtual ~CSpaceOperation()
virtual ~CSpaceOperationAddEntity()
virtual ~CSpaceOperationRemoveEntity()
This class is the base of all XML-configurable ARGoS interface.
void Set(const Real f_x, const Real f_y, const Real f_z)
Sets the vector contents from Cartesian coordinates.