Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 11059


Ignore:
Timestamp:
Jan 13, 2016, 10:19:21 PM (9 years ago)
Author:
landauf
Message:

return const-ref to collections instead of pointer

Location:
code/branches/cpp11_v3/src
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • code/branches/cpp11_v3/src/modules/overlays/hud/HUDWeapon.cc

    r11054 r11059  
    4444        weaponModeHUDActualSize_ = Vector2(0.0f,0.0f);
    4545
    46         weaponModes_ = NULL;
    4746        weaponIndex_ = 0;
    4847        hudWeaponModes_.clear();
     
    148147        destroyHUDChilds();
    149148
    150         weaponModes_ = weapon_->getAllWeaponmodes();
    151 
    152149        updateSize();
    153150        createHUDChilds();
     
    157154    void HUDWeapon::createHUDChilds()
    158155    {
    159         if (weaponModes_ == NULL)
     156        if (weapon_ == NULL)
    160157        {
    161158            return;
     
    164161        int positionIndex = 0;
    165162
    166         for (std::multimap<unsigned int, WeaponMode*>::iterator it = weaponModes_->begin(); it != weaponModes_->end(); ++it)
     163        for (std::multimap<unsigned int, WeaponMode*>::const_iterator it = weapon_->getAllWeaponmodes().begin(); it != weapon_->getAllWeaponmodes().end(); ++it)
    167164        {
    168165            HUDWeaponMode* hudWeaponMode = new HUDWeaponMode(this->getContext());
     
    208205    void HUDWeapon::updateSize()
    209206    {
    210         if (weaponModes_ != NULL)
    211         {
    212             this->setSize(Vector2(weaponModeHUDActualSize_.x,weaponModeHUDActualSize_.y*weaponModes_->size()));
     207        if (weapon_ != NULL)
     208        {
     209            this->setSize(Vector2(weaponModeHUDActualSize_.x,weaponModeHUDActualSize_.y*weapon_->getAllWeaponmodes().size()));
    213210            updatePosition();
    214211        }       
     
    217214    void HUDWeapon::updatePosition()
    218215    {
    219         if (weaponModes_ != NULL)
     216        if (weapon_ != NULL)
    220217        {
    221218            this->setPosition(Vector2(weaponModeHUDActualSize_.x*weaponIndex_,0.0f) + this->positionOffset_);
  • code/branches/cpp11_v3/src/modules/overlays/hud/HUDWeapon.h

    r11052 r11059  
    9494        WeakPtr<Weapon> weapon_;
    9595
    96         std::multimap<unsigned int, WeaponMode*>* weaponModes_;
    9796        std::vector<WeakPtr<HUDWeaponMode> > hudWeaponModes_;
    9897
  • code/branches/cpp11_v3/src/modules/overlays/hud/HUDWeaponSystem.cc

    r11054 r11059  
    126126        destroyHUDChilds();
    127127
    128         std::vector<WeaponPack*>* weaponPacks = owner_->getAllWeaponPacks();
     128        if (owner_->getWeaponSystem())
     129        {
     130            const std::vector<WeaponPack*>& weaponPacks = owner_->getWeaponSystem()->getAllWeaponPacks();
    129131
    130         for (std::vector<WeaponPack*>::const_iterator itPacks = weaponPacks->begin(); itPacks != weaponPacks->end(); ++itPacks)
    131         {
    132             std::vector<Weapon*>* weapons = (*itPacks)->getAllWeapons();
     132            for (std::vector<WeaponPack*>::const_iterator itPacks = weaponPacks.begin(); itPacks != weaponPacks.end(); ++itPacks)
     133            {
     134                const std::vector<Weapon*>& weapons = (*itPacks)->getAllWeapons();
    133135
    134             for (std::vector<Weapon*>::const_iterator itWeapons = weapons->begin(); itWeapons != weapons->end(); ++itWeapons)
    135             {
    136                 this->weapons_.push_back(*itWeapons);
     136                for (std::vector<Weapon*>::const_iterator itWeapons = weapons.begin(); itWeapons != weapons.end(); ++itWeapons)
     137                {
     138                    this->weapons_.push_back(*itWeapons);
     139                }
    137140            }
     141
     142            createHUDChilds();
     143            positionHUDChilds();
    138144        }
    139 
    140         createHUDChilds();
    141         positionHUDChilds();
    142145    }
    143146
  • code/branches/cpp11_v3/src/orxonox/weaponsystem/Weapon.h

    r11054 r11059  
    5757            void addWeaponmode(WeaponMode* weaponmode);
    5858            WeaponMode* getWeaponmode(unsigned int index) const;
    59             inline std::multimap<unsigned int, WeaponMode*>* getAllWeaponmodes()
    60                 { return &weaponmodes_; }
     59            inline const std::multimap<unsigned int, WeaponMode*>& getAllWeaponmodes() const
     60                { return weaponmodes_; }
    6161            inline int getNumWeaponModes() const
    6262                { return weaponmodes_.size(); }
  • code/branches/cpp11_v3/src/orxonox/weaponsystem/WeaponPack.cc

    r11054 r11059  
    124124    }
    125125
    126     std::vector<Weapon*>* WeaponPack::getAllWeapons()
    127     {
    128         return &weapons_;       
    129     }   
    130 
    131126    void WeaponPack::addDefaultWeaponmodeLink(DefaultWeaponmodeLink* link)
    132127    {
  • code/branches/cpp11_v3/src/orxonox/weaponsystem/WeaponPack.h

    r11054 r11059  
    5252            void removeWeapon(Weapon * weapon);
    5353            Weapon * getWeapon(unsigned int index) const;
    54             std::vector<Weapon*>* getAllWeapons();
     54            inline const std::vector<Weapon*>& getAllWeapons() const
     55                { return weapons_; }
    5556
    5657            inline size_t getNumWeapons() const
  • code/branches/cpp11_v3/src/orxonox/weaponsystem/WeaponSystem.cc

    r11054 r11059  
    240240    }
    241241
    242     std::vector<WeaponPack *> * WeaponSystem::getAllWeaponPacks()
    243     {
    244         return &weaponPacks_;
    245     }   
    246 
    247242    bool WeaponSystem::swapWeaponSlots(WeaponSlot * wSlot1, WeaponSlot * wSlot2)
    248243    {
  • code/branches/cpp11_v3/src/orxonox/weaponsystem/WeaponSystem.h

    r11052 r11059  
    6767            void removeWeaponPack(WeaponPack * wPack);
    6868            WeaponPack * getWeaponPack(unsigned int index) const;
    69             std::vector<WeaponPack *> * getAllWeaponPacks();
     69            inline const std::vector<WeaponPack *>& getAllWeaponPacks() const
     70                { return weaponPacks_; }
    7071
    7172            // configure slots and firemodes
  • code/branches/cpp11_v3/src/orxonox/worldentities/pawns/Pawn.cc

    r11054 r11059  
    513513    }
    514514
    515     std::vector<WeaponPack *> * Pawn::getAllWeaponPacks()
    516     {
    517         if (this->weaponSystem_)
    518             return this->weaponSystem_->getAllWeaponPacks();
    519         else
    520             return 0;       
    521     }
    522 
    523515    void Pawn::addMunitionXML(Munition* munition)
    524516    {
  • code/branches/cpp11_v3/src/orxonox/worldentities/pawns/Pawn.h

    r11054 r11059  
    170170            void addWeaponPackXML(WeaponPack * wPack);
    171171            WeaponPack * getWeaponPack(unsigned int index) const;
    172             std::vector<WeaponPack *> * getAllWeaponPacks();
    173172
    174173            void addMunitionXML(Munition* munition);
Note: See TracChangeset for help on using the changeset viewer.