summaryrefslogtreecommitdiff
path: root/src/Subject.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/Subject.cc')
-rw-r--r--src/Subject.cc58
1 files changed, 29 insertions, 29 deletions
diff --git a/src/Subject.cc b/src/Subject.cc
index 3e9618b..3811255 100644
--- a/src/Subject.cc
+++ b/src/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.1 2002/09/07 20:30:45 fluxgen Exp $ 22// $Id: Subject.cc,v 1.2 2002/12/01 13:41:59 rathnor Exp $
23 23
24#include "Subject.hh" 24#include "Subject.hh"
25#include "Observer.hh" 25#include "Observer.hh"
@@ -32,49 +32,49 @@ namespace FbTk {
32Subject::SubjectList Subject::s_subjectlist; 32Subject::SubjectList Subject::s_subjectlist;
33 33
34Subject::Subject() { 34Subject::Subject() {
35 s_subjectlist.push_back(this); 35 s_subjectlist.push_back(this);
36} 36}
37 37
38Subject::~Subject() { 38Subject::~Subject() {
39 SubjectList::iterator it = s_subjectlist.begin(); 39 SubjectList::iterator it = s_subjectlist.begin();
40 SubjectList::iterator it_end = s_subjectlist.end(); 40 SubjectList::iterator it_end = s_subjectlist.end();
41 for (; it != it_end; ++it) { 41 for (; it != it_end; ++it) {
42 if (this == (*it)) { 42 if (this == (*it)) {
43 s_subjectlist.erase(it); 43 s_subjectlist.erase(it);
44 break; 44 break;
45 } 45 }
46 } 46 }
47} 47}
48 48
49void Subject::attach(Observer *obj) { 49void Subject::attach(Observer *obj) {
50 m_observerlist.push_back(obj); 50 m_observerlist.push_back(obj);
51 // no need to have more than one instance of an observer 51 // no need to have more than one instance of an observer
52 std::unique(m_observerlist.begin(), m_observerlist.end()); 52 std::unique(m_observerlist.begin(), m_observerlist.end());
53} 53}
54 54
55void Subject::detach(Observer *obj) { 55void Subject::detach(Observer *obj) {
56 ObserverList::iterator it = m_observerlist.begin(); 56 ObserverList::iterator it = m_observerlist.begin();
57 ObserverList::iterator it_end = m_observerlist.end(); 57 ObserverList::iterator it_end = m_observerlist.end();
58 for (; it != it_end; ++it) { 58 for (; it != it_end; ++it) {
59 if (obj == (*it)) { 59 if (obj == (*it)) {
60 m_observerlist.erase(it); 60 m_observerlist.erase(it);
61 break; 61 break;
62 } 62 }
63 } 63 }
64} 64}
65 65
66void Subject::notify() { 66void Subject::notify() {
67 ObserverList::iterator it = m_observerlist.begin(); 67 ObserverList::iterator it = m_observerlist.begin();
68 for (; it != m_observerlist.end(); ++it) { 68 for (; it != m_observerlist.end(); ++it) {
69 (*it)->update(this); 69 (*it)->update(this);
70 } 70 }
71} 71}
72 72
73void Subject::removeObserver(Observer *obj) { 73void Subject::removeObserver(Observer *obj) {
74 SubjectList::iterator it = s_subjectlist.begin(); 74 SubjectList::iterator it = s_subjectlist.begin();
75 for(; it != s_subjectlist.end(); ++it) { 75 for(; it != s_subjectlist.end(); ++it) {
76 (*it)->detach(obj); 76 (*it)->detach(obj);
77 } 77 }
78} 78}
79 79
80}; // end namespace FbTk 80}; // end namespace FbTk