00001 /****************************************************************** 00002 * CAVERNsoft 00003 * Copyright (C) 1994-2000 Electronic Visualization Laboratory, 00004 * all rights reserved 00005 * By Jason Leigh, Yong-joo Cho, Naveen Krishnaprasad, Chris Scharver, 00006 * Stuart Bailey, Atul Nayak, Shalini Venkataraman 00007 * University of Illinois at Chicago 00008 * 00009 * This publication and its text and code may not be copied for commercial 00010 * use without the express written permission of the University of Illinois 00011 * at Chicago 00012 * The contributors disclaim any representation of warranty: use this 00013 * code at your own risk. 00014 * Direct questions, comments etc to cavern@evl.uic.edu 00015 ******************************************************************/ 00016 00017 // Based almost entirely on the work of Russel Winder 00018 00019 #ifndef _CAVERNmisc_observer_c 00020 #define _CAVERNmisc_observer_c 00021 00022 #ifdef WIN32 00023 #include <list> 00024 using namespace std; 00025 #else 00026 #include <list.h> 00027 #endif 00028 00029 00030 00031 class CAVERNmisc_subject_c ; 00032 00046 class CAVERNmisc_observer_c 00047 { 00048 public: 00049 virtual ~CAVERNmisc_observer_c() {} ; 00050 00051 00059 virtual void update(CAVERNmisc_subject_c * ) = 0 ; 00060 protected: 00061 CAVERNmisc_observer_c() {} 00062 00063 }; 00064 00078 class CAVERNmisc_subject_c 00079 { 00080 public: 00081 virtual ~CAVERNmisc_subject_c() {}; 00082 00089 virtual void attach(CAVERNmisc_observer_c *) ; 00090 00091 00098 virtual void detach(CAVERNmisc_observer_c *) ; 00099 00100 00105 virtual void notify() ; 00106 private: 00107 list<CAVERNmisc_observer_c *> m_ListOfObservers ; 00108 }; 00109 00110 00111 inline void CAVERNmisc_subject_c::attach(CAVERNmisc_observer_c *o) 00112 { 00113 m_ListOfObservers.push_back(o) ; 00114 } 00115 00116 inline void CAVERNmisc_subject_c::detach(CAVERNmisc_observer_c *o) 00117 { 00118 m_ListOfObservers.remove(o) ; 00119 } 00120 00121 inline void CAVERNmisc_subject_c::notify() 00122 { 00123 00124 for (list<CAVERNmisc_observer_c *>::iterator i = m_ListOfObservers.begin() ; 00125 i != m_ListOfObservers.end() ; 00126 ++i) { 00127 (*i)->update(this) ; 00128 } 00129 } 00130 00131 #endif