Skip to content

Commit 4edf29d

Browse files
committed
enh(ilpincy#2): Const accessor functions
- Added so that lists of entities of a given type are also available in const-qualified loop functions +semver: enh
1 parent 5101304 commit 4edf29d

File tree

5 files changed

+34
-17
lines changed

5 files changed

+34
-17
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ cmake_install.cmake
1818
doinst.sh
1919
slack-desc
2020
TAGS
21+
.dir-locals.el

src/core/simulator/loop_functions.h

+4
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ namespace argos {
180180
return m_cSpace;
181181
}
182182

183+
inline const CSpace& GetSpace() const {
184+
return m_cSpace;
185+
}
186+
183187
/**
184188
* Moves the entity to the wanted position and orientation.
185189
* @param c_entity The positional component of the entity to move.

src/core/simulator/space/space.cpp

+10-12
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace argos {
3030
m_pcFloorEntity(NULL),
3131
m_ptPhysicsEngines(NULL),
3232
m_ptMedia(NULL) {}
33-
33+
3434
/****************************************/
3535
/****************************************/
3636

@@ -105,16 +105,14 @@ namespace argos {
105105
/****************************************/
106106
/****************************************/
107107

108-
CSpace::TMapPerType& CSpace::GetEntitiesByType(const std::string& str_type) {
109-
TMapPerTypePerId::iterator itEntities = m_mapEntitiesPerTypePerId.find(str_type);
110-
if (itEntities != m_mapEntitiesPerTypePerId.end()){
111-
return itEntities->second;
112-
}
113-
else {
114-
THROW_ARGOSEXCEPTION("Entity map for type \"" << str_type << "\" not found.");
115-
}
108+
CSpace::TMapPerType& CSpace::GetEntitiesByTypeImpl(const std::string& str_type) const {
109+
TMapPerTypePerId::const_iterator itEntities = m_mapEntitiesPerTypePerId.find(str_type);
110+
if(itEntities != m_mapEntitiesPerTypePerId.end()){
111+
return const_cast<CSpace::TMapPerType&>(itEntities->second);
112+
} else {
113+
THROW_ARGOSEXCEPTION("Entity map for type \"" << str_type << "\" not found.");
114+
}
116115
}
117-
118116
/****************************************/
119117
/****************************************/
120118

@@ -156,7 +154,7 @@ namespace argos {
156154
m_vecControllableEntities.erase(it);
157155
}
158156
}
159-
157+
160158
/****************************************/
161159
/****************************************/
162160

@@ -216,7 +214,7 @@ namespace argos {
216214
THROW_ARGOSEXCEPTION(ossMsg.str());
217215
}
218216
}
219-
217+
220218
/****************************************/
221219
/****************************************/
222220

src/core/simulator/space/space.h

+14-4
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ namespace argos {
140140
/**
141141
* Returns the entity with the given id.
142142
* @param str_id The id of the wanted entity
143-
* @return The entity with the given id.
143+
* @return The entity with the given id.
144144
* @throws CARGoSException if an entity with the wanted id does not exist
145145
*/
146146
inline CEntity& GetEntity(const std::string& str_id) {
@@ -157,7 +157,7 @@ namespace argos {
157157
* The pattern must be a valid regexp.
158158
* @param t_buffer A vector filled with all the entities that match the given pattern.
159159
* @param str_pattern The pattern to match.
160-
* @return The entity with the given id.
160+
* @return The entity with the given id.
161161
* @throws CARGoSException if the regexp is not valid.
162162
*/
163163
void GetEntitiesMatching(CEntity::TVector& t_buffer,
@@ -208,7 +208,14 @@ namespace argos {
208208
* @see TMapPerType
209209
* @see GetEntityMapPerTypePerId()
210210
*/
211-
TMapPerType& GetEntitiesByType(const std::string& str_type);
211+
212+
TMapPerType& GetEntitiesByType(const std::string& str_type) {
213+
return GetEntitiesByTypeImpl(str_type);
214+
}
215+
216+
const TMapPerType& GetEntitiesByType(const std::string& str_type) const {
217+
return GetEntitiesByTypeImpl(str_type);
218+
}
212219

213220
/**
214221
* Returns the floor entity.
@@ -392,7 +399,7 @@ namespace argos {
392399
virtual void AddControllableEntity(CControllableEntity& c_entity);
393400
virtual void RemoveControllableEntity(CControllableEntity& c_entity);
394401
virtual void AddEntityToPhysicsEngine(CEmbodiedEntity& c_entity);
395-
402+
396403
protected:
397404

398405
virtual void UpdateControllableEntitiesAct() = 0;
@@ -452,6 +459,9 @@ namespace argos {
452459

453460
/** A pointer to the list of media */
454461
CMedium::TVector* m_ptMedia;
462+
463+
private:
464+
TMapPerType& GetEntitiesByTypeImpl(const std::string& str_type) const;
455465
};
456466

457467
/****************************************/

src/plugins/robots/foot-bot/simulator/footbot_entity.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,15 @@ namespace argos {
5656
virtual void Init(TConfigurationNode& t_tree);
5757
virtual void Reset();
5858
virtual void UpdateComponents();
59-
59+
6060
inline CControllableEntity& GetControllableEntity() {
6161
return *m_pcControllableEntity;
6262
}
6363

64+
inline const CControllableEntity& GetControllableEntity() const {
65+
return *m_pcControllableEntity;
66+
}
67+
6468
inline CFootBotDistanceScannerEquippedEntity& GetDistanceScannerEquippedEntity() {
6569
return *m_pcDistanceScannerEquippedEntity;
6670
}

0 commit comments

Comments
 (0)