diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-09-26 20:08:44 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-09-28 21:17:59 +0300 |
commit | c430b75e370a21a17f80d4ba3acd84111828a462 (patch) | |
tree | 6d4ea8421de26c623c4196a7dd2aa3d86c5add01 /src | |
parent | 1dcb42c708c92216c7c9cacd3d3c9301e71e6006 (diff) | |
download | manaplus-c430b75e370a21a17f80d4ba3acd84111828a462.tar.gz manaplus-c430b75e370a21a17f80d4ba3acd84111828a462.tar.bz2 manaplus-c430b75e370a21a17f80d4ba3acd84111828a462.tar.xz manaplus-c430b75e370a21a17f80d4ba3acd84111828a462.zip |
add const for methods return values.
Diffstat (limited to 'src')
35 files changed, 65 insertions, 63 deletions
diff --git a/src/actorspritemanager.h b/src/actorspritemanager.h index 0e3319394..a32ee3e4d 100644 --- a/src/actorspritemanager.h +++ b/src/actorspritemanager.h @@ -281,10 +281,10 @@ class ActorSpriteManager final: public ConfigListener defList(Pickup, Items) defList(IgnorePickup, Items) - std::map<std::string, int> getAttackMobsMap() const A_WARN_UNUSED + const std::map<std::string, int> &getAttackMobsMap() const A_WARN_UNUSED { return mAttackMobsMap; } - std::map<std::string, int> getPriorityAttackMobsMap() + const std::map<std::string, int> &getPriorityAttackMobsMap() const A_WARN_UNUSED { return mPriorityAttackMobsMap; } diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp index 99900dbab..bbfde2adb 100644 --- a/src/animatedsprite.cpp +++ b/src/animatedsprite.cpp @@ -137,7 +137,7 @@ bool AnimatedSprite::play(const std::string &spriteAction) return true; } - Action *const action = mSprite->getAction(spriteAction, mNumber); + const Action *const action = mSprite->getAction(spriteAction, mNumber); if (!action) return false; @@ -374,7 +374,7 @@ void AnimatedSprite::setAlpha(float alpha) } } -void *AnimatedSprite::getHash() +const void *AnimatedSprite::getHash() const { if (mFrame) return mFrame; diff --git a/src/animatedsprite.h b/src/animatedsprite.h index 89fef3195..6ca44bb80 100644 --- a/src/animatedsprite.h +++ b/src/animatedsprite.h @@ -91,7 +91,7 @@ class AnimatedSprite final : public Sprite void setAlpha(float alpha) override; - void *getHash() override A_WARN_UNUSED; + const void *getHash() const override A_WARN_UNUSED; bool updateNumber(const unsigned num); @@ -135,7 +135,7 @@ class AnimatedSprite final : public Sprite unsigned int mFrameTime; /**< The time since start of frame. */ SpriteDef *mSprite; /**< The sprite definition. */ - Action *mAction; /**< The currently active action. */ + const Action *mAction; /**< The currently active action. */ Animation *mAnimation; /**< The currently active animation. */ Frame *mFrame; /**< The currently active frame. */ unsigned mNumber; diff --git a/src/being/being.cpp b/src/being/being.cpp index 82e4da2f9..bcf444df3 100644 --- a/src/being/being.cpp +++ b/src/being/being.cpp @@ -870,7 +870,7 @@ void Being::removeGuild(const int id) mGuilds.erase(id); } -Guild *Being::getGuild(const std::string &guildName) const +const Guild *Being::getGuild(const std::string &guildName) const { FOR_EACH (GuildsMapCIter, itr, mGuilds) { @@ -882,7 +882,7 @@ Guild *Being::getGuild(const std::string &guildName) const return nullptr; } -Guild *Being::getGuild(const int id) const +const Guild *Being::getGuild(const int id) const { const std::map<int, Guild*>::const_iterator itr = mGuilds.find(id); if (itr != mGuilds.end()) diff --git a/src/being/being.h b/src/being/being.h index 1668d17eb..ddc083c34 100644 --- a/src/being/being.h +++ b/src/being/being.h @@ -322,12 +322,12 @@ class Being : public ActorSprite, public ConfigListener /** * Returns a pointer to the specified guild that the being is in. */ - Guild *getGuild(const std::string &guildName) const A_WARN_UNUSED; + const Guild *getGuild(const std::string &guildName) const A_WARN_UNUSED; /** * Returns a pointer to the specified guild that the being is in. */ - Guild *getGuild(const int id) const A_WARN_UNUSED; + const Guild *getGuild(const int id) const A_WARN_UNUSED; /** * Returns a pointer to the specified guild that the being is in. @@ -425,7 +425,7 @@ class Being : public ActorSprite, public ConfigListener const BeingInfo *getInfo() const A_WARN_UNUSED { return mInfo; } - TargetCursorSize getTargetCursorSize() const A_WARN_UNUSED; + TargetCursorSize getTargetCursorSize() const override A_WARN_UNUSED; int getTargetOffsetX() const A_WARN_UNUSED { diff --git a/src/being/compoundsprite.h b/src/being/compoundsprite.h index d8c0cf849..5cdebd6d6 100644 --- a/src/being/compoundsprite.h +++ b/src/being/compoundsprite.h @@ -31,7 +31,7 @@ class Image; -typedef std::list <void*> VectorPointers; +typedef std::list <const void*> VectorPointers; class CompoundItem final { diff --git a/src/configuration.h b/src/configuration.h index 85e55d14a..3210958bb 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -319,7 +319,7 @@ class Configuration final : public ConfigurationObject bool resetBoolValue(const std::string &key); - const std::string getConfigPath() const A_WARN_UNUSED + const std::string &getConfigPath() const A_WARN_UNUSED { return mConfigPath; } /** diff --git a/src/game.cpp b/src/game.cpp index 40585df95..6bae44e49 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -629,7 +629,7 @@ void Game::slowLogic() if (viewport && !errorMessage.empty()) { - const Map *const map = viewport->getCurrentMap(); + const Map *const map = viewport->getMap(); if (map) { logger->log("state: %d", client->getState()); diff --git a/src/gui/equipmentwindow.h b/src/gui/equipmentwindow.h index 2d2e2ca81..5fd69c23a 100644 --- a/src/gui/equipmentwindow.h +++ b/src/gui/equipmentwindow.h @@ -85,7 +85,7 @@ class EquipmentWindow final : public Window, public gcn::ActionListener void mousePressed(gcn::MouseEvent& mouseEvent) override; - Item* getEquipment(int i) const A_WARN_UNUSED + const Item* getEquipment(const int i) const A_WARN_UNUSED { return mEquipment ? mEquipment->getEquipment(i) : nullptr; } void setBeing(Being *const being); diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index ed770047f..c12365cc6 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -1239,7 +1239,7 @@ void PopupMenu::handleLink(const std::string &link, { if (viewport) { - const Map *const map = viewport->getCurrentMap(); + const Map *const map = viewport->getMap(); if (map) { SpecialLayer *const specialLayer = map->getSpecialLayer(); diff --git a/src/gui/quitdialog.cpp b/src/gui/quitdialog.cpp index da67231d5..b601fe323 100644 --- a/src/gui/quitdialog.cpp +++ b/src/gui/quitdialog.cpp @@ -151,7 +151,7 @@ void QuitDialog::action(const gcn::ActionEvent &event) { if (viewport) { - const Map *const map = viewport->getCurrentMap(); + const Map *const map = viewport->getMap(); if (map) map->saveExtraLayer(); } diff --git a/src/gui/sdlfont.cpp b/src/gui/sdlfont.cpp index d332b59db..65ba14fc6 100644 --- a/src/gui/sdlfont.cpp +++ b/src/gui/sdlfont.cpp @@ -599,7 +599,7 @@ void SDLFont::doClean() } } -TextChunkList *SDLFont::getCache() const +const TextChunkList *SDLFont::getCache() const { return mCache; } diff --git a/src/gui/sdlfont.h b/src/gui/sdlfont.h index eedc4c6e0..55dafe744 100644 --- a/src/gui/sdlfont.h +++ b/src/gui/sdlfont.h @@ -125,7 +125,7 @@ class SDLFont final : public gcn::Font int getHeight() const override A_WARN_UNUSED; - TextChunkList *getCache() const A_WARN_UNUSED; + const TextChunkList *getCache() const A_WARN_UNUSED; /** * @see Font::drawString diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp index 1f36d6de9..672928551 100644 --- a/src/gui/skilldialog.cpp +++ b/src/gui/skilldialog.cpp @@ -629,14 +629,20 @@ void SkillDialog::addSkill(const int id, const int level, const int range, } } -SkillInfo* SkillDialog::getSkill(const int id) +SkillInfo* SkillDialog::getSkill(const int id) const { - return mSkills[id]; + SkillMap::const_iterator it = mSkills.find(id); + if (it != mSkills.end()) + return (*it).second; + return nullptr; } -SkillInfo* SkillDialog::getSkillByItem(const int itemId) +SkillInfo* SkillDialog::getSkillByItem(const int itemId) const { - return mSkills[itemId - SKILL_MIN_ID]; + SkillMap::const_iterator it = mSkills.find(itemId - SKILL_MIN_ID); + if (it != mSkills.end()) + return (*it).second; + return nullptr; } void SkillDialog::widgetResized(const gcn::Event &event) diff --git a/src/gui/skilldialog.h b/src/gui/skilldialog.h index 9406293a4..9715a3bf3 100644 --- a/src/gui/skilldialog.h +++ b/src/gui/skilldialog.h @@ -76,9 +76,9 @@ class SkillDialog final : public Window, public gcn::ActionListener void addSkill(const int id, const int level, const int range, const bool modifiable); - SkillInfo* getSkill(const int id) A_WARN_UNUSED; + SkillInfo* getSkill(const int id) const A_WARN_UNUSED; - SkillInfo* getSkillByItem(const int itemId) A_WARN_UNUSED; + SkillInfo* getSkillByItem(const int itemId) const A_WARN_UNUSED; bool hasSkills() const A_WARN_UNUSED { return !mSkills.empty(); } diff --git a/src/gui/viewport.h b/src/gui/viewport.h index 3d491e9c2..45b5fd753 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -229,12 +229,6 @@ class Viewport final : public WindowContainer, void scrollBy(const int x, const int y) { mPixelViewX += x; mPixelViewY += y; } - /** - * Returns the current map object. - */ - Map *getCurrentMap() const A_WARN_UNUSED - { return mMap; } - int getDebugPath() const A_WARN_UNUSED { return mShowDebugPath; } diff --git a/src/item.h b/src/item.h index d8ede3995..b9939c6e1 100644 --- a/src/item.h +++ b/src/item.h @@ -163,7 +163,7 @@ class Item unsigned char getColor() const A_WARN_UNUSED { return mColor; } - std::string &getDescription() A_WARN_UNUSED + const std::string &getDescription() const A_WARN_UNUSED { return mDescription; } int mId; /**< Item type id. */ diff --git a/src/map.cpp b/src/map.cpp index 026774138..2154cf66c 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -647,7 +647,7 @@ void Map::drawAmbientLayers(Graphics *const graphics, const LayerType type, BLOCK_END("Map::drawAmbientLayers") } -Tileset *Map::getTilesetWithGid(const int gid) const +const Tileset *Map::getTilesetWithGid(const int gid) const { if (gid >= 0 && gid < mIndexedTilesetsSize) return mIndexedTilesets[gid]; @@ -727,7 +727,7 @@ bool Map::contains(const int x, const int y) const return x >= 0 && y >= 0 && x < mWidth && y < mHeight; } -MetaTile *Map::getMetaTile(const int x, const int y) const +const MetaTile *Map::getMetaTile(const int x, const int y) const { return &mMetaTiles[x + y * mWidth]; } @@ -1322,7 +1322,7 @@ MapItem *Map::findPortalXY(const int x, const int y) const return nullptr; } -TileAnimation *Map::getAnimationForGid(const int gid) const +const TileAnimation *Map::getAnimationForGid(const int gid) const { if (mTileAnimations.empty()) return nullptr; @@ -214,12 +214,12 @@ class Map final : public Properties, public ConfigListener /** * Finds the tile set that a tile with the given global id is part of. */ - Tileset *getTilesetWithGid(const int gid) const A_WARN_UNUSED; + const Tileset *getTilesetWithGid(const int gid) const A_WARN_UNUSED; /** * Get tile reference. */ - MetaTile *getMetaTile(const int x, const int y) const A_WARN_UNUSED; + const MetaTile *getMetaTile(const int x, const int y) const A_WARN_UNUSED; /** * Marks a tile as occupied. @@ -363,7 +363,8 @@ class Map final : public Properties, public ConfigListener /** * Gets the tile animation for a specific gid */ - TileAnimation *getAnimationForGid(const int gid) const A_WARN_UNUSED; + const TileAnimation *getAnimationForGid(const int gid) + const A_WARN_UNUSED; void optionChanged(const std::string &value) override; @@ -374,7 +375,7 @@ class Map final : public Properties, public ConfigListener void setPvpMode(const int mode); - ObjectsLayer* getObjectsLayer() const A_WARN_UNUSED + const ObjectsLayer* getObjectsLayer() const A_WARN_UNUSED { return mObjects; } std::string getObjectData(const unsigned x, const unsigned y, diff --git a/src/net/download.cpp b/src/net/download.cpp index 71169d207..9dd90a1d1 100644 --- a/src/net/download.cpp +++ b/src/net/download.cpp @@ -194,7 +194,7 @@ void Download::cancel() mThread = nullptr; } -char *Download::getError() const +const char *Download::getError() const { return mError; } diff --git a/src/net/download.h b/src/net/download.h index 33f7ae3b3..8850b3512 100644 --- a/src/net/download.h +++ b/src/net/download.h @@ -87,7 +87,7 @@ class Download final */ void cancel(); - char *getError() const A_WARN_UNUSED; + const char *getError() const A_WARN_UNUSED; void setIgnoreError(const bool n) { mIgnoreError = n; } diff --git a/src/net/ea/loginhandler.cpp b/src/net/ea/loginhandler.cpp index 23f9f91c0..59d72dd78 100644 --- a/src/net/ea/loginhandler.cpp +++ b/src/net/ea/loginhandler.cpp @@ -121,7 +121,7 @@ void LoginHandler::registerAccount(LoginData *const loginData1) const sendLoginRegister(username, loginData1->password, loginData1->email); } -Worlds LoginHandler::getWorlds() const +const Worlds &LoginHandler::getWorlds() const { return mWorlds; } diff --git a/src/net/ea/loginhandler.h b/src/net/ea/loginhandler.h index 994029247..e84da5ce4 100644 --- a/src/net/ea/loginhandler.h +++ b/src/net/ea/loginhandler.h @@ -60,7 +60,7 @@ class LoginHandler : public Net::LoginHandler virtual void registerAccount(LoginData *const loginData) const override; - virtual Worlds getWorlds() const override A_WARN_UNUSED; + virtual const Worlds &getWorlds() const override A_WARN_UNUSED; virtual void clearWorlds() override; diff --git a/src/net/loginhandler.h b/src/net/loginhandler.h index 019e9b846..229e9a4c6 100644 --- a/src/net/loginhandler.h +++ b/src/net/loginhandler.h @@ -52,7 +52,7 @@ class LoginHandler void setServer(const ServerInfo &server) { mServer = server; } - ServerInfo getServer() const A_WARN_UNUSED + const ServerInfo &getServer() const A_WARN_UNUSED { return mServer; } virtual void connect() = 0; @@ -99,7 +99,7 @@ class LoginHandler virtual void unregisterAccount(const std::string &username, const std::string &password) const = 0; - virtual Worlds getWorlds() const A_WARN_UNUSED = 0; + virtual const Worlds &getWorlds() const A_WARN_UNUSED = 0; virtual void clearWorlds() = 0; diff --git a/src/net/messageout.cpp b/src/net/messageout.cpp index ab279020f..1a295a066 100644 --- a/src/net/messageout.cpp +++ b/src/net/messageout.cpp @@ -110,7 +110,7 @@ void MessageOut::writeStringNoLog(const std::string &string, int length) PacketCounters::incOutBytes(length); } -char *MessageOut::getData() const +const char *MessageOut::getData() const { return mData; } diff --git a/src/net/messageout.h b/src/net/messageout.h index 68d4b53a3..0fcd6ce15 100644 --- a/src/net/messageout.h +++ b/src/net/messageout.h @@ -62,7 +62,7 @@ class MessageOut /** * Returns the content of the message. */ - virtual char *getData() const A_WARN_UNUSED; + virtual const char *getData() const A_WARN_UNUSED; /** * Returns the length of the data. diff --git a/src/party.h b/src/party.h index 62d346c83..78fea9528 100644 --- a/src/party.h +++ b/src/party.h @@ -37,7 +37,7 @@ class PartyMember final : public Avatar public: A_DELETE_COPY(PartyMember) - Party *getParty() const A_WARN_UNUSED + const Party *getParty() const A_WARN_UNUSED { return mParty; } bool getLeader() const A_WARN_UNUSED diff --git a/src/resources/dye.h b/src/resources/dye.h index ba0b378d0..c5e60b520 100644 --- a/src/resources/dye.h +++ b/src/resources/dye.h @@ -116,13 +116,13 @@ class Dye final /** * Return special dye palete (S) */ - DyePalette *getSPalete() const A_WARN_UNUSED + const DyePalette *getSPalete() const A_WARN_UNUSED { return mDyePalettes[sPaleteIndex]; } /** * Return special dye palete (A) */ - DyePalette *getAPalete() const A_WARN_UNUSED + const DyePalette *getAPalete() const A_WARN_UNUSED { return mDyePalettes[aPaleteIndex]; } /** diff --git a/src/resources/openglimagehelper.cpp b/src/resources/openglimagehelper.cpp index ba9931f55..a036a7e0e 100644 --- a/src/resources/openglimagehelper.cpp +++ b/src/resources/openglimagehelper.cpp @@ -67,14 +67,14 @@ Image *OpenGLImageHelper::load(SDL_RWops *const rw, Dye const &dye) const { case 1: { - DyePalette *const pal = dye.getSPalete(); + const DyePalette *const pal = dye.getSPalete(); if (pal) pal->replaceSOGLColor(pixels, surf->w * surf->h); break; } case 2: { - DyePalette *const pal = dye.getAPalete(); + const DyePalette *const pal = dye.getAPalete(); if (pal) pal->replaceAOGLColor(pixels, surf->w * surf->h); break; diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp index a855e90ba..af0ada0dc 100644 --- a/src/resources/spritedef.cpp +++ b/src/resources/spritedef.cpp @@ -37,8 +37,8 @@ SpriteReference *SpriteReference::Empty = nullptr; extern int serverVersion; -Action *SpriteDef::getAction(const std::string &action, - const unsigned num) const +const Action *SpriteDef::getAction(const std::string &action, + const unsigned num) const { Actions::const_iterator i = mActions.find(num); if (i == mActions.end() && num != 100) diff --git a/src/resources/spritedef.h b/src/resources/spritedef.h index 533042c02..f7415e187 100644 --- a/src/resources/spritedef.h +++ b/src/resources/spritedef.h @@ -145,8 +145,8 @@ class SpriteDef final : public Resource /** * Returns the specified action. */ - Action *getAction(const std::string &action, - const unsigned num) const A_WARN_UNUSED; + const Action *getAction(const std::string &action, + const unsigned num) const A_WARN_UNUSED; unsigned findNumber(const unsigned num) const A_WARN_UNUSED; diff --git a/src/spellmanager.cpp b/src/spellmanager.cpp index 2038c478a..91cfb1ff2 100644 --- a/src/spellmanager.cpp +++ b/src/spellmanager.cpp @@ -61,7 +61,7 @@ TextCommand* SpellManager::getSpell(const int spellId) const return it != mSpells.end() ? (*it).second : nullptr; } -TextCommand* SpellManager::getSpellByItem(const int itemId) const +const TextCommand* SpellManager::getSpellByItem(const int itemId) const { return getSpell(itemId - SPELL_MIN_ID); } @@ -116,7 +116,7 @@ bool SpellManager::addSpell(TextCommand *const spell) return false; } -std::vector<TextCommand*> SpellManager::getAll() const +const std::vector<TextCommand*> &SpellManager::getAll() const { return mSpellsVector; } diff --git a/src/spellmanager.h b/src/spellmanager.h index db4abff1c..e6323da51 100644 --- a/src/spellmanager.h +++ b/src/spellmanager.h @@ -45,13 +45,14 @@ class SpellManager final TextCommand *getSpell(const int spellId) const A_WARN_UNUSED; - TextCommand* getSpellByItem(const int itemId) const A_WARN_UNUSED; + const TextCommand* getSpellByItem(const int itemId) + const A_WARN_UNUSED; bool addSpell(TextCommand *const spell); TextCommand *createNewSpell() const A_WARN_UNUSED; - std::vector<TextCommand*> getAll() const A_WARN_UNUSED; + const std::vector<TextCommand*> &getAll() const A_WARN_UNUSED; void useItem(const int itemId) const; diff --git a/src/sprite.h b/src/sprite.h index 3ec3fe00d..c31accdd4 100644 --- a/src/sprite.h +++ b/src/sprite.h @@ -108,10 +108,10 @@ class Sprite */ virtual unsigned int getFrameCount() const A_WARN_UNUSED = 0; - virtual void *getHash() A_WARN_UNUSED + virtual const void *getHash() const A_WARN_UNUSED { return nullptr; } - virtual void *getHash2() A_WARN_UNUSED + virtual const void *getHash2() const A_WARN_UNUSED { return this; } virtual bool updateNumber(const unsigned num) = 0; diff --git a/src/textcommand.h b/src/textcommand.h index b39cafaff..81f91d7d4 100644 --- a/src/textcommand.h +++ b/src/textcommand.h @@ -159,7 +159,7 @@ class TextCommand final { mCommandType = commandType; } bool isEmpty() const A_WARN_UNUSED - { return mCommand == "" && mSymbol == ""; } + { return mCommand.empty() && mSymbol.empty(); } Image *getImage() const A_WARN_UNUSED { return mImage; } |