Observable.cxx
Go to the documentation of this file.
1 
12 // for memfun1
13 #ifdef HAVE_CONFIG_H
14 #include "config.h"
15 #else
16 #ifdef _MSC_VER
17 #include "msdevstudio/MSconfig.h"
18 #endif
19 #endif
20 
21 #include "Observable.h"
22 
23 #include "Observer.h"
24 
25 #include <algorithm>
26 #include <functional>
27 
28 #ifdef ITERATOR_MEMBER_DEFECT
29 using namespace std;
30 #else
31 using std::bind2nd;
32 using std::for_each;
33 using std::list;
34 using std::mem_fun;
35 #endif
36 
37 using namespace hippodraw;
38 
39 Observable::Observable ()
40 {
41 // m_list.clear();
42 }
43 
44 /* virtual */
45 Observable::~ Observable ()
46 {
47  // Don't need to do anything because the list will clear itself when
48  // it is destroyed
49 }
50 
51 /* virtual */
52 void Observable::addObserver ( hippodraw::Observer * observer )
53 {
54  m_list.push_back ( observer );
55 }
56 
57 /* virtual */
59 Observable::
60 getObservers ( ) const
61 {
62  return m_list;
63 }
64 
65 /* virtual */
66 void Observable::removeObserver ( hippodraw::Observer * observer )
67 {
68  m_list.remove ( observer );
69 }
70 
71 /* virtual */
72 void Observable::notifyObservers ( Action action ) const
73 {
74 #ifdef BIND2ND_DEFECT
75 // list < Observer * >::const_iterator first = m_list.begin ();
76  ObserverList_t::const_iterator first = m_list.begin ();
77 
78  for ( ; first != m_list.end (); ++first ) {
79  ( (*first)->*action ) ( this );
80  }
81 #else
82 #ifdef MEMFUN1_DEFECT
83  for_each ( m_list.begin (), m_list.end (),
84  bind2nd ( mem_fun1 ( action ), this ) );
85 #else
86  for_each ( m_list.begin (), m_list.end (),
87  bind2nd ( mem_fun ( action ), this ) );
88 #endif
89 #endif
90 }
91 
92 /* virtual */
93 void Observable::notifyObservers ( ) const
94 {
95  notifyObservers ( &hippodraw::Observer::update );
96 }

Generated for HippoDraw Class Library by doxygen