diff --git a/components/cluster/clusterlistener.cpp b/components/cluster/clusterlistener.cpp index 137dd4458..5cf0b456a 100644 --- a/components/cluster/clusterlistener.cpp +++ b/components/cluster/clusterlistener.cpp @@ -1401,13 +1401,11 @@ void ClusterListener::MessageHandler(const Endpoint::Ptr& sender, const Dictiona if (localConfig->GetLength() != remoteConfig->GetLength()) configChange = true; - String key; - Value value; ObjectLock olock(remoteConfig); - BOOST_FOREACH(boost::tie(key, value), remoteConfig) { - Dictionary::Ptr remoteFile = value; + BOOST_FOREACH(const Dictionary::Pair& kv, remoteConfig) { + Dictionary::Ptr remoteFile = kv.second; bool writeFile = false; - String hash = SHA256(key); + String hash = SHA256(kv.first); String path = dir + "/" + hash; if (!localConfig->Contains(hash)) @@ -1437,8 +1435,8 @@ void ClusterListener::MessageHandler(const Endpoint::Ptr& sender, const Dictiona olock.Unlock(); ObjectLock olock2(localConfig); - BOOST_FOREACH(boost::tie(key, boost::tuples::ignore), localConfig) { - String path = dir + "/" + key; + BOOST_FOREACH(const Dictionary::Pair& kv, localConfig) { + String path = dir + "/" + kv.first; Log(LogInformation, "cluster", "Removing obsolete config file: " + path); (void) unlink(path.CStr()); configChange = true; diff --git a/components/compat/statusdatawriter.cpp b/components/compat/statusdatawriter.cpp index b024b2127..2440b662c 100644 --- a/components/compat/statusdatawriter.cpp +++ b/components/compat/statusdatawriter.cpp @@ -71,9 +71,9 @@ void StatusDataWriter::DumpComments(std::ostream& fp, const Service::Ptr& owner, ObjectLock olock(comments); - String id; - Comment::Ptr comment; - BOOST_FOREACH(boost::tie(id, comment), comments) { + BOOST_FOREACH(const Dictionary::Pair& kv, comments) { + Comment::Ptr comment = kv.second; + if (comment->IsExpired()) continue; @@ -107,10 +107,8 @@ void StatusDataWriter::DumpTimePeriod(std::ostream& fp, const TimePeriod::Ptr& t if (ranges) { ObjectLock olock(ranges); - String key; - Value value; - BOOST_FOREACH(boost::tie(key, value), ranges) { - fp << "\t" << key << "\t" << value << "\n"; + BOOST_FOREACH(const Dictionary::Pair& kv, ranges) { + fp << "\t" << kv.first << "\t" << kv.second << "\n"; } } @@ -167,9 +165,9 @@ void StatusDataWriter::DumpDowntimes(std::ostream& fp, const Service::Ptr& owner ObjectLock olock(downtimes); - String id; - Downtime::Ptr downtime; - BOOST_FOREACH(boost::tie(id, downtime), downtimes) { + BOOST_FOREACH(const Dictionary::Pair& kv, downtimes) { + Downtime::Ptr downtime = kv.second; + if (downtime->IsExpired()) continue; @@ -518,16 +516,14 @@ void StatusDataWriter::DumpCustomAttributes(std::ostream& fp, const DynamicObjec return; ObjectLock olock(custom); - String key; - Value value; - BOOST_FOREACH(boost::tie(key, value), custom) { + BOOST_FOREACH(const Dictionary::Pair& kv, custom) { fp << "\t"; - if (key != "notes" && key != "action_url" && key != "notes_url" && - key != "icon_image" && key != "icon_image_alt" && key != "statusmap_image" && "2d_coords") + if (kv.first != "notes" && kv.first != "action_url" && kv.first != "notes_url" && + kv.first != "icon_image" && kv.first != "icon_image_alt" && kv.first != "statusmap_image" && kv.first != "2d_coords") fp << "_"; - fp << key << "\t" << value << "\n"; + fp << kv.first << "\t" << kv.second << "\n"; } } diff --git a/components/db_ido_mysql/idomysqlconnection.cpp b/components/db_ido_mysql/idomysqlconnection.cpp index ba89dad7e..f4bcfa9b3 100644 --- a/components/db_ido_mysql/idomysqlconnection.cpp +++ b/components/db_ido_mysql/idomysqlconnection.cpp @@ -485,18 +485,17 @@ void IdoMysqlConnection::InternalExecuteQuery(const DbQuery& query) where << " WHERE "; ObjectLock olock(query.WhereCriteria); - String key; Value value; bool first = true; - BOOST_FOREACH(boost::tie(key, value), query.WhereCriteria) { - if (!FieldToEscapedString(key, value, &value)) + BOOST_FOREACH(const Dictionary::Pair& kv, query.WhereCriteria) { + if (!FieldToEscapedString(kv.first, kv.second, &value)) return; if (!first) where << " AND "; - where << key << " = " << value; + where << kv.first << " = " << value; if (first) first = false; @@ -537,31 +536,30 @@ void IdoMysqlConnection::InternalExecuteQuery(const DbQuery& query) } if (type == DbQueryInsert || type == DbQueryUpdate) { - String cols; - String values; + std::ostringstream colbuf, valbuf; ObjectLock olock(query.Fields); - String key; - Value value; bool first = true; - BOOST_FOREACH(boost::tie(key, value), query.Fields) { - if (!FieldToEscapedString(key, value, &value)) + BOOST_FOREACH(const Dictionary::Pair& kv, query.Fields) { + Value value; + + if (!FieldToEscapedString(kv.first, kv.second, &value)) return; if (type == DbQueryInsert) { if (!first) { - cols += ", "; - values += ", "; + colbuf << ", "; + valbuf << ", "; } - cols += key; - values += value; + colbuf << kv.first; + valbuf << value; } else { if (!first) qbuf << ", "; - qbuf << " " << key << " = " << value; + qbuf << " " << kv.first << " = " << value; } if (first) @@ -569,7 +567,7 @@ void IdoMysqlConnection::InternalExecuteQuery(const DbQuery& query) } if (type == DbQueryInsert) - qbuf << " (" << cols << ") VALUES (" << values << ")"; + qbuf << " (" << colbuf.str() << ") VALUES (" << valbuf.str() << ")"; } if (type != DbQueryInsert) diff --git a/components/db_ido_pgsql/idopgsqlconnection.cpp b/components/db_ido_pgsql/idopgsqlconnection.cpp index c512af847..761d4b400 100644 --- a/components/db_ido_pgsql/idopgsqlconnection.cpp +++ b/components/db_ido_pgsql/idopgsqlconnection.cpp @@ -501,18 +501,17 @@ void IdoPgsqlConnection::InternalExecuteQuery(const DbQuery& query) where << " WHERE "; ObjectLock olock(query.WhereCriteria); - String key; Value value; bool first = true; - BOOST_FOREACH(boost::tie(key, value), query.WhereCriteria) { - if (!FieldToEscapedString(key, value, &value)) + BOOST_FOREACH(const Dictionary::Pair& kv, query.WhereCriteria) { + if (!FieldToEscapedString(kv.first, kv.second, &value)) return; if (!first) where << " AND "; - where << key << " = " << value; + where << kv.first << " = " << value; if (first) first = false; @@ -553,31 +552,29 @@ void IdoPgsqlConnection::InternalExecuteQuery(const DbQuery& query) } if (type == DbQueryInsert || type == DbQueryUpdate) { - String cols; - String values; + std::ostringstream colbuf, valbuf; ObjectLock olock(query.Fields); - String key; Value value; bool first = true; - BOOST_FOREACH(boost::tie(key, value), query.Fields) { - if (!FieldToEscapedString(key, value, &value)) + BOOST_FOREACH(const Dictionary::Pair& kv, query.Fields) { + if (!FieldToEscapedString(kv.first, kv.second, &value)) return; if (type == DbQueryInsert) { if (!first) { - cols += ", "; - values += ", "; + colbuf << ", "; + valbuf << ", "; } - cols += key; - values += value; + colbuf << kv.first; + valbuf << value; } else { if (!first) qbuf << ", "; - qbuf << " " << key << " = " << value; + qbuf << " " << kv.first << " = " << value; } if (first) @@ -585,7 +582,7 @@ void IdoPgsqlConnection::InternalExecuteQuery(const DbQuery& query) } if (type == DbQueryInsert) - qbuf << " (" << cols << ") VALUES (" << values << ")"; + qbuf << " (" << colbuf.str() << ") VALUES (" << valbuf.str() << ")"; } if (type != DbQueryInsert) diff --git a/components/perfdata/graphitewriter.cpp b/components/perfdata/graphitewriter.cpp index b76845a70..b2df6cf55 100644 --- a/components/perfdata/graphitewriter.cpp +++ b/components/perfdata/graphitewriter.cpp @@ -107,17 +107,16 @@ void GraphiteWriter::CheckResultHandler(const Service::Ptr& service, const Check Dictionary::Ptr perfdata = pdv; - String key; - Value value; - BOOST_FOREACH(boost::tie(key, value), perfdata) { + ObjectLock olock(perfdata); + BOOST_FOREACH(const Dictionary::Pair& kv, perfdata) { double valueNum; - if (!value.IsObjectType()) - valueNum = value; + if (!kv.second.IsObjectType()) + valueNum = kv.second; else - valueNum = static_cast(value)->GetValue(); + valueNum = static_cast(kv.second)->GetValue(); - String escaped_key = key; + String escaped_key = kv.first; SanitizeMetric(escaped_key); boost::algorithm::replace_all(escaped_key, "::", "."); diff --git a/lib/base/dictionary.cpp b/lib/base/dictionary.cpp index 70aad23e3..37509e797 100644 --- a/lib/base/dictionary.cpp +++ b/lib/base/dictionary.cpp @@ -21,7 +21,6 @@ #include "base/objectlock.h" #include "base/debug.h" #include -#include #include #include @@ -211,10 +210,8 @@ Dictionary::Ptr Dictionary::ShallowClone(void) const Dictionary::Ptr clone = make_shared(); - String key; - Value value; - BOOST_FOREACH(boost::tie(key, value), m_Data) { - clone->Set(key, value); + BOOST_FOREACH(const Dictionary::Pair& kv, m_Data) { + clone->Set(kv.first, kv.second); } return clone; @@ -252,10 +249,8 @@ cJSON *Dictionary::ToJson(void) const try { ObjectLock olock(this); - String key; - Value value; - BOOST_FOREACH(boost::tie(key, value), m_Data) { - cJSON_AddItemToObject(json, key.CStr(), value.ToJson()); + BOOST_FOREACH(const Dictionary::Pair& kv, m_Data) { + cJSON_AddItemToObject(json, kv.first.CStr(), kv.second.ToJson()); } } catch (...) { cJSON_Delete(json); diff --git a/lib/base/dictionary.h b/lib/base/dictionary.h index 48eb491ca..b3da9905e 100644 --- a/lib/base/dictionary.h +++ b/lib/base/dictionary.h @@ -43,6 +43,8 @@ public: */ typedef std::map::iterator Iterator; + typedef std::pair Pair; + Value Get(const char *key) const; Value Get(const String& key) const; void Set(const String& key, const Value& value); diff --git a/lib/base/process-unix.cpp b/lib/base/process-unix.cpp index 01bd68a40..b6b67d626 100644 --- a/lib/base/process-unix.cpp +++ b/lib/base/process-unix.cpp @@ -24,7 +24,6 @@ #include "base/logger_fwd.h" #include "base/utility.h" #include -#include #include #include #include @@ -92,12 +91,10 @@ ProcessResult Process::Run(void) if (m_ExtraEnvironment) { ObjectLock olock(m_ExtraEnvironment); - String key; - Value value; int index = envc; - BOOST_FOREACH(boost::tie(key, value), m_ExtraEnvironment) { - String kv = key + "=" + Convert::ToString(value); - envp[index] = strdup(kv.CStr()); + BOOST_FOREACH(const Dictionary::Pair& kv, m_ExtraEnvironment) { + String skv = kv.first + "=" + Convert::ToString(kv.second); + envp[index] = strdup(skv.CStr()); index++; } } diff --git a/lib/base/registry.h b/lib/base/registry.h index 5195ee8f9..666fa9f59 100644 --- a/lib/base/registry.h +++ b/lib/base/registry.h @@ -27,7 +27,6 @@ #include #include #include -#include namespace icinga { @@ -87,9 +86,10 @@ public: items = m_Items; } - String name; - BOOST_FOREACH(boost::tie(name, boost::tuples::ignore), items) { - OnUnregistered(name); + typedef typename std::pair ItemMapPair; + + BOOST_FOREACH(const ItemMapPair& kv, items) { + OnUnregistered(kv.first); } { diff --git a/lib/base/serializer.cpp b/lib/base/serializer.cpp index 449222ce6..22156084d 100644 --- a/lib/base/serializer.cpp +++ b/lib/base/serializer.cpp @@ -22,7 +22,6 @@ #include "base/application.h" #include "base/objectlock.h" #include -#include #include using namespace icinga; @@ -90,10 +89,8 @@ static Dictionary::Ptr SerializeDictionary(const Dictionary::Ptr& input, int att ObjectLock olock(input); - String key; - Value value; - BOOST_FOREACH(boost::tie(key, value), input) { - result->Set(key, Serialize(value, attributeTypes)); + BOOST_FOREACH(const Dictionary::Pair& kv, input) { + result->Set(kv.first, Serialize(kv.second, attributeTypes)); } return result; @@ -140,10 +137,8 @@ static Dictionary::Ptr DeserializeDictionary(const Dictionary::Ptr& input, int a ObjectLock olock(input); - String key; - Value value; - BOOST_FOREACH(boost::tie(key, value), input) { - result->Set(key, Deserialize(value, attributeTypes)); + BOOST_FOREACH(const Dictionary::Pair& kv, input) { + result->Set(kv.first, Deserialize(kv.second, attributeTypes)); } return result; diff --git a/lib/config/configitem.cpp b/lib/config/configitem.cpp index 4dec4c46e..3e8bc90c5 100644 --- a/lib/config/configitem.cpp +++ b/lib/config/configitem.cpp @@ -25,7 +25,6 @@ #include "base/logger_fwd.h" #include "base/debug.h" #include -#include #include using namespace icinga; @@ -170,10 +169,8 @@ DynamicObject::Ptr ConfigItem::Commit(void) { ObjectLock olock(properties); - String key; - Value data; - BOOST_FOREACH(boost::tie(key, data), properties) { - attrs->Set(key, data); + BOOST_FOREACH(const Dictionary::Pair& kv, properties) { + attrs->Set(kv.first, kv.second); } } @@ -243,9 +240,8 @@ bool ConfigItem::ActivateItems(bool validateOnly) Log(LogInformation, "config", "Linking config items..."); - ConfigItem::Ptr item; - BOOST_FOREACH(boost::tie(boost::tuples::ignore, item), m_Items) { - item->Link(); + BOOST_FOREACH(const ItemMap::value_type& kv, m_Items) { + kv.second->Link(); } if (ConfigCompilerContext::GetInstance()->HasErrors()) @@ -253,8 +249,8 @@ bool ConfigItem::ActivateItems(bool validateOnly) Log(LogInformation, "config", "Validating config items (step 1)..."); - BOOST_FOREACH(boost::tie(boost::tuples::ignore, item), m_Items) { - item->ValidateItem(); + BOOST_FOREACH(const ItemMap::value_type& kv, m_Items) { + kv.second->ValidateItem(); } if (ConfigCompilerContext::GetInstance()->HasErrors()) @@ -264,8 +260,8 @@ bool ConfigItem::ActivateItems(bool validateOnly) std::vector objects; - BOOST_FOREACH(boost::tie(boost::tuples::ignore, item), m_Items) { - DynamicObject::Ptr object = item->Commit(); + BOOST_FOREACH(const ItemMap::value_type& kv, m_Items) { + DynamicObject::Ptr object = kv.second->Commit(); if (object) objects.push_back(object); @@ -277,8 +273,8 @@ bool ConfigItem::ActivateItems(bool validateOnly) Log(LogInformation, "config", "Validating config items (step 2)..."); - BOOST_FOREACH(boost::tie(boost::tuples::ignore, item), m_Items) { - item->ValidateItem(); + BOOST_FOREACH(const ItemMap::value_type& kv, m_Items) { + kv.second->ValidateItem(); } if (ConfigCompilerContext::GetInstance()->HasErrors()) diff --git a/lib/config/configtype.cpp b/lib/config/configtype.cpp index 8cc412b20..d9b1106f8 100644 --- a/lib/config/configtype.cpp +++ b/lib/config/configtype.cpp @@ -22,7 +22,6 @@ #include "base/objectlock.h" #include "base/convert.h" #include "base/scriptfunction.h" -#include #include using namespace icinga; @@ -145,18 +144,16 @@ void ConfigType::ValidateDictionary(const Dictionary::Ptr& dictionary, ObjectLock olock(dictionary); - String key; - Value value; - BOOST_FOREACH(boost::tie(key, value), dictionary) { + BOOST_FOREACH(const Dictionary::Pair& kv, dictionary) { TypeValidationResult overallResult = ValidationUnknownField; std::vector subRuleLists; String hint; - locations.push_back("Attribute '" + key + "'"); + locations.push_back("Attribute '" + kv.first + "'"); BOOST_FOREACH(const TypeRuleList::Ptr& ruleList, ruleLists) { TypeRuleList::Ptr subRuleList; - TypeValidationResult result = ruleList->ValidateAttribute(key, value, &subRuleList, &hint); + TypeValidationResult result = ruleList->ValidateAttribute(kv.first, kv.second, &subRuleList, &hint); if (subRuleList) subRuleLists.push_back(subRuleList); @@ -184,10 +181,10 @@ void ConfigType::ValidateDictionary(const Dictionary::Ptr& dictionary, ConfigCompilerContext::GetInstance()->AddMessage(true, message); } - if (!subRuleLists.empty() && value.IsObjectType()) - ValidateDictionary(value, subRuleLists, locations); - else if (!subRuleLists.empty() && value.IsObjectType()) - ValidateArray(value, subRuleLists, locations); + if (!subRuleLists.empty() && kv.second.IsObjectType()) + ValidateDictionary(kv.second, subRuleLists, locations); + else if (!subRuleLists.empty() && kv.second.IsObjectType()) + ValidateArray(kv.second, subRuleLists, locations); locations.pop_back(); } diff --git a/lib/config/expression.cpp b/lib/config/expression.cpp index 88528b540..cd3b53e9e 100644 --- a/lib/config/expression.cpp +++ b/lib/config/expression.cpp @@ -23,7 +23,6 @@ #include "base/debug.h" #include "base/array.h" #include -#include #include using namespace icinga; @@ -54,10 +53,8 @@ Value Expression::DeepClone(const Value& value) ObjectLock olock(dict); - String key; - Value item; - BOOST_FOREACH(boost::tuples::tie(key, item), dict) { - result->Set(key, DeepClone(item)); + BOOST_FOREACH(const Dictionary::Pair& kv, dict) { + result->Set(kv.first, DeepClone(kv.second)); } return result; @@ -136,8 +133,8 @@ void Expression::Execute(const Dictionary::Ptr& dictionary) const String key; Value value; - BOOST_FOREACH(boost::tie(key, value), valueDict) { - dict->Set(key, DeepClone(value)); + BOOST_FOREACH(const Dictionary::Pair& kv, valueDict) { + dict->Set(kv.first, DeepClone(kv.second)); } newValue = dict; diff --git a/lib/db_ido/dbtype.cpp b/lib/db_ido/dbtype.cpp index 13722a385..45c14c75d 100644 --- a/lib/db_ido/dbtype.cpp +++ b/lib/db_ido/dbtype.cpp @@ -22,7 +22,6 @@ #include "base/objectlock.h" #include "base/debug.h" #include -#include #include using namespace icinga; @@ -70,11 +69,11 @@ DbType::Ptr DbType::GetByName(const String& name) DbType::Ptr DbType::GetByID(long tid) { - String name; - DbType::Ptr type; - BOOST_FOREACH(boost::tie(name, type), GetTypes()) { - if (type->GetTypeID() == tid) - return type; + boost::mutex::scoped_lock lock(GetStaticMutex()); + + BOOST_FOREACH(const TypeMap::value_type& kv, GetTypes()) { + if (kv.second->GetTypeID() == tid) + return kv.second; } return DbType::Ptr(); diff --git a/lib/db_ido/hostdbobject.cpp b/lib/db_ido/hostdbobject.cpp index 801e9ff7e..90a2fb3d0 100644 --- a/lib/db_ido/hostdbobject.cpp +++ b/lib/db_ido/hostdbobject.cpp @@ -29,7 +29,6 @@ #include "base/convert.h" #include "base/objectlock.h" #include -#include using namespace icinga; @@ -277,14 +276,12 @@ void HostDbObject::OnConfigUpdate(void) if (customvars) { ObjectLock olock (customvars); - String key; - Value value; - BOOST_FOREACH(boost::tie(key, value), customvars) { - Log(LogDebug, "db_ido", "host customvar key: '" + key + "' value: '" + Convert::ToString(value) + "'"); + BOOST_FOREACH(const Dictionary::Pair& kv, customvars) { + Log(LogDebug, "db_ido", "host customvar key: '" + kv.first + "' value: '" + Convert::ToString(kv.second) + "'"); Dictionary::Ptr fields3 = make_shared(); - fields3->Set("varname", Convert::ToString(key)); - fields3->Set("varvalue", Convert::ToString(value)); + fields3->Set("varname", Convert::ToString(kv.first)); + fields3->Set("varvalue", Convert::ToString(kv.second)); fields3->Set("config_type", 1); fields3->Set("has_been_modified", 0); fields3->Set("object_id", host); diff --git a/lib/db_ido/servicedbobject.cpp b/lib/db_ido/servicedbobject.cpp index 497594725..d4797e01a 100644 --- a/lib/db_ido/servicedbobject.cpp +++ b/lib/db_ido/servicedbobject.cpp @@ -31,7 +31,6 @@ #include "icinga/externalcommandprocessor.h" #include "icinga/compatutility.h" #include -#include #include using namespace icinga; @@ -278,14 +277,12 @@ void ServiceDbObject::OnConfigUpdate(void) if (customvars) { ObjectLock olock(customvars); - String key; - Value value; - BOOST_FOREACH(boost::tie(key, value), customvars) { - Log(LogDebug, "db_ido", "service customvar key: '" + key + "' value: '" + Convert::ToString(value) + "'"); + BOOST_FOREACH(const Dictionary::Pair& kv, customvars) { + Log(LogDebug, "db_ido", "service customvar key: '" + kv.first + "' value: '" + Convert::ToString(kv.second) + "'"); Dictionary::Ptr fields2 = make_shared(); - fields2->Set("varname", Convert::ToString(key)); - fields2->Set("varvalue", Convert::ToString(value)); + fields2->Set("varname", Convert::ToString(kv.first)); + fields2->Set("varvalue", Convert::ToString(kv.second)); fields2->Set("config_type", 1); fields2->Set("has_been_modified", 0); fields2->Set("object_id", service); @@ -330,10 +327,8 @@ void ServiceDbObject::AddComments(const Service::Ptr& service) ObjectLock olock(comments); - String comment_id; - Comment::Ptr comment; - BOOST_FOREACH(boost::tie(comment_id, comment), comments) { - AddComment(service, comment); + BOOST_FOREACH(const Dictionary::Pair& kv, comments) { + AddComment(service, kv.second); } } @@ -494,10 +489,8 @@ void ServiceDbObject::AddDowntimes(const Service::Ptr& service) ObjectLock olock(downtimes); - String downtime_id; - Downtime::Ptr downtime; - BOOST_FOREACH(boost::tie(downtime_id, downtime), downtimes) { - AddDowntime(service, downtime); + BOOST_FOREACH(const Dictionary::Pair& kv, downtimes) { + AddDowntime(service, kv.second); } } diff --git a/lib/db_ido/timeperioddbobject.cpp b/lib/db_ido/timeperioddbobject.cpp index 327bba42b..6aab46775 100644 --- a/lib/db_ido/timeperioddbobject.cpp +++ b/lib/db_ido/timeperioddbobject.cpp @@ -26,7 +26,6 @@ #include "base/exception.h" #include "base/objectlock.h" #include -#include using namespace icinga; @@ -70,10 +69,8 @@ void TimePeriodDbObject::OnConfigUpdate(void) time_t refts = Utility::GetTime(); ObjectLock olock(ranges); - String key; - Value value; - BOOST_FOREACH(boost::tie(key, value), ranges) { - int wday = LegacyTimePeriod::WeekdayFromString(key); + BOOST_FOREACH(const Dictionary::Pair& kv, ranges) { + int wday = LegacyTimePeriod::WeekdayFromString(kv.first); if (wday == -1) continue; @@ -99,7 +96,7 @@ void TimePeriodDbObject::OnConfigUpdate(void) #endif /* _MSC_VER */ Array::Ptr segments = make_shared(); - LegacyTimePeriod::ProcessTimeRanges(value, &reference, segments); + LegacyTimePeriod::ProcessTimeRanges(kv.second, &reference, segments); ObjectLock olock(segments); BOOST_FOREACH(const Value& vsegment, segments) { diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index 97ef657fc..8796e668a 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -26,7 +26,6 @@ #include "base/debug.h" #include "base/convert.h" #include -#include #include #include #include @@ -464,14 +463,14 @@ Dictionary::Ptr CompatUtility::GetCustomVariableConfig(const DynamicObject::Ptr& ObjectLock olock(custom); String key; Value value; - BOOST_FOREACH(boost::tie(key, value), custom) { - if (key == "notes" || - key == "action_url" || - key == "notes_url" || - key == "icon_image" || - key == "icon_image_alt" || - key == "statusmap_image" || - key == "2d_coords") + BOOST_FOREACH(const Dictionary::Pair& kv, custom) { + if (kv.first == "notes" || + kv.first == "action_url" || + kv.first == "notes_url" || + kv.first == "icon_image" || + kv.first == "icon_image_alt" || + kv.first == "statusmap_image" || + kv.first == "2d_coords") continue; customvars->Set(key, value); diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp index cac47e1b7..2977e31f6 100644 --- a/lib/icinga/host.cpp +++ b/lib/icinga/host.cpp @@ -33,7 +33,6 @@ #include "base/serializer.h" #include "config/configitembuilder.h" #include "config/configcompilercontext.h" -#include #include using namespace icinga; @@ -151,19 +150,14 @@ void Host::UpdateSlaveServices(void) return; ObjectLock olock(service_descriptions); - String svcname; - Value svcdesc; - BOOST_FOREACH(boost::tie(svcname, svcdesc), service_descriptions) { - if (svcdesc.IsScalar()) - svcname = svcdesc; - + BOOST_FOREACH(const Dictionary::Pair& kv, service_descriptions) { std::ostringstream namebuf; - namebuf << GetName() << ":" << svcname; + namebuf << GetName() << ":" << kv.first; String name = namebuf.str(); std::vector path; path.push_back("services"); - path.push_back(svcname); + path.push_back(kv.first); DebugInfo di; item->GetLinkedExpressionList()->FindDebugInfoPath(path, di); @@ -175,13 +169,13 @@ void Host::UpdateSlaveServices(void) builder->SetType("Service"); builder->SetName(name); builder->AddExpression("host", OperatorSet, GetName()); - builder->AddExpression("display_name", OperatorSet, svcname); - builder->AddExpression("short_name", OperatorSet, svcname); + builder->AddExpression("display_name", OperatorSet, kv.first); + builder->AddExpression("short_name", OperatorSet, kv.first); - if (!svcdesc.IsObjectType()) + if (!kv.second.IsObjectType()) BOOST_THROW_EXCEPTION(std::invalid_argument("Service description must be either a string or a dictionary.")); - Dictionary::Ptr service = svcdesc; + Dictionary::Ptr service = kv.second; Array::Ptr templates = service->Get("templates"); @@ -211,14 +205,9 @@ std::set Host::GetServices(void) const boost::mutex::scoped_lock lock(m_ServicesMutex); std::set services; - Service::WeakPtr wservice; - BOOST_FOREACH(boost::tie(boost::tuples::ignore, wservice), m_Services) { - Service::Ptr service = wservice.lock(); - - if (!service) - continue; - - services.insert(service); + typedef std::pair ServicePair; + BOOST_FOREACH(const ServicePair& kv, m_Services) { + services.insert(kv.second); } return services; diff --git a/lib/icinga/macroprocessor.cpp b/lib/icinga/macroprocessor.cpp index c5d520a98..29531b9d4 100644 --- a/lib/icinga/macroprocessor.cpp +++ b/lib/icinga/macroprocessor.cpp @@ -24,7 +24,6 @@ #include "base/objectlock.h" #include "base/logger_fwd.h" #include "base/context.h" -#include #include using namespace icinga; diff --git a/lib/icinga/notification.cpp b/lib/icinga/notification.cpp index 57ca6dbaa..e89fd5c8d 100644 --- a/lib/icinga/notification.cpp +++ b/lib/icinga/notification.cpp @@ -27,7 +27,6 @@ #include "base/utility.h" #include "base/convert.h" #include "base/exception.h" -#include #include using namespace icinga; diff --git a/lib/icinga/pluginutility.cpp b/lib/icinga/pluginutility.cpp index e1657774a..4f7883455 100644 --- a/lib/icinga/pluginutility.cpp +++ b/lib/icinga/pluginutility.cpp @@ -135,7 +135,7 @@ Value PluginUtility::ParsePerfdata(const String& perfdata) String PluginUtility::FormatPerfdata(const Value& perfdata) { - String output; + std::ostringstream result; if (!perfdata.IsObjectType()) return perfdata; @@ -144,14 +144,15 @@ String PluginUtility::FormatPerfdata(const Value& perfdata) ObjectLock olock(dict); - String key; - Value value; - BOOST_FOREACH(boost::tie(key, value), dict) { - if (!output.IsEmpty()) - output += " "; + bool first = true; + BOOST_FOREACH(const Dictionary::Pair& kv, dict) { + if (!first) + result << " "; + else + first = false; - output += key + "=" + PerfdataValue::Format(value); + result << kv.first << "=" << PerfdataValue::Format(kv.second); } - return output; + return result.str(); } diff --git a/lib/icinga/service-comment.cpp b/lib/icinga/service-comment.cpp index b06f4c25d..bfeae0a87 100644 --- a/lib/icinga/service-comment.cpp +++ b/lib/icinga/service-comment.cpp @@ -24,7 +24,6 @@ #include "base/timer.h" #include "base/utility.h" #include -#include using namespace icinga; @@ -90,12 +89,11 @@ void Service::RemoveAllComments(void) Dictionary::Ptr comments = GetComments(); ObjectLock olock(comments); - String id; - BOOST_FOREACH(boost::tie(id, boost::tuples::ignore), comments) { - ids.push_back(id); + BOOST_FOREACH(const Dictionary::Pair& kv, comments) { + ids.push_back(kv.first); } - BOOST_FOREACH(id, ids) { + BOOST_FOREACH(const String& id, ids) { RemoveComment(id); } } @@ -173,16 +171,16 @@ void Service::AddCommentsToCache(void) boost::mutex::scoped_lock lock(l_CommentMutex); - String id; - Comment::Ptr comment; - BOOST_FOREACH(boost::tie(id, comment), comments) { + BOOST_FOREACH(const Dictionary::Pair& kv, comments) { + Comment::Ptr comment = kv.second; + int legacy_id = comment->GetLegacyId(); if (legacy_id >= l_NextCommentID) l_NextCommentID = legacy_id + 1; - l_LegacyCommentsCache[legacy_id] = id; - l_CommentsCache[id] = GetSelf(); + l_LegacyCommentsCache[legacy_id] = kv.first; + l_CommentsCache[kv.first] = GetSelf(); } } @@ -195,11 +193,11 @@ void Service::RemoveCommentsByType(int type) { ObjectLock olock(comments); - String id; - Comment::Ptr comment; - BOOST_FOREACH(boost::tie(id, comment), comments) { + BOOST_FOREACH(const Dictionary::Pair& kv, comments) { + Comment::Ptr comment = kv.second; + if (comment->GetEntryType() == type) - removedComments.push_back(id); + removedComments.push_back(kv.first); } } @@ -217,11 +215,11 @@ void Service::RemoveExpiredComments(void) { ObjectLock olock(comments); - String id; - Comment::Ptr comment; - BOOST_FOREACH(boost::tie(id, comment), comments) { + BOOST_FOREACH(const Dictionary::Pair& kv, comments) { + Comment::Ptr comment = kv.second; + if (comment->IsExpired()) - expiredComments.push_back(id); + expiredComments.push_back(kv.first); } } diff --git a/lib/icinga/service-downtime.cpp b/lib/icinga/service-downtime.cpp index d1442239b..3a397a827 100644 --- a/lib/icinga/service-downtime.cpp +++ b/lib/icinga/service-downtime.cpp @@ -24,7 +24,6 @@ #include "base/timer.h" #include "base/utility.h" #include "base/convert.h" -#include #include using namespace icinga; @@ -144,9 +143,8 @@ void Service::TriggerDowntimes(void) { ObjectLock olock(downtimes); - String id; - BOOST_FOREACH(boost::tie(id, boost::tuples::ignore), downtimes) { - ids.push_back(id); + BOOST_FOREACH(const Dictionary::Pair& kv, downtimes) { + ids.push_back(kv.first); } } @@ -180,9 +178,8 @@ void Service::TriggerDowntime(const String& id) Dictionary::Ptr triggers = downtime->GetTriggers(); ObjectLock olock(triggers); - String tid; - BOOST_FOREACH(boost::tie(tid, boost::tuples::ignore), triggers) { - TriggerDowntime(tid); + BOOST_FOREACH(const Dictionary::Pair& kv, triggers) { + TriggerDowntime(kv.first); } OnDowntimeTriggered(owner, downtime); @@ -241,16 +238,16 @@ void Service::AddDowntimesToCache(void) ObjectLock olock(downtimes); - String id; - Downtime::Ptr downtime; - BOOST_FOREACH(boost::tie(id, downtime), downtimes) { + BOOST_FOREACH(const Dictionary::Pair& kv, downtimes) { + Downtime::Ptr downtime = kv.second; + int legacy_id = downtime->GetLegacyId(); if (legacy_id >= l_NextDowntimeID) l_NextDowntimeID = legacy_id + 1; - l_LegacyDowntimesCache[legacy_id] = id; - l_DowntimesCache[id] = GetSelf(); + l_LegacyDowntimesCache[legacy_id] = kv.first; + l_DowntimesCache[kv.first] = GetSelf(); } } @@ -263,11 +260,11 @@ void Service::RemoveExpiredDowntimes(void) { ObjectLock olock(downtimes); - String id; - Downtime::Ptr downtime; - BOOST_FOREACH(boost::tie(id, downtime), downtimes) { + BOOST_FOREACH(const Dictionary::Pair& kv, downtimes) { + Downtime::Ptr downtime = kv.second; + if (downtime->IsExpired()) - expiredDowntimes.push_back(id); + expiredDowntimes.push_back(kv.first); } } @@ -289,8 +286,9 @@ bool Service::IsInDowntime(void) const ObjectLock olock(downtimes); - Downtime::Ptr downtime; - BOOST_FOREACH(boost::tie(boost::tuples::ignore, downtime), downtimes) { + BOOST_FOREACH(const Dictionary::Pair& kv, downtimes) { + Downtime::Ptr downtime = kv.second; + if (downtime->IsActive()) return true; } @@ -305,8 +303,9 @@ int Service::GetDowntimeDepth(void) const ObjectLock olock(downtimes); - Downtime::Ptr downtime; - BOOST_FOREACH(boost::tie(boost::tuples::ignore, downtime), downtimes) { + BOOST_FOREACH(const Dictionary::Pair& kv, downtimes) { + Downtime::Ptr downtime = kv.second; + if (downtime->IsActive()) downtime_depth++; } diff --git a/lib/icinga/service-flapping.cpp b/lib/icinga/service-flapping.cpp index 67b7af938..0c167adca 100644 --- a/lib/icinga/service-flapping.cpp +++ b/lib/icinga/service-flapping.cpp @@ -25,7 +25,6 @@ #include "base/timer.h" #include "base/utility.h" #include "base/convert.h" -#include #include using namespace icinga; diff --git a/lib/icinga/service-notification.cpp b/lib/icinga/service-notification.cpp index 6128301c9..c411b9bb0 100644 --- a/lib/icinga/service-notification.cpp +++ b/lib/icinga/service-notification.cpp @@ -27,7 +27,6 @@ #include "base/exception.h" #include "base/context.h" #include "config/configitembuilder.h" -#include #include using namespace icinga; @@ -110,16 +109,14 @@ void Service::UpdateSlaveNotifications(void) ObjectLock olock(descs); - String nfcname; - Value nfcdesc; - BOOST_FOREACH(boost::tie(nfcname, nfcdesc), descs) { + BOOST_FOREACH(const Dictionary::Pair& kv, descs) { std::ostringstream namebuf; - namebuf << GetName() << ":" << nfcname; + namebuf << GetName() << ":" << kv.first; String name = namebuf.str(); std::vector path; path.push_back("notifications"); - path.push_back(nfcname); + path.push_back(kv.first); DebugInfo di; item->GetLinkedExpressionList()->FindDebugInfoPath(path, di); @@ -133,10 +130,7 @@ void Service::UpdateSlaveNotifications(void) builder->AddExpression("host", OperatorSet, GetHost()->GetName()); builder->AddExpression("service", OperatorSet, GetShortName()); - if (!nfcdesc.IsObjectType()) - BOOST_THROW_EXCEPTION(std::invalid_argument("Notification description must be a dictionary.")); - - Dictionary::Ptr notification = nfcdesc; + Dictionary::Ptr notification = kv.second; Array::Ptr templates = notification->Get("templates"); diff --git a/lib/methods/legacytimeperiod.cpp b/lib/methods/legacytimeperiod.cpp index 027df543a..fd56d31dc 100644 --- a/lib/methods/legacytimeperiod.cpp +++ b/lib/methods/legacytimeperiod.cpp @@ -26,7 +26,6 @@ #include "base/debug.h" #include #include -#include #include using namespace icinga; @@ -413,17 +412,15 @@ Array::Ptr LegacyTimePeriod::ScriptFunc(const TimePeriod::Ptr& tp, double begin, #endif /* _MSC_VER */ ObjectLock olock(ranges); - String key; - Value value; - BOOST_FOREACH(boost::tie(key, value), ranges) { - if (!IsInDayDefinition(key, &reference)) { - Log(LogDebug, "icinga", "Not in day definition '" + key + "'."); + BOOST_FOREACH(const Dictionary::Pair& kv, ranges) { + if (!IsInDayDefinition(kv.first, &reference)) { + Log(LogDebug, "icinga", "Not in day definition '" + kv.first + "'."); continue; } - Log(LogDebug, "icinga", "In day definition '" + key + "'."); + Log(LogDebug, "icinga", "In day definition '" + kv.first + "'."); - ProcessTimeRanges(value, &reference, segments); + ProcessTimeRanges(kv.second, &reference, segments); } } } diff --git a/test/base-dictionary.cpp b/test/base-dictionary.cpp index c6dfac9ff..e8119b93b 100644 --- a/test/base-dictionary.cpp +++ b/test/base-dictionary.cpp @@ -82,23 +82,21 @@ BOOST_AUTO_TEST_CASE(foreach) bool seen_test1 = false, seen_test2 = false; - String key; - Value value; - BOOST_FOREACH(boost::tie(key, value), dictionary) { - BOOST_CHECK(key == "test1" || key == "test2"); + BOOST_FOREACH(const Dictionary::Pair& kv, dictionary) { + BOOST_CHECK(kv.first == "test1" || kv.first == "test2"); - if (key == "test1") { + if (kv.first == "test1") { BOOST_CHECK(!seen_test1); seen_test1 = true; - BOOST_CHECK(value == 7); + BOOST_CHECK(kv.second == 7); continue; - } else if (key == "test2") { + } else if (kv.first == "test2") { BOOST_CHECK(!seen_test2); seen_test2 = true; - BOOST_CHECK(value == "hello world"); + BOOST_CHECK(kv.second == "hello world"); } }