From 07f5c0fbfb43b099fa09b273a1074093c7579903 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Sat, 1 Aug 2015 17:41:55 +0200 Subject: Replace some loops with iterators to foreach loops --- src/RemoteControl.h | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) (limited to 'src/RemoteControl.h') diff --git a/src/RemoteControl.h b/src/RemoteControl.h index b94ed6c..8c3362c 100644 --- a/src/RemoteControl.h +++ b/src/RemoteControl.h @@ -102,20 +102,18 @@ class RemoteControllers { } void add_controllable(RemoteControllable *rc) { - for (std::list::iterator it = m_controllers.begin(); - it != m_controllers.end(); ++it) { - (*it)->enrol(rc); + for (auto &controller : m_controllers) { + controller->enrol(rc); } } void check_faults() { - for (std::list::iterator it = m_controllers.begin(); - it != m_controllers.end(); ++it) { - if ((*it)->fault_detected()) + for (auto &controller : m_controllers) { + if (controller->fault_detected()) { etiLog.level(warn) << "Detected Remote Control fault, restarting it"; - (*it)->restart(); + controller->restart(); } } } @@ -147,9 +145,8 @@ class RemoteControllable { /* Return a list of possible parameters that can be set */ virtual std::list get_supported_parameters() const { std::list parameterlist; - for (std::list< std::vector >::const_iterator it = m_parameters.begin(); - it != m_parameters.end(); ++it) { - parameterlist.push_back((*it)[0]); + for (const auto& param : m_parameters) { + parameterlist.push_back(param[0]); } return parameterlist; } @@ -255,12 +252,10 @@ class RemoteControllerTelnet : public BaseRemoteController { RemoteControllable* controllable = get_controllable_(name); std::list< std::vector > allparams; - std::list params = controllable->get_supported_parameters(); - for (std::list::iterator it = params.begin(); - it != params.end(); ++it) { + for (auto ¶m : controllable->get_supported_parameters()) { std::vector item; - item.push_back(*it); - item.push_back(controllable->get_parameter(*it)); + item.push_back(param); + item.push_back(controllable->get_parameter(param)); allparams.push_back(item); } @@ -363,15 +358,15 @@ class RemoteControllerZmq : public BaseRemoteController { RemoteControllable* controllable = get_controllable_(name); std::list< std::vector > allparams; - std::list params = controllable->get_supported_parameters(); - for (std::list::iterator it = params.begin(); - it != params.end(); ++it) { + + for (auto ¶m : controllable->get_supported_parameters()) { std::vector item; - item.push_back(*it); - item.push_back(controllable->get_parameter(*it)); + item.push_back(param); + item.push_back(controllable->get_parameter(param)); allparams.push_back(item); } + return allparams; } -- cgit v1.2.3