From d520bc81a1d0131736343cd414a0227bf5b624ff Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Sun, 19 Nov 2017 20:28:26 +0100 Subject: [PATCH] simplify this example and please sonar we basically empty the different sets by unref-ing the actions one by one. a while loop thus seems more adequate --- teshsuite/surf/surf_usage/surf_usage.cpp | 36 +++++++++--------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/teshsuite/surf/surf_usage/surf_usage.cpp b/teshsuite/surf/surf_usage/surf_usage.cpp index 90914d6477..57b800a1c3 100644 --- a/teshsuite/surf/surf_usage/surf_usage.cpp +++ b/teshsuite/surf/surf_usage/surf_usage.cpp @@ -67,40 +67,32 @@ int main(int argc, char **argv) XBT_DEBUG("\t CPU actions"); simgrid::surf::ActionList* action_list = surf_cpu_model_pm->getFailedActionSet(); - for(simgrid::surf::ActionList::iterator it(action_list->begin()), itNext = it, itend(action_list->end()) ; - it != itend ; it=itNext) { - ++itNext; - simgrid::surf::Action *action = static_cast(&*it); - XBT_INFO(" CPU Failed action"); - XBT_DEBUG("\t * Failed : %p", action); - action->unref(); + while (not action_list->empty()) { + simgrid::surf::Action* action = &*action_list->begin(); + XBT_INFO(" CPU Failed action"); + XBT_DEBUG("\t * Failed : %p", action); + action->unref(); } action_list = surf_cpu_model_pm->getDoneActionSet(); - for(simgrid::surf::ActionList::iterator it(action_list->begin()), itNext = it, itend(action_list->end()) ; - it != itend ; it=itNext) { - ++itNext; - simgrid::surf::Action *action = static_cast(&*it); + while (not action_list->empty()) { + simgrid::surf::Action* action = &*action_list->begin(); XBT_INFO(" CPU Done action"); XBT_DEBUG("\t * Done : %p", action); action->unref(); } action_list = surf_network_model->getFailedActionSet(); - for(simgrid::surf::ActionList::iterator it(action_list->begin()), itNext = it, itend(action_list->end()) ; - it != itend ; it=itNext) { - ++itNext; - simgrid::surf::Action *action = static_cast(&*it); - XBT_INFO(" Network Failed action"); - XBT_DEBUG("\t * Failed : %p", action); - action->unref(); + while (not action_list->empty()) { + simgrid::surf::Action* action = &*action_list->begin(); + XBT_INFO(" Network Failed action"); + XBT_DEBUG("\t * Failed : %p", action); + action->unref(); } action_list = surf_network_model->getDoneActionSet(); - for(simgrid::surf::ActionList::iterator it(action_list->begin()), itNext = it, itend(action_list->end()) ; - it != itend ; it=itNext) { - ++itNext; - simgrid::surf::Action *action = static_cast(&*it); + while (not action_list->empty()) { + simgrid::surf::Action* action = &*action_list->begin(); XBT_INFO(" Network Done action"); XBT_DEBUG("\t * Done : %p", action); action->unref(); -- 2.20.1