Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
berry::ListenerList< T, C > Class Template Reference

#include <berryListenerList.h>

Public Member Functions

void Add (const T &listener)
 
QList< T > GetListeners () const
 
bool IsEmpty () const
 
void Remove (const T &listener)
 
int Size () const
 
void Clear ()
 

Detailed Description

template<class T, typename C = ListenerListEquals>
class berry::ListenerList< T, C >

This class is a thread safe list that is designed for storing lists of listeners. The implementation is optimized for minimal memory footprint, frequent reads and infrequent writes. Modification of the list is synchronized and relatively expensive, while accessing the listeners is very fast. Readers are given access to the underlying array data structure for reading, with the trust that they will not modify the underlying array.

A listener list handles the same listener being added multiple times, and tolerates removal of listeners that are the same as other listeners in the list. For this purpose, listeners can be compared with each other using a custom comparison functor.

Use the GetListeners method when notifying listeners. The recommended code sequence for notifying all registered listeners of say, FooListener::EventHappened(), is:

QList<FooListener*> listeners = myListenerList.GetListeners();
for (int i = 0; i &lt; listeners.size(); ++i)
{
listeners[i]->EventHappened(event);
}

Definition at line 63 of file berryListenerList.h.

Member Function Documentation

template<class T , typename C = ListenerListEquals>
void berry::ListenerList< T, C >::Add ( const T &  listener)
inline

Adds a listener to this list. This method has no effect if the same listener is already registered.

Parameters
listenerthe non-null listener to add

Definition at line 74 of file berryListenerList.h.

template<class T , typename C = ListenerListEquals>
void berry::ListenerList< T, C >::Clear ( )
inline

Removes all listeners from this list.

Definition at line 159 of file berryListenerList.h.

template<class T , typename C = ListenerListEquals>
QList<T> berry::ListenerList< T, C >::GetListeners ( ) const
inline

Returns an array containing all the registered listeners. The resulting array is unaffected by subsequent adds or removes. If there are no listeners registered, the result is an empty array. Use this method when notifying listeners, so that any modifications to the listener list during the notification will have no effect on the notification itself.

Warning
Callers of this method must not modify the returned array.
Returns
the list of registered listeners

Definition at line 104 of file berryListenerList.h.

template<class T , typename C = ListenerListEquals>
bool berry::ListenerList< T, C >::IsEmpty ( ) const
inline

Returns whether this listener list is empty.

Returns
true if there are no registered listeners, and false otherwise

Definition at line 116 of file berryListenerList.h.

template<class T , typename C = ListenerListEquals>
void berry::ListenerList< T, C >::Remove ( const T &  listener)
inline

Removes a listener from this list. Has no effect if the same listener was not already registered.

Parameters
listenerthe listener to remove

Definition at line 128 of file berryListenerList.h.

template<class T , typename C = ListenerListEquals>
int berry::ListenerList< T, C >::Size ( void  ) const
inline

Returns the number of registered listeners.

Returns
the number of registered listeners

Definition at line 150 of file berryListenerList.h.


The documentation for this class was generated from the following file: