cgma
CubitObserver.hpp
Go to the documentation of this file.
00001 //- Class: CubitObserver
00002 //- Description: Observer class - *very* rudimentary implementation
00003 //- Owner:  Tim Tautges
00004 
00005 #ifndef CUBITOBSERVER_HPP
00006 #define CUBITOBSERVER_HPP
00007 
00008 #include "CubitDefines.h"
00009 #include "CubitEntity.hpp"
00010 #include "CubitEvent.hpp"
00011 #include "DLIList.hpp"
00012 #include "CGMUtilConfigure.h"
00013 
00014 class CubitObservable;
00015 
00016 class CUBIT_UTIL_EXPORT CubitObserver
00017 {
00018 public:
00019 
00020   CubitObserver();
00021   
00022   virtual ~CubitObserver();
00023 
00024   CubitStatus watch_observable(CubitObservable *observable)
00025     { return register_observable(observable); }
00026     //- Cause this observer to watch the specified observable.
00027   
00028     //- Request that this observer stop watching the specified observable
00029   CubitStatus stop_watching_observable(CubitObservable *observable)
00030     { return unregister_observable(observable); }
00031   
00032    
00033   virtual void notify_observer(const CubitEvent *observer_event) = 0;
00034     // This should be called through the
00035     // CubitObservable::notify_observers generic notify function.
00036     // NOTE: VERY IMPORTANT: when implementing this function, leaf
00037     // classes should call register_observable() or
00038     // unregister_observable() if the event is one of construction or
00039     // destruction, resp.; this makes sure the observable knows we're
00040     // observing it, or unhooks us from the observable.  A count of
00041     // observables being observed is also kept, to prevent stale
00042     // pointers on observables
00043 
00044   CubitStatus register_observable(CubitObservable *observable);
00045     //- Cause this observer to watch the specified observable.
00046   
00047   CubitStatus unregister_observable(CubitObservable *observable);
00048     //- remove this observer from the observable's list, and if successful,
00049     //- decrement the observable count  
00050 
00052   static CubitStatus register_observer(CubitObserver* obs);
00054   static CubitStatus unregister_observer(CubitObserver* obs);
00055 
00056 private:
00057 
00058   int observableCount;
00059     //- number of observables to which this observer is registered
00060 }; // 
00061 
00062 #endif
00063 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines