diff options
author | fluxgen <fluxgen> | 2003-09-08 15:38:46 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2003-09-08 15:38:46 (GMT) |
commit | a4e781298c7e884506f0aa6efeea8efb84e3ee00 (patch) | |
tree | 706dbcede262c4720263a2b3cde8db8efb25df5a /src/FbTk/Subject.cc | |
parent | 8679fd20b1a8ddd2858922b3cd3d34d3b53dc065 (diff) | |
download | fluxbox-a4e781298c7e884506f0aa6efeea8efb84e3ee00.zip fluxbox-a4e781298c7e884506f0aa6efeea8efb84e3ee00.tar.bz2 |
fixed dead observer while notifying
Diffstat (limited to 'src/FbTk/Subject.cc')
-rw-r--r-- | src/FbTk/Subject.cc | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/src/FbTk/Subject.cc b/src/FbTk/Subject.cc index 961d6a8..a575cfd 100644 --- a/src/FbTk/Subject.cc +++ b/src/FbTk/Subject.cc | |||
@@ -19,7 +19,7 @@ | |||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
20 | // DEALINGS IN THE SOFTWARE. | 20 | // DEALINGS IN THE SOFTWARE. |
21 | 21 | ||
22 | // $Id: Subject.cc,v 1.2 2003/08/19 16:03:26 fluxgen Exp $ | 22 | // $Id: Subject.cc,v 1.3 2003/09/08 15:38:46 fluxgen Exp $ |
23 | 23 | ||
24 | #include "Subject.hh" | 24 | #include "Subject.hh" |
25 | #include "Observer.hh" | 25 | #include "Observer.hh" |
@@ -31,7 +31,7 @@ namespace FbTk { | |||
31 | 31 | ||
32 | Subject::SubjectList Subject::s_subjectlist; | 32 | Subject::SubjectList Subject::s_subjectlist; |
33 | 33 | ||
34 | Subject::Subject() { | 34 | Subject::Subject():m_notify_mode(false) { |
35 | s_subjectlist.push_back(this); | 35 | s_subjectlist.push_back(this); |
36 | } | 36 | } |
37 | 37 | ||
@@ -48,14 +48,28 @@ void Subject::attach(Observer *obj) { | |||
48 | } | 48 | } |
49 | 49 | ||
50 | void Subject::detach(Observer *obj) { | 50 | void Subject::detach(Observer *obj) { |
51 | m_observerlist.erase(std::remove(m_observerlist.begin(), | 51 | if (m_notify_mode) |
52 | m_observerlist.end(), obj), | 52 | m_dead_observers.push_back(obj); |
53 | m_observerlist.end()); | 53 | else { |
54 | m_observerlist.erase(std::remove(m_observerlist.begin(), | ||
55 | m_observerlist.end(), obj), | ||
56 | m_observerlist.end()); | ||
57 | } | ||
54 | } | 58 | } |
55 | 59 | ||
56 | void Subject::notify() { | 60 | void Subject::notify() { |
61 | m_notify_mode = true; | ||
57 | std::for_each(m_observerlist.begin(), m_observerlist.end(), | 62 | std::for_each(m_observerlist.begin(), m_observerlist.end(), |
58 | std::bind2nd(std::mem_fun(&Observer::update), this)); | 63 | std::bind2nd(std::mem_fun(&Observer::update), this)); |
64 | m_notify_mode = false; | ||
65 | |||
66 | // remove dead observers | ||
67 | if (m_dead_observers.size()) { | ||
68 | std::for_each(m_dead_observers.begin(), | ||
69 | m_dead_observers.end(), | ||
70 | std::bind1st(std::mem_fun(&Subject::detach), this)); | ||
71 | m_dead_observers.clear(); | ||
72 | } | ||
59 | } | 73 | } |
60 | 74 | ||
61 | void Subject::removeObserver(Observer *obj) { | 75 | void Subject::removeObserver(Observer *obj) { |