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