Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Observable.cxx

Go to the documentation of this file.
00001 
00012 #ifdef HAVE_CONFIG_H
00013 #include "config.h"
00014 #else
00015 #ifdef _MSC_VER
00016 #include "msdevstudio/MSconfig.h"
00017 #endif
00018 #endif
00019 
00020 #include "Observable.h"
00021 
00022 #include "Observer.h"
00023 
00024 #include <algorithm>
00025 #include <functional>
00026 
00027 #ifdef ITERATOR_MEMBER_DEFECT
00028 using namespace std;
00029 #else
00030 using std::bind2nd;
00031 using std::for_each;
00032 using std::list;
00033 using std::mem_fun;
00034 #endif
00035 
00036 Observable::Observable ()
00037 {
00038   m_list.clear();
00039 }
00040 
00041 /* virtual */
00042 Observable::~ Observable ()
00043 {
00044   // Don't need to do anything because the list will clear itself when
00045   // it is destroyed
00046 }
00047 
00048 /* virtual */
00049 void Observable::addObserver ( hippodraw::Observer * observer )
00050 {
00051   m_list.push_back ( observer );
00052 }
00053 
00054 /* virtual */
00055 const Observable::ObserverList_t &
00056 Observable::
00057 getObservers ( ) const
00058 {
00059   return m_list;
00060 }
00061 
00062 /* virtual */
00063 void Observable::removeObserver ( hippodraw::Observer * observer )
00064 {
00065   m_list.remove ( observer );
00066 }
00067 
00068 /* virtual */
00069 void Observable::notifyObservers ( Action action ) const
00070 {
00071 #ifdef BIND2ND_DEFECT
00072 //   list < Observer * >::const_iterator first = m_list.begin ();
00073   ObserverList_t::const_iterator first = m_list.begin ();
00074 
00075   for ( ; first != m_list.end (); ++first ) {
00076     ( (*first)->*action ) ( this );
00077   }
00078 #else
00079 #ifdef MEMFUN1_DEFECT
00080   for_each ( m_list.begin (), m_list.end (),
00081              bind2nd ( mem_fun1 ( action ), this ) );
00082 #else
00083   for_each ( m_list.begin (), m_list.end (),
00084              bind2nd ( mem_fun ( action ), this ) );
00085 #endif
00086 #endif
00087 }
00088 
00089 /* virtual */
00090 void Observable::notifyObservers ( ) const
00091 {
00092   notifyObservers ( &hippodraw::Observer::update );
00093 }

Generated for HippoDraw-1.14.8.5 by doxygen 1.4.3