core/vgui/vgui_observable.h
Go to the documentation of this file.
00001 // This is core/vgui/vgui_observable.h
00002 #ifndef vgui_observable_h_
00003 #define vgui_observable_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief  Base class for classes that want to broadcast messages to observers.
00010 // \author fsm
00011 //
00012 //  Contains class  vgui_observable.
00013 //
00014 // \verbatim
00015 //  Modifications
00016 //   17-Sep-2002 K.Y.McGaul - Added doxygen style comments.
00017 //   31-Jul-2010 Peter Vanroose - minor bug fix (operator= instead of operator==)
00018 // \endverbatim
00019 
00020 #include <vcl_vector.h>
00021 class vgui_observer;
00022 class vgui_message;
00023 
00024 
00025 //: Base class for classes that want to broadcast messages to observers.
00026 //
00027 //  Objects from classes derived from vgui_observable can broadcast a
00028 //  vgui_message or an update using notify() to all the vgui_observer's
00029 //  attached to themselves.
00030 class vgui_observable
00031 {
00032  public:
00033   //: Constructor - create a default observable.
00034   vgui_observable() { }
00035 
00036   //: Destructor.
00037   virtual ~vgui_observable();
00038 
00039   //: Attach the given observer to receive notify messages.
00040   void attach(vgui_observer*);
00041 
00042   //: Detach the given observer.
00043   void detach(vgui_observer*);
00044 
00045   //: Returns a list of all the observers for this observable.
00046   void get_observers(vcl_vector<vgui_observer*>&) const;
00047 
00048   //: Broadcast an update to all observers of this class.
00049   virtual void notify() const;
00050 
00051   //: Broadcast a message to all observers of this class.
00052   virtual void notify(const vgui_message &) const;
00053 
00054  private:
00055   //: List of all observers for this observable.
00056   vcl_vector<vgui_observer*> observers;
00057 
00058   //: Disallow assignment.
00059   vgui_observable(vgui_observable const&) { }
00060 
00061   //: Disallow assignment.
00062   vgui_observable& operator=(vgui_observable const&) { return *this; }
00063 };
00064 
00065 #endif // vgui_observable_h_