diff --git a/src/clientiface.cpp b/src/clientiface.cpp index 33d07364a..c7166ce51 100644 --- a/src/clientiface.cpp +++ b/src/clientiface.cpp @@ -261,10 +261,9 @@ void RemoteClient::GetNextBlocks ( Get the border/face dot coordinates of a "d-radiused" box */ - std::vector list = FacePositionCache::getFacePositions(d); + const auto &list = FacePositionCache::getFacePositions(d); - std::vector::iterator li; - for (li = list.begin(); li != list.end(); ++li) { + for (auto li = list.begin(); li != list.end(); ++li) { v3s16 p = *li + center; /* diff --git a/src/database/database-sqlite3.cpp b/src/database/database-sqlite3.cpp index e73f9c77f..6f6ad341e 100644 --- a/src/database/database-sqlite3.cpp +++ b/src/database/database-sqlite3.cpp @@ -942,8 +942,8 @@ void ModStorageDatabaseSQLite3::listMods(std::vector *res) return 0; }, (void *) res, &errmsg); if (status != SQLITE_OK) { - DatabaseException e(std::string("Error trying to list mods with metadata: ") + errmsg); + auto msg = std::string("Error trying to list mods with metadata: ") + errmsg; sqlite3_free(errmsg); - throw e; + throw DatabaseException(msg); } } diff --git a/src/inventory.cpp b/src/inventory.cpp index c99147323..a0f0ea9a2 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -392,7 +392,7 @@ bool ItemStack::itemFits(ItemStack newitem, return newitem.empty(); } -bool ItemStack::stacksWith(ItemStack other) const +bool ItemStack::stacksWith(const ItemStack &other) const { return (this->name == other.name && this->wear == other.wear && diff --git a/src/inventory.h b/src/inventory.h index 3109246d4..64ca857fc 100644 --- a/src/inventory.h +++ b/src/inventory.h @@ -164,7 +164,7 @@ struct ItemStack // Checks if another itemstack would stack with this one. // Does not check if the item actually fits in the stack. - bool stacksWith(ItemStack other) const; + bool stacksWith(const ItemStack &other) const; // Takes some items. // If there are not enough, takes as many as it can. diff --git a/src/mapgen/mg_schematic.cpp b/src/mapgen/mg_schematic.cpp index 1e44ae34e..28a1abf83 100644 --- a/src/mapgen/mg_schematic.cpp +++ b/src/mapgen/mg_schematic.cpp @@ -625,7 +625,7 @@ void Schematic::condenseContentIds() numids++; m_nodenames.push_back(m_ndef->get(c).name); - nodeidmap.emplace(std::make_pair(c, id)); + nodeidmap.emplace(c, id); } else { id = it->second; } diff --git a/src/script/cpp_api/s_mainmenu.cpp b/src/script/cpp_api/s_mainmenu.cpp index 1e9ba3a41..290758e4a 100644 --- a/src/script/cpp_api/s_mainmenu.cpp +++ b/src/script/cpp_api/s_mainmenu.cpp @@ -21,7 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "cpp_api/s_internal.h" #include "common/c_converter.h" -void ScriptApiMainMenu::setMainMenuData(MainMenuDataForScript *data) +void ScriptApiMainMenu::setMainMenuData(const MainMenuDataForScript *data) { SCRIPTAPI_PRECHECKHEADER @@ -38,7 +38,7 @@ void ScriptApiMainMenu::setMainMenuData(MainMenuDataForScript *data) lua_pop(L, 1); } -void ScriptApiMainMenu::handleMainMenuEvent(std::string text) +void ScriptApiMainMenu::handleMainMenuEvent(const std::string &text) { SCRIPTAPI_PRECHECKHEADER diff --git a/src/script/cpp_api/s_mainmenu.h b/src/script/cpp_api/s_mainmenu.h index 470577a29..7085c649b 100644 --- a/src/script/cpp_api/s_mainmenu.h +++ b/src/script/cpp_api/s_mainmenu.h @@ -29,13 +29,13 @@ public: * Hand over MainMenuDataForScript to lua to inform lua of the content * @param data the data */ - void setMainMenuData(MainMenuDataForScript *data); + void setMainMenuData(const MainMenuDataForScript *data); /** * process events received from formspec * @param text events in textual form */ - void handleMainMenuEvent(std::string text); + void handleMainMenuEvent(const std::string &text); /** * process field data received from formspec diff --git a/src/script/lua_api/l_item.cpp b/src/script/lua_api/l_item.cpp index c245ba5ba..c68046b5d 100644 --- a/src/script/lua_api/l_item.cpp +++ b/src/script/lua_api/l_item.cpp @@ -678,7 +678,7 @@ int ModApiItem::l_get_content_id(lua_State *L) // If this is called at mod load time, NodeDefManager isn't aware of // aliases yet, so we need to handle them manually - std::string alias_name = idef->getAlias(name); + const auto &alias_name = idef->getAlias(name); content_t content_id; if (alias_name != name) { diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp index f3aa22ebc..eef3cd635 100644 --- a/src/script/lua_api/l_mainmenu.cpp +++ b/src/script/lua_api/l_mainmenu.cpp @@ -43,7 +43,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "common/c_converter.h" /******************************************************************************/ -std::string ModApiMainMenu::getTextData(lua_State *L, std::string name) +std::string ModApiMainMenu::getTextData(lua_State *L, const std::string &name) { lua_getglobal(L, "gamedata"); @@ -56,7 +56,7 @@ std::string ModApiMainMenu::getTextData(lua_State *L, std::string name) } /******************************************************************************/ -int ModApiMainMenu::getIntegerData(lua_State *L, std::string name,bool& valid) +int ModApiMainMenu::getIntegerData(lua_State *L, const std::string &name, bool& valid) { lua_getglobal(L, "gamedata"); @@ -65,14 +65,14 @@ int ModApiMainMenu::getIntegerData(lua_State *L, std::string name,bool& valid) if(lua_isnil(L, -1)) { valid = false; return -1; - } + } valid = true; return luaL_checkinteger(L, -1); } /******************************************************************************/ -int ModApiMainMenu::getBoolData(lua_State *L, std::string name,bool& valid) +int ModApiMainMenu::getBoolData(lua_State *L, const std::string &name, bool& valid) { lua_getglobal(L, "gamedata"); @@ -81,7 +81,7 @@ int ModApiMainMenu::getBoolData(lua_State *L, std::string name,bool& valid) if(lua_isnil(L, -1)) { valid = false; return false; - } + } valid = true; return readParam(L, -1); @@ -553,7 +553,7 @@ int ModApiMainMenu::l_create_world(lua_State *L) // Set the settings for world creation // this is a bad hack but the best we have right now.. StringMap backup; - for (auto it : use_settings) { + for (auto &it : use_settings) { if (g_settings->existsLocal(it.first)) backup[it.first] = g_settings->get(it.first); g_settings->set(it.first, it.second); @@ -569,7 +569,7 @@ int ModApiMainMenu::l_create_world(lua_State *L) } // Restore previous settings - for (auto it : use_settings) { + for (auto &it : use_settings) { auto it2 = backup.find(it.first); if (it2 == backup.end()) g_settings->remove(it.first); // wasn't set before diff --git a/src/script/lua_api/l_mainmenu.h b/src/script/lua_api/l_mainmenu.h index 6cb8b6d2c..a5fff3872 100644 --- a/src/script/lua_api/l_mainmenu.h +++ b/src/script/lua_api/l_mainmenu.h @@ -34,7 +34,7 @@ private: * @param name name of variable to read * @return string value of requested variable */ - static std::string getTextData(lua_State *L, std::string name); + static std::string getTextData(lua_State *L, const std::string &name); /** * read an integer variable from gamedata table within lua stack @@ -42,7 +42,7 @@ private: * @param name name of variable to read * @return integer value of requested variable */ - static int getIntegerData(lua_State *L, std::string name,bool& valid); + static int getIntegerData(lua_State *L, const std::string &name, bool& valid); /** * read a bool variable from gamedata table within lua stack @@ -50,7 +50,7 @@ private: * @param name name of variable to read * @return bool value of requested variable */ - static int getBoolData(lua_State *L, std::string name,bool& valid); + static int getBoolData(lua_State *L, const std::string &name ,bool& valid); /** * Checks if a path may be modified. Paths in the temp directory or the user diff --git a/src/settings.cpp b/src/settings.cpp index b537005aa..8b89bf489 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -403,7 +403,7 @@ bool Settings::updateConfigFile(const char *filename) bool Settings::parseCommandLine(int argc, char *argv[], - std::map &allowed_options) + const std::map &allowed_options) { int nonopt_index = 0; for (int i = 1; i < argc; i++) { @@ -424,8 +424,7 @@ bool Settings::parseCommandLine(int argc, char *argv[], std::string name = arg_name.substr(2); - std::map::iterator n; - n = allowed_options.find(name); + auto n = allowed_options.find(name); if (n == allowed_options.end()) { errorstream << "Unknown command-line parameter \"" << arg_name << "\"" << std::endl; diff --git a/src/settings.h b/src/settings.h index 4b0787343..1aeec0255 100644 --- a/src/settings.h +++ b/src/settings.h @@ -147,7 +147,7 @@ public: bool updateConfigFile(const char *filename); // NOTE: Types of allowed_options are ignored. Returns success. bool parseCommandLine(int argc, char *argv[], - std::map &allowed_options); + const std::map &allowed_options); bool parseConfigLines(std::istream &is); void writeLines(std::ostream &os, u32 tab_depth=0) const; diff --git a/src/texture_override.cpp b/src/texture_override.cpp index 88f754f88..7dc9dfa8c 100644 --- a/src/texture_override.cpp +++ b/src/texture_override.cpp @@ -46,7 +46,7 @@ static const std::map override_LUT = { { "*", OverrideTarget::ALL_FACES } }; -TextureOverrideSource::TextureOverrideSource(std::string filepath) +TextureOverrideSource::TextureOverrideSource(const std::string &filepath) { std::ifstream infile(filepath.c_str()); std::string line; @@ -115,7 +115,7 @@ TextureOverrideSource::TextureOverrideSource(std::string filepath) } //! Get all overrides that apply to item definitions -std::vector TextureOverrideSource::getItemTextureOverrides() +std::vector TextureOverrideSource::getItemTextureOverrides() const { std::vector found_overrides; @@ -128,7 +128,7 @@ std::vector TextureOverrideSource::getItemTextureOverrides() } //! Get all overrides that apply to node definitions -std::vector TextureOverrideSource::getNodeTileOverrides() +std::vector TextureOverrideSource::getNodeTileOverrides() const { std::vector found_overrides; diff --git a/src/texture_override.h b/src/texture_override.h index 237efcba1..19e55689c 100644 --- a/src/texture_override.h +++ b/src/texture_override.h @@ -70,13 +70,13 @@ struct TextureOverride class TextureOverrideSource { public: - TextureOverrideSource(std::string filepath); + TextureOverrideSource(const std::string &filepath); //! Get all overrides that apply to item definitions - std::vector getItemTextureOverrides(); + std::vector getItemTextureOverrides() const; //! Get all overrides that apply to node definitions - std::vector getNodeTileOverrides(); + std::vector getNodeTileOverrides() const; private: std::vector m_overrides; diff --git a/src/util/enriched_string.cpp b/src/util/enriched_string.cpp index 941f8b08d..7edbf8eb7 100644 --- a/src/util/enriched_string.cpp +++ b/src/util/enriched_string.cpp @@ -59,10 +59,11 @@ void EnrichedString::clear() m_background = irr::video::SColor(0, 0, 0, 0); } -void EnrichedString::operator=(const wchar_t *str) +EnrichedString &EnrichedString::operator=(const wchar_t *str) { clear(); addAtEnd(translate_string(std::wstring(str)), m_default_color); + return *this; } void EnrichedString::addAtEnd(const std::wstring &s, SColor initial_color) diff --git a/src/util/enriched_string.h b/src/util/enriched_string.h index 4e249eac5..b48408ac6 100644 --- a/src/util/enriched_string.h +++ b/src/util/enriched_string.h @@ -34,7 +34,7 @@ public: const video::SColor &color = video::SColor(255, 255, 255, 255)); EnrichedString(const std::wstring &string, const std::vector &colors); - void operator=(const wchar_t *str); + EnrichedString &operator=(const wchar_t *str); void clear(); diff --git a/src/util/string.cpp b/src/util/string.cpp index 52b7c71ff..1ac295bb4 100644 --- a/src/util/string.cpp +++ b/src/util/string.cpp @@ -846,7 +846,7 @@ std::string sanitizeDirName(const std::string &str, const std::string &optional_ { std::wstring safe_name = utf8_to_wide(str); - for (std::wstring disallowed_name : disallowed_dir_names) { + for (auto &disallowed_name : disallowed_dir_names) { if (str_equal(safe_name, disallowed_name, true)) { safe_name = utf8_to_wide(optional_prefix) + safe_name; break;