ReFRACtor
|
Mixin for a class that allows other classes to observe it state. More...
#include <observer.h>
Classes | |
class | PointerDead |
class | PointerEqual |
Public Member Functions | |
virtual | ~Observable () |
virtual void | add_observer (Observer< T > &Obs)=0 |
Add an observer. More... | |
void | add_observer_and_keep_reference (boost::shared_ptr< Observer< T > > &Obs) |
Add an observer and keep a reference to it. More... | |
virtual void | remove_observer (Observer< T > &Obs)=0 |
Remove an observer. More... | |
Protected Member Functions | |
void | add_observer_do (Observer< T > &Obs, T &t) |
Add an observer. More... | |
void | add_observer_do (Observer< T > &Obs) |
void | clean_dead_ptr () |
Remove any dead pointers. More... | |
void | notify_update_do (const T &Self) |
Function to call to notify Observers of a state change. More... | |
void | remove_observer_do (Observer< T > &Obs, T &t) |
Remove an observer. More... | |
void | remove_observer_do (Observer< T > &Obs) |
Protected Attributes | |
std::list< boost::weak_ptr< Observer< T > > > | olist |
std::vector< boost::shared_ptr< Observer< T > > > | ref_list |
Mixin for a class that allows other classes to observe it state.
When the object state has been updated, the class should call notify_update.
A note on lifetime of objects. When an Observer is destroyed, nothing special needs to be done. The Observable is automatically notified that the Object no longer exists, and shouldn't receive notify_update messages anymore. Likewise, nothing special happens when the Observable is destroyed, this Observe simple receives no more messages from that Observable since it never changes after it is dead.
In some cases, you might actually want the lifetime of the Observer to be controlled by the Observable. This would be for a class that has no other purpose than to observe another class, say something that writes out diagnostic messages whenever a StateVector is updated or something like that. In those cases, you can use the add_observer_and_keep_reference instead of just add_observer. This stashes a copy of the RefPtr so that as long as the Observable exists the registered Observer will also.
The relationship between Observer and Observable is m to n, a Observer can be attached to any number of Observables, and likewise an Observable can have any number of Observers attached.
Definition at line 12 of file observer.h.
|
inlinevirtual |
Definition at line 93 of file observer.h.
|
pure virtual |
Add an observer.
Implemented in FullPhysics::StandardForwardModel, FullPhysics::IterativeSolver, FullPhysics::ConnorSolver, FullPhysics::RtAtmosphere, FullPhysics::RadiativeTransferFixedStokesCoefficient, FullPhysics::Pressure, FullPhysics::Absorber, FullPhysics::Aerosol, FullPhysics::AerosolProperty, FullPhysics::Ground, FullPhysics::Temperature, FullPhysics::AerosolExtinction, FullPhysics::StateVector, FullPhysics::Altitude, FullPhysics::Instrument, FullPhysics::SurfaceTemperature, FullPhysics::AbsorberVmr, FullPhysics::InstrumentCorrection, FullPhysics::RadiativeTransferRetrievable, FullPhysics::SpectrumEffect, FullPhysics::Ils, FullPhysics::Dispersion, and FullPhysics::StokesCoefficient.
|
inline |
Add an observer and keep a reference to it.
See the discussion in the Observer class description for details.
Definition at line 107 of file observer.h.
|
inlineprotected |
Add an observer.
Definition at line 148 of file observer.h.
|
inlineprotected |
Definition at line 159 of file observer.h.
|
inlineprotected |
Remove any dead pointers.
Definition at line 196 of file observer.h.
|
inlineprotected |
Function to call to notify Observers of a state change.
The object should pass itself to this function, so it can be passed to the Observers.
Definition at line 121 of file observer.h.
|
pure virtual |
Remove an observer.
Implemented in FullPhysics::StandardForwardModel, FullPhysics::IterativeSolver, FullPhysics::ConnorSolver, FullPhysics::RtAtmosphere, FullPhysics::RadiativeTransferFixedStokesCoefficient, FullPhysics::Pressure, FullPhysics::Absorber, FullPhysics::Aerosol, FullPhysics::AerosolProperty, FullPhysics::Ground, FullPhysics::Temperature, FullPhysics::AerosolExtinction, FullPhysics::StateVector, FullPhysics::SurfaceTemperature, FullPhysics::Altitude, FullPhysics::Instrument, FullPhysics::AbsorberVmr, FullPhysics::InstrumentCorrection, FullPhysics::RadiativeTransferRetrievable, FullPhysics::SpectrumEffect, FullPhysics::Ils, FullPhysics::Dispersion, and FullPhysics::StokesCoefficient.
|
inlineprotected |
Remove an observer.
Definition at line 173 of file observer.h.
|
inlineprotected |
Definition at line 181 of file observer.h.
|
protected |
Definition at line 200 of file observer.h.
|
protected |
Definition at line 201 of file observer.h.