prototype_joint_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  /* Init parent */
24  /* Go through the joints */
25  TConfigurationNodeIterator itJoint("joint");
26  for(itJoint = itJoint.begin(&t_tree);
27  itJoint != itJoint.end();
28  ++itJoint) {
29  /* for each <joint/> node */
30  auto* pcJointEntity = new CPrototypeJointEntity(this);
31  pcJointEntity->Init(*itJoint);
32  AddComponent(*pcJointEntity);
33  m_vecJoints.push_back(pcJointEntity);
34  }
35  }
36  catch(CARGoSException& ex) {
37  THROW_ARGOSEXCEPTION_NESTED("Failed to initialize joint equipped entity \"" << GetId() << "\".", ex);
38  }
39  }
40 
41  /****************************************/
42  /****************************************/
43 
45  auto itJoint =
46  std::find_if(std::begin(m_vecJoints),
47  std::end(m_vecJoints),
48  [str_id] (const CPrototypeJointEntity* pc_joint) {
49  return (pc_joint->GetId() == str_id);
50  });
51  ARGOS_ASSERT(itJoint != std::end(m_vecJoints),
52  "CPrototypeJointEquippedEntity::GetJoint(), id=\"" <<
53  GetId() <<
54  "\": joint not found: str_id = " <<
55  str_id);
56  return **itJoint;
57  }
58 
59  /****************************************/
60  /****************************************/
61 
63  ARGOS_ASSERT(un_index < m_vecJoints.size(),
64  "CPrototypeJointEquippedEntity::GetJoint(), id=\"" <<
65  GetId() <<
66  "\": index out of bounds: un_index = " <<
67  un_index <<
68  ", m_vecJoints.size() = " <<
69  m_vecJoints.size());
70  return *m_vecJoints[un_index];
71  }
72 
73  /****************************************/
74  /****************************************/
75 
77 
78  /****************************************/
79  /****************************************/
80 
81 }
#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.
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)
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.
CPrototypeJointEntity & GetJoint(UInt32 un_index)
CPrototypeJointEquippedEntity(CComposableEntity *pc_parent)