[Orxonox-commit 5885] r10545 - in code/branches/cpp11/src: libraries/core/object orxonox/chat orxonox/controllers
bknecht at orxonox.net
bknecht at orxonox.net
Tue Jul 14 23:23:58 CEST 2015
Author: bknecht
Date: 2015-07-14 23:23:57 +0200 (Tue, 14 Jul 2015)
New Revision: 10545
Modified:
code/branches/cpp11/src/libraries/core/object/ObjectListBase.h
code/branches/cpp11/src/orxonox/chat/ChatManager.cc
code/branches/cpp11/src/orxonox/controllers/ArtificialController.cc
Log:
rewrote a couple of for loops to use C++11 notation. Also made small change in ObjectList so it can almost be used like a normal list with C++11 notation
Modified: code/branches/cpp11/src/libraries/core/object/ObjectListBase.h
===================================================================
--- code/branches/cpp11/src/libraries/core/object/ObjectListBase.h 2015-06-07 13:24:55 UTC (rev 10544)
+++ code/branches/cpp11/src/libraries/core/object/ObjectListBase.h 2015-07-14 21:23:57 UTC (rev 10545)
@@ -92,6 +92,11 @@
this->removeFromList();
}
+ operator T*()
+ {
+ return object_;
+ }
+
T* object_; //!< The object
};
Modified: code/branches/cpp11/src/orxonox/chat/ChatManager.cc
===================================================================
--- code/branches/cpp11/src/orxonox/chat/ChatManager.cc 2015-06-07 13:24:55 UTC (rev 10544)
+++ code/branches/cpp11/src/orxonox/chat/ChatManager.cc 2015-07-14 21:23:57 UTC (rev 10545)
@@ -104,8 +104,8 @@
}
// notify all listeners
- for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
- it->incomingChat(text, name);
+ for (ChatListener* listener : ObjectList<ChatListener>())
+ listener->incomingChat(text, name);
}
Modified: code/branches/cpp11/src/orxonox/controllers/ArtificialController.cc
===================================================================
--- code/branches/cpp11/src/orxonox/controllers/ArtificialController.cc 2015-06-07 13:24:55 UTC (rev 10544)
+++ code/branches/cpp11/src/orxonox/controllers/ArtificialController.cc 2015-07-14 21:23:57 UTC (rev 10545)
@@ -204,8 +204,8 @@
void ArtificialController::setAllBotLevel(float level)
{
- for (ObjectList<ArtificialController>::iterator it = ObjectList<ArtificialController>::begin(); it != ObjectList<ArtificialController>::end(); ++it)
- it->setBotLevel(level);
+ for (ArtificialController* controller : ObjectList<ArtificialController>())
+ controller->setBotLevel(level);
}
void ArtificialController::setPreviousMode()
@@ -228,10 +228,10 @@
int ArtificialController::getFiremode(std::string name)
{
- for (std::map< std::string, int >::iterator it = this->weaponModes_.begin(); it != this->weaponModes_.end(); ++it)
+ for (auto firemode : this->weaponModes_)
{
- if (it->first == name)
- return it->second;
+ if (firemode.first == name)
+ return firemode.second;
}
return -1;
}
@@ -256,19 +256,19 @@
void ArtificialController::updatePointsOfInterest(std::string name, float searchDistance)
{
WorldEntity* waypoint = NULL;
- for (ObjectList<WorldEntity>::iterator it = ObjectList<WorldEntity>::begin(); it != ObjectList<WorldEntity>::end(); ++it)
+ for (WorldEntity* we : ObjectList<WorldEntity>())
{
- if((*it)->getIdentifier() == ClassByString(name))
+ if(we->getIdentifier() == ClassByString(name))
{
ControllableEntity* controllable = this->getControllableEntity();
if(!controllable) continue;
- float actualDistance = ( (*it)->getPosition() - controllable->getPosition() ).length();
+ float actualDistance = ( we->getPosition() - controllable->getPosition() ).length();
if(actualDistance > searchDistance || actualDistance < 5.0f) continue;
// TODO: PickupSpawner: adjust waypoint accuracy to PickupSpawner's triggerdistance
// TODO: ForceField: analyze is angle between forcefield boost and own flying direction is acceptable
else
{
- waypoint = *it;
+ waypoint = we;
break;
}
}
More information about the Orxonox-commit
mailing list