HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_NotifierList.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_NotifierList.h ( UT Library, C++)
7  *
8  * COMMENTS: An list that keeps track of the notifiers. It is
9  * used by classes that register callbacks with notifiers.
10  * Its main function is to unregister any callbacks with
11  * all the notifiers that still would invoke them at the
12  * destruction time of the notifier list.
13  *
14  * Notifier list should be a member variable (not a reference
15  * or a pointer to a list) of the class that owns
16  * the methods registered with the notifiers. This way the
17  * destructor of the UT_NotifierList will be invoked when
18  * the class with callbacks is destroyed, and the notifiers
19  * will unregister the callbacks through the UT_NotifierList
20  * destructor.
21  *
22  *
23  * HOW TO SET UP THE NOTIFIER AND THE CALLBACK:
24  *
25  * see UT_Notifier.h for the instructions
26  */
27 
28 #ifndef __UT_NotifierList_h__
29 #define __UT_NotifierList_h__
30 
31 #include "UT_API.h"
32 #include "UT_ValArray.h"
33 
34 class UT_Notifier;
35 
37 {
38 public:
39  // constructor
41  virtual ~UT_NotifierList();
42 
43  // ----------------------------------------------------------------------
44  // Removes all notifiers from the private list of notifiers.
45  // Also asks each of these notifiers to remove the observer
46  // associated with this list from the notifier's own list of observers.
47  // ----------------------------------------------------------------------
48  virtual void removeAllNotifiers();
49 
50 
51 protected:
52 
53  // NB: only UT_NotifierImpl should call addNotifier() and removeNotifier()
54  // when it registers and unregisters callbacks. We thus make these
55  // two methods protected and make the UT_NotifierImpl the friend
56  // of this class (UT_NotifierList). But, UT_NotifierImpl should not
57  // use any private members, especially the private list itself.
58  template <typename T> friend class UT_NotifierImpl;
59 
60  // adds the notifier to private list of notifiers
61  virtual void addNotifier( UT_Notifier &notifier );
62 
63  // removes the notifier from private list of notifiers
64  virtual void removeNotifier( UT_Notifier &notifier );
65 
66 private:
67 
68  // a list of notifiers in which we expressed an interst.
69  // This list is kept around so that when we are destructed, we know
70  // from which notifiers we need to remove interest. Otherwise,
71  // notifiers may use nonexistent observers leading to core dump.
72  UT_ValArray< UT_Notifier * > myNotifiers;
73 };
74 
75 #endif //__UT_NotifierList_h__
#define UT_API
Definition: UT_API.h:13