00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Rafal Jaroszkiewicz 00008 * Side Effects Software Inc 00009 * 477 Richmond Street West 00010 * Toronto, Ontario 00011 * Canada M5V 3E7 00012 * 416-504-9876 00013 * 00014 * NAME: UT_NotifierList.h ( UT Library, C++) 00015 * 00016 * COMMENTS: An list that keeps track of the notifiers. It is 00017 * used by classes that register callbacks with notifiers. 00018 * Its main function is to unregister any callbacks with 00019 * all the notifiers that still would invoke them at the 00020 * destruction time of the notifier list. 00021 * 00022 * Notifier list should be a member variable (not a reference 00023 * or a pointer to a list) of the class that owns 00024 * the methods registered with the notifiers. This way the 00025 * destructor of the UT_NotifierList will be invoked when 00026 * the class with callbacks is destroyed, and the notifiers 00027 * will unregister the callbacks through the UT_NotifierList 00028 * destructor. 00029 * 00030 * 00031 * HOW TO SET UP THE NOTIFIER AND THE CALLBACK: 00032 * 00033 * see UT_Notifier.h for the instructions 00034 */ 00035 00036 #ifndef __UT_NotifierList_h__ 00037 #define __UT_NotifierList_h__ 00038 00039 #include "UT_API.h" 00040 #include "UT_PtrArray.h" 00041 00042 class UT_Notifier; 00043 00044 class UT_API UT_NotifierList 00045 { 00046 public: 00047 // constructor 00048 UT_NotifierList(); 00049 virtual ~UT_NotifierList(); 00050 00051 // ---------------------------------------------------------------------- 00052 // Removes all notifiers from the private list of notifiers. 00053 // Also asks each of these notifiers to remove the observer 00054 // associated with this list from the notifier's own list of observers. 00055 // ---------------------------------------------------------------------- 00056 virtual void removeAllNotifiers(); 00057 00058 00059 protected: 00060 00061 // NB: only UT_NotifierImpl should call addNotifier() and removeNotifier() 00062 // when it registers and unregisters callbacks. We thus make these 00063 // two methods protected and make the UT_NotifierImpl the friend 00064 // of this class (UT_NotifierList). But, UT_NotifierImpl should not 00065 // use any private members, especially the private list itself. 00066 template <typename T> friend class UT_NotifierImpl; 00067 00068 // adds the notifier to private list of notifiers 00069 virtual void addNotifier( UT_Notifier ¬ifier ); 00070 00071 // removes the notifier from private list of notifiers 00072 virtual void removeNotifier( UT_Notifier ¬ifier ); 00073 00074 private: 00075 00076 // a list of notifiers in which we expressed an interst. 00077 // This list is kept around so that when we are destructed, we know 00078 // from which notifiers we need to remove interest. Otherwise, 00079 // notifiers may use nonexistent observers leading to core dump. 00080 UT_PtrArray< UT_Notifier * > myNotifiers; 00081 }; 00082 00083 #endif //__UT_NotifierList_h__
1.5.9