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;
std::vector< CEntity * > TVector
A vector of entities.
bool operator()(const CEntity &c_a, const CEntity &c_b) const
virtual void SetEnabled(bool b_enabled)
Enables or disables an entity.
A generic entity comparator, used in containers that must be ordered deterministically.
void Enable()
Enables the entity.
CEntity(CComposableEntity *pc_parent)
Class constructor.
bool HasParent() const
Returns true if this entity has a parent.
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
Type to use as return value for operation outcome.
RETURN_TYPE Dispatch(PLUGIN &t_plugin, CEntity &c_entity)
virtual ~CEntity()
Class destructor.
RETURN_TYPE Hook(PLUGIN &t_plugin, CEntity &c_entity)
virtual std::string GetTypeDescription() const
Returns a string label for this class.
CEntity & GetRootEntity()
Returns the root entity containing this entity.
Basic class for an entity that contains other entities.
unordered_map< std::string, CEntity * > TMap
A map of entities.
std::multimap< std::string, CEntity * > TMultiMap
A multi-map of entities.
SOperationOutcome(bool b_value)
ssize_t GetIndex() const
Returns the entity index.
virtual void Update()
Updates the state of this entity.
bool IsEnabled() const
Returns true if the entity is enabled.
virtual void Reset()
Resets the state of the entity to whatever it was after Init() or the standalone constructor was call...
void SetIndex(ssize_t n_idx)
Sets the entity index.
virtual void Init(TConfigurationNode &t_tree)
Initializes the state of the entity from the XML configuration tree.
void Disable()
Disables the entity.
The basic operation to be stored in the vtable.
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...
const std::string & GetId() const
Returns the id of this entity.
CComposableEntity & GetParent()
Returns this entity's parent.
The namespace containing all the ARGoS related code.
TConfigurationNode * GetConfigurationNode()
Returns a pointer to the configuration node that was used to create this entity.
std::string GetContext() const
Returns the context of this entity.
void SetParent(CComposableEntity &c_parent)
Sets this entity's parent.
This class is the base of all XML-configurable ARGoS interface.
bool operator()(const CEntity *pc_a, const CEntity *pc_b) const
virtual void Destroy()
Destroys the entity, undoing whatever was done by Init() or by the standalone constructor.
Helper to make a class hierarchy vtable-enabled.