From 72e038f03e8640494c487f54a7f85031a16c2177 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Mon, 11 Apr 2016 12:00:19 +0200 Subject: [PATCH] When a counter is stepped, reset recursively all slaves Fixes bug #10063. --- src/Counters.cpp | 22 +++++++++++++++------- src/Counters.h | 6 +++--- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/Counters.cpp b/src/Counters.cpp index fe26040449..0b17aa1b9b 100644 --- a/src/Counters.cpp +++ b/src/Counters.cpp @@ -265,6 +265,19 @@ int Counters::value(docstring const & ctr) const } +void Counters::resetSlaves(docstring const & ctr) +{ + CounterList::iterator it = counterList_.begin(); + CounterList::iterator const end = counterList_.end(); + for (; it != end; ++it) { + if (it->second.master() == ctr) { + it->second.reset(); + resetSlaves(it->first); + } + } +} + + void Counters::step(docstring const & ctr, UpdateType utype) { CounterList::iterator it = counterList_.find(ctr); @@ -280,13 +293,8 @@ void Counters::step(docstring const & ctr, UpdateType utype) counter_stack_.pop_back(); counter_stack_.push_back(ctr); } - it = counterList_.begin(); - CounterList::iterator const end = counterList_.end(); - for (; it != end; ++it) { - if (it->second.master() == ctr) { - it->second.reset(); - } - } + + resetSlaves(ctr); } diff --git a/src/Counters.h b/src/Counters.h index ce122c4140..4ba0d00484 100644 --- a/src/Counters.h +++ b/src/Counters.h @@ -128,10 +128,10 @@ public: void addto(docstring const & ctr, int val); /// int value(docstring const & ctr) const; - /// Increment by one counter named by arg, and zeroes slave + /// Reset recursively all the counters that are slaves of the one named by \c ctr. + void resetSlaves(docstring const & ctr); + /// Increment by one counter named by \c ctr, and zeroes slave /// counter(s) for which it is the master. - /// Sub-slaves are not zeroed! That happens at slave's first - /// step 0->1. Seems to be sufficient. /// \param utype determines whether we track the counters. void step(docstring const & ctr, UpdateType utype); /// Reset all counters, and all the internal data structures