From da34a2b33e1f600ec11172f599384b9a92835403 Mon Sep 17 00:00:00 2001 From: kwolekr Date: Tue, 19 May 2015 02:24:14 -0400 Subject: Replace instances of std::map with StringMap Also, clean up surrounding code style Replace by-value parameter passing with const refs when possible Fix post-increment of iterators --- src/game.cpp | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'src/game.cpp') diff --git a/src/game.cpp b/src/game.cpp index e27ec37dd..7e3ab802c 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -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 fields; + StringMap fields; fields["text"] = ntext; m_client->sendNodemetaFields(m_p, "", fields); } - void gotText(std::map 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 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 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::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++; } } -- cgit v1.2.3