Use 'auto' for iterator declarations

fixes #12561
This commit is contained in:
Gunnar Beutner 2016-08-27 08:33:15 +02:00
parent 03b593fa67
commit 5058c5d75b
15 changed files with 30 additions and 39 deletions

View File

@ -30,7 +30,7 @@ ConfigObject::Ptr ConfigType::GetObject(const String& name) const
{ {
boost::mutex::scoped_lock lock(m_Mutex); 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()) if (nt == m_ObjectMap.end())
return ConfigObject::Ptr(); return ConfigObject::Ptr();

View File

@ -54,7 +54,7 @@ std::vector<Object::Ptr> DependencyGraph::GetParents(const Object::Ptr& child)
std::vector<Object::Ptr> objects; std::vector<Object::Ptr> objects;
boost::mutex::scoped_lock lock(m_Mutex); boost::mutex::scoped_lock lock(m_Mutex);
std::map<Object *, std::map<Object *, int> >::const_iterator it = m_Dependencies.find(child.get()); auto it = m_Dependencies.find(child.get());
if (it != m_Dependencies.end()) { if (it != m_Dependencies.end()) {
typedef std::pair<Object *, int> kv_pair; typedef std::pair<Object *, int> kv_pair;

View File

@ -37,7 +37,7 @@ Value Dictionary::Get(const String& key) const
{ {
ObjectLock olock(this); ObjectLock olock(this);
std::map<String, Value>::const_iterator it = m_Data.find(key); auto it = m_Data.find(key);
if (it == m_Data.end()) if (it == m_Data.end())
return Empty; return Empty;
@ -56,7 +56,7 @@ bool Dictionary::Get(const String& key, Value *result) const
{ {
ObjectLock olock(this); ObjectLock olock(this);
std::map<String, Value>::const_iterator it = m_Data.find(key); auto it = m_Data.find(key);
if (it == m_Data.end()) if (it == m_Data.end())
return false; return false;

View File

@ -93,8 +93,7 @@ public:
{ {
boost::mutex::scoped_lock lock(m_Mutex); boost::mutex::scoped_lock lock(m_Mutex);
typename ItemMap::const_iterator it; auto it = m_Items.find(name);
it = m_Items.find(name);
if (it == m_Items.end()) if (it == m_Items.end())
return T(); return T();

View File

@ -121,7 +121,7 @@ CLICommand::Ptr CLICommand::GetByName(const std::vector<String>& name)
{ {
boost::mutex::scoped_lock lock(GetRegistryMutex()); boost::mutex::scoped_lock lock(GetRegistryMutex());
std::map<std::vector<String>, CLICommand::Ptr>::const_iterator it = GetRegistry().find(name); auto it = GetRegistry().find(name);
if (it == GetRegistry().end()) if (it == GetRegistry().end())
return CLICommand::Ptr(); return CLICommand::Ptr();

View File

@ -26,7 +26,6 @@
#include "icinga/service.hpp" #include "icinga/service.hpp"
#include "icinga/command.hpp" #include "icinga/command.hpp"
#include "icinga/compatutility.hpp" #include "icinga/compatutility.hpp"
#include "base/objectlock.hpp"
#include "base/timer.hpp" #include "base/timer.hpp"
#include "base/utility.hpp" #include "base/utility.hpp"
#include <boost/thread/thread.hpp> #include <boost/thread/thread.hpp>
@ -65,31 +64,28 @@ private:
template<typename T> template<typename T>
void DumpNameList(std::ostream& fp, const T& list) void DumpNameList(std::ostream& fp, const T& list)
{ {
typename T::const_iterator it;
bool first = true; bool first = true;
for (it = list.begin(); it != list.end(); it++) { for (const auto& obj : list) {
if (!first) if (!first)
fp << ","; fp << ",";
else else
first = false; first = false;
ObjectLock olock(*it); fp << obj->GetName();
fp << (*it)->GetName();
} }
} }
template<typename T> template<typename T>
void DumpStringList(std::ostream& fp, const T& list) void DumpStringList(std::ostream& fp, const T& list)
{ {
typename T::const_iterator it;
bool first = true; bool first = true;
for (it = list.begin(); it != list.end(); it++) { for (const auto& str : list) {
if (!first) if (!first)
fp << ","; fp << ",";
else else
first = false; first = false;
fp << *it; fp << str;
} }
} }

View File

@ -112,7 +112,7 @@ bool ApplyRule::IsValidSourceType(const String& sourceType)
bool ApplyRule::IsValidTargetType(const String& sourceType, const String& targetType) 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()) if (it == m_Types.end())
return false; return false;
@ -130,7 +130,7 @@ bool ApplyRule::IsValidTargetType(const String& sourceType, const String& target
std::vector<String> ApplyRule::GetTargetTypes(const String& sourceType) std::vector<String> ApplyRule::GetTargetTypes(const String& sourceType)
{ {
TypeMap::const_iterator it = m_Types.find(sourceType); auto it = m_Types.find(sourceType);
if (it == m_Types.end()) if (it == m_Types.end())
return std::vector<String>(); return std::vector<String>();

View File

@ -315,7 +315,7 @@ void ConfigCompiler::AddIncludeSearchDir(const String& dir)
std::vector<ZoneFragment> ConfigCompiler::GetZoneDirs(const String& zone) std::vector<ZoneFragment> ConfigCompiler::GetZoneDirs(const String& zone)
{ {
boost::mutex::scoped_lock lock(m_ZoneDirsMutex); boost::mutex::scoped_lock lock(m_ZoneDirsMutex);
std::map<String, std::vector<ZoneFragment> >::const_iterator it = m_ZoneDirs.find(zone); auto it = m_ZoneDirs.find(zone);
if (it == m_ZoneDirs.end()) if (it == m_ZoneDirs.end())
return std::vector<ZoneFragment>(); return std::vector<ZoneFragment>();
else else

View File

@ -318,9 +318,11 @@ void ConfigItem::Register(void)
if (!m_Abstract && dynamic_cast<NameComposer *>(type.get())) if (!m_Abstract && dynamic_cast<NameComposer *>(type.get()))
m_UnnamedItems.push_back(this); m_UnnamedItems.push_back(this);
else { 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; std::ostringstream msgbuf;
msgbuf << "A configuration item of type '" << GetType() msgbuf << "A configuration item of type '" << GetType()
<< "' and name '" << GetName() << "' already exists (" << "' 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); 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()) if (it == m_Items.end())
return ConfigItem::Ptr(); return ConfigItem::Ptr();
ConfigItem::ItemMap::const_iterator it2 = it->second.find(name); auto it2 = it->second.find(name);
if (it2 == it->second.end()) if (it2 == it->second.end())
return ConfigItem::Ptr(); return ConfigItem::Ptr();
@ -634,7 +636,7 @@ std::vector<ConfigItem::Ptr> ConfigItem::GetItems(const String& type)
boost::mutex::scoped_lock lock(m_Mutex); 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()) if (it == m_Items.end())
return items; return items;

View File

@ -310,9 +310,7 @@ String DbConnection::GetConfigHash(const DbType::Ptr& type, const DbReference& o
if (!objid.IsValid()) if (!objid.IsValid())
return String(); return String();
std::map<std::pair<DbType::Ptr, DbReference>, String>::const_iterator it; auto it = m_ConfigHashes.find(std::make_pair(type, objid));
it = m_ConfigHashes.find(std::make_pair(type, objid));
if (it == m_ConfigHashes.end()) if (it == m_ConfigHashes.end())
return String(); return String();
@ -330,9 +328,7 @@ void DbConnection::SetObjectID(const DbObject::Ptr& dbobj, const DbReference& db
DbReference DbConnection::GetObjectID(const DbObject::Ptr& dbobj) const DbReference DbConnection::GetObjectID(const DbObject::Ptr& dbobj) const
{ {
std::map<DbObject::Ptr, DbReference>::const_iterator it; auto it = m_ObjectIDs.find(dbobj);
it = m_ObjectIDs.find(dbobj);
if (it == m_ObjectIDs.end()) if (it == m_ObjectIDs.end())
return DbReference(); return DbReference();
@ -366,9 +362,7 @@ DbReference DbConnection::GetInsertID(const DbType::Ptr& type, const DbReference
if (!objid.IsValid()) if (!objid.IsValid())
return DbReference(); return DbReference();
std::map<std::pair<DbType::Ptr, DbReference>, DbReference>::const_iterator it; auto it = m_InsertIDs.find(std::make_pair(type, objid));
it = m_InsertIDs.find(std::make_pair(type, objid));
if (it == m_InsertIDs.end()) if (it == m_InsertIDs.end())
return DbReference(); return DbReference();

View File

@ -65,7 +65,7 @@ DbType::Ptr DbType::GetByName(const String& name)
typeName = name; typeName = name;
boost::mutex::scoped_lock lock(GetStaticMutex()); boost::mutex::scoped_lock lock(GetStaticMutex());
DbType::TypeMap::const_iterator it = GetTypes().find(typeName); auto it = GetTypes().find(typeName);
if (it == GetTypes().end()) if (it == GetTypes().end())
return DbType::Ptr(); return DbType::Ptr();
@ -89,7 +89,7 @@ DbObject::Ptr DbType::GetOrCreateObjectByName(const String& name1, const String&
{ {
ObjectLock olock(this); 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()) if (it != m_Objects.end())
return it->second; return it->second;

View File

@ -53,7 +53,7 @@ int icinga::FilterArrayToInt(const Array::Ptr& typeFilters, const std::map<Strin
if (!typeFilter.IsString()) if (!typeFilter.IsString())
return -1; return -1;
std::map<String, int>::const_iterator it = filterMap.find(typeFilter); auto it = filterMap.find(typeFilter);
if (it == filterMap.end()) if (it == filterMap.end())
return -1; return -1;

View File

@ -138,7 +138,7 @@ Service::Ptr Host::GetServiceByShortName(const Value& name)
{ {
boost::mutex::scoped_lock lock(m_ServicesMutex); boost::mutex::scoped_lock lock(m_ServicesMutex);
std::map<String, Service::Ptr>::const_iterator it = m_Services.find(name); auto it = m_Services.find(name);
if (it != m_Services.end()) if (it != m_Services.end())
return it->second; return it->second;

View File

@ -106,7 +106,7 @@ Column Table::GetColumn(const String& name) const
if (dname.Find(prefix) == 0) if (dname.Find(prefix) == 0)
dname = dname.SubStr(prefix.GetLength()); dname = dname.SubStr(prefix.GetLength());
std::map<String, Column>::const_iterator it = m_Columns.find(dname); auto it = m_Columns.find(dname);
if (it == m_Columns.end()) if (it == m_Columns.end())
BOOST_THROW_EXCEPTION(std::invalid_argument("Column '" + dname + "' does not exist in table '" + GetName() + "'.")); BOOST_THROW_EXCEPTION(std::invalid_argument("Column '" + dname + "' does not exist in table '" + GetName() + "'."));

View File

@ -146,7 +146,7 @@ const std::map<String, std::vector<String> >& Url::GetQuery(void) const
String Url::GetQueryElement(const String& name) const String Url::GetQueryElement(const String& name) const
{ {
std::map<String, std::vector<String> >::const_iterator it = m_Query.find(name); auto it = m_Query.find(name);
if (it == m_Query.end()) if (it == m_Query.end())
return String(); return String();
@ -156,7 +156,7 @@ String Url::GetQueryElement(const String& name) const
const std::vector<String>& Url::GetQueryElements(const String& name) const const std::vector<String>& Url::GetQueryElements(const String& name) const
{ {
std::map<String, std::vector<String> >::const_iterator it = m_Query.find(name); auto it = m_Query.find(name);
if (it == m_Query.end()) { if (it == m_Query.end()) {
static std::vector<String> emptyVector; static std::vector<String> emptyVector;