aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk')
-rw-r--r--src/FbTk/Subject.cc24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/FbTk/Subject.cc b/src/FbTk/Subject.cc
index 08a211c..7ff80cf 100644
--- a/src/FbTk/Subject.cc
+++ b/src/FbTk/Subject.cc
@@ -58,16 +58,22 @@ void Subject::detach(Observer *obj) {
58} 58}
59 59
60void Subject::notify() { 60void Subject::notify() {
61 m_notify_mode = true; 61 ObserverList::iterator it = m_observerlist.begin(),
62 std::for_each(m_observerlist.begin(), m_observerlist.end(), 62 it_end = m_observerlist.end();
63 std::bind2nd(std::mem_fun(&Observer::update), this)); 63 for (; it != it_end; ++it) {
64 m_notify_mode = false; 64 m_notify_mode = true;
65 (*it)->update(this);
66 ObserverList::iterator d_it = m_dead_observers.begin(),
67 d_it_end = m_dead_observers.end();
68 m_notify_mode = false;
65 69
66 // remove dead observers 70 // there might be dead observers later in the list, so we must remove
67 if (!m_dead_observers.empty()) { 71 // them now
68 std::for_each(m_dead_observers.begin(), 72 for (; d_it != d_it_end; ++d_it) {
69 m_dead_observers.end(), 73 if (*d_it == *it)
70 std::bind1st(std::mem_fun(&Subject::detach), this)); 74 --it; // don't invalidate our iterator
75 detach(*d_it);
76 }
71 m_dead_observers.clear(); 77 m_dead_observers.clear();
72 } 78 }
73} 79}