diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-01-04 15:50:56 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-01-04 15:50:56 +0300 |
commit | d0adcf0e3c8a1db5e06bbbb8ae950ea5ebeeb8eb (patch) | |
tree | 33e51821fd54d88d46df4e328f60ba148971ca55 /src | |
parent | 39cec87cfa8b1605239f4b06388bbb07f2a16a89 (diff) | |
download | mv-d0adcf0e3c8a1db5e06bbbb8ae950ea5ebeeb8eb.tar.gz mv-d0adcf0e3c8a1db5e06bbbb8ae950ea5ebeeb8eb.tar.bz2 mv-d0adcf0e3c8a1db5e06bbbb8ae950ea5ebeeb8eb.tar.xz mv-d0adcf0e3c8a1db5e06bbbb8ae950ea5ebeeb8eb.zip |
Add stringmap typedefs.
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/actormanager.cpp | 47 | ||||
-rw-r--r-- | src/actormanager.h | 13 | ||||
-rw-r--r-- | src/configuration.cpp | 2 | ||||
-rw-r--r-- | src/gui/skin.cpp | 2 | ||||
-rw-r--r-- | src/gui/skin.h | 6 | ||||
-rw-r--r-- | src/gui/theme.cpp | 3 | ||||
-rw-r--r-- | src/gui/windows/equipmentwindow.cpp | 4 | ||||
-rw-r--r-- | src/gui/windows/equipmentwindow.h | 3 | ||||
-rw-r--r-- | src/input/inputmanager.cpp | 8 | ||||
-rw-r--r-- | src/input/inputmanager.h | 6 | ||||
-rw-r--r-- | src/particle/imageparticle.cpp | 6 | ||||
-rw-r--r-- | src/particle/imageparticle.h | 4 | ||||
-rw-r--r-- | src/resources/db/itemdb.cpp | 3 | ||||
-rw-r--r-- | src/resources/mapreader.cpp | 7 | ||||
-rw-r--r-- | src/utils/stringmap.h | 31 |
17 files changed, 92 insertions, 55 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7fddb7a97..42d34a1b4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -763,6 +763,7 @@ SET(SRCS utils/sdlhelper.cpp utils/sdlhelper.h utils/sdlmemoryobject.h + utils/stringmap.h utils/stringutils.cpp utils/stringutils.h utils/stringvector.h diff --git a/src/Makefile.am b/src/Makefile.am index 8a5388af1..6052be132 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -132,6 +132,7 @@ dyecmd_SOURCES = gui/cliprect.cpp \ utils/sdlhelper.cpp \ utils/sdlhelper.h \ utils/sdlmemoryobject.h \ + utils/stringmap.h \ utils/stringutils.cpp \ utils/stringutils.h \ utils/timer.cpp \ diff --git a/src/actormanager.cpp b/src/actormanager.cpp index 506d1e79e..499471b02 100644 --- a/src/actormanager.cpp +++ b/src/actormanager.cpp @@ -74,15 +74,16 @@ class FindBeingFunctor final public: bool operator() (const ActorSprite *const actor) const { - if (!actor || actor->getType() == ActorType::FloorItem + if (!actor + || actor->getType() == ActorType::FloorItem || actor->getType() == ActorType::Portal) { return false; } const Being *const b = static_cast<const Being* const>(actor); - const unsigned other_y = y + ((b->getType() - == ActorType::Npc) ? 1 : 0); + const unsigned other_y = y + + ((b->getType() == ActorType::Npc) ? 1 : 0); const Vector &pos = b->getPosition(); return (static_cast<unsigned>(pos.x) / mapTileSize == x && (static_cast<unsigned>(pos.y) / mapTileSize == y @@ -121,10 +122,10 @@ class SortBeingFunctor final { int w1 = defaultPriorityIndex; int w2 = defaultPriorityIndex; - const std::map<std::string, int>::const_iterator it1 - = priorityBeings->find(being1->getName()); - const std::map<std::string, int>::const_iterator it2 - = priorityBeings->find(being2->getName()); + const StringIntMapCIter it1 = priorityBeings->find( + being1->getName()); + const StringIntMapCIter it2 = priorityBeings->find( + being2->getName()); if (it1 != priorityBeings->end()) w1 = (*it1).second; if (it2 != priorityBeings->end()) @@ -161,10 +162,10 @@ class SortBeingFunctor final { int w1 = defaultAttackIndex; int w2 = defaultAttackIndex; - const std::map<std::string, int>::const_iterator it1 - = attackBeings->find(being1->getName()); - const std::map<std::string, int>::const_iterator it2 - = attackBeings->find(being2->getName()); + const StringIntMapCIter it1 = attackBeings->find( + being1->getName()); + const StringIntMapCIter it2 = attackBeings->find( + being2->getName()); if (it1 != attackBeings->end()) w1 = (*it1).second; if (it2 != attackBeings->end()) @@ -176,8 +177,8 @@ class SortBeingFunctor final return (being1->getName() < being2->getName()); } - std::map<std::string, int> *attackBeings; - std::map<std::string, int> *priorityBeings; + StringIntMap *attackBeings; + StringIntMap *priorityBeings; int x; int y; int defaultAttackIndex; @@ -919,8 +920,8 @@ Being *ActorManager::findNearestLivingBeing(const Being *const aroundBeing, std::set<std::string> attackMobs; std::set<std::string> priorityMobs; std::set<std::string> ignoreAttackMobs; - std::map<std::string, int> attackMobsMap; - std::map<std::string, int> priorityMobsMap; + StringIntMap attackMobsMap; + StringIntMap priorityMobsMap; int defaultAttackIndex = 10000; int defaultPriorityIndex = 10000; const int attackRange = localPlayer->getAttackRange(); @@ -959,8 +960,7 @@ Being *ActorManager::findNearestLivingBeing(const Being *const aroundBeing, beingActorSorter.attackRange = attackRange; if (ignoreAttackMobs.find("") != ignoreAttackMobs.end()) ignoreDefault = true; - std::map<std::string, int>::const_iterator - itr = attackMobsMap.find(""); + StringIntMapCIter itr = attackMobsMap.find(""); if (itr != attackMobsMap.end()) defaultAttackIndex = (*itr).second; itr = priorityMobsMap.find(""); @@ -1136,8 +1136,8 @@ Being *ActorManager::findNearestLivingBeing(const Being *const aroundBeing, int w2 = defaultPriorityIndex; if (closestBeing) { - const std::map<std::string, int>::const_iterator it2 - = priorityMobsMap.find(being->getName()); + const StringIntMapCIter it2 = priorityMobsMap.find( + being->getName()); if (it2 != priorityMobsMap.end()) w2 = (*it2).second; @@ -1161,8 +1161,8 @@ Being *ActorManager::findNearestLivingBeing(const Being *const aroundBeing, { dist = d; closestBeing = being; - const std::map<std::string, int>::const_iterator it1 - = priorityMobsMap.find(being->getName()); + const StringIntMapCIter it1 = priorityMobsMap.find( + being->getName()); if (it1 != priorityMobsMap.end()) index = (*it1).second; else @@ -1628,10 +1628,9 @@ void ActorManager::rebuildPickupItems() } int ActorManager::getIndexByName(const std::string &name, - const std::map<std::string, int> &map) + const StringIntMap &map) { - const std::map<std::string, int>::const_iterator - i = map.find(name); + const StringIntMapCIter i = map.find(name); if (i == map.end()) return -1; diff --git a/src/actormanager.h b/src/actormanager.h index b9799d614..c3fc8d195 100644 --- a/src/actormanager.h +++ b/src/actormanager.h @@ -27,6 +27,7 @@ #include "listeners/configlistener.h" +#include "utils/stringmap.h" #include "utils/stringvector.h" #include "localconsts.h" @@ -289,12 +290,10 @@ class ActorManager final: public ConfigListener defList(Pickup, Items) defList(IgnorePickup, Items) - const std::map<std::string, int> &getAttackMobsMap() - const A_WARN_UNUSED + const StringIntMap &getAttackMobsMap() const A_WARN_UNUSED { return mAttackMobsMap; } - const std::map<std::string, int> &getPriorityAttackMobsMap() - const A_WARN_UNUSED + const StringIntMap &getPriorityAttackMobsMap() const A_WARN_UNUSED { return mPriorityAttackMobsMap; } int getAttackMobIndex(const std::string &name) const A_WARN_UNUSED; @@ -305,7 +304,7 @@ class ActorManager final: public ConfigListener int getPickupItemIndex(const std::string &name) const A_WARN_UNUSED; static int getIndexByName(const std::string &name, - const std::map<std::string, int> &map) + const StringIntMap &map) A_WARN_UNUSED; bool checkForPickup(const FloorItem *const item) const A_WARN_UNUSED; @@ -349,12 +348,12 @@ class ActorManager final: public ConfigListener #define defVarsP(mob) \ std::list<std::string> mPriority##mob;\ std::set<std::string> mPriority##mob##Set;\ - std::map<std::string, int> mPriority##mob##Map; + StringIntMap mPriority##mob##Map; #define defVars(mob) \ std::list<std::string> m##mob;\ std::set<std::string> m##mob##Set;\ - std::map<std::string, int> m##mob##Map;\ + StringIntMap m##mob##Map;\ std::list<std::string> mIgnore##mob;\ std::set<std::string> mIgnore##mob##Set; diff --git a/src/configuration.cpp b/src/configuration.cpp index 99bb2f4be..df098dc90 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -33,7 +33,7 @@ #include "debug.h" #ifdef DEBUG_CONFIG -std::map<std::string, int> optionsCount; +StringIntMap optionsCount; #define GETLOG() if (logger) {logger->log("config get: " + key); \ if (mIsMain) optionsCount[key] = 1; } #else diff --git a/src/gui/skin.cpp b/src/gui/skin.cpp index 42c93b80e..5ffd3c7c9 100644 --- a/src/gui/skin.cpp +++ b/src/gui/skin.cpp @@ -37,7 +37,7 @@ Skin::Skin(ImageRect *const restrict skin, const ImageRect *const restrict images, const std::string &filePath, const std::string &name, const int padding, const int titlePadding, - std::map<std::string, int> *restrict const options) : + StringIntMap *restrict const options) : instances(1), mFilePath(filePath), mName(name), diff --git a/src/gui/skin.h b/src/gui/skin.h index 6350fd878..150c04eeb 100644 --- a/src/gui/skin.h +++ b/src/gui/skin.h @@ -25,6 +25,8 @@ #ifndef GUI_SKIN_H #define GUI_SKIN_H +#include "utils/stringmap.h" + #include <map> #include <string> @@ -42,7 +44,7 @@ class Skin final const std::string &name = "", const int padding = 3, const int titlePadding = 4, - std::map<std::string, int> *restrict const options = nullptr); + StringIntMap *restrict const options = nullptr); A_DELETE_COPY(Skin) @@ -130,7 +132,7 @@ class Skin final Image *mStickyImageDown; /**< Sticky Button Image */ int mPadding; int mTitlePadding; - std::map<std::string, int> *mOptions; + StringIntMap *mOptions; }; #endif // GUI_SKIN_H diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp index be1433e87..9898aebfc 100644 --- a/src/gui/theme.cpp +++ b/src/gui/theme.cpp @@ -400,8 +400,7 @@ Skin *Theme::readSkin(const std::string &filename, const bool full) int stickySpacing = 3; int stickyPadding = 3; int resizePadding = 2; - std::map<std::string, int> *const mOptions - = new std::map<std::string, int>(); + StringIntMap *const mOptions = new StringIntMap; // iterate <widget>'s for_each_xml_child_node(widgetNode, rootNode) diff --git a/src/gui/windows/equipmentwindow.cpp b/src/gui/windows/equipmentwindow.cpp index 17cb77621..e50b0c488 100644 --- a/src/gui/windows/equipmentwindow.cpp +++ b/src/gui/windows/equipmentwindow.cpp @@ -59,7 +59,7 @@ EquipmentWindow *equipmentWindow = nullptr; EquipmentWindow *beingEquipmentWindow = nullptr; static const int BOX_COUNT = 27; -std::map<std::string, int> EquipmentWindow::mSlotNames; +StringIntMap EquipmentWindow::mSlotNames; EquipmentWindow::EquipmentWindow(Equipment *const equipment, Being *const being, @@ -689,7 +689,7 @@ void EquipmentWindow::prepareSlotNames() int EquipmentWindow::parseSlotName(const std::string &name) { - std::map<std::string, int>::const_iterator it = mSlotNames.find(name); + StringIntMapCIter it = mSlotNames.find(name); if (it != mSlotNames.end()) return (*it).second; return -1; diff --git a/src/gui/windows/equipmentwindow.h b/src/gui/windows/equipmentwindow.h index 0b6439f31..27526486a 100644 --- a/src/gui/windows/equipmentwindow.h +++ b/src/gui/windows/equipmentwindow.h @@ -28,6 +28,7 @@ #include "gui/widgets/window.h" +#include "utils/stringmap.h" #include "utils/xml.h" #include "listeners/actionlistener.h" @@ -125,7 +126,7 @@ class EquipmentWindow final : public Window, static int parseSlotName(const std::string &name) A_WARN_UNUSED; - static std::map<std::string, int> mSlotNames; + static StringIntMap mSlotNames; Equipment *mEquipment; diff --git a/src/input/inputmanager.cpp b/src/input/inputmanager.cpp index 48bf1b083..7500116cf 100644 --- a/src/input/inputmanager.cpp +++ b/src/input/inputmanager.cpp @@ -439,8 +439,7 @@ std::string InputManager::getKeyValueString(const int index) const std::string InputManager::getKeyValueByName(const std::string &keyName) { - const std::map<std::string, int>::const_iterator - it = mNameMap.find(keyName); + const StringIntMapCIter it = mNameMap.find(keyName); if (it == mNameMap.end()) return std::string(); @@ -449,8 +448,7 @@ std::string InputManager::getKeyValueByName(const std::string &keyName) std::string InputManager::getKeyValueByNameLong(const std::string &keyName) { - const std::map<std::string, int>::const_iterator - it = mNameMap.find(keyName); + const StringIntMapCIter it = mNameMap.find(keyName); if (it == mNameMap.end()) return std::string(); @@ -770,7 +768,7 @@ bool InputManager::executeChatCommand(const std::string &cmd, const std::string &args, ChatTab *const tab) { - const std::map<std::string, int>::const_iterator it = mChatMap.find(cmd); + const StringIntMapCIter it = mChatMap.find(cmd); if (it != mChatMap.end()) { ActionFuncPtr func = *(inputActionData[(*it).second].action); diff --git a/src/input/inputmanager.h b/src/input/inputmanager.h index cb483e684..6205f2d11 100644 --- a/src/input/inputmanager.h +++ b/src/input/inputmanager.h @@ -26,6 +26,8 @@ #include "events/inputevent.h" +#include "utils/stringmap.h" + #include <list> #include <string> #include <map> @@ -142,8 +144,8 @@ class InputManager final int mMask; - std::map<std::string, int> mNameMap; - std::map<std::string, int> mChatMap; + StringIntMap mNameMap; + StringIntMap mChatMap; InputFunction mKey[InputAction::TOTAL]; }; diff --git a/src/particle/imageparticle.cpp b/src/particle/imageparticle.cpp index f6676303a..dbef1dd32 100644 --- a/src/particle/imageparticle.cpp +++ b/src/particle/imageparticle.cpp @@ -28,7 +28,7 @@ #include "debug.h" -std::map<std::string, int> ImageParticle::imageParticleCountByName; +StringIntMap ImageParticle::imageParticleCountByName; ImageParticle::ImageParticle(Image *const image) : Particle(), @@ -39,7 +39,7 @@ ImageParticle::ImageParticle(Image *const image) : mImage->incRef(); const std::string &name = mImage->getIdPath(); - std::map<std::string, int>::iterator it + StringIntMapIter it = ImageParticle::imageParticleCountByName.find(name); if (it == ImageParticle::imageParticleCountByName.end()) ImageParticle::imageParticleCountByName[name] = 1; @@ -53,7 +53,7 @@ ImageParticle::~ImageParticle() if (mImage) { const std::string &name = mImage->getIdPath(); - std::map<std::string, int>::iterator it + StringIntMapIter it = ImageParticle::imageParticleCountByName.find(name); if (it != ImageParticle::imageParticleCountByName.end()) { diff --git a/src/particle/imageparticle.h b/src/particle/imageparticle.h index 0a092d966..dcc705a71 100644 --- a/src/particle/imageparticle.h +++ b/src/particle/imageparticle.h @@ -25,6 +25,8 @@ #include "particle/particle.h" +#include "utils/stringmap.h" + #include <map> class Image; @@ -60,7 +62,7 @@ class ImageParticle notfinal : public Particle virtual void setAlpha(const float alpha) override final { mAlpha = alpha; } - static std::map<std::string, int> imageParticleCountByName; + static StringIntMap imageParticleCountByName; protected: Image *mImage; /**< The image used for this particle. */ }; diff --git a/src/resources/db/itemdb.cpp b/src/resources/db/itemdb.cpp index 45fda0e66..da8072980 100644 --- a/src/resources/db/itemdb.cpp +++ b/src/resources/db/itemdb.cpp @@ -39,6 +39,7 @@ #include "utils/delete2.h" #include "utils/dtor.h" +#include "utils/stringmap.h" #include "debug.h" @@ -50,7 +51,7 @@ namespace bool mLoaded = false; bool mConstructed = false; StringVect mTagNames; - std::map<std::string, int> mTags; + StringIntMap mTags; std::map<std::string, ItemSoundEvent::Type> mSoundNames; } // namespace diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index 337b76df4..c2ccd9dc5 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -45,6 +45,7 @@ #include "utils/base64.h" #include "utils/delete2.h" +#include "utils/stringmap.h" #include <iostream> #include <zlib.h> @@ -969,7 +970,7 @@ Tileset *MapReader::readTileset(XmlNodePtr node, if (isProps) { // read tile properties to a map for simpler handling - std::map<std::string, int> tileProperties; + StringIntMap tileProperties; for_each_xml_child_node(propertyNode, tileNode) { if (!xmlNameEqual(propertyNode, "property")) @@ -998,9 +999,9 @@ Tileset *MapReader::readTileset(XmlNodePtr node, for (int i = 0; ; i++) { const std::string iStr(toString(i)); - const std::map<std::string, int>::const_iterator iFrame + StringIntMapCIter iFrame = tileProperties.find("animation-frame" + iStr); - const std::map<std::string, int>::const_iterator iDelay + StringIntMapCIter iDelay = tileProperties.find("animation-delay" + iStr); // possible need add random attribute? if (iFrame != tileProperties.end() diff --git a/src/utils/stringmap.h b/src/utils/stringmap.h new file mode 100644 index 000000000..e76515e18 --- /dev/null +++ b/src/utils/stringmap.h @@ -0,0 +1,31 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012-2015 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef UTILS_STRINGMAP_H +#define UTILS_STRINGMAP_H + +#include <string> +#include <map> + +typedef std::map<std::string, int> StringIntMap; +typedef StringIntMap::iterator StringIntMapIter; +typedef StringIntMap::const_iterator StringIntMapCIter; + +#endif // UTILS_STRINGMAP_H |