cgma
CubitObservable.hpp
Go to the documentation of this file.
00001 //- Class: CubitObservable
00002 //- Description: Observable class - *very* rudimentary implementation
00003 //- Owner:  Tim Tautges
00004 
00005 #ifndef CUBITOBSERVABLE_HPP
00006 #define CUBITOBSERVABLE_HPP
00007 
00008 #include "CubitDefines.h"
00009 #include "DLIList.hpp" 
00010 #include "CGMUtilConfigure.h"
00011 
00012 class CubitEvent;
00013 class CubitObserver;
00014 
00015 class CUBIT_UTIL_EXPORT CubitObservable
00016 {
00017 
00018 public:
00019 
00020   friend class CubitObserver;
00021   friend class CubitEventDispatcher;
00022 
00023   CubitObservable();
00024   
00025   virtual ~CubitObservable();
00026 
00027   void get_observer_list(DLIList<CubitObserver*> &observers);
00028     //- copy the observer list; return just the non-null observers.
00029 
00030   void notify_observers( const CubitEvent *event );
00031     //R CubitStatus
00032     //R- An AND of the result returned by each observer for the event.
00033     //- Notify all observers of an event.
00034     //- Process will proceed even if an observer returns failure for
00035     //- a notification.
00036 
00037 protected:
00038   void remove_from_observers();
00039     //- unregister this observable from all observers       
00040 
00041 
00042     //- IMPORTANT: keep add_observer and remove_observer private,
00043     //- so that they can only be accessed from CubitObserver; all register/
00044     //- unregister actions go through CubitObserver!!!
00045   virtual CubitStatus add_observer(CubitObserver *observer);
00046     //- add the observer to this observable; returns CUBIT_FAILURE
00047     //- if this observer contained this observable already
00048 
00049   virtual CubitStatus remove_observer(CubitObserver *observer);
00050     //- remove the observer from this observable; returns CUBIT_SUCCESS
00051     //- if this observable contained this observer
00052 
00053   DLIList <CubitObserver*> *observerList;
00054     //- pointer to list of observers of this entity
00055     //- This list may contain NULL pointers. This is used to make sure
00056     //- each observer is notified once and only once.
00057 
00058     CubitObservable( const CubitObservable& );
00059     void operator=( const CubitObservable&);
00060 }; // 
00061 
00062 #endif
00063 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines