Replace instances of std::map<std::string, std::string> with StringMap
authorkwolekr <kwolekr@minetest.net>
Tue, 19 May 2015 06:24:14 +0000 (02:24 -0400)
committerkwolekr <kwolekr@minetest.net>
Tue, 19 May 2015 20:10:49 +0000 (16:10 -0400)
Also, clean up surrounding code style
Replace by-value parameter passing with const refs when possible
Fix post-increment of iterators

25 files changed:
src/ban.cpp
src/ban.h
src/client.cpp
src/client.h
src/content_mapnode.cpp
src/game.cpp
src/guiEngine.cpp
src/guiEngine.h
src/guiFileSelectMenu.cpp
src/guiFormSpecMenu.cpp
src/guiFormSpecMenu.h
src/httpfetch.cpp
src/httpfetch.h
src/itemdef.cpp
src/network/serverpackethandler.cpp
src/nodemetadata.cpp
src/nodemetadata.h
src/script/cpp_api/s_mainmenu.cpp
src/script/cpp_api/s_mainmenu.h
src/script/cpp_api/s_node.cpp
src/script/cpp_api/s_node.h
src/script/cpp_api/s_player.cpp
src/script/cpp_api/s_player.h
src/script/lua_api/l_nodemeta.cpp
src/shader.cpp

index 55d9b22feea47cca3a986f9a4c002d2fa8fdf159..7c1a68d458af2d330150198c8d812dc1d79df0c9 100644 (file)
@@ -56,7 +56,7 @@ void BanManager::load()
                infostream<<"BanManager: failed loading from "<<m_banfilepath<<std::endl;
                throw SerializationError("BanManager::load(): Couldn't open file");
        }
