9 #include <argos3/core/utility/string_utilities.h>
23 const std::string& str_id) :
30 for(CEntity::TMultiMap::iterator it = m_mapComponents.begin();
31 it != m_mapComponents.end();
49 for(CEntity::TMultiMap::iterator it = m_mapComponents.begin();
50 it != m_mapComponents.end();
52 it->second->SetEnabled(b_enabled);
60 for(CEntity::TMultiMap::iterator it = m_mapComponents.begin();
61 it != m_mapComponents.end();
63 if(it->second->IsEnabled()) {
73 m_mapComponents.insert(
74 std::pair<std::string, CEntity*>(
77 m_vecComponents.push_back(&c_component);
85 CEntity::TMultiMap::iterator it =
FindComponent(str_component);
86 if(it == m_mapComponents.end()) {
89 CEntity& cRetVal = *(it->second);
90 m_mapComponents.erase(it);
92 for(i = 0; i < m_vecComponents.size() && m_vecComponents[i] != &cRetVal; ++i);
93 if(i < m_vecComponents.size()) {
94 m_vecComponents.erase(m_vecComponents.begin() + i);
97 THROW_ARGOSEXCEPTION(
"Element \"" << str_component <<
"\" not found in the component vector, but present in the map. BUG!");
112 size_t unFirstSeparatorIdx = str_path.find(
".");
113 std::string strFrontIdentifier;
114 if(unFirstSeparatorIdx == std::string::npos) strFrontIdentifier = str_path;
115 else strFrontIdentifier = str_path.substr(0, unFirstSeparatorIdx);
117 CEntity::TMultiMap::iterator itComponent =
FindComponent(strFrontIdentifier);
118 if(itComponent != m_mapComponents.end()) {
119 if(unFirstSeparatorIdx == std::string::npos) {
121 return *(itComponent->second);
126 if(pcComposableEntity != NULL) {
128 return pcComposableEntity->
GetComponent(str_path.substr(unFirstSeparatorIdx + 1, std::string::npos));
133 <<
"\" is not a composable entity");
152 size_t unFirstSeparatorIdx = str_path.find(
".");
153 std::string strFrontIdentifier;
154 if(unFirstSeparatorIdx == std::string::npos) strFrontIdentifier = str_path;
155 else strFrontIdentifier = str_path.substr(0, unFirstSeparatorIdx);
157 CEntity::TMultiMap::iterator itComponent =
FindComponent(strFrontIdentifier);
158 if(itComponent != m_mapComponents.end()) {
159 if(unFirstSeparatorIdx == std::string::npos) {
166 if(pcComposableEntity != NULL) {
168 return pcComposableEntity->
HasComponent(str_path.substr(unFirstSeparatorIdx + 1, std::string::npos));
187 std::string::size_type unIdentifierStart = str_component.find(
'[');
188 if(unIdentifierStart != std::string::npos) {
190 std::string::size_type unIdentifierEnd = str_component.rfind(
']');
191 if(unIdentifierEnd != std::string::npos &&
192 unIdentifierEnd > unIdentifierStart) {
195 std::string strBaseType = str_component.substr(0, unIdentifierStart);
196 if(m_mapComponents.count(strBaseType) == 0) {
198 return m_mapComponents.end();
202 std::string strComponentId = str_component.substr(unIdentifierStart + 1, unIdentifierEnd - unIdentifierStart - 1);
204 std::pair<CEntity::TMultiMap::iterator,
205 CEntity::TMultiMap::iterator> cRange = m_mapComponents.equal_range(strBaseType);
207 CEntity::TMultiMap::iterator itComponent;
209 for(itComponent = cRange.first;
210 (itComponent != cRange.second) && (itComponent->second->GetId() != strComponentId);
213 if(itComponent != cRange.second) {
219 return m_mapComponents.end();
230 return m_mapComponents.find(str_component);
virtual void SetEnabled(bool b_enabled)
Enables or disables an entity.
#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.
#define THROW_ARGOSEXCEPTION_NESTED(message, nested)
This macro throws an ARGoS exception with the passed message and nesting the passed exception...
virtual std::string GetTypeDescription() const
Returns a string label for this class.
Basic class for an entity that contains other entities.
void AddComponent(CEntity &c_component)
Adds a component to this composable entity.
CComposableEntity(CComposableEntity *pc_parent)
Class constructor.
The exception that wraps all errors in ARGoS.
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.
REGISTER_STANDARD_SPACE_OPERATIONS_ON_COMPOSABLE(CComposableEntity)
The namespace containing all the ARGoS related code.
std::string GetContext() const
Returns the context of this entity.
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.