prototype_link_equipped_entity.cpp
Go to the documentation of this file.
1 
8 
9 namespace argos {
10 
11  /****************************************/
12  /****************************************/
13 
15  CComposableEntity(pc_parent) {}
16 
17  /****************************************/
18  /****************************************/
19 
21  try {
22  /* Initialize the parent */
24  /* Initialize the links */
25  TConfigurationNodeIterator itLink("link");
26  for(itLink = itLink.begin(&t_tree);
27  itLink != itLink.end();
28  ++itLink) {
29  auto* pcLinkEntity = new CPrototypeLinkEntity(this);
30  pcLinkEntity->Init(*itLink);
31  AddComponent(*pcLinkEntity);
32  m_vecLinks.push_back(pcLinkEntity);
33  }
34  /* Get the reference link */
35  std::string strReferenceLink;
36  GetNodeAttribute(t_tree, "ref", strReferenceLink);
37  auto itReferenceLink =
38  std::find_if(std::begin(m_vecLinks),
39  std::end(m_vecLinks),
40  [strReferenceLink] (const CPrototypeLinkEntity* pc_link) {
41  return (pc_link->GetId() == strReferenceLink);
42  });
43  /* Move the reference link to the front of the vector */
44  if(itReferenceLink == std::end(m_vecLinks)) {
45  THROW_ARGOSEXCEPTION("The reference link \"" << strReferenceLink << "\" not found.");
46  }
47  else {
48  if(itReferenceLink != std::begin(m_vecLinks)) {
49  CPrototypeLinkEntity* pcReferenceLink = *itReferenceLink;
50  *itReferenceLink = m_vecLinks.front();
51  m_vecLinks.front() = pcReferenceLink;
52  }
53  }
54  }
55  catch(CARGoSException& ex) {
56  THROW_ARGOSEXCEPTION_NESTED("Failed to initialize link equipped entity \"" << GetId() << "\".", ex);
57  }
58  }
59 
60  /****************************************/
61  /****************************************/
62 
64  auto itLink =
65  std::find_if(std::begin(m_vecLinks),
66  std::end(m_vecLinks),
67  [str_id] (const CPrototypeLinkEntity* pc_link) {
68  return (pc_link->GetId() == str_id);
69  });
70  ARGOS_ASSERT(itLink != std::end(m_vecLinks),
71  "CPrototypeLinkEquippedEntity::GetLink(), id=\"" <<
72  GetId() <<
73  "\": link not found: str_id = " <<
74  str_id);
75  return **itLink;
76  }
77 
78  /****************************************/
79  /****************************************/
80 
82  ARGOS_ASSERT(un_index < m_vecLinks.size(),
83  "CPrototypeLinkEquippedEntity::GetLink(), id=\"" <<
84  GetId() <<
85  "\": index out of bounds: un_index = " <<
86  un_index <<
87  ", m_vecLinks.size() = " <<
88  m_vecLinks.size());
89  return *m_vecLinks[un_index];
90  }
91 
92  /****************************************/
93  /****************************************/
94 
96 
97  /****************************************/
98  /****************************************/
99 
100 }
#define ARGOS_ASSERT(condition, message)
When code is compiled in debug, this macro throws an ARGoS exception with the passed message if the s...
#define THROW_ARGOSEXCEPTION_NESTED(message, nested)
This macro throws an ARGoS exception with the passed message and nesting the passed exception.
#define THROW_ARGOSEXCEPTION(message)
This macro throws an ARGoS exception with the passed message.
unsigned int UInt32
32-bit unsigned integer.
Definition: datatypes.h:97
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
ticpp::Iterator< ticpp::Element > TConfigurationNodeIterator
The iterator for the ARGoS configuration XML node.
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
REGISTER_STANDARD_SPACE_OPERATIONS_ON_COMPOSABLE(CComposableEntity)
void GetNodeAttribute(TConfigurationNode &t_node, const std::string &str_attribute, T &t_buffer)
Returns the value of a node's attribute.
Basic class for an entity that contains other entities.
void AddComponent(CEntity &c_component)
Adds a component to this composable entity.
const std::string & GetId() const
Returns the id of this entity.
Definition: entity.h:157
virtual void Init(TConfigurationNode &t_tree)
Initializes the state of the entity from the XML configuration tree.
Definition: entity.cpp:40
The exception that wraps all errors in ARGoS.
virtual void Init(TConfigurationNode &t_tree)
Initializes the state of the entity from the XML configuration tree.
CPrototypeLinkEntity & GetLink(UInt32 un_index)
CPrototypeLinkEquippedEntity(CComposableEntity *pc_parent)