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/ban.cpp | 49 ++++++++++++++++++++----------------------------- 1 file changed, 20 insertions(+), 29 deletions(-) (limited to 'src/ban.cpp') diff --git a/src/ban.cpp b/src/ban.cpp index 55d9b22fe..7c1a68d45 100644 --- a/src/ban.cpp +++ b/src/ban.cpp @@ -56,7 +56,7 @@ void BanManager::load() infostream<<"BanManager: failed loading from "<::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 "<::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::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::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() { -- cgit v1.2.3