template<typename ListenerClass, typename ArrayType = Array<ListenerClass*>>
class juce::ListenerList< ListenerClass, ArrayType >
Holds a set of objects and can invoke a member function callback on each object in the set with a single call.
It is safe to add listeners, remove listeners, clear the listeners, and even delete the ListenerList itself during any listener callback. If you don't need these extra guarantees consider using a LightweightListenerList instead.
If a Listener is added during a callback, it is guaranteed not to be called in the same iteration.
If a Listener is removed during a callback, it is guaranteed not to be called if it hasn't already been called.
If the ListenerList is cleared or deleted during a callback, it is guaranteed that no more listeners will be called.
It is NOT safe to make concurrent calls to the listeners without a mutex. If you need this functionality, either use a LightweightListenerList or a ThreadSafeListenerList.
When calling listeners the iteration can be escaped early by using a "BailOutChecker". A BailOutChecker is a type that has a public member function with the following signature:
bool shouldBailOut() const
This function will be called before making a call to each listener. For an example see the DummyBailOutChecker.
- See also
- LightweightListenerList, ThreadSafeListenerList
|
| ListenerList ()=default |
| Creates an empty list.
|
| ~ListenerList () |
| Destructor.
|
void | add (ListenerClass *listenerToAdd) |
| Adds a listener to the list.
|
void | remove (ListenerClass *listenerToRemove) |
| Removes a listener from the list.
|
ErasedScopeGuard | addScoped (ListenerClass &listenerToAdd) |
| Adds a listener that will be automatically removed again when the Guard is destroyed.
|
int | size () const noexcept |
| Returns the number of registered listeners.
|
bool | isEmpty () const noexcept |
| Returns true if no listeners are registered, false otherwise.
|
void | clear () |
| Clears the list.
|
bool | contains (ListenerClass *listener) const noexcept |
| Returns true if the specified listener has been added to the list.
|
const ArrayType & | getListeners () const noexcept |
| Returns the raw array of listeners.
|
template<typename Callback> |
void | call (Callback &&callback) |
| Calls an invokable object for each listener in the list.
|
template<typename Callback> |
void | callExcluding (ListenerClass *listenerToExclude, Callback &&callback) |
| Calls an invokable object for each listener in the list, except for the listener specified by listenerToExclude.
|
template<typename Callback, typename BailOutCheckerType> |
void | callChecked (const BailOutCheckerType &bailOutChecker, Callback &&callback) |
| Calls an invokable object for each listener in the list, additionally checking the bail-out checker before each call.
|
template<typename Callback, typename BailOutCheckerType> |
void | callCheckedExcluding (ListenerClass *listenerToExclude, const BailOutCheckerType &bailOutChecker, Callback &&callback) |
| Calls an invokable object for each listener in the list, except for the listener specified by listenerToExclude, additionally checking the bail-out checker before each call.
|
template<typename... MethodArgs, typename... Args> |
void | call (void(ListenerClass::*callbackFunction)(MethodArgs...), Args &&... args) |
| Calls a specific listener method for each listener in the list.
|
template<typename... MethodArgs, typename... Args> |
void | callExcluding (ListenerClass *listenerToExclude, void(ListenerClass::*callbackFunction)(MethodArgs...), Args &&... args) |
| Calls a specific listener method for each listener in the list, except for the listener specified by listenerToExclude.
|
template<typename BailOutCheckerType, typename... MethodArgs, typename... Args> |
void | callChecked (const BailOutCheckerType &bailOutChecker, void(ListenerClass::*callbackFunction)(MethodArgs...), Args &&... args) |
| Calls a specific listener method for each listener in the list, additionally checking the bail-out checker before each call.
|
template<typename BailOutCheckerType, typename... MethodArgs, typename... Args> |
void | callCheckedExcluding (ListenerClass *listenerToExclude, const BailOutCheckerType &bailOutChecker, void(ListenerClass::*callbackFunction)(MethodArgs...), Args &&... args) |
| Calls a specific listener method for each listener in the list, except for the listener specified by listenerToExclude, additionally checking the bail-out checker before each call.
|
template<typename ListenerClass, typename ArrayType = Array<ListenerClass*>>
Adds a listener to the list.
A listener can only be added once, so if the listener is already in the list, this method has no effect.
If a Listener is added during a callback, it is guaranteed not to be called in the same iteration.
- See also
- remove
Referenced by addScoped().
template<typename ListenerClass, typename ArrayType = Array<ListenerClass*>>
template<typename Callback, typename BailOutCheckerType>
void juce::ListenerList< ListenerClass, ArrayType >::callCheckedExcluding |
( |
ListenerClass * | listenerToExclude, |
|
|
const BailOutCheckerType & | bailOutChecker, |
|
|
Callback && | callback ) |
|
inline |
template<typename ListenerClass, typename ArrayType = Array<ListenerClass*>>
template<typename BailOutCheckerType, typename... MethodArgs, typename... Args>
void juce::ListenerList< ListenerClass, ArrayType >::callCheckedExcluding |
( |
ListenerClass * | listenerToExclude, |
|
|
const BailOutCheckerType & | bailOutChecker, |
|
|
void(ListenerClass::* | callbackFunction )(MethodArgs...), |
|
|
Args &&... | args ) |
|
inline |
Calls a specific listener method for each listener in the list, except for the listener specified by listenerToExclude, additionally checking the bail-out checker before each call.
See the class description for info about writing a bail-out checker.