From 5058c5d75bdc7d65282cabbb12358b0bb1fb0667 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Sat, 27 Aug 2016 08:33:15 +0200 Subject: [PATCH] Use 'auto' for iterator declarations fixes #12561 --- lib/base/configtype.cpp | 2 +- lib/base/dependencygraph.cpp | 2 +- lib/base/dictionary.cpp | 4 ++-- lib/base/registry.hpp | 3 +-- lib/cli/clicommand.cpp | 2 +- lib/compat/statusdatawriter.hpp | 12 ++++-------- lib/config/applyrule.cpp | 4 ++-- lib/config/configcompiler.cpp | 2 +- lib/config/configitem.cpp | 12 +++++++----- lib/db_ido/dbconnection.cpp | 12 +++--------- lib/db_ido/dbtype.cpp | 4 ++-- lib/icinga/customvarobject.cpp | 2 +- lib/icinga/host.cpp | 2 +- lib/livestatus/table.cpp | 2 +- lib/remote/url.cpp | 4 ++-- 15 files changed, 30 insertions(+), 39 deletions(-) diff --git a/lib/base/configtype.cpp b/lib/base/configtype.cpp index 6c41a5e3d..12877bfeb 100644 --- a/lib/base/configtype.cpp +++ b/lib/base/configtype.cpp @@ -30,7 +30,7 @@ ConfigObject::Ptr ConfigType::GetObject(const String& name) const { boost::mutex::scoped_lock lock(m_Mutex); - ConfigType::ObjectMap::const_iterator nt = m_ObjectMap.find(name); + auto nt = m_ObjectMap.find(name); if (nt == m_ObjectMap.end()) return ConfigObject::Ptr(); diff --git a/lib/base/dependencygraph.cpp b/lib/base/dependencygraph.cpp index 3cf67e172..9f8e563fa 100644 --- a/lib/base/dependencygraph.cpp +++ b/lib/base/dependencygraph.cpp @@ -54,7 +54,7 @@ std::vector DependencyGraph::GetParents(const Object::Ptr& child) std::vector objects; boost::mutex::scoped_lock lock(m_Mutex); - std::map >::const_iterator it = m_Dependencies.find(child.get()); + auto it = m_Dependencies.find(child.get()); if (it != m_Dependencies.end()) { typedef std::pair kv_pair; diff --git a/lib/base/dictionary.cpp b/lib/base/dictionary.cpp index 5d8da2549..e44cca127 100644 --- a/lib/base/dictionary.cpp +++ b/lib/base/dictionary.cpp @@ -37,7 +37,7 @@ Value Dictionary::Get(const String& key) const { ObjectLock olock(this); - std::map::const_iterator it = m_Data.find(key); + auto it = m_Data.find(key); if (it == m_Data.end()) return Empty; @@ -56,7 +56,7 @@ bool Dictionary::Get(const String& key, Value *result) const { ObjectLock olock(this); - std::map::const_iterator it = m_Data.find(key); + auto it = m_Data.find(key); if (it == m_Data.end()) return false; diff --git a/lib/base/registry.hpp b/lib/base/registry.hpp index b99ff412d..a0f281484 100644 --- a/lib/base/registry.hpp +++ b/lib/base/registry.hpp @@ -93,8 +93,7 @@ public: { boost::mutex::scoped_lock lock(m_Mutex); - typename ItemMap::const_iterator it; - it = m_Items.find(name); + auto it = m_Items.find(name); if (it == m_Items.end()) return T(); diff --git a/lib/cli/clicommand.cpp b/lib/cli/clicommand.cpp index 47b90c5d9..d4e830a04 100644 --- a/lib/cli/clicommand.cpp +++ b/lib/cli/clicommand.cpp @@ -121,7 +121,7 @@ CLICommand::Ptr CLICommand::GetByName(const std::vector& name) { boost::mutex::scoped_lock lock(GetRegistryMutex()); - std::map, CLICommand::Ptr>::const_iterator it = GetRegistry().find(name); + auto it = GetRegistry().find(name); if (it == GetRegistry().end()) return CLICommand::Ptr(); diff --git a/lib/compat/statusdatawriter.hpp b/lib/compat/statusdatawriter.hpp index b906b9a8f..05b46a495 100644 --- a/lib/compat/statusdatawriter.hpp +++ b/lib/compat/statusdatawriter.hpp @@ -26,7 +26,6 @@ #include "icinga/service.hpp" #include "icinga/command.hpp" #include "icinga/compatutility.hpp" -#include "base/objectlock.hpp" #include "base/timer.hpp" #include "base/utility.hpp" #include @@ -65,31 +64,28 @@ private: template void DumpNameList(std::ostream& fp, const T& list) { - typename T::const_iterator it; bool first = true; - for (it = list.begin(); it != list.end(); it++) { + for (const auto& obj : list) { if (!first) fp << ","; else first = false; - ObjectLock olock(*it); - fp << (*it)->GetName(); + fp << obj->GetName(); } } template void DumpStringList(std::ostream& fp, const T& list) { - typename T::const_iterator it; bool first = true; - for (it = list.begin(); it != list.end(); it++) { + for (const auto& str : list) { if (!first) fp << ","; else first = false; - fp << *it; + fp << str; } } diff --git a/lib/config/applyrule.cpp b/lib/config/applyrule.cpp index 73f3688aa..b7bb72e08 100644 --- a/lib/config/applyrule.cpp +++ b/lib/config/applyrule.cpp @@ -112,7 +112,7 @@ bool ApplyRule::IsValidSourceType(const String& sourceType) bool ApplyRule::IsValidTargetType(const String& sourceType, const String& targetType) { - TypeMap::const_iterator it = m_Types.find(sourceType); + auto it = m_Types.find(sourceType); if (it == m_Types.end()) return false; @@ -130,7 +130,7 @@ bool ApplyRule::IsValidTargetType(const String& sourceType, const String& target std::vector ApplyRule::GetTargetTypes(const String& sourceType) { - TypeMap::const_iterator it = m_Types.find(sourceType); + auto it = m_Types.find(sourceType); if (it == m_Types.end()) return std::vector(); diff --git a/lib/config/configcompiler.cpp b/lib/config/configcompiler.cpp index 0f26b7b78..e226a268b 100644 --- a/lib/config/configcompiler.cpp +++ b/lib/config/configcompiler.cpp @@ -315,7 +315,7 @@ void ConfigCompiler::AddIncludeSearchDir(const String& dir) std::vector ConfigCompiler::GetZoneDirs(const String& zone) { boost::mutex::scoped_lock lock(m_ZoneDirsMutex); - std::map >::const_iterator it = m_ZoneDirs.find(zone); + auto it = m_ZoneDirs.find(zone); if (it == m_ZoneDirs.end()) return std::vector(); else diff --git a/lib/config/configitem.cpp b/lib/config/configitem.cpp index 073ec95a8..8b4f93ce3 100644 --- a/lib/config/configitem.cpp +++ b/lib/config/configitem.cpp @@ -318,9 +318,11 @@ void ConfigItem::Register(void) if (!m_Abstract && dynamic_cast(type.get())) m_UnnamedItems.push_back(this); else { - ItemMap::const_iterator it = m_Items[m_Type].find(m_Name); + auto& items = m_Items[m_Type]; - if (it != m_Items[m_Type].end()) { + auto it = items.find(m_Name); + + if (it != items.end()) { std::ostringstream msgbuf; msgbuf << "A configuration item of type '" << GetType() << "' and name '" << GetName() << "' already exists (" @@ -358,12 +360,12 @@ ConfigItem::Ptr ConfigItem::GetByTypeAndName(const String& type, const String& n { boost::mutex::scoped_lock lock(m_Mutex); - ConfigItem::TypeMap::const_iterator it = m_Items.find(type); + auto it = m_Items.find(type); if (it == m_Items.end()) return ConfigItem::Ptr(); - ConfigItem::ItemMap::const_iterator it2 = it->second.find(name); + auto it2 = it->second.find(name); if (it2 == it->second.end()) return ConfigItem::Ptr(); @@ -634,7 +636,7 @@ std::vector ConfigItem::GetItems(const String& type) boost::mutex::scoped_lock lock(m_Mutex); - TypeMap::const_iterator it = m_Items.find(type); + auto it = m_Items.find(type); if (it == m_Items.end()) return items; diff --git a/lib/db_ido/dbconnection.cpp b/lib/db_ido/dbconnection.cpp index 1d4e22829..a9d46bb7e 100644 --- a/lib/db_ido/dbconnection.cpp +++ b/lib/db_ido/dbconnection.cpp @@ -310,9 +310,7 @@ String DbConnection::GetConfigHash(const DbType::Ptr& type, const DbReference& o if (!objid.IsValid()) return String(); - std::map, String>::const_iterator it; - - it = m_ConfigHashes.find(std::make_pair(type, objid)); + auto it = m_ConfigHashes.find(std::make_pair(type, objid)); if (it == m_ConfigHashes.end()) return String(); @@ -330,9 +328,7 @@ void DbConnection::SetObjectID(const DbObject::Ptr& dbobj, const DbReference& db DbReference DbConnection::GetObjectID(const DbObject::Ptr& dbobj) const { - std::map::const_iterator it; - - it = m_ObjectIDs.find(dbobj); + auto it = m_ObjectIDs.find(dbobj); if (it == m_ObjectIDs.end()) return DbReference(); @@ -366,9 +362,7 @@ DbReference DbConnection::GetInsertID(const DbType::Ptr& type, const DbReference if (!objid.IsValid()) return DbReference(); - std::map, DbReference>::const_iterator it; - - it = m_InsertIDs.find(std::make_pair(type, objid)); + auto it = m_InsertIDs.find(std::make_pair(type, objid)); if (it == m_InsertIDs.end()) return DbReference(); diff --git a/lib/db_ido/dbtype.cpp b/lib/db_ido/dbtype.cpp index bb6f4e8de..ceb99914e 100644 --- a/lib/db_ido/dbtype.cpp +++ b/lib/db_ido/dbtype.cpp @@ -65,7 +65,7 @@ DbType::Ptr DbType::GetByName(const String& name) typeName = name; boost::mutex::scoped_lock lock(GetStaticMutex()); - DbType::TypeMap::const_iterator it = GetTypes().find(typeName); + auto it = GetTypes().find(typeName); if (it == GetTypes().end()) return DbType::Ptr(); @@ -89,7 +89,7 @@ DbObject::Ptr DbType::GetOrCreateObjectByName(const String& name1, const String& { ObjectLock olock(this); - DbType::ObjectMap::const_iterator it = m_Objects.find(std::make_pair(name1, name2)); + auto it = m_Objects.find(std::make_pair(name1, name2)); if (it != m_Objects.end()) return it->second; diff --git a/lib/icinga/customvarobject.cpp b/lib/icinga/customvarobject.cpp index 88e79ec83..5b7cda967 100644 --- a/lib/icinga/customvarobject.cpp +++ b/lib/icinga/customvarobject.cpp @@ -53,7 +53,7 @@ int icinga::FilterArrayToInt(const Array::Ptr& typeFilters, const std::map::const_iterator it = filterMap.find(typeFilter); + auto it = filterMap.find(typeFilter); if (it == filterMap.end()) return -1; diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp index 99dafe8f4..8786735a8 100644 --- a/lib/icinga/host.cpp +++ b/lib/icinga/host.cpp @@ -138,7 +138,7 @@ Service::Ptr Host::GetServiceByShortName(const Value& name) { boost::mutex::scoped_lock lock(m_ServicesMutex); - std::map::const_iterator it = m_Services.find(name); + auto it = m_Services.find(name); if (it != m_Services.end()) return it->second; diff --git a/lib/livestatus/table.cpp b/lib/livestatus/table.cpp index 45f616d74..a128dda22 100644 --- a/lib/livestatus/table.cpp +++ b/lib/livestatus/table.cpp @@ -106,7 +106,7 @@ Column Table::GetColumn(const String& name) const if (dname.Find(prefix) == 0) dname = dname.SubStr(prefix.GetLength()); - std::map::const_iterator it = m_Columns.find(dname); + auto it = m_Columns.find(dname); if (it == m_Columns.end()) BOOST_THROW_EXCEPTION(std::invalid_argument("Column '" + dname + "' does not exist in table '" + GetName() + "'.")); diff --git a/lib/remote/url.cpp b/lib/remote/url.cpp index e9ceac605..a87aa0624 100644 --- a/lib/remote/url.cpp +++ b/lib/remote/url.cpp @@ -146,7 +146,7 @@ const std::map >& Url::GetQuery(void) const String Url::GetQueryElement(const String& name) const { - std::map >::const_iterator it = m_Query.find(name); + auto it = m_Query.find(name); if (it == m_Query.end()) return String(); @@ -156,7 +156,7 @@ String Url::GetQueryElement(const String& name) const const std::vector& Url::GetQueryElements(const String& name) const { - std::map >::const_iterator it = m_Query.find(name); + auto it = m_Query.find(name); if (it == m_Query.end()) { static std::vector emptyVector;