From d14ebd8126f91eadc8a3a2465044160d9148b6b5 Mon Sep 17 00:00:00 2001 From: Michael Allwright Date: Fri, 30 Mar 2018 15:14:17 +0200 Subject: [PATCH] Updated entity enable/disable logic to be consistent with fffd3e5e8fc5d9f5369d9dc605c6a88217db6421 --- .../entities/directional_led_entity.cpp | 81 +++++++++++------- .../entities/directional_led_entity.h | 29 ++----- .../directional_led_equipped_entity.cpp | 26 +++--- .../directional_led_equipped_entity.h | 12 +-- .../simulator/entities/radio_entity.cpp | 77 +++++++++++++---- src/plugins/simulator/entities/radio_entity.h | 31 +++---- .../entities/radio_equipped_entity.cpp | 23 ++--- .../entities/radio_equipped_entity.h | 12 +-- src/plugins/simulator/entities/tag_entity.cpp | 83 ++++++++++++------- src/plugins/simulator/entities/tag_entity.h | 28 ++----- .../entities/tag_equipped_entity.cpp | 29 +++---- .../simulator/entities/tag_equipped_entity.h | 12 +-- 12 files changed, 235 insertions(+), 208 deletions(-) diff --git a/src/plugins/simulator/entities/directional_led_entity.cpp b/src/plugins/simulator/entities/directional_led_entity.cpp index 806bacca..70f4212f 100644 --- a/src/plugins/simulator/entities/directional_led_entity.cpp +++ b/src/plugins/simulator/entities/directional_led_entity.cpp @@ -69,16 +69,25 @@ namespace argos { /****************************************/ void CDirectionalLEDEntity::Destroy() { - if(HasMedium()) { - RemoveFromMedium(); - } + Disable(); } /****************************************/ /****************************************/ void CDirectionalLEDEntity::SetEnabled(bool b_enabled) { - CEntity::SetEnabled(m_cColor != CColor::BLACK); + /* Perform generic enable behavior */ + CEntity::SetEnabled(b_enabled); + if(b_enabled) { + /* Enable entity in medium */ + if(m_pcMedium && GetIndex() >= 0) + m_pcMedium->AddEntity(*this); + } + else { + /* Disable entity in medium */ + if(m_pcMedium) + m_pcMedium->RemoveEntity(*this); + } } /****************************************/ @@ -92,35 +101,21 @@ namespace argos { /****************************************/ /****************************************/ - void CDirectionalLEDEntity::AddToMedium(CDirectionalLEDMedium& c_medium) { - if(HasMedium()) RemoveFromMedium(); - m_pcMedium = &c_medium; - c_medium.AddEntity(*this); - Enable(); - } - - /****************************************/ - /****************************************/ - - void CDirectionalLEDEntity::RemoveFromMedium() { - try { - GetMedium().RemoveEntity(*this); - m_pcMedium = nullptr; - Disable(); - } - catch(CARGoSException& ex) { - THROW_ARGOSEXCEPTION_NESTED("Can't remove directional LED entity \"" << GetContext() + GetId() << "\" from medium.", ex); + CDirectionalLEDMedium& CDirectionalLEDEntity::GetMedium() const { + if(m_pcMedium == nullptr) { + THROW_ARGOSEXCEPTION("directional LED entity \"" << GetContext() << + GetId() << "\" has no associated medium."); } + return *m_pcMedium; } /****************************************/ /****************************************/ - - CDirectionalLEDMedium& CDirectionalLEDEntity::GetMedium() const { - if(m_pcMedium == nullptr) { - THROW_ARGOSEXCEPTION("Directional LED entity \"" << GetContext() + GetId() << "\" has no medium associated."); - } - return *m_pcMedium; + + void CDirectionalLEDEntity::SetMedium(CDirectionalLEDMedium& c_medium) { + if(m_pcMedium != nullptr && m_pcMedium != &c_medium) + m_pcMedium->RemoveEntity(*this); + m_pcMedium = &c_medium; } /****************************************/ @@ -167,7 +162,35 @@ namespace argos { /****************************************/ /****************************************/ - REGISTER_STANDARD_SPACE_OPERATIONS_ON_ENTITY(CDirectionalLEDEntity); + class CSpaceOperationAddCDirectionalLEDEntity : public CSpaceOperationAddEntity { + public: + void ApplyTo(CSpace& c_space, CDirectionalLEDEntity& c_entity) { + /* Add entity to space - this ensures that the directional LED entity + * gets an id before being added to the directional LED medium */ + c_space.AddEntity(c_entity); + /* Enable the directional LED entity, if it's enabled - this ensures that + * the entity gets added to the directional LED medium if it's enabled */ + c_entity.SetEnabled(c_entity.IsEnabled()); + } + }; + + class CSpaceOperationRemoveCDirectionalLEDEntity : public CSpaceOperationRemoveEntity { + public: + void ApplyTo(CSpace& c_space, CDirectionalLEDEntity& c_entity) { + /* Disable the entity - this ensures that the entity is + * removed from the directional LED medium */ + c_entity.Disable(); + /* Remove the directional LED entity from space */ + c_space.RemoveEntity(c_entity); + } + }; + + REGISTER_SPACE_OPERATION(CSpaceOperationAddEntity, + CSpaceOperationAddCDirectionalLEDEntity, + CDirectionalLEDEntity); + REGISTER_SPACE_OPERATION(CSpaceOperationRemoveEntity, + CSpaceOperationRemoveCDirectionalLEDEntity, + CDirectionalLEDEntity); /****************************************/ /****************************************/ diff --git a/src/plugins/simulator/entities/directional_led_entity.h b/src/plugins/simulator/entities/directional_led_entity.h index a66bcedf..f2e15932 100644 --- a/src/plugins/simulator/entities/directional_led_entity.h +++ b/src/plugins/simulator/entities/directional_led_entity.h @@ -102,24 +102,6 @@ namespace argos { return "directional_led"; } - /** - * Adds the directional LEDs to the wanted directional LED medium. - * If this LED has already been added to a medium, the LED is - * removed from that medium and then added to the passed one. - * This behavior is to enforce that, at any time, an LED is - * under the control of (at most) a single medium. - * @param c_medium The LED medium. - * @see CDirectionalLEDMedium - */ - void AddToMedium(CDirectionalLEDMedium& c_medium); - - /** - * Removes the directional LEDs from the specified directional LED medium. - * @param c_medium The LED medium. - * @see CDirectionalLEDMedium - */ - void RemoveFromMedium(); - /** * Returns true if this directional LED is associated to a medium. * @return true if this directional LED is associated to a medium. @@ -130,12 +112,19 @@ namespace argos { } /** - * Returns the medium associated to this LED. - * @return The medium associated to this LED. + * Returns the medium associated to this directional LED. + * @return The medium associated to this directional LED. * @see CDirectionalLEDMedium */ CDirectionalLEDMedium& GetMedium() const; + /** + * Sets the medium associated to this entity. + * @param c_medium The medium to associate to this entity. + * @see CDirectionalLEDMedium + */ + void SetMedium(CDirectionalLEDMedium& c_medium); + protected: CRadians m_cObservableAngle; diff --git a/src/plugins/simulator/entities/directional_led_equipped_entity.cpp b/src/plugins/simulator/entities/directional_led_equipped_entity.cpp index 2c3c045a..8168da6e 100644 --- a/src/plugins/simulator/entities/directional_led_equipped_entity.cpp +++ b/src/plugins/simulator/entities/directional_led_equipped_entity.cpp @@ -70,7 +70,8 @@ namespace argos { * 3. the "body" is an embodied entity * If any of the above is false, this line will bomb out. */ - CEmbodiedEntity& cBody = GetParent().GetComponent("body"); + CEmbodiedEntity& cBody = + GetParent().GetComponent("body"); /* Add the LED to this container */ m_vecInstances.emplace_back(*pcLED, cBody.GetAnchor(strAnchorId), @@ -99,7 +100,9 @@ namespace argos { /****************************************/ void CDirectionalLEDEquippedEntity::Enable() { - CEntity::Enable(); + /* Perform generic enable behavior */ + CComposableEntity::Enable(); + /* Enable anchors */ for(SInstance& s_instance : m_vecInstances) { s_instance.Anchor.Enable(); } @@ -109,7 +112,9 @@ namespace argos { /****************************************/ void CDirectionalLEDEquippedEntity::Disable() { - CEntity::Disable(); + /* Perform generic disable behavior */ + CComposableEntity::Disable(); + /* Disable anchors */ for(SInstance& s_instance : m_vecInstances) { s_instance.Anchor.Disable(); } @@ -196,21 +201,10 @@ namespace argos { /****************************************/ /****************************************/ - void CDirectionalLEDEquippedEntity::AddToMedium(CDirectionalLEDMedium& c_medium) { + void CDirectionalLEDEquippedEntity::SetMedium(CDirectionalLEDMedium& c_medium) { for(SInstance& s_instance : m_vecInstances) { - s_instance.LED.AddToMedium(c_medium); + s_instance.LED.SetMedium(c_medium); } - Enable(); - } - - /****************************************/ - /****************************************/ - - void CDirectionalLEDEquippedEntity::RemoveFromMedium() { - for(SInstance& s_instance : m_vecInstances) { - s_instance.LED.RemoveFromMedium(); - } - Disable(); } /****************************************/ diff --git a/src/plugins/simulator/entities/directional_led_equipped_entity.h b/src/plugins/simulator/entities/directional_led_equipped_entity.h index 257823b2..46da31a0 100644 --- a/src/plugins/simulator/entities/directional_led_equipped_entity.h +++ b/src/plugins/simulator/entities/directional_led_equipped_entity.h @@ -124,17 +124,11 @@ namespace argos { void SetLEDColors(const std::vector& vec_colors); /** - * Adds the LEDs to the wanted LED medium. - * @param c_medium The LED medium. + * Sets the medium associated to this entity. + * @param c_medium The medium to associate to this entity. * @see CDirectionalLEDMedium */ - void AddToMedium(CDirectionalLEDMedium& c_medium); - - /** - * Removes the LEDs from the associated LED medium. - * @see CDirectionalLEDMedium - */ - void RemoveFromMedium(); + void SetMedium(CDirectionalLEDMedium& c_medium); virtual std::string GetTypeDescription() const { return "directional_leds"; diff --git a/src/plugins/simulator/entities/radio_entity.cpp b/src/plugins/simulator/entities/radio_entity.cpp index 463f9136..924efde4 100644 --- a/src/plugins/simulator/entities/radio_entity.cpp +++ b/src/plugins/simulator/entities/radio_entity.cpp @@ -43,33 +43,43 @@ namespace argos { /****************************************/ /****************************************/ - void CRadioEntity::AddToMedium(CRadioMedium& c_medium) { - if(HasMedium()) RemoveFromMedium(); - m_pcMedium = &c_medium; - c_medium.AddEntity(*this); - Enable(); + void CRadioEntity::Reset() { + /* Erase received messages */ + m_vecData.clear(); } /****************************************/ /****************************************/ - void CRadioEntity::RemoveFromMedium() { - try { - GetMedium().RemoveEntity(*this); - m_pcMedium = nullptr; - Disable(); + void CRadioEntity::Destroy() { + Disable(); + } + + /****************************************/ + /****************************************/ + + void CRadioEntity::SetEnabled(bool b_enabled) { + /* Perform generic enable behavior */ + CEntity::SetEnabled(b_enabled); + if(b_enabled) { + /* Enable entity in medium */ + if(m_pcMedium && GetIndex() >= 0) + m_pcMedium->AddEntity(*this); } - catch(CARGoSException& ex) { - THROW_ARGOSEXCEPTION_NESTED("Can't remove radio entity \"" << GetContext() + GetId() << "\" from medium.", ex); + else { + /* Disable entity in medium */ + if(m_pcMedium) + m_pcMedium->RemoveEntity(*this); } } /****************************************/ /****************************************/ - + CRadioMedium& CRadioEntity::GetMedium() const { if(m_pcMedium == nullptr) { - THROW_ARGOSEXCEPTION("Radio entity \"" << GetContext() + GetId() << "\" has no medium associated."); + THROW_ARGOSEXCEPTION("radio entity \"" << GetContext() << GetId() << + "\" has no associated medium."); } return *m_pcMedium; } @@ -77,6 +87,15 @@ namespace argos { /****************************************/ /****************************************/ + void CRadioEntity::SetMedium(CRadioMedium& c_medium) { + if(m_pcMedium != nullptr && m_pcMedium != &c_medium) + m_pcMedium->RemoveEntity(*this); + m_pcMedium = &c_medium; + } + + /****************************************/ + /****************************************/ + void CRadioEntitySpaceHashUpdater::operator()(CAbstractSpaceHash& c_space_hash, CRadioEntity& c_element) { /* Calculate the position of the radop in the space hash */ @@ -112,7 +131,35 @@ namespace argos { /****************************************/ /****************************************/ - REGISTER_STANDARD_SPACE_OPERATIONS_ON_ENTITY(CRadioEntity); + class CSpaceOperationAddCRadioEntity : public CSpaceOperationAddEntity { + public: + void ApplyTo(CSpace& c_space, CRadioEntity& c_entity) { + /* Add entity to space - this ensures that the radio entity + * gets an id before being added to the radio medium */ + c_space.AddEntity(c_entity); + /* Enable the radio entity, if it's enabled - this ensures that + * the entity gets added to the radio if it's enabled */ + c_entity.SetEnabled(c_entity.IsEnabled()); + } + }; + + class CSpaceOperationRemoveCRadioEntity : public CSpaceOperationRemoveEntity { + public: + void ApplyTo(CSpace& c_space, CRadioEntity& c_entity) { + /* Disable the entity - this ensures that the entity is + * removed from the radio medium */ + c_entity.Disable(); + /* Remove the radio entity from space */ + c_space.RemoveEntity(c_entity); + } + }; + + REGISTER_SPACE_OPERATION(CSpaceOperationAddEntity, + CSpaceOperationAddCRadioEntity, + CRadioEntity); + REGISTER_SPACE_OPERATION(CSpaceOperationRemoveEntity, + CSpaceOperationRemoveCRadioEntity, + CRadioEntity); /****************************************/ /****************************************/ diff --git a/src/plugins/simulator/entities/radio_entity.h b/src/plugins/simulator/entities/radio_entity.h index afc212da..2e0861b4 100644 --- a/src/plugins/simulator/entities/radio_entity.h +++ b/src/plugins/simulator/entities/radio_entity.h @@ -43,7 +43,11 @@ namespace argos { virtual void Init(TConfigurationNode& t_tree); - virtual void Reset() {} + virtual void Reset(); + + virtual void Destroy(); + + virtual void SetEnabled(bool b_enabled); /** * Returns a constant reference to the received data. @@ -104,24 +108,6 @@ namespace argos { return "radio"; } - /** - * Adds the radios to the specified radio medium. - * If this radio has already been added to a medium, the radio is - * first removed from that medium and then added to the passed one. - * This behavior is to enforce that, at any time, a radio is - * under the control of (at most) a single medium. - * @param c_medium The radio medium. - * @see CRadioMedium - */ - void AddToMedium(CRadioMedium& c_medium); - - /** - * Removes the radios from the specified radio medium. - * @param c_medium The radio medium. - * @see CRadioMedium - */ - void RemoveFromMedium(); - /** * Returns true if this radio is associated to a medium. * @return true if this radio is associated to a medium. @@ -138,6 +124,13 @@ namespace argos { */ CRadioMedium& GetMedium() const; + /** + * Sets the medium associated to this entity. + * @param c_medium The medium to associate to this entity. + * @see CRadioMedium + */ + void SetMedium(CRadioMedium& c_medium); + protected: Real m_fRange; diff --git a/src/plugins/simulator/entities/radio_equipped_entity.cpp b/src/plugins/simulator/entities/radio_equipped_entity.cpp index ba3f2fd5..7830119d 100644 --- a/src/plugins/simulator/entities/radio_equipped_entity.cpp +++ b/src/plugins/simulator/entities/radio_equipped_entity.cpp @@ -92,7 +92,9 @@ namespace argos { /****************************************/ void CRadioEquippedEntity::Enable() { - CEntity::Enable(); + /* Perform generic enable behavior */ + CComposableEntity::Enable(); + /* Enable anchors */ for(SInstance& s_instance : m_vecInstances) { s_instance.Anchor.Enable(); } @@ -102,7 +104,9 @@ namespace argos { /****************************************/ void CRadioEquippedEntity::Disable() { - CEntity::Disable(); + /* Perform generic disable behavior */ + CComposableEntity::Disable(); + /* Disable anchors */ for(SInstance& s_instance : m_vecInstances) { s_instance.Anchor.Disable(); } @@ -140,21 +144,10 @@ namespace argos { /****************************************/ /****************************************/ - void CRadioEquippedEntity::AddToMedium(CRadioMedium& c_medium) { + void CRadioEquippedEntity::SetMedium(CRadioMedium& c_medium) { for(SInstance& s_instance : m_vecInstances) { - s_instance.Radio.AddToMedium(c_medium); + s_instance.Radio.SetMedium(c_medium); } - Enable(); - } - - /****************************************/ - /****************************************/ - - void CRadioEquippedEntity::RemoveFromMedium() { - for(SInstance& s_instance : m_vecInstances) { - s_instance.Radio.RemoveFromMedium(); - } - Disable(); } /****************************************/ diff --git a/src/plugins/simulator/entities/radio_equipped_entity.h b/src/plugins/simulator/entities/radio_equipped_entity.h index 9573b0ca..ec87f8f4 100644 --- a/src/plugins/simulator/entities/radio_equipped_entity.h +++ b/src/plugins/simulator/entities/radio_equipped_entity.h @@ -100,17 +100,11 @@ namespace argos { } /** - * Adds the radios to the specified radio medium. - * @param c_medium The radio medium. + * Sets the medium associated to this entity. + * @param c_medium The medium to associate to this entity. * @see CRadioMedium */ - void AddToMedium(CRadioMedium& c_medium); - - /** - * Removes the radios from the associated radio medium. - * @see CRadioMedium - */ - void RemoveFromMedium(); + void SetMedium(CRadioMedium& c_medium); virtual std::string GetTypeDescription() const { return "radios"; diff --git a/src/plugins/simulator/entities/tag_entity.cpp b/src/plugins/simulator/entities/tag_entity.cpp index 4c43b1c1..597704de 100644 --- a/src/plugins/simulator/entities/tag_entity.cpp +++ b/src/plugins/simulator/entities/tag_entity.cpp @@ -71,16 +71,25 @@ namespace argos { /****************************************/ void CTagEntity::Destroy() { - if(HasMedium()) { - RemoveFromMedium(); - } + Disable(); } /****************************************/ /****************************************/ void CTagEntity::SetEnabled(bool b_enabled) { - CEntity::SetEnabled(m_strPayload.length() > 0); + /* Perform generic enable behavior */ + CEntity::SetEnabled(b_enabled); + if(b_enabled) { + /* Enable entity in medium */ + if(m_pcMedium && GetIndex() >= 0) + m_pcMedium->AddEntity(*this); + } + else { + /* Disable entity in medium */ + if(m_pcMedium) + m_pcMedium->RemoveEntity(*this); + } } /****************************************/ @@ -91,36 +100,13 @@ namespace argos { SetEnabled(m_strPayload.length() > 0); } - /****************************************/ - /****************************************/ - - void CTagEntity::AddToMedium(CTagMedium& c_medium) { - if(HasMedium()) RemoveFromMedium(); - m_pcMedium = &c_medium; - c_medium.AddEntity(*this); - Enable(); - } - - /****************************************/ - /****************************************/ - - void CTagEntity::RemoveFromMedium() { - try { - GetMedium().RemoveEntity(*this); - m_pcMedium = nullptr; - Disable(); - } - catch(CARGoSException& ex) { - THROW_ARGOSEXCEPTION_NESTED("Can't remove tag entity \"" << GetContext() + GetId() << "\" from medium.", ex); - } - } - /****************************************/ /****************************************/ CTagMedium& CTagEntity::GetMedium() const { if(m_pcMedium == nullptr) { - THROW_ARGOSEXCEPTION("Tag entity \"" << GetContext() + GetId() << "\" has no medium associated."); + THROW_ARGOSEXCEPTION("Tag entity \"" << GetContext() + GetId() << + "\" has no medium associated."); } return *m_pcMedium; } @@ -128,6 +114,15 @@ namespace argos { /****************************************/ /****************************************/ + void CTagEntity::SetMedium(CTagMedium& c_medium) { + if(m_pcMedium != NULL && m_pcMedium != &c_medium) + m_pcMedium->RemoveEntity(*this); + m_pcMedium = &c_medium; + } + + /****************************************/ + /****************************************/ + void CTagEntitySpaceHashUpdater::operator()(CAbstractSpaceHash& c_space_hash, CTagEntity& c_element) { /* Discard tags without a payload */ @@ -169,7 +164,35 @@ namespace argos { /****************************************/ /****************************************/ - REGISTER_STANDARD_SPACE_OPERATIONS_ON_ENTITY(CTagEntity); + class CSpaceOperationAddCTagEntity : public CSpaceOperationAddEntity { + public: + void ApplyTo(CSpace& c_space, CTagEntity& c_entity) { + /* Add entity to space - this ensures that the tag entity + * gets an id before being added to the tag medium */ + c_space.AddEntity(c_entity); + /* Enable the tag entity, if it's enabled - this ensures that + * the entity gets added to the tag if it's enabled */ + c_entity.SetEnabled(c_entity.IsEnabled()); + } + }; + + class CSpaceOperationRemoveCTagEntity : public CSpaceOperationRemoveEntity { + public: + void ApplyTo(CSpace& c_space, CTagEntity& c_entity) { + /* Disable the entity - this ensures that the entity is + * removed from the tag medium */ + c_entity.Disable(); + /* Remove the tag entity from space */ + c_space.RemoveEntity(c_entity); + } + }; + + REGISTER_SPACE_OPERATION(CSpaceOperationAddEntity, + CSpaceOperationAddCTagEntity, + CTagEntity); + REGISTER_SPACE_OPERATION(CSpaceOperationRemoveEntity, + CSpaceOperationRemoveCTagEntity, + CTagEntity); /****************************************/ /****************************************/ diff --git a/src/plugins/simulator/entities/tag_entity.h b/src/plugins/simulator/entities/tag_entity.h index 442055aa..5b92607b 100644 --- a/src/plugins/simulator/entities/tag_entity.h +++ b/src/plugins/simulator/entities/tag_entity.h @@ -110,31 +110,13 @@ namespace argos { return "tag"; } - /** - * Adds the tags to the specified tag medium. - * If this tag has already been added to a medium, the tag is - * removed from that medium and then added to the passed one. - * This behavior is to enforce that, at any time, a tag is - * under the control of (at most) a single medium. - * @param c_medium The tag medium. - * @see CTagMedium - */ - void AddToMedium(CTagMedium& c_medium); - - /** - * Removes the tags from the specified tag medium. - * @param c_medium The tag medium. - * @see CTagMedium - */ - void RemoveFromMedium(); - /** * Returns true if this tag is associated to a medium. * @return true if this tag is associated to a medium. * @see CTagMedium */ inline bool HasMedium() const { - return m_pcMedium != NULL; + return m_pcMedium != nullptr; } /** @@ -144,6 +126,14 @@ namespace argos { */ CTagMedium& GetMedium() const; + /** + * Sets the medium associated to this entity. + * @param c_medium The medium to associate to this entity. + * @see CTagMedium + */ + void SetMedium(CTagMedium& c_medium); + + protected: CRadians m_cObservableAngle; diff --git a/src/plugins/simulator/entities/tag_equipped_entity.cpp b/src/plugins/simulator/entities/tag_equipped_entity.cpp index 1cf0ae15..a97cfe8f 100644 --- a/src/plugins/simulator/entities/tag_equipped_entity.cpp +++ b/src/plugins/simulator/entities/tag_equipped_entity.cpp @@ -99,7 +99,9 @@ namespace argos { /****************************************/ void CTagEquippedEntity::Enable() { - CEntity::Enable(); + /* Perform generic enable behavior */ + CComposableEntity::Enable(); + /* Enable anchors */ for(SInstance& s_instance : m_vecInstances) { s_instance.Anchor.Enable(); } @@ -109,7 +111,9 @@ namespace argos { /****************************************/ void CTagEquippedEntity::Disable() { - CEntity::Disable(); + /* Perform generic disable behavior */ + CComposableEntity::Disable(); + /* Disable anchors */ for(SInstance& s_instance : m_vecInstances) { s_instance.Anchor.Disable(); } @@ -121,7 +125,7 @@ namespace argos { CTagEntity& CTagEquippedEntity::GetTag(UInt32 un_index) { ARGOS_ASSERT(un_index < m_vecInstances.size(), "CTagEquippedEntity::GetTag(), id=\"" << - GetContext() + GetId() << + GetContext() << GetId() << "\": index out of bounds: un_index = " << un_index << ", m_vecInstances.size() = " << @@ -136,7 +140,7 @@ namespace argos { const std::string& str_payload) { ARGOS_ASSERT(un_index < m_vecInstances.size(), "CTagEquippedEntity::SetTagPayload(), id=\"" << - GetContext() + GetId() << + GetContext() << GetId() << "\": index out of bounds: un_index = " << un_index << ", m_vecInstances.size() = " << @@ -165,7 +169,7 @@ namespace argos { else { THROW_ARGOSEXCEPTION( "CTagEquippedEntity::SetTagPayloads(), id=\"" << - GetContext() + GetId() << + GetContext() << GetId() << "\": number of tags (" << m_vecInstances.size() << ") does not equal the passed payload vector size (" << @@ -196,21 +200,10 @@ namespace argos { /****************************************/ /****************************************/ - void CTagEquippedEntity::AddToMedium(CTagMedium& c_medium) { + void CTagEquippedEntity::SetMedium(CTagMedium& c_medium) { for(SInstance& s_instance : m_vecInstances) { - s_instance.Tag.AddToMedium(c_medium); + s_instance.Tag.SetMedium(c_medium); } - Enable(); - } - - /****************************************/ - /****************************************/ - - void CTagEquippedEntity::RemoveFromMedium() { - for(SInstance& s_instance : m_vecInstances) { - s_instance.Tag.RemoveFromMedium(); - } - Disable(); } /****************************************/ diff --git a/src/plugins/simulator/entities/tag_equipped_entity.h b/src/plugins/simulator/entities/tag_equipped_entity.h index 53b73eca..3d9aab77 100644 --- a/src/plugins/simulator/entities/tag_equipped_entity.h +++ b/src/plugins/simulator/entities/tag_equipped_entity.h @@ -124,17 +124,11 @@ namespace argos { void SetTagPayloads(const std::vector& vec_payloads); /** - * Adds the tags to the specified tag medium. - * @param c_medium The tag medium. + * Sets the medium associated to this entity. + * @param c_medium The medium to associate to this entity. * @see CTagMedium */ - void AddToMedium(CTagMedium& c_medium); - - /** - * Removes the tags from the associated tag medium. - * @see CTagMedium - */ - void RemoveFromMedium(); + void SetMedium(CTagMedium& c_medium); virtual std::string GetTypeDescription() const { return "tags";