From d0adcf0e3c8a1db5e06bbbb8ae950ea5ebeeb8eb Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 4 Jan 2015 15:50:56 +0300 Subject: Add stringmap typedefs. --- src/CMakeLists.txt | 1 + src/Makefile.am | 1 + src/actormanager.cpp | 47 ++++++++++++++++++------------------- src/actormanager.h | 13 +++++----- src/configuration.cpp | 2 +- src/gui/skin.cpp | 2 +- src/gui/skin.h | 6 +++-- src/gui/theme.cpp | 3 +-- src/gui/windows/equipmentwindow.cpp | 4 ++-- src/gui/windows/equipmentwindow.h | 3 ++- src/input/inputmanager.cpp | 8 +++---- src/input/inputmanager.h | 6 +++-- src/particle/imageparticle.cpp | 6 ++--- src/particle/imageparticle.h | 4 +++- src/resources/db/itemdb.cpp | 3 ++- src/resources/mapreader.cpp | 7 +++--- src/utils/stringmap.h | 31 ++++++++++++++++++++++++ 17 files changed, 92 insertions(+), 55 deletions(-) create mode 100644 src/utils/stringmap.h (limited to 'src') 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(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(pos.x) / mapTileSize == x && (static_cast(pos.y) / mapTileSize == y @@ -121,10 +122,10 @@ class SortBeingFunctor final { int w1 = defaultPriorityIndex; int w2 = defaultPriorityIndex; - const std::map::const_iterator it1 - = priorityBeings->find(being1->getName()); - const std::map::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::const_iterator it1 - = attackBeings->find(being1->getName()); - const std::map::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 *attackBeings; - std::map *priorityBeings; + StringIntMap *attackBeings; + StringIntMap *priorityBeings; int x; int y; int defaultAttackIndex; @@ -919,8 +920,8 @@ Being *ActorManager::findNearestLivingBeing(const Being *const aroundBeing, std::set attackMobs; std::set priorityMobs; std::set ignoreAttackMobs; - std::map attackMobsMap; - std::map 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::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::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::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 &map) + const StringIntMap &map) { - const std::map::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 &getAttackMobsMap() - const A_WARN_UNUSED + const StringIntMap &getAttackMobsMap() const A_WARN_UNUSED { return mAttackMobsMap; } - const std::map &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 &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 mPriority##mob;\ std::set mPriority##mob##Set;\ - std::map mPriority##mob##Map; + StringIntMap mPriority##mob##Map; #define defVars(mob) \ std::list m##mob;\ std::set m##mob##Set;\ - std::map m##mob##Map;\ + StringIntMap m##mob##Map;\ std::list mIgnore##mob;\ std::set 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 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 *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 #include @@ -42,7 +44,7 @@ class Skin final const std::string &name = "", const int padding = 3, const int titlePadding = 4, - std::map *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 *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 *const mOptions - = new std::map(); + StringIntMap *const mOptions = new StringIntMap; // iterate '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 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::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 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::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::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::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 #include #include @@ -142,8 +144,8 @@ class InputManager final int mMask; - std::map mNameMap; - std::map 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 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::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::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 class Image; @@ -60,7 +62,7 @@ class ImageParticle notfinal : public Particle virtual void setAlpha(const float alpha) override final { mAlpha = alpha; } - static std::map 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 mTags; + StringIntMap mTags; std::map 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 #include @@ -969,7 +970,7 @@ Tileset *MapReader::readTileset(XmlNodePtr node, if (isProps) { // read tile properties to a map for simpler handling - std::map 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::const_iterator iFrame + StringIntMapCIter iFrame = tileProperties.find("animation-frame" + iStr); - const std::map::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 . + */ + +#ifndef UTILS_STRINGMAP_H +#define UTILS_STRINGMAP_H + +#include +#include + +typedef std::map StringIntMap; +typedef StringIntMap::iterator StringIntMapIter; +typedef StringIntMap::const_iterator StringIntMapCIter; + +#endif // UTILS_STRINGMAP_H -- cgit v1.2.3-60-g2f50