13 #ifndef __UT_Notifier_C__
14 #define __UT_Notifier_C__
20 template <
typename EVENT_TYPE>
22 : myNotifyingFlag( false ),
23 myPendingRemovalFlag( false )
27 template <
typename EVENT_TYPE>
34 template <
typename EVENT_TYPE>
40 for( i = 0; i < myObservers.entries(); i ++ )
41 if( myObservers(i).first == &list )
48 template <
typename EVENT_TYPE>
52 return ( 0 <= getObserverIndex( list ));
56 template <
typename EVENT_TYPE>
61 bool already_registered;
64 already_registered = hasObserver( list );
68 if( ! already_registered )
70 ObserverPair pair( &list, callback );
73 myObservers.append( pair );
79 template <
typename EVENT_TYPE>
86 i = getObserverIndex( list );
93 myObservers(i).first = NULL;
94 myPendingRemovalFlag =
true;
98 myObservers.removeIndex( i );
108 template <
typename EVENT_TYPE>
115 for( i = myObservers.entries(); i -- > 0; )
117 if( myObservers(i).first )
118 myObservers(i).first->removeNotifier( *
this );
119 myObservers.removeIndex( i );
123 template <
typename EVENT_TYPE>
130 for( i = myObservers.entries(); i -- > 0; )
131 if( myObservers(i).first == NULL )
132 myObservers.removeIndex( i );
135 myPendingRemovalFlag =
false;
138 template <
typename EVENT_TYPE>
146 old_notifying = myNotifyingFlag;
147 myNotifyingFlag =
true;
152 n = myObservers.entries();
153 for( i = 0; i <
n; i++ )
154 if( myObservers(i).
first )
155 myObservers(i).second( event );
158 myNotifyingFlag = old_notifying;
161 if( !myNotifyingFlag && myPendingRemovalFlag )
165 template <
typename EVENT_TYPE>
168 return myObservers.entries() > 0;
171 #endif // __UT_Notifier_C__
virtual void addNotifier(UT_Notifier ¬ifier)
virtual bool hasObserver(const UT_NotifierList &list) const
void removeObserver(UT_NotifierList &list) override
virtual void notifyObservers(EVENT_TYPE event)
~UT_NotifierImpl() override
virtual void removeNotifier(UT_Notifier ¬ifier)
bool hasObservers() const
virtual void addObserver(UT_NotifierList &list, Callback &callback)