Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 5, 2015, 10:47:51 PM (9 years ago)
Author:
landauf
Message:

use range-based for-loop where it makes sense (e.g. ObjectList)

Location:
code/branches/cpp11_v2/src/libraries/network
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • code/branches/cpp11_v2/src/libraries/network/Client.cc

    r10624 r10919  
    161161        {
    162162          std::vector<packet::Gamestate*> gamestates = GamestateManager::getGamestates();
    163           std::vector<packet::Gamestate*>::iterator it;
    164           for( it = gamestates.begin(); it != gamestates.end(); ++it )
     163          for( packet::Gamestate* gamestate : gamestates )
    165164          {
    166             (*it)->send( static_cast<Host*>(this) );
     165            gamestate->send( static_cast<Host*>(this) );
    167166          }
    168167        }
  • code/branches/cpp11_v2/src/libraries/network/ClientConnectionListener.cc

    r10624 r10919  
    4444    void ClientConnectionListener::broadcastClientConnected(unsigned int clientID)
    4545    {
    46         for (ObjectList<ClientConnectionListener>::iterator it = ObjectList<ClientConnectionListener>::begin(); it != ObjectList<ClientConnectionListener>::end(); ++it)
    47             it->clientConnected(clientID);
     46        for (ClientConnectionListener* listener : ObjectList<ClientConnectionListener>())
     47            listener->clientConnected(clientID);
    4848    }
    4949
    5050    void ClientConnectionListener::broadcastClientDisconnected(unsigned int clientID)
    5151    {
    52         for (ObjectList<ClientConnectionListener>::iterator it = ObjectList<ClientConnectionListener>::begin(); it != ObjectList<ClientConnectionListener>::end(); ++it)
    53             it->clientDisconnected(clientID);
     52        for (ClientConnectionListener* listener : ObjectList<ClientConnectionListener>())
     53            listener->clientDisconnected(clientID);
    5454    }
    5555
  • code/branches/cpp11_v2/src/libraries/network/Connection.cc

    r10768 r10919  
    237237  void Connection::disconnectPeersInternal()
    238238  {
    239     std::map<uint32_t, ENetPeer*>::iterator it;
    240     for( it=this->peerMap_.begin(); it!=this->peerMap_.end(); ++it )
    241     {
    242       enet_peer_disconnect(it->second, 0);
     239    for( const auto& mapEntry : this->peerMap_ )
     240    {
     241      enet_peer_disconnect(mapEntry.second, 0);
    243242    }
    244243    uint32_t iterations = NETWORK_DISCONNECT_TIMEOUT/NETWORK_WAIT_TIMEOUT;
  • code/branches/cpp11_v2/src/libraries/network/FunctionCallManager.cc

    r10918 r10919  
    5454void FunctionCallManager::sendCalls(orxonox::Host* host)
    5555{
    56   std::map<uint32_t, packet::FunctionCalls*>::iterator it;
    57   for (it = FunctionCallManager::sPeerMap_.begin(); it != FunctionCallManager::sPeerMap_.end(); ++it )
     56  for (const auto& mapEntry : FunctionCallManager::sPeerMap_ )
    5857  {
    5958    assert(!FunctionCallManager::sPeerMap_.empty());
    60     it->second->send(host);
     59    mapEntry.second->send(host);
    6160  }
    6261  FunctionCallManager::sPeerMap_.clear();
  • code/branches/cpp11_v2/src/libraries/network/GamestateManager.cc

    r10769 r10919  
    7070  {
    7171    if( this->currentGamestate_ )
    72         delete this->currentGamestate_;std::map<unsigned int, packet::Gamestate*>::iterator it;
    73     for( it = gamestateQueue.begin(); it != gamestateQueue.end(); ++it )
    74       delete it->second;
    75     std::map<uint32_t, peerInfo>::iterator peerIt;
    76     std::map<uint32_t, packet::Gamestate*>::iterator gamestateIt;
    77     for( peerIt = peerMap_.begin(); peerIt != peerMap_.end(); ++peerIt )
    78     {
    79       for( gamestateIt = peerIt->second.gamestates.begin(); gamestateIt != peerIt->second.gamestates.end(); ++gamestateIt )
    80         delete gamestateIt->second;
     72        delete this->currentGamestate_;
     73    for( const auto& mapEntry : gamestateQueue )
     74      delete mapEntry.second;
     75    for( const auto& mapEntryPeer : peerMap_ )
     76    {
     77      for( const auto& mapEntryGamestate : mapEntryPeer.second.gamestates )
     78        delete mapEntryGamestate.second;
    8179    }
    8280//     this->trafficControl_->destroy();
     
    107105    if( this->gamestateQueue.empty() )
    108106        return true;
    109     std::map<unsigned int, packet::Gamestate*>::iterator it;
    110107    // now push only the most recent gamestates we received (ignore obsolete ones)
    111     for(it = gamestateQueue.begin(); it!=gamestateQueue.end(); it++)
    112     {
    113       OrxVerify(processGamestate(it->second), "ERROR: could not process Gamestate");
    114       sendAck( it->second->getID(), it->second->getPeerID() );
    115       delete it->second;
     108    for(const auto& mapEntry : gamestateQueue)
     109    {
     110      OrxVerify(processGamestate(mapEntry.second), "ERROR: could not process Gamestate");
     111      sendAck( mapEntry.second->getID(), mapEntry.second->getPeerID() );
     112      delete mapEntry.second;
    116113    }
    117114    // now clear the queue
     
    177174    std::vector<packet::Gamestate*> peerGamestates;
    178175   
    179     std::map<uint32_t, peerInfo>::iterator peerIt;
    180     for( peerIt=peerMap_.begin(); peerIt!=peerMap_.end(); ++peerIt )
    181     {
    182       if( !peerIt->second.isSynched )
     176    for( const auto& mapEntry : peerMap_ )
     177    {
     178      if( !mapEntry.second.isSynched )
    183179      {
    184180        orxout(verbose_more, context::network) << "Server: not sending gamestate" << endl;
    185181        continue;
    186182      }
    187       orxout(verbose_more, context::network) << "client id: " << peerIt->first << endl;
     183      orxout(verbose_more, context::network) << "client id: " << mapEntry.first << endl;
    188184      orxout(verbose_more, context::network) << "Server: doing gamestate gamestate preparation" << endl;
    189       int peerID = peerIt->first; //get client id
    190 
    191       unsigned int lastAckedGamestateID = peerIt->second.lastAckedGamestateID;
     185      int peerID = mapEntry.first; //get client id
     186
     187      unsigned int lastAckedGamestateID = mapEntry.second.lastAckedGamestateID;
    192188
    193189      packet::Gamestate* baseGamestate=nullptr;
     
    340336  {
    341337    assert(peerMap_.find(peerID)!=peerMap_.end());
    342     std::map<uint32_t, packet::Gamestate*>::iterator peerIt;
    343     for( peerIt = peerMap_[peerID].gamestates.begin(); peerIt!=peerMap_[peerID].gamestates.end(); ++peerIt )
    344     {
    345       delete peerIt->second;
     338    for( const auto& mapEntry : peerMap_[peerID].gamestates )
     339    {
     340      delete mapEntry.second;
    346341    }
    347342    peerMap_.erase(peerMap_.find(peerID));
  • code/branches/cpp11_v2/src/libraries/network/Host.cc

    r10916 r10919  
    107107  void Host::doReceiveChat(const std::string& message, unsigned int sourceID, unsigned int targetID)
    108108  {
    109     for (ObjectList<NetworkChatListener>::iterator it = ObjectList<NetworkChatListener>::begin(); it != ObjectList<NetworkChatListener>::end(); ++it)
    110       it->incomingChat(message, sourceID);
     109    for (NetworkChatListener* listener : ObjectList<NetworkChatListener>())
     110      listener->incomingChat(message, sourceID);
    111111  }
    112112
  • code/branches/cpp11_v2/src/libraries/network/MasterServer.cc

    r10765 r10919  
    4949  MasterServer::listServers( void )
    5050  {
    51     /* get an iterator */
    52     std::list<ServerListElem>::iterator i;
    53 
    5451    /* print list header */
    5552    orxout(user_info) << "List of connected servers" << std::endl;
    5653
    5754    /* loop through list elements */
    58     for( i = MasterServer::getInstance()->mainlist.serverlist.begin();
    59       i != MasterServer::getInstance()->mainlist.serverlist.end(); ++i )
     55    for( const ServerListElem& elem : MasterServer::getInstance()->mainlist.serverlist )
    6056    {
    61       orxout(user_info) << "  " << (*i).ServerInfo.getServerIP() << std::endl;
     57      orxout(user_info) << "  " << elem.ServerInfo.getServerIP() << std::endl;
    6258    }
    6359
     
    112108  MasterServer::helper_sendlist( ENetEvent *event )
    113109  {
    114     /* get an iterator */
    115     std::list<ServerListElem>::iterator i;
    116 
    117110    /* packet holder */
    118111    ENetPacket *reply;
    119112
    120113    /* loop through list elements */
    121     for( i = mainlist.serverlist.begin(); i
    122         != mainlist.serverlist.end(); ++i )
     114    for( const ServerListElem& elem : mainlist.serverlist )
    123115    {
    124116      /* send this particular server */
    125117      /* build reply string */
    126       int packetlen = MSPROTO_SERVERLIST_ITEM_LEN + 1 + (*i).ServerInfo.getServerIP().length() + 1 + (*i).ServerInfo.getServerName().length() + 1 + sizeof((*i).ServerInfo.getClientNumber()) + 1;
     118      int packetlen = MSPROTO_SERVERLIST_ITEM_LEN + 1 + elem.ServerInfo.getServerIP().length() + 1 + elem.ServerInfo.getServerName().length() + 1 + sizeof(elem.ServerInfo.getClientNumber()) + 1;
    127119      char *tosend = (char *)calloc(packetlen ,1 );
    128120      if( !tosend )
     
    131123      }
    132124      sprintf( tosend, "%s %s %s %u", MSPROTO_SERVERLIST_ITEM,
    133           (*i).ServerInfo.getServerIP().c_str(), (*i).ServerInfo.getServerName().c_str(), (*i).ServerInfo.getClientNumber());
     125          elem.ServerInfo.getServerIP().c_str(), elem.ServerInfo.getServerName().c_str(), elem.ServerInfo.getClientNumber());
    134126
    135127      /* create packet from it */
     
    167159  MasterServer::helper_cleanupServers( void )
    168160  {
    169     /* get an iterator */
    170     std::list<ServerListElem>::iterator i;
    171 
    172161    if( mainlist.serverlist.size() == 0 )
    173162      return;
    174163
    175164    /* loop through list elements */
    176     for( i = mainlist.serverlist.begin(); i
    177         != mainlist.serverlist.end(); ++i )
     165    for( const ServerListElem& elem : mainlist.serverlist )
    178166    { /* see if we have a disconnected peer */
    179       if( (*i).peer &&
    180          ((*i).peer->state == ENET_PEER_STATE_DISCONNECTED ||
    181           (*i).peer->state == ENET_PEER_STATE_ZOMBIE ))
     167      if( elem.peer &&
     168         (elem.peer->state == ENET_PEER_STATE_DISCONNECTED ||
     169          elem.peer->state == ENET_PEER_STATE_ZOMBIE ))
    182170      {
    183171        /* Remove it from the list */
    184         orxout(internal_warning) << (char*)(*i).peer->data << " timed out.\n";
    185         mainlist.delServerByName( (*i).ServerInfo.getServerName() );
     172        orxout(internal_warning) << (char*)elem.peer->data << " timed out.\n";
     173        mainlist.delServerByName( elem.ServerInfo.getServerName() );
    186174
    187175        /* stop iterating, we manipulated the list */
  • code/branches/cpp11_v2/src/libraries/network/PeerList.cc

    r10765 r10919  
    6565  bool
    6666  PeerList::remPeerByAddr( ENetAddress addr )
    67   { /* get an iterator */
    68     std::list<ENetPeer *>::iterator i;
    69 
     67  {
    7068    /* loop through list elements */
    71     for( i = peerlist.begin(); i != peerlist.end(); ++i )
    72       if( !sub_compAddr((*i)->address, addr ) )
     69    for( ENetPeer* peer : peerlist )
     70      if( !sub_compAddr(peer->address, addr ) )
    7371      { /* found this name, remove and quit */
    74         this->peerlist.remove( *i );
     72        this->peerlist.remove( peer );
    7573        return true;
    7674      }
     
    8280  ENetPeer *
    8381  PeerList::findPeerByAddr( ENetAddress addr )
    84   { /* get an iterator */
    85     std::list<ENetPeer *>::iterator i;
    86 
     82  {
    8783    /* loop through list elements */
    88     for( i = peerlist.begin(); i != peerlist.end(); ++i )
    89       if( !sub_compAddr((*i)->address, addr ) )
     84    for( ENetPeer* peer : peerlist )
     85      if( !sub_compAddr(peer->address, addr ) )
    9086        /* found this name, remove and quit */
    91         return *i;
     87        return peer;
    9288
    9389    /* not found */
  • code/branches/cpp11_v2/src/libraries/network/Server.cc

    r10768 r10919  
    232232  {
    233233    std::vector<packet::Gamestate*> gamestates = GamestateManager::getGamestates();
    234     std::vector<packet::Gamestate*>::iterator it;
    235     for( it = gamestates.begin(); it != gamestates.end(); ++it )
     234    for( packet::Gamestate* gamestate : gamestates )
    236235    {
    237       (*it)->send(static_cast<Host*>(this));
     236      gamestate->send(static_cast<Host*>(this));
    238237    }
    239238    return true;
     
    434433      return true;
    435434
    436     std::vector<uint32_t>::iterator it;
    437     for( it=this->clientIDs_.begin(); it!=this->clientIDs_.end(); ++it )
    438       if( *it == targetID )
     435    for( uint32_t id : this->clientIDs_ )
     436      if( id == targetID )
    439437        return true;
    440438
  • code/branches/cpp11_v2/src/libraries/network/packet/ClassID.cc

    r10769 r10919  
    5555
    5656  //calculate total needed size (for all strings and integers)
    57   std::map<std::string, Identifier*>::const_iterator it = IdentifierManager::getInstance().getIdentifierByStringMap().begin();
    58   for(;it != IdentifierManager::getInstance().getIdentifierByStringMap().end();++it){
    59     id = it->second;
     57  for(const auto& mapEntry : IdentifierManager::getInstance().getIdentifierByStringMap()){
     58    id = mapEntry.second;
    6059    if(id == nullptr || !id->hasFactory())
    6160      continue;
  • code/branches/cpp11_v2/src/libraries/network/packet/Gamestate.cc

    r10918 r10919  
    213213  {
    214214    std::list<uint32_t> v1;
    215     ObjectList<Synchronisable>::iterator it;
    216     for (it = ObjectList<Synchronisable>::begin(); it != ObjectList<Synchronisable>::end(); ++it)
    217     {
    218       if (it->getObjectID() == OBJECTID_UNKNOWN)
    219       {
    220         if (it->objectMode_ != 0x0)
     215    for (Synchronisable* synchronisable : ObjectList<Synchronisable>())
     216    {
     217      if (synchronisable->getObjectID() == OBJECTID_UNKNOWN)
     218      {
     219        if (synchronisable->objectMode_ != 0x0)
    221220        {
    222221          orxout(user_error, context::packets) << "Found object with OBJECTID_UNKNOWN on the client with objectMode != 0x0!" << endl;
    223222          orxout(user_error, context::packets) << "Possible reason for this error: Client created a synchronized object without the Server's approval." << endl;
    224           orxout(user_error, context::packets) << "Objects class: " << it->getIdentifier()->getName() << endl;
     223          orxout(user_error, context::packets) << "Objects class: " << synchronisable->getIdentifier()->getName() << endl;
    225224          assert(false);
    226225        }
     
    228227      else
    229228      {
    230         std::list<uint32_t>::iterator it2;
    231         for (it2 = v1.begin(); it2 != v1.end(); ++it2)
     229        for (uint32_t id : v1)
    232230        {
    233           if (it->getObjectID() == *it2)
     231          if (synchronisable->getObjectID() == id)
    234232          {
    235233            orxout(user_error, context::packets) << "Found duplicate objectIDs on the client!" << endl
     
    239237          }
    240238        }
    241         v1.push_back(it->getObjectID());
     239        v1.push_back(synchronisable->getObjectID());
    242240      }
    243241    }
     
    762760  uint32_t size = 0;
    763761  uint32_t nrOfVariables = 0;
    764     // get the start of the Synchronisable list
    765   ObjectList<Synchronisable>::iterator it;
    766762    // get total size of gamestate
    767   for(it = ObjectList<Synchronisable>::begin(); it; ++it){
    768     size+=it->getSize(id, mode); // size of the actual data of the synchronisable
    769     nrOfVariables += it->getNrOfVariables();
     763  for(Synchronisable* synchronisable : ObjectList<Synchronisable>()){
     764    size+=synchronisable->getSize(id, mode); // size of the actual data of the synchronisable
     765    nrOfVariables += synchronisable->getNrOfVariables();
    770766  }
    771767//   orxout() << "allocating " << nrOfVariables << " ints" << endl;
  • code/branches/cpp11_v2/src/libraries/network/packet/ServerInformation.h

    r10857 r10919  
    5050        void          send( ENetPeer* peer );
    5151        void          setServerName(std::string name) { this->serverName_ = name; }
    52         std::string   getServerName() { return this->serverName_; }
     52        std::string   getServerName() const { return this->serverName_; }
    5353        void          setServerIP( std::string IP ) { this->serverIP_ = IP; }
    54         std::string   getServerIP() { return this->serverIP_; }
     54        std::string   getServerIP() const { return this->serverIP_; }
    5555        void          setClientNumber( int clientNumber ) { this->clientNumber_ = clientNumber; }
    56         int           getClientNumber() { return this->clientNumber_; }
    57         uint32_t      getServerRTT() { return this->serverRTT_; }
     56        int           getClientNumber() const { return this->clientNumber_; }
     57        uint32_t      getServerRTT() const { return this->serverRTT_; }
    5858
    5959      private:
  • code/branches/cpp11_v2/src/libraries/network/synchronisable/Synchronisable.cc

    r10916 r10919  
    266266    assert(this->classID_==this->getIdentifier()->getNetworkID());
    267267    assert(this->objectID_!=OBJECTID_UNKNOWN);
    268     std::vector<SynchronisableVariableBase*>::iterator i;
    269268
    270269    // start copy header
     
    276275//     orxout(verbose, context::network) << "objectid: " << this->objectID_ << ":";
    277276    // copy to location
    278     for(i=syncList_.begin(); i!=syncList_.end(); ++i)
    279     {
    280       uint32_t varsize = (*i)->getData( mem, mode );
     277    for(SynchronisableVariableBase* variable : syncList_)
     278    {
     279      uint32_t varsize = variable->getData( mem, mode );
    281280//       orxout(verbose, context::network) << " " << varsize;
    282281      tempsize += varsize;
     
    348347      assert( this->getContextID() == syncHeader2.getContextID() );
    349348      mem += SynchronisableHeader::getSize();
    350       std::vector<SynchronisableVariableBase *>::iterator i;
    351       for(i=syncList_.begin(); i!=syncList_.end(); ++i)
     349      for(SynchronisableVariableBase* variable : syncList_)
    352350      {
    353351        assert( mem <= data+syncHeader2.getDataSize()+SynchronisableHeader::getSize() ); // always make sure we don't exceed the datasize in our stream
    354         (*i)->putData( mem, mode, forceCallback );
     352        variable->putData( mem, mode, forceCallback );
    355353      }
    356354      assert(mem == data+syncHeaderLight.getDataSize()+SynchronisableHeader::getSize() );
     
    388386    assert( mode==state_ );
    389387    tsize += this->dataSize_;
    390     std::vector<SynchronisableVariableBase*>::iterator i;
    391     for(i=stringList_.begin(); i!=stringList_.end(); ++i)
    392     {
    393       tsize += (*i)->getSize( mode );
     388    for(SynchronisableVariableBase* variable : stringList_)
     389    {
     390      tsize += variable->getSize( mode );
    394391    }
    395392    return tsize;
Note: See TracChangeset for help on using the changeset viewer.