From: Gunnar Beutner Date: Tue, 17 Jul 2012 08:29:30 +0000 (+0200) Subject: Use Boost.Range instead of tie(). X-Git-Tag: v0.0.1~216 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=78215843cf60eb22637c4d95d58c97c19e02c03f;p=icinga2 Use Boost.Range instead of tie(). --- diff --git a/base/application.cpp b/base/application.cpp index fe17a1dda..6ee53623e 100644 --- a/base/application.cpp +++ b/base/application.cpp @@ -61,8 +61,7 @@ Application::~Application(void) m_ShuttingDown = true; /* stop all components */ - Component::Ptr component; - BOOST_FOREACH(tie(tuples::ignore, component), m_Components) { + BOOST_FOREACH(const Component::Ptr& component, m_Components | map_values) { component->Stop(); } diff --git a/base/i2-base.h b/base/i2-base.h index 94db9f57a..848375442 100644 --- a/base/i2-base.h +++ b/base/i2-base.h @@ -124,6 +124,8 @@ using std::type_info; #include #include #include +#include +#include using boost::shared_ptr; using boost::weak_ptr; @@ -137,8 +139,8 @@ using boost::mutex; using boost::condition_variable; using boost::system_time; using boost::tie; - -namespace tuples = boost::tuples; +using boost::adaptors::map_keys; +using boost::adaptors::map_values; #if defined(__APPLE__) && defined(__MACH__) # pragma GCC diagnostic ignored "-Wdeprecated-declarations" diff --git a/base/process.cpp b/base/process.cpp index 38990a89f..2000ed0f3 100644 --- a/base/process.cpp +++ b/base/process.cpp @@ -66,8 +66,7 @@ void Process::WorkerThreadProc(void) FD_ZERO(&readfds); - int fd; - BOOST_FOREACH(tie(fd, tuples::ignore), tasks) { + BOOST_FOREACH(int fd, tasks | map_keys) { if (fd > nfds) nfds = fd; diff --git a/cib/host.cpp b/cib/host.cpp index 90cfdcb39..d0614d04a 100644 --- a/cib/host.cpp +++ b/cib/host.cpp @@ -69,8 +69,7 @@ set Host::GetParents(void) const if (GetProperty("dependencies", &dependencies)) { dependencies = Service::ResolveDependencies(*this, dependencies); - Variant dependency; - BOOST_FOREACH(tie(tuples::ignore, dependency), dependencies) { + BOOST_FOREACH(const Variant& dependency, dependencies | map_values) { Service service = Service::GetByName(dependency); string parent = service.GetHost().GetName(); @@ -99,8 +98,7 @@ bool Host::IsReachable(void) const if (GetProperty("dependencies", &dependencies)) { dependencies = Service::ResolveDependencies(*this, dependencies); - Variant dependency; - BOOST_FOREACH(tie(tuples::ignore, dependency), dependencies) { + BOOST_FOREACH(const Variant& dependency, dependencies | map_values) { Service service = Service::GetByName(dependency); if (!service.IsReachable() || @@ -119,8 +117,7 @@ bool Host::IsUp(void) const if (GetProperty("hostchecks", &hostchecks)) { hostchecks = Service::ResolveDependencies(*this, hostchecks); - Variant hostcheck; - BOOST_FOREACH(tie(tuples::ignore, hostcheck), hostchecks) { + BOOST_FOREACH(const Variant& hostcheck, hostchecks | map_values) { Service service = Service::GetByName(hostcheck); if (service.GetState() != StateOK && service.GetState() != StateWarning) { diff --git a/cib/service.cpp b/cib/service.cpp index 6e1ec9bd6..6a4d4bc16 100644 --- a/cib/service.cpp +++ b/cib/service.cpp @@ -117,8 +117,7 @@ void Service::GetDependenciesRecursive(const Dictionary::Ptr& result) const { if (!dependencies) return; - Variant dependency; - BOOST_FOREACH(tie(tuples::ignore, dependency), dependencies) { + BOOST_FOREACH(const Variant& dependency, dependencies | map_values) { if (result->Contains(dependency)) continue; @@ -148,8 +147,7 @@ bool Service::IsReachable(void) const Dictionary::Ptr dependencies = boost::make_shared(); GetDependenciesRecursive(dependencies); - Variant dependency; - BOOST_FOREACH(tie(tuples::ignore, dependency), dependencies) { + BOOST_FOREACH(const Variant& dependency, dependencies | map_values) { Service service = Service::GetByName(dependency); /* ignore ourselves */ @@ -379,8 +377,7 @@ bool Service::IsAllowedChecker(const string& checker) const if (!checkers) return true; - Variant pattern; - BOOST_FOREACH(tie(tuples::ignore, pattern), checkers) { + BOOST_FOREACH(const Variant& pattern, checkers | map_values) { if (Utility::Match(pattern, checker)) return true; } @@ -395,8 +392,7 @@ Dictionary::Ptr Service::ResolveDependencies(Host host, const Dictionary::Ptr& d Dictionary::Ptr result = boost::make_shared(); - Variant dependency; - BOOST_FOREACH(tie(tuples::ignore, dependency), dependencies) { + BOOST_FOREACH(const Variant& dependency, dependencies | map_values) { string name; if (services && services->Contains(dependency)) diff --git a/components/compat/compatcomponent.cpp b/components/compat/compatcomponent.cpp index 8e7403205..0895dcf02 100644 --- a/components/compat/compatcomponent.cpp +++ b/components/compat/compatcomponent.cpp @@ -233,16 +233,14 @@ void CompatComponent::StatusTimerHandler(void) ConfigObject::TMap::Range range; range = ConfigObject::GetObjects("host"); - ConfigObject::Ptr object; - BOOST_FOREACH(tie(tuples::ignore, object), range) { + BOOST_FOREACH(const ConfigObject::Ptr& object, range | map_values) { Host host = object; Dictionary::Ptr dict; dict = host.GetGroups(); if (dict) { - Variant hostgroup; - BOOST_FOREACH(tie(tuples::ignore, hostgroup), dict) { + BOOST_FOREACH(const Variant& hostgroup, dict | map_values) { hostgroups[hostgroup].push_back(host.GetName()); } } @@ -278,7 +276,7 @@ void CompatComponent::StatusTimerHandler(void) map > servicegroups; - BOOST_FOREACH(tie(tuples::ignore, object), range) { + BOOST_FOREACH(const ConfigObject::Ptr& object, range | map_values) { Service service = object; Dictionary::Ptr dict; @@ -286,8 +284,7 @@ void CompatComponent::StatusTimerHandler(void) dict = service.GetGroups(); if (dict) { - Variant servicegroup; - BOOST_FOREACH(tie(tuples::ignore, servicegroup), dict) { + BOOST_FOREACH(const Variant& servicegroup, dict | map_values) { servicegroups[servicegroup].push_back(service); } } diff --git a/components/convenience/conveniencecomponent.cpp b/components/convenience/conveniencecomponent.cpp index afcfcea92..cb56b1205 100644 --- a/components/convenience/conveniencecomponent.cpp +++ b/components/convenience/conveniencecomponent.cpp @@ -150,8 +150,7 @@ void ConvenienceComponent::HostCommittedHandler(const ConfigItem::Ptr& item) } if (oldServices) { - ConfigItem::Ptr service; - BOOST_FOREACH(tie(tuples::ignore, service), oldServices) { + BOOST_FOREACH(const ConfigItem::Ptr& service, oldServices | map_values) { if (!newServices->Contains(service->GetName())) service->Unregister(); } @@ -176,8 +175,7 @@ void ConvenienceComponent::HostRemovedHandler(const ConfigItem::Ptr& item) if (!services) return; - ConfigItem::Ptr service; - BOOST_FOREACH(tie(tuples::ignore, service), services) { + BOOST_FOREACH(const ConfigItem::Ptr& service, services | map_values) { service->Unregister(); } } diff --git a/components/delegation/delegationcomponent.cpp b/components/delegation/delegationcomponent.cpp index d061e0759..a8ea618e0 100644 --- a/components/delegation/delegationcomponent.cpp +++ b/components/delegation/delegationcomponent.cpp @@ -275,13 +275,12 @@ void DelegationComponent::DelegationTimerHandler(void) if (delegated > 0) { if (need_clear) { - Endpoint::Ptr endpoint; - BOOST_FOREACH(tie(endpoint, tuples::ignore), histogram) { + BOOST_FOREACH(const Endpoint::Ptr& endpoint, histogram | map_keys) { ClearServices(endpoint); } } - BOOST_FOREACH(Service& service, services) { + BOOST_FOREACH(const Service& service, services) { string checker = service.GetChecker(); Endpoint::Ptr endpoint = EndpointManager::GetInstance()->GetEndpointByIdentity(checker); diff --git a/components/discovery/discoverycomponent.cpp b/components/discovery/discoverycomponent.cpp index 3e2adc0f3..a975b2843 100644 --- a/components/discovery/discoverycomponent.cpp +++ b/components/discovery/discoverycomponent.cpp @@ -168,11 +168,11 @@ void DiscoveryComponent::NewEndpointHandler(const Endpoint::Ptr& endpoint) // register published/subscribed topics for this endpoint ComponentDiscoveryInfo::Ptr info = ic->second; - BOOST_FOREACH(string publication, info->Publications) { + BOOST_FOREACH(const string& publication, info->Publications) { endpoint->RegisterPublication(publication); } - BOOST_FOREACH(string subscription, info->Subscriptions) { + BOOST_FOREACH(const string& subscription, info->Subscriptions) { endpoint->RegisterSubscription(subscription); } @@ -301,14 +301,14 @@ void DiscoveryComponent::SendDiscoveryMessage(const string& method, const string set::iterator i; Dictionary::Ptr subscriptions = boost::make_shared(); - BOOST_FOREACH(string subscription, info->Subscriptions) { + BOOST_FOREACH(const string &subscription, info->Subscriptions) { subscriptions->Add(subscription); } params.SetSubscriptions(subscriptions); Dictionary::Ptr publications = boost::make_shared(); - BOOST_FOREACH(string publication, info->Publications) { + BOOST_FOREACH(const string& publication, info->Publications) { publications->Add(publication); } @@ -327,14 +327,12 @@ bool DiscoveryComponent::HasMessagePermission(const Dictionary::Ptr& roles, cons ConfigObject::TMap::Range range = ConfigObject::GetObjects("role"); - ConfigObject::Ptr role; - BOOST_FOREACH(tie(tuples::ignore, role), range) { + BOOST_FOREACH(const ConfigObject::Ptr& role, range | map_values) { Dictionary::Ptr permissions; if (!role->GetProperty(messageType, &permissions)) continue; - Variant permission; - BOOST_FOREACH(tie(tuples::ignore, permission), permissions) { + BOOST_FOREACH(const Variant& permission, permissions | map_values) { if (Utility::Match(permission, message)) return true; } @@ -378,8 +376,7 @@ void DiscoveryComponent::ProcessDiscoveryMessage(const string& identity, const D Dictionary::Ptr publications; if (message.GetPublications(&publications)) { - Variant publication; - BOOST_FOREACH(tie(tuples::ignore, publication), publications) { + BOOST_FOREACH(const Variant& publication, publications | map_values) { if (trusted || HasMessagePermission(roles, "publications", publication)) { info->Publications.insert(publication); if (endpoint) @@ -390,8 +387,7 @@ void DiscoveryComponent::ProcessDiscoveryMessage(const string& identity, const D Dictionary::Ptr subscriptions; if (message.GetSubscriptions(&subscriptions)) { - Variant subscription; - BOOST_FOREACH(tie(tuples::ignore, subscription), subscriptions) { + BOOST_FOREACH(const Variant& subscription, subscriptions | map_values) { if (trusted || HasMessagePermission(roles, "subscriptions", subscription)) { info->Subscriptions.insert(subscription); if (endpoint) @@ -459,8 +455,7 @@ void DiscoveryComponent::DiscoveryTimerHandler(void) /* check whether we have to reconnect to one of our upstream endpoints */ ConfigObject::TMap::Range range = ConfigObject::GetObjects("endpoint"); - ConfigObject::Ptr object; - BOOST_FOREACH(tie(tuples::ignore, object), range) { + BOOST_FOREACH(const ConfigObject::Ptr& object, range | map_values) { /* Check if we're already connected to this endpoint. */ if (endpointManager->GetEndpointByIdentity(object->GetName())) continue; diff --git a/icinga/endpointmanager.cpp b/icinga/endpointmanager.cpp index 272819e35..0d56ca466 100644 --- a/icinga/endpointmanager.cpp +++ b/icinga/endpointmanager.cpp @@ -240,8 +240,7 @@ void EndpointManager::SendAnycastMessage(Endpoint::Ptr sender, throw invalid_argument("Message is missing the 'method' property."); vector candidates; - Endpoint::Ptr endpoint; - BOOST_FOREACH(tie(tuples::ignore, endpoint), m_Endpoints) { + BOOST_FOREACH(const Endpoint::Ptr& endpoint, m_Endpoints | map_values) { /* don't forward messages between non-local endpoints */ if (!sender->IsLocal() && !endpoint->IsLocal()) continue; @@ -275,8 +274,7 @@ void EndpointManager::SendMulticastMessage(Endpoint::Ptr sender, if (!message.GetMethod(&method)) throw invalid_argument("Message is missing the 'method' property."); - Endpoint::Ptr recipient; - BOOST_FOREACH(tie(tuples::ignore, recipient), m_Endpoints) { + BOOST_FOREACH(const Endpoint::Ptr& recipient, m_Endpoints | map_values) { /* don't forward messages back to the sender */ if (sender == recipient) continue;