-       
+
        while(!is.eof() && is.good())
        {
                std::string line;
@@ -74,18 +74,14 @@ void BanManager::load()
 void BanManager::save()
 {
        JMutexAutoLock lock(m_mutex);
-       infostream<<"BanManager: saving to "<<m_banfilepath<<std::endl;
+       infostream << "BanManager: saving to " << m_banfilepath << std::endl;
        std::ostringstream ss(std::ios_base::binary);
 
-       for(std::map<std::string, std::string>::iterator
-                       i = m_ips.begin();
-                       i != m_ips.end(); i++)
-       {
-               ss << i->first << "|" << i->second << "\n";
-       }
+       for (StringMap::iterator it = m_ips.begin(); it != m_ips.end(); ++it)
+               ss << it->first << "|" << it->second << "\n";
 
-       if(!fs::safeWriteToFile(m_banfilepath, ss.str())) {
-               infostream<<"BanManager: failed saving to "<<m_banfilepath<<std::endl;
+       if (!fs::safeWriteToFile(m_banfilepath, ss.str())) {
+               infostream << "BanManager: failed saving to " << m_banfilepath << std::endl;
                throw SerializationError("BanManager::save(): Couldn't write file");
        }
 
@@ -102,25 +98,23 @@ std::string BanManager::getBanDescription(const std::string &ip_or_name)
 {
        JMutexAutoLock lock(m_mutex);
        std::string s = "";
-       for(std::map<std::string, std::string>::iterator
-                       i = m_ips.begin();
-                       i != m_ips.end(); i++)
-       {
-               if(i->first == ip_or_name || i->second == ip_or_name
-                               || ip_or_name == "")
-                       s += i->first + "|" + i->second + ", ";
+       for (StringMap::iterator it = m_ips.begin(); it != m_ips.end(); ++it) {
+               if (it->first  == ip_or_name || it->second == ip_or_name
+                               || ip_or_name == "") {
+                       s += it->first + "|" + it->second + ", ";
+               }
        }
-       s = s.substr(0, s.size()-2);
+       s = s.substr(0, s.size() - 2);
        return s;
 }
 
 std::string BanManager::getBanName(const std::string &ip)
 {
        JMutexAutoLock lock(m_mutex);
-       std::map<std::string, std::string>::iterator i = m_ips.find(ip);
-       if(i == m_ips.end())
+       StringMap::iterator it = m_ips.find(ip);
+       if (it == m_ips.end())
                return "";
-       return i->second;
+       return it->second;
 }
 
 void BanManager::add(const std::string &ip, const std::string &name)
@@ -133,19 +127,16 @@ void BanManager::add(const std::string &ip, const std::string &name)
 void BanManager::remove(const std::string &ip_or_name)
 {
        JMutexAutoLock lock(m_mutex);
-       for(std::map<std::string, std::string>::iterator
-                       i = m_ips.begin();
-                       i != m_ips.end();)
-       {
-               if((i->first == ip_or_name) || (i->second == ip_or_name)) {
-                       m_ips.erase(i++);
+       for (StringMap::iterator it = m_ips.begin(); it != m_ips.end();) {
+               if ((it->first == ip_or_name) || (it->second == ip_or_name)) {
+                       m_ips.erase(it++);
                } else {
-                       ++i;
+                       ++it;
                }
        }
        m_modified = true;
 }
-       
+
 
 bool BanManager::isModified()
 {
index 02a472f51c825bab81fd9536a317d98459b88f7a..5db7179defef48165f2be7e85cb314ed4ac5e5c8 100644 (file)
--- a/src/ban.h
+++ b/src/ban.h
@@ -20,8 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #ifndef BAN_HEADER
 #define BAN_HEADER
 
-#include <map>
-#include <string>
+#include "util/string.h"
 #include "jthread/jthread.h"
 #include "jthread/jmutex.h"
 #include "exceptions.h"
@@ -43,7 +42,7 @@ public:
 private:
        JMutex m_mutex;
        std::string m_banfilepath;
-       std::map<std::string, std::string> m_ips;
+       StringMap m_ips;
        bool m_modified;
 
 };
index 1d0245c45d9bda53f11df6ab48a3d45483fab062..de813187574ddba26ca117e42467d074e98f37dc 100644 (file)
@@ -1102,7 +1102,7 @@ void Client::sendRemovedSounds(std::vector<s32> &soundList)
 }
 
 void Client::sendNodemetaFields(v3s16 p, const std::string &formname,
-               const std::map<std::string, std::string> &fields)
+               const StringMap &fields)
 {
        size_t fields_size = fields.size();
 
@@ -1112,10 +1112,10 @@ void Client::sendNodemetaFields(v3s16 p, const std::string &formname,
 
        pkt << p << formname << (u16) (fields_size & 0xFFFF);
 
-       for(std::map<std::string, std::string>::const_iterator
-                       i = fields.begin(); i != fields.end(); i++) {
-               const std::string &name = i->first;
-               const std::string &value = i->second;
+       StringMap::const_iterator it;
+       for (it = fields.begin(); it != fields.end(); ++it) {
+               const std::string &name = it->first;
+               const std::string &value = it->second;
                pkt << name;
                pkt.putLongString(value);
        }
@@ -1124,7 +1124,7 @@ void Client::sendNodemetaFields(v3s16 p, const std::string &formname,
 }
 
 void Client::sendInventoryFields(const std::string &formname,
-               const std::map<std::string, std::string> &fields)
+               const StringMap &fields)
 {
        size_t fields_size = fields.size();
        FATAL_ERROR_IF(fields_size > 0xFFFF, "Unsupported number of inventory fields");
@@ -1132,10 +1132,10 @@ void Client::sendInventoryFields(const std::string &formname,
        NetworkPacket pkt(TOSERVER_INVENTORY_FIELDS, 0);
        pkt << formname << (u16) (fields_size & 0xFFFF);
 
-       for(std::map<std::string, std::string>::const_iterator
-                       i = fields.begin(); i != fields.end(); i++) {
-               const std::string &name  = i->first;
-               const std::string &value = i->second;
+       StringMap::const_iterator it;
+       for (it = fields.begin(); it != fields.end(); ++it) {
+               const std::string &name  = it->first;
+               const std::string &value = it->second;
                pkt << name;
                pkt.putLongString(value);
        }
@@ -1918,14 +1918,13 @@ ParticleManager* Client::getParticleManager()
 
 scene::IAnimatedMesh* Client::getMesh(const std::string &filename)
 {
-       std::map<std::string, std::string>::const_iterator i =
-                       m_mesh_data.find(filename);
-       if(i == m_mesh_data.end()){
-               errorstream<<"Client::getMesh(): Mesh not found: \""<<filename<<"\""
-                               <<std::endl;
+       StringMap::const_iterator it = m_mesh_data.find(filename);
+       if (it == m_mesh_data.end()) {
+               errorstream << "Client::getMesh(): Mesh not found: \"" << filename
+                       << "\"" << std::endl;
                return NULL;
        }
-       const std::string &data    = i->second;
+       const std::string &data    = it->second;
        scene::ISceneManager *smgr = m_device->getSceneManager();
 
        // Create the mesh, remove it from cache and return it
index 87cf8ce4533b176a2dd525041b945a201953b0ae..56f040909f1eb204341477c988cfc35e51e8aced 100644 (file)
@@ -405,13 +405,13 @@ public:
        void interact(u8 action, const PointedThing& pointed);
 
        void sendNodemetaFields(v3s16 p, const std::string &formname,
-                       const std::map<std::string, std::string> &fields);
+               const StringMap &fields);
        void sendInventoryFields(const std::string &formname,
-                       const std::map<std::string, std::string> &fields);
+               const StringMap &fields);
        void sendInventoryAction(InventoryAction *a);
        void sendChatMessage(const std::wstring &message);
        void sendChangePassword(const std::string &oldpassword,
-                               const std::string &newpassword);
+               const std::string &newpassword);
        void sendDamage(u8 damage);
        void sendBreath(u16 breath);
        void sendRespawn();
@@ -648,7 +648,7 @@ private:
        std::map<std::string, Inventory*> m_detached_inventories;
 
        // Storage for mesh data for creating multiple instances of the same mesh
-       std::map<std::string, std::string> m_mesh_data;
+       StringMap m_mesh_data;
 
        // own state
        LocalClientState m_state;
index 44d0b8e386685f72ec3000a4fcce5120608b32f1..5e2a5c816e3361838153a43ca417dd5cc09310c2 100644 (file)
@@ -23,7 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "mapnode.h"
 #include "nodedef.h"
 #include "nameidmapping.h"
-#include <map>
+#include "util/string.h"
 
 /*
        Legacy node content type IDs
@@ -218,14 +218,13 @@ public:
        }
        std::string get(const std::string &old)
        {
-               std::map<std::string, std::string>::const_iterator i;
-               i = old_to_new.find(old);
-               if(i == old_to_new.end())
+               StringMap::const_iterator it = old_to_new.find(old);
+               if (it == old_to_new.end())
                        return "";
-               return i->second;
+               return it->second;
        }
 private:
-       std::map<std::string, std::string> old_to_new;
+       StringMap old_to_new;
 };
 
 NewNameGetter newnamegetter;
index e27ec37dd2d0d1ebfd1557d5093a2cc96845292d..7e3ab802c6cd91cf29e99df302d50d4665898219 100644 (file)
@@ -87,11 +87,11 @@ struct TextDestNodeMetadata : public TextDest {
                std::string ntext = wide_to_narrow(text);
                infostream << "Submitting 'text' field of node at (" << m_p.X << ","
                           << m_p.Y << "," << m_p.Z << "): " << ntext << std::endl;
-               std::map<std::string, std::string> fields;
+               StringMap fields;
                fields["text"] = ntext;
                m_client->sendNodemetaFields(m_p, "", fields);
        }
-       void gotText(std::map<std::string, std::string> fields)
+       void gotText(const StringMap &fields)
        {
                m_client->sendNodemetaFields(m_p, "", fields);
        }
@@ -111,7 +111,7 @@ struct TextDestPlayerInventory : public TextDest {
                m_client = client;
                m_formname = formname;
        }
-       void gotText(std::map<std::string, std::string> fields)
+       void gotText(const StringMap &fields)
        {
                m_client->sendInventoryFields(m_formname, fields);
        }
@@ -138,7 +138,7 @@ struct LocalFormspecHandler : public TextDest {
                errorstream << "LocalFormspecHandler::gotText old style message received" << std::endl;
        }
 
-       void gotText(std::map<std::string, std::string> fields)
+       void gotText(const StringMap &fields)
        {
                if (m_formname == "MT_PAUSE_MENU") {
                        if (fields.find("btn_sound") != fields.end()) {
@@ -180,9 +180,9 @@ struct LocalFormspecHandler : public TextDest {
 
                        if ((fields.find("btn_send") != fields.end()) ||
                                        (fields.find("quit") != fields.end())) {
-                               if (fields.find("f_text") != fields.end()) {
-                                       m_client->typeChatMessage(narrow_to_wide(fields["f_text"]));
-                               }
+                               StringMap::const_iterator it = fields.find("f_text");
+                               if (it != fields.end())
+                                       m_client->typeChatMessage(narrow_to_wide(it->second));
 
                                return;
                        }
@@ -210,12 +210,14 @@ struct LocalFormspecHandler : public TextDest {
                        return;
                }
 
-               errorstream << "LocalFormspecHandler::gotText unhandled >" << m_formname << "< event" << std::endl;
-               int i = 0;
+               errorstream << "LocalFormspecHandler::gotText unhandled >"
+                       << m_formname << "< event" << std::endl;
 
-               for (std::map<std::string, std::string>::iterator iter = fields.begin();
-                               iter != fields.end(); iter++) {
-                       errorstream << "\t" << i << ": " << iter->first << "=" << iter->second << std::endl;
+               int i = 0;
+               StringMap::const_iterator it;
+               for (it = fields.begin(); it != fields.end(); ++it) {
+                       errorstream << "\t" << i << ": " << it->first
+                               << "=" << it->second << std::endl;
                        i++;
                }
        }
index 752f9ddd25af8fd44fe591bbb515c215e1d5b6c8..3248ef1124e546d9277fd6bf4825bea00c70fcc3 100644 (file)
@@ -53,7 +53,7 @@ TextDestGuiEngine::TextDestGuiEngine(GUIEngine* engine)
 }
 
 /******************************************************************************/
-void TextDestGuiEngine::gotText(std::map<std::string, std::string> fields)
+void TextDestGuiEngine::gotText(const StringMap &fields)
 {
        m_engine->getScriptIface()->handleMainMenuButtons(fields);
 }
index e57573220b107f8136756d389a3dda6429b9ded2..d527f722243dc735832a682bf1f3e0f71fc31950 100644 (file)
@@ -73,7 +73,7 @@ public:
         * receive fields transmitted by guiFormSpecMenu
         * @param fields map containing formspec field elements currently active
         */
-       void gotText(std::map<std::string, std::string> fields);
+       void gotText(const StringMap &fields);
 
        /**
         * receive text/events transmitted by guiFormSpecMenu
index e98b025c62233a308f1d8242899e18a39dbd7f46..9b43ab60295b731d12a439e7d8a3af8219bb94e7 100644 (file)
@@ -84,7 +84,7 @@ void GUIFileSelectMenu::drawMenu()
 
 void GUIFileSelectMenu::acceptInput() {
        if ((m_text_dst != 0) && (this->m_formname != "")){
-               std::map<std::string, std::string> fields;
+               StringMap fields;
 
                if (m_accepted)
                        fields[m_formname + "_accepted"] = wide_to_narrow(m_fileOpenDialog->getFileName());
index 5f67bb22afbd3b96f5325cc2522f39cfbab51b9e..d53c9b3afebf962187f4fa6fa29dabb7736950c3 100644 (file)
@@ -2579,7 +2579,7 @@ void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode=quit_mode_no)
 {
        if(m_text_dst)
        {
-               std::map<std::string, std::string> fields;
+               StringMap fields;
 
                if (quitmode == quit_mode_accept) {
                        fields["quit"] = "true";
index 73dc7af62fce72336f3b3e162c05b5acfecc0c1e..f7259578293190fe173ad26d991cfcdacc714896 100644 (file)
@@ -56,7 +56,7 @@ struct TextDest
        virtual ~TextDest() {};
        // This is deprecated I guess? -celeron55
        virtual void gotText(std::wstring text){}
-       virtual void gotText(std::map<std::string, std::string> fields) = 0;
+       virtual void gotText(const StringMap &fields) = 0;
        virtual void setFormName(std::string formname)
        { m_formname = formname;};
 
index c60e141fc087fbdcd40fc09d1ec2a437db1a88da..56cdad2b112df13a59268c7668c7ee5df4819ccd 100644 (file)
@@ -266,8 +266,7 @@ HTTPFetchOngoing::HTTPFetchOngoing(HTTPFetchRequest request_, CurlHandlePool *po
                curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
        } else if (request.multipart) {
                curl_httppost *last = NULL;
-               for (std::map<std::string, std::string>::iterator it =
-                                       request.post_fields.begin();
+               for (StringMap::iterator it = request.post_fields.begin();
                                it != request.post_fields.end(); ++it) {
                        curl_formadd(&post, &last,
                                        CURLFORM_NAMELENGTH, it->first.size(),
@@ -282,10 +281,8 @@ HTTPFetchOngoing::HTTPFetchOngoing(HTTPFetchRequest request_, CurlHandlePool *po
        } else if (request.post_data.empty()) {
                curl_easy_setopt(curl, CURLOPT_POST, 1);
                std::string str;
-               for (std::map<std::string, std::string>::iterator it =
-                                       request.post_fields.begin();
-                               it != request.post_fields.end();
-                               ++it) {
+               for (StringMap::iterator it = request.post_fields.begin();
+                               it != request.post_fields.end(); ++it) {
                        if (str != "")
                                str += "&";
                        str += urlencode(it->first);
index 50a4c93d81cf3079be8f69d95f16c10264ba59ec..c44c8d2d3894449f8ffd3f98045a5cfff9e0d15a 100644 (file)
@@ -20,9 +20,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #ifndef HTTPFETCH_HEADER
 #define HTTPFETCH_HEADER
 
-#include <string>
 #include <vector>
-#include <map>
+#include "util/string.h"
 #include "config.h"
 
 // Can be used in place of "caller" in asynchronous transfers to discard result
@@ -54,7 +53,7 @@ struct HTTPFetchRequest
 
        // POST fields.  Fields are escaped properly.
        // If this is empty a GET request is done instead.
-       std::map<std::string, std::string> post_fields;
+       StringMap post_fields;
 
        // Raw POST data, overrides post_fields.
        std::string post_data;
index 95c1e47fc88513642668daedcb7127cd129b38b8..0133b1b3f2a288940709f354df04ff1a99cb12a1 100644 (file)
@@ -280,26 +280,23 @@ public:
        }
        virtual std::string getAlias(const std::string &name) const
        {
-               std::map<std::string, std::string>::const_iterator i;
-               i = m_aliases.find(name);
-               if(i != m_aliases.end())
-                       return i->second;
+               StringMap::const_iterator it = m_aliases.find(name);
+               if (it != m_aliases.end())
+                       return it->second;
                return name;
        }
        virtual std::set<std::string> getAll() const
        {
                std::set<std::string> result;
-               for(std::map<std::string, ItemDefinition*>::const_iterator
-                               i = m_item_definitions.begin();
-                               i != m_item_definitions.end(); i++)
-               {
-                       result.insert(i->first);
+               for(std::map<std::string, ItemDefinition *>::const_iterator
+                               it = m_item_definitions.begin();
+                               it != m_item_definitions.end(); ++it) {
+                       result.insert(it->first);
                }
-               for(std::map<std::string, std::string>::const_iterator
-                               i = m_aliases.begin();
-                               i != m_aliases.end(); i++)
-               {
-                       result.insert(i->first);
+               for (StringMap::const_iterator
+                               it = m_aliases.begin();
+                               it != m_aliases.end(); ++it) {
+                       result.insert(it->first);
                }
                return result;
        }
@@ -571,22 +568,24 @@ public:
                writeU8(os, 0); // version
                u16 count = m_item_definitions.size();
                writeU16(os, count);
-               for(std::map<std::string, ItemDefinition*>::const_iterator
-                               i = m_item_definitions.begin();
-                               i != m_item_definitions.end(); i++)
-               {
-                       ItemDefinition *def = i->second;
+
+               for (std::map<std::string, ItemDefinition *>::const_iterator
+                               it = m_item_definitions.begin();
+                               it != m_item_definitions.end(); ++it) {
+                       ItemDefinition *def = it->second;
                        // Serialize ItemDefinition and write wrapped in a string
                        std::ostringstream tmp_os(std::ios::binary);
                        def->serialize(tmp_os, protocol_version);
-                       os<<serializeString(tmp_os.str());
+                       os << serializeString(tmp_os.str());
                }
+
                writeU16(os, m_aliases.size());
-               for(std::map<std::string, std::string>::const_iterator
-                       i = m_aliases.begin(); i != m_aliases.end(); i++)
-               {
-                       os<<serializeString(i->first);
-                       os<<serializeString(i->second);
+
+               for (StringMap::const_iterator
+                               it = m_aliases.begin();
+                               it != m_aliases.end(); ++it) {
+                       os << serializeString(it->first);
+                       os << serializeString(it->second);
                }
        }
        void deSerialize(std::istream &is)
@@ -633,7 +632,7 @@ private:
        // Key is name
        std::map<std::string, ItemDefinition*> m_item_definitions;
        // Aliases
-       std::map<std::string, std::string> m_aliases;
+       StringMap m_aliases;
 #ifndef SERVER
        // The id of the thread that is allowed to use irrlicht directly
        threadid_t m_main_thread;
index ea1528c644011f8e815e421d05d85f9c0cb79f96..f658e106fa7b8d13757e6fce4fe3f5bc88c53bc2 100644 (file)
@@ -192,7 +192,7 @@ void Server::handleCommand_Init(NetworkPacket* pkt)
 
        {
                std::string reason;
-               if(m_script->on_prejoinplayer(playername, addr_s, reason)) {
+               if (m_script->on_prejoinplayer(playername, addr_s, &reason)) {
                        actionstream << "Server: Player with the name \"" << playerName << "\" "
                                        << "tried to connect from " << addr_s << " "
                                        << "but it was disallowed for the following reason: "
@@ -480,7 +480,7 @@ void Server::handleCommand_Init_Legacy(NetworkPacket* pkt)
 
        {
                std::string reason;
-               if (m_script->on_prejoinplayer(playername, addr_s, reason)) {
+               if (m_script->on_prejoinplayer(playername, addr_s, &reason)) {
                        actionstream << "Server: Player with the name \"" << playername << "\" "
                                        << "tried to connect from " << addr_s << " "
                                        << "but it was disallowed for the following reason: "
@@ -1742,7 +1742,7 @@ void Server::handleCommand_NodeMetaFields(NetworkPacket* pkt)
 
        *pkt >> p >> formname >> num;
 
-       std::map<std::string, std::string> fields;
+       StringMap fields;
        for (u16 k = 0; k < num; k++) {
                std::string fieldname;
                *pkt >> fieldname;
@@ -1792,7 +1792,7 @@ void Server::handleCommand_InventoryFields(NetworkPacket* pkt)
 
        *pkt >> formname >> num;
 
-       std::map<std::string, std::string> fields;
+       StringMap fields;
        for (u16 k = 0; k < num; k++) {
                std::string fieldname;
                *pkt >> fieldname;
index bd54d225688d1c99755d3db07c7b38ca5e9a9bf0..d4da7a5ed4dc3d3620f58419fb8785928a5f4f9b 100644 (file)
@@ -45,10 +45,11 @@ void NodeMetadata::serialize(std::ostream &os) const
 {
        int num_vars = m_stringvars.size();
        writeU32(os, num_vars);
-       for(std::map<std::string, std::string>::const_iterator
-                       i = m_stringvars.begin(); i != m_stringvars.end(); i++){
-               os<<serializeString(i->first);
-               os<<serializeLongString(i->second);
+       for (StringMap::const_iterator
+                       it = m_stringvars.begin();
+                       it != m_stringvars.end(); ++it) {
+               os << serializeString(it->first);
+               os << serializeLongString(it->second);
        }
 
        m_inventory->serialize(os);
@@ -203,11 +204,10 @@ void NodeMetadataList::clear()
 std::string NodeMetadata::getString(const std::string &name,
        unsigned short recursion) const
 {
-       std::map<std::string, std::string>::const_iterator it;
-       it = m_stringvars.find(name);
-       if (it == m_stringvars.end()) {
+       StringMap::const_iterator it = m_stringvars.find(name);
+       if (it == m_stringvars.end())
                return "";
-       }
+
        return resolveString(it->second, recursion);
 }
 
index acd45bdf9bde4f3b7c85a6029a84bb536bfe7c01..8e84e5af30a15cf9bed380de3b0a3969ab5e9b36 100644 (file)
@@ -21,10 +21,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #define NODEMETADATA_HEADER
 
 #include "irr_v3d.h"
-#include <string>
 #include <iostream>
 #include <vector>
-#include <map>
+#include "util/string.h"
 
 /*
        NodeMetadata stores arbitary amounts of data for special blocks.
@@ -54,19 +53,19 @@ public:
        void setString(const std::string &name, const std::string &var);
        // Support variable names in values
        std::string resolveString(const std::string &str, unsigned short recursion = 0) const;
-       std::map<std::string, std::string> getStrings() const
+       StringMap getStrings() const
        {
                return m_stringvars;
        }
 
        // The inventory
-       InventorygetInventory()
+       Inventory *getInventory()
        {
                return m_inventory;
        }
 
 private:
-       std::map<std::string, std::string> m_stringvars;
+       StringMap m_stringvars;
        Inventory *m_inventory;
 };
 
index ef8cea6c9c0eba2f5b7f3aa065cd31a82329f906..0bb247fa012757f80bae12887062c07aa28e0a2e 100644 (file)
@@ -53,7 +53,7 @@ void ScriptApiMainMenu::handleMainMenuEvent(std::string text)
                scriptError();
 }
 
-void ScriptApiMainMenu::handleMainMenuButtons(std::map<std::string, std::string> fields)
+void ScriptApiMainMenu::handleMainMenuButtons(const StringMap &fields)
 {
        SCRIPTAPI_PRECHECKHEADER
 
@@ -69,8 +69,8 @@ void ScriptApiMainMenu::handleMainMenuButtons(std::map<std::string, std::string>
 
        // Convert fields to a Lua table
        lua_newtable(L);
-       std::map<std::string, std::string>::const_iterator it;
-       for (it = fields.begin(); it != fields.end(); it++){
+       StringMap::const_iterator it;
+       for (it = fields.begin(); it != fields.end(); ++it) {
                const std::string &name = it->first;
                const std::string &value = it->second;
                lua_pushstring(L, name.c_str());
index 53dcd37e93fb8f503f9460145b00d1b6d1d57001..6994b578befccb2199e9afe50382235bd2d26ad9 100644 (file)
@@ -21,7 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #define S_MAINMENU_H_
 
 #include "cpp_api/s_base.h"
-#include <map>
+#include "util/string.h"
 
 class ScriptApiMainMenu
                : virtual public ScriptApiBase
@@ -43,7 +43,7 @@ public:
         * process field data recieved from formspec
         * @param fields data in field format
         */
-       void handleMainMenuButtons(std::map<std::string, std::string> fields);
+       void handleMainMenuButtons(const StringMap &fields);
 };
 
 #endif /* S_MAINMENU_H_ */
index e3d3fb58bdf0be434ef5290a1f93e86ef5b79151..7df712ca085f58f4e52e236168c3c941d9b5d413 100644 (file)
@@ -200,7 +200,7 @@ bool ScriptApiNode::node_on_timer(v3s16 p, MapNode node, f32 dtime)
 
 void ScriptApiNode::node_on_receive_fields(v3s16 p,
                const std::string &formname,
-               const std::map<std::string, std::string> &fields,
+               const StringMap &fields,
                ServerActiveObject *sender)
 {
        SCRIPTAPI_PRECHECKHEADER
@@ -220,8 +220,8 @@ void ScriptApiNode::node_on_receive_fields(v3s16 p,
        push_v3s16(L, p);                    // pos
        lua_pushstring(L, formname.c_str()); // formname
        lua_newtable(L);                     // fields
-       std::map<std::string, std::string>::const_iterator it;
-       for (it = fields.begin(); it != fields.end(); it++){
+       StringMap::const_iterator it;
+       for (it = fields.begin(); it != fields.end(); it++) {
                const std::string &name = it->first;
                const std::string &value = it->second;
                lua_pushstring(L, name.c_str());
index b3a6c83b5cd0fd55c3298770166924c467f7d279..fe1180cb3b3eb7ce2c111566ba6d6d8f49426455 100644 (file)
@@ -20,11 +20,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #ifndef S_NODE_H_
 #define S_NODE_H_
 
-#include <map>
-
 #include "irr_v3d.h"
 #include "cpp_api/s_base.h"
 #include "cpp_api/s_nodemeta.h"
+#include "util/string.h"
 
 struct MapNode;
 class ServerActiveObject;
@@ -47,7 +46,7 @@ public:
        bool node_on_timer(v3s16 p, MapNode node, f32 dtime);
        void node_on_receive_fields(v3s16 p,
                        const std::string &formname,
-                       const std::map<std::string, std::string> &fields,
+                       const StringMap &fields,
                        ServerActiveObject *sender);
        void node_falling_update(v3s16 p);
        void node_falling_update_single(v3s16 p);
index d56766824b403aceb0e8fa9a026816ca3fbe918d..9b2c3753cb1b78ded1596d30cd5b2c358f796bd9 100644 (file)
@@ -83,7 +83,10 @@ bool ScriptApiPlayer::on_respawnplayer(ServerActiveObject *player)
        return positioning_handled_by_some;
 }
 
-bool ScriptApiPlayer::on_prejoinplayer(std::string name, std::string ip, std::string &reason)
+bool ScriptApiPlayer::on_prejoinplayer(
+       const std::string &name,
+       const std::string &ip,
+       std::string *reason)
 {
        SCRIPTAPI_PRECHECKHEADER
 
@@ -94,7 +97,7 @@ bool ScriptApiPlayer::on_prejoinplayer(std::string name, std::string ip, std::st
        lua_pushstring(L, ip.c_str());
        script_run_callbacks(L, 2, RUN_CALLBACKS_MODE_OR);
        if (lua_isstring(L, -1)) {
-               reason.assign(lua_tostring(L, -1));
+               reason->assign(lua_tostring(L, -1));
                return true;
        }
        return false;
@@ -142,7 +145,7 @@ void ScriptApiPlayer::on_cheat(ServerActiveObject *player,
 
 void ScriptApiPlayer::on_playerReceiveFields(ServerActiveObject *player,
                const std::string &formname,
-               const std::map<std::string, std::string> &fields)
+               const StringMap &fields)
 {
        SCRIPTAPI_PRECHECKHEADER
 
@@ -156,17 +159,19 @@ void ScriptApiPlayer::on_playerReceiveFields(ServerActiveObject *player,
        lua_pushstring(L, formname.c_str());
        // param 3
        lua_newtable(L);
-       for(std::map<std::string, std::string>::const_iterator
-                       i = fields.begin(); i != fields.end(); i++){
-               const std::string &name = i->first;
-               const std::string &value = i->second;
+       StringMap::const_iterator it;
+       for (it = fields.begin(); it != fields.end(); ++it) {
+               const std::string &name = it->first;
+               const std::string &value = it->second;
                lua_pushstring(L, name.c_str());
                lua_pushlstring(L, value.c_str(), value.size());
                lua_settable(L, -3);
        }
        script_run_callbacks(L, 3, RUN_CALLBACKS_MODE_OR_SC);
 }
-ScriptApiPlayer::~ScriptApiPlayer() {
+
+ScriptApiPlayer::~ScriptApiPlayer()
+{
 }
 
 
index a0f764cd5c7770beb4c0ca4cc292d6993a5c5af7..9c8d1d1ad8f55a17c96f0575af6fec2ae6d5cb93 100644 (file)
@@ -20,10 +20,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #ifndef S_PLAYER_H_
 #define S_PLAYER_H_
 
-#include <map>
-
 #include "cpp_api/s_base.h"
 #include "irr_v3d.h"
+#include "util/string.h"
 
 struct ToolCapabilities;
 
@@ -36,17 +35,16 @@ public:
        void on_newplayer(ServerActiveObject *player);
        void on_dieplayer(ServerActiveObject *player);
        bool on_respawnplayer(ServerActiveObject *player);
-       bool on_prejoinplayer(std::string name, std::string ip, std::string &reason);
+       bool on_prejoinplayer(const std::string &name, const std::string &ip,
+               std::string *reason);
        void on_joinplayer(ServerActiveObject *player);
        void on_leaveplayer(ServerActiveObject *player);
        void on_cheat(ServerActiveObject *player, const std::string &cheat_type);
        bool on_punchplayer(ServerActiveObject *player,
                ServerActiveObject *hitter, float time_from_last_punch,
                const ToolCapabilities *toolcap, v3f dir, s16 damage);
-
        void on_playerReceiveFields(ServerActiveObject *player,
-                       const std::string &formname,
-                       const std::map<std::string, std::string> &fields);
+               const std::string &formname, const StringMap &fields);
 };
 
 
index 906cc3172e4721082e994056f44d68310f55149f..6cdbe5c68d86ee239e63c7a9ee2bb2737d7de94a 100644 (file)
@@ -190,32 +190,34 @@ int NodeMetaRef::l_to_table(lua_State *L)
        NodeMetaRef *ref = checkobject(L, 1);
 
        NodeMetadata *meta = getmeta(ref, true);
-       if(meta == NULL){
+       if (meta == NULL) {
                lua_pushnil(L);
                return 1;
        }
        lua_newtable(L);
+
        // fields
        lua_newtable(L);
        {
-               std::map<std::string, std::string> fields = meta->getStrings();
-               for(std::map<std::string, std::string>::const_iterator
-                               i = fields.begin(); i != fields.end(); i++){
-                       const std::string &name = i->first;
-                       const std::string &value = i->second;
+               StringMap fields = meta->getStrings();
+               for (StringMap::const_iterator
+                               it = fields.begin(); it != fields.end(); ++it) {
+                       const std::string &name = it->first;
+                       const std::string &value = it->second;
                        lua_pushlstring(L, name.c_str(), name.size());
                        lua_pushlstring(L, value.c_str(), value.size());
                        lua_settable(L, -3);
                }
        }
        lua_setfield(L, -2, "fields");
+
        // inventory
        lua_newtable(L);
        Inventory *inv = meta->getInventory();
-       if(inv){
-               std::vector<const InventoryList*> lists = inv->getLists();
-               for(std::vector<const InventoryList*>::const_iterator
-                               i = lists.begin(); i != lists.end(); i++){
+       if (inv) {
+               std::vector<const InventoryList *> lists = inv->getLists();
+               for(std::vector<const InventoryList *>::const_iterator
+                               i = lists.begin(); i != lists.end(); i++) {
                        push_inventory_list(L, inv, (*i)->getName().c_str());
                        lua_setfield(L, -2, (*i)->getName().c_str());
                }
index ea2de3f1e85e4bfe4010bd5af646341d668bdf36..a467c2ea96dae18568bb2a56fd099ed06a5eabcf 100644 (file)
@@ -103,10 +103,8 @@ std::string getShaderPath(const std::string &name_of_shader,
 class SourceShaderCache
 {
 public:
-       void insert(const std::string &name_of_shader,
-                       const std::string &filename,
-                       const std::string &program,
-                       bool prefer_local)
+       void insert(const std::string &name_of_shader, const std::string &filename,
+               const std::string &program, bool prefer_local)
        {
                std::string combined = name_of_shader + DIR_DELIM + filename;
                // Try to use local shader instead if asked to
@@ -122,42 +120,43 @@ public:
                }
                m_programs[combined] = program;
        }
+
        std::string get(const std::string &name_of_shader,
-                       const std::string &filename)
+               const std::string &filename)
        {
                std::string combined = name_of_shader + DIR_DELIM + filename;
-               std::map<std::string, std::string>::iterator n;
-               n = m_programs.find(combined);
-               if(n != m_programs.end())
+               StringMap::iterator n = m_programs.find(combined);
+               if (n != m_programs.end())
                        return n->second;
                return "";
        }
+
        // Primarily fetches from cache, secondarily tries to read from filesystem
        std::string getOrLoad(const std::string &name_of_shader,
-                       const std::string &filename)
+               const std::string &filename)
        {
                std::string combined = name_of_shader + DIR_DELIM + filename;
-               std::map<std::string, std::string>::iterator n;
-               n = m_programs.find(combined);
-               if(n != m_programs.end())
+               StringMap::iterator n = m_programs.find(combined);
+               if (n != m_programs.end())
                        return n->second;
                std::string path = getShaderPath(name_of_shader, filename);
-               if(path == ""){
-                       infostream<<"SourceShaderCache::getOrLoad(): No path found for \""
-                                       <<combined<<"\""<<std::endl;
+               if (path == "") {
+                       infostream << "SourceShaderCache::getOrLoad(): No path found for \""
+                               << combined << "\"" << std::endl;
                        return "";
                }
-               infostream<<"SourceShaderCache::getOrLoad(): Loading path \""<<path
-                               <<"\""<<std::endl;
+               infostream << "SourceShaderCache::getOrLoad(): Loading path \""
+                       << path << "\"" << std::endl;
                std::string p = readFile(path);
-               if(p != ""){
+               if (p != "") {
                        m_programs[combined] = p;
                        return p;
                }
                return "";
        }
 private:
-       std::map<std::string, std::string> m_programs;
+       StringMap m_programs;
+
        std::string readFile(const std::string &path)
        {
                std::ifstream is(path.c_str(), std::ios::binary);
@@ -274,23 +273,23 @@ public:
 
                The id 0 points to a null shader. Its material is EMT_SOLID.
        */
-       u32 getShaderIdDirect(const std::string &name, 
+       u32 getShaderIdDirect(const std::string &name,
                const u8 material_type, const u8 drawtype);
 
        /*
                If shader specified by the name pointed by the id doesn't
-               exist, create it, then return id. 
+               exist, create it, then return id.
 
                Can be called from any thread. If called from some other thread
                and not found in cache, the call is queued to the main thread
                for processing.
        */
-       
+
        u32 getShader(const std::string &name,
                const u8 material_type, const u8 drawtype);
-       
+
        ShaderInfo getShaderInfo(u32 id);
-       
+
        // Processes queued shader requests from other threads.
        // Shall be called from the main thread.
        void processQueue();
@@ -391,7 +390,7 @@ ShaderSource::~ShaderSource()
        }
 }
 
-u32 ShaderSource::getShader(const std::string &name, 
+u32 ShaderSource::getShader(const std::string &name,
                const u8 material_type, const u8 drawtype)
 {
        /*
@@ -435,7 +434,7 @@ u32 ShaderSource::getShader(const std::string &name,
 /*
        This method generates all the shaders
 */
-u32 ShaderSource::getShaderIdDirect(const std::string &name, 
+u32 ShaderSource::getShaderIdDirect(const std::string &name,
                const u8 material_type, const u8 drawtype)
 {
        //infostream<<"getShaderIdDirect(): name=\""<<name<<"\""<<std::endl;
@@ -494,7 +493,7 @@ ShaderInfo ShaderSource::getShaderInfo(u32 id)
 
 void ShaderSource::processQueue()
 {
+
 
 }
 
@@ -572,7 +571,7 @@ ShaderInfo generate_shader(std::string name, u8 material_type, u8 drawtype,
                        shaderinfo.base_material = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
                break;
        }
-       
+
        bool enable_shaders = g_settings->getBool("enable_shaders");
        if(!enable_shaders)
                return shaderinfo;
@@ -648,7 +647,7 @@ ShaderInfo generate_shader(std::string name, u8 material_type, u8 drawtype,
                "NDT_FIRELIKE",
                "NDT_GLASSLIKE_FRAMED_OPTIONAL"
        };
-       
+
        for (int i = 0; i < 14; i++){
                shaders_header += "#define ";
                shaders_header += drawTypes[i];
@@ -741,10 +740,10 @@ ShaderInfo generate_shader(std::string name, u8 material_type, u8 drawtype,
        shaders_header += "#define ENABLE_WAVING_LEAVES ";
        if (g_settings->getBool("enable_waving_leaves"))
                shaders_header += "1\n";
-       else    
+       else
                shaders_header += "0\n";
 
-       shaders_header += "#define ENABLE_WAVING_PLANTS ";              
+       shaders_header += "#define ENABLE_WAVING_PLANTS ";
        if (g_settings->getBool("enable_waving_plants"))
                shaders_header += "1\n";
        else