5 #include <boost/shared_ptr.hpp> 6 #include <boost/weak_ptr.hpp> 7 #include <boost/foreach.hpp> 106 void add_observer_and_keep_reference
108 { ref_list.push_back(Obs); add_observer(*Obs); }
114 virtual void remove_observer(
Observer<T>& Obs) = 0;
124 BOOST_FOREACH(boost::weak_ptr<
Observer<T> >& t, olist) {
127 t2->notify_update(Self);
140 {
return w.lock().get() == t_; }
150 PointerEqual
p(Obs.this_obj.get());
151 bool already_added = std::find_if(olist.begin(), olist.end(),
p) != olist.end();
152 if (!already_added) {
153 olist.push_back(boost::weak_ptr<
Observer<T> >(Obs.this_obj));
161 PointerEqual
p(Obs.this_obj.get());
162 bool already_added = std::find_if(olist.begin(), olist.end(),
p) != olist.end();
163 if (!already_added) {
164 olist.push_back(boost::weak_ptr<
Observer<T> >(Obs.this_obj));
175 PointerEqual
p(Obs.this_obj.get());
183 PointerEqual
p(Obs.this_obj.get());
191 {
return w.expired(); }
200 std::list<boost::weak_ptr<Observer<T> > >
olist;
201 std::vector<boost::shared_ptr<Observer<T> > >
ref_list;
bool operator()(const boost::weak_ptr< Observer< T > > &w)
void remove_observer_do(Observer< T > &Obs)
virtual void notify_add(T &Observed_object)
Called when an object is added to an Observable.
virtual void notify_remove(T &Observed_object)
Called when an object is removed from an Observable.
std::vector< boost::shared_ptr< Observer< T > > > ref_list
void clean_dead_ptr()
Remove any dead pointers.
std::list< boost::weak_ptr< Observer< T > > > olist
void add_observer_do(Observer< T > &Obs, T &t)
Add an observer.
boost::shared_ptr< T > to_ptr(T &t)
Helper routine to get a shared_ptr from a reference.
void remove_observer_do(Observer< T > &Obs, T &t)
Remove an observer.
void notify_update_do(const T &Self)
Function to call to notify Observers of a state change.
virtual void notify_update(const T &Observed_object)
Called when the Observed object is updated.
Mixin for a class that allows other classes to observe it state.
bool operator()(const boost::weak_ptr< Observer< T > > &w)
virtual void notify_add()
void add_observer_do(Observer< T > &Obs)
Contains classes to abstract away details in various Spurr Radiative Transfer software.
For use with SWIG, it is useful to have a base class that everything can be cast to.
PointerEqual(Observer< T > *t)
Simple Mixin to be and Observer of another object of class T.
virtual void notify_remove()