18 class CComposableEntity;
22 #include <argos3/core/utility/datatypes/datatypes.h>
23 #include <argos3/core/utility/configuration/argos_configuration.h>
24 #include <argos3/core/utility/configuration/base_configurable_resource.h>
25 #include <argos3/core/utility/plugins/factory.h>
26 #include <argos3/core/utility/plugins/vtable.h>
32 #if defined(__apple_build_version__ )
34 # if __clang_major__ >= 5
36 # include <unordered_map>
37 using std::unordered_map;
40 # include <tr1/unordered_map>
41 using std::tr1::unordered_map;
45 # include <tr1/unordered_map>
46 using std::tr1::unordered_map;
100 typedef unordered_map<std::string, CEntity*>
TMap;
123 const std::string& str_id);
157 inline const std::string&
GetId()
const {
172 return (m_pcParent != NULL);
206 m_pcParent = &c_parent;
330 template <
typename LABEL,
typename PLUGIN,
typename RETURN_TYPE>
333 template <
typename DERIVED,
typename OPERATION_IMPL>
335 return Dispatch<DERIVED, OPERATION_IMPL>(t_plugin, c_entity);
338 template <
typename DERIVED,
typename OPERATION_IMPL>
341 OPERATION_IMPL& tOperation =
static_cast<OPERATION_IMPL&
>(*this);
343 DERIVED& tDerived =
static_cast<DERIVED&
>(c_entity);
345 return tOperation.ApplyTo(t_plugin, tDerived);
362 template <
typename LABEL,
typename PLUGIN,
typename RETURN_TYPE>
363 class CEntityOperationInstanceHolder {
365 ~CEntityOperationInstanceHolder() {
366 while(!m_vecOperationInstances.empty()) {
367 if(m_vecOperationInstances.back() != NULL) {
368 delete m_vecOperationInstances.back();
370 m_vecOperationInstances.pop_back();
373 template <
typename DERIVED>
374 void Add(CEntityOperation<LABEL, PLUGIN, RETURN_TYPE>* pc_operation) {
376 size_t unIndex = GetTag<DERIVED, CEntity>();
378 if(unIndex >= m_vecOperationInstances.size()) {
383 m_vecOperationInstances.resize(unIndex+1, NULL);
385 m_vecOperationInstances[unIndex] = pc_operation;
387 CEntityOperation<LABEL, PLUGIN, RETURN_TYPE>* operator[](
size_t un_index)
const {
388 if(un_index >= m_vecOperationInstances.size()) {
391 return m_vecOperationInstances[un_index];
394 std::vector<CEntityOperation<LABEL, PLUGIN, RETURN_TYPE>*> m_vecOperationInstances;
404 template <
typename LABEL,
typename PLUGIN,
typename RETURN_VALUE>
405 CEntityOperationInstanceHolder<LABEL, PLUGIN, RETURN_VALUE>& GetEntityOperationInstanceHolder() {
406 static CEntityOperationInstanceHolder<LABEL, PLUGIN, RETURN_VALUE> cHolder;
417 template<
typename LABEL,
typename PLUGIN,
typename RETURN_VALUE>
420 TFunction tFunction = GetVTable<LABEL, CEntity, TFunction>()[c_entity.GetTag()];
421 if(tFunction != NULL) {
423 if(pcOperation != NULL) {
424 return (pcOperation->*tFunction)(t_plugin, c_entity);
427 return RETURN_VALUE();
432 #define REGISTER_ENTITY(CLASSNAME, \
439 REGISTER_SYMBOL(CEntity, \
451 #define REGISTER_ENTITY_OPERATION(LABEL, PLUGIN, OPERATION, RETURN_VALUE, DERIVED) \
452 class C ## LABEL ## PLUGIN ## OPERATION ## RETURN_VALUE ## DERIVED { \
453 typedef RETURN_VALUE (CEntityOperation<LABEL, PLUGIN, RETURN_VALUE>::*TFunction)(PLUGIN&, CEntity&); \
455 C ## LABEL ## PLUGIN ## OPERATION ## RETURN_VALUE ## DERIVED() { \
456 GetVTable<LABEL, CEntity, TFunction>().Add<DERIVED>(&OPERATION::Hook<DERIVED, OPERATION>); \
457 GetEntityOperationInstanceHolder<LABEL, PLUGIN, RETURN_VALUE>().Add<DERIVED>(new OPERATION()); \
459 } c ## LABEL ## PLUGIN ## OPERATION ## RETURN_VALUE ## DERIVED;
The namespace containing all the ARGoS related code.
RETURN_VALUE CallEntityOperation(PLUGIN &t_plugin, CEntity &c_entity)
Calls the operation corresponding to the given context and operand Skips the function call if the ope...
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
Basic class for an entity that contains other entities.
virtual void Reset()
Resets the state of the entity to whatever it was after Init() or the standalone constructor was call...
void Disable()
Disables the entity.
std::vector< CEntity * > TVector
A vector of entities.
virtual void Update()
Updates the state of this entity.
const std::string & GetId() const
Returns the id of this entity.
void SetIndex(ssize_t n_idx)
Sets the entity index.
CEntity & GetRootEntity()
Returns the root entity containing this entity.
std::string GetContext() const
Returns the context of this entity.
std::multimap< std::string, CEntity * > TMultiMap
A multi-map of entities.
TConfigurationNode * GetConfigurationNode()
Returns a pointer to the configuration node that was used to create this entity.
bool IsEnabled() const
Returns true if the entity is enabled.
CEntity(CComposableEntity *pc_parent)
Class constructor.
void Enable()
Enables the entity.
virtual ~CEntity()
Class destructor.
CComposableEntity & GetParent()
Returns this entity's parent.
virtual void SetEnabled(bool b_enabled)
Enables or disables an entity.
void SetParent(CComposableEntity &c_parent)
Sets this entity's parent.
virtual void Destroy()
Destroys the entity, undoing whatever was done by Init() or by the standalone constructor.
virtual std::string GetTypeDescription() const
Returns a string label for this class.
bool HasParent() const
Returns true if this entity has a parent.
ssize_t GetIndex() const
Returns the entity index.
virtual void Init(TConfigurationNode &t_tree)
Initializes the state of the entity from the XML configuration tree.
unordered_map< std::string, CEntity * > TMap
A map of entities.
A generic entity comparator, used in containers that must be ordered deterministically.
bool operator()(const CEntity &c_a, const CEntity &c_b) const
bool operator()(const CEntity *pc_a, const CEntity *pc_b) const
The basic operation to be stored in the vtable.
RETURN_TYPE Hook(PLUGIN &t_plugin, CEntity &c_entity)
RETURN_TYPE Dispatch(PLUGIN &t_plugin, CEntity &c_entity)
Type to use as return value for operation outcome.
SOperationOutcome(bool b_value)
This class is the base of all XML-configurable ARGoS interface.
Helper to make a class hierarchy vtable-enabled.