Holds a set of objects and can invoke a member function callback on each object in the set with a single call. More...
#include <juce_ListenerList.h>


Classes | |
| struct | DummyBailOutChecker |
| A dummy bail-out checker that always returns false. More... | |
| struct | Iterator |
Public Types | |
| using | ListenerType = ListenerClass |
| using | ThisType = ListenerList< ListenerClass, ArrayType > |
Public Member Functions | |
| ListenerList ()=default | |
| Creates an empty list. | |
| ~ListenerList () | |
| Destructor. | |
| void | add (ListenerClass *listenerToAdd) |
| Adds a listener to the list. | |
| ErasedScopeGuard | addScoped (ListenerClass &listenerToAdd) |
| Adds a listener that will be automatically removed again when the Guard is destroyed. | |
| template<typename Callback > | |
| void | call (Callback &&callback) |
| Calls an invokable object for each listener in the list. | |
| 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 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 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 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 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 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... 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. | |
| 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. | |
| bool | isEmpty () const noexcept |
| Returns true if no listeners are registered, false otherwise. | |
| void | remove (ListenerClass *listenerToRemove) |
| Removes a listener from the list. | |
| int | size () const noexcept |
| Returns the number of registered listeners. | |
Private Types | |
| using | SafeIterators = std::vector< Iterator * > |
| using | ScopedLockType = typename ArrayType::ScopedLockType |
| using | SharedIterators = std::shared_ptr< SafeIterators > |
| using | SharedListeners = std::shared_ptr< ArrayType > |
| enum class | State { uninitialised , initialising , initialised } |
Private Member Functions | |
| bool | initialised () const noexcept |
| void | initialiseIfNeeded () noexcept |
Private Attributes | |
| SharedIterators | iterators |
| SharedListeners | listeners |
| std::atomic< State > | state { State::uninitialised } |
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:
This function will be called before making a call to each listener. For an example see the DummyBailOutChecker.
@tags{Core}
| using juce::ListenerList< ListenerClass, ArrayType >::ListenerType = ListenerClass |
|
private |
|
private |
|
private |
|
private |
| using juce::ListenerList< ListenerClass, ArrayType >::ThisType = ListenerList<ListenerClass, ArrayType> |
|
strongprivate |
|
default |
Creates an empty list.
|
inline |
Destructor.
References juce::ListenerList< ListenerClass, ArrayType >::clear().
|
inline |
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.
References juce::ListenerList< ListenerClass, ArrayType >::initialiseIfNeeded(), jassertfalse, and juce::ListenerList< ListenerClass, ArrayType >::listeners.
Referenced by juce::OpenGLContext::NativeContext::addListener(), and juce::ListenerList< ListenerClass, ArrayType >::addScoped().
|
inline |
Adds a listener that will be automatically removed again when the Guard is destroyed.
Be very careful to ensure that the ErasedScopeGuard is destroyed or released before the ListenerList is destroyed, otherwise the ErasedScopeGuard may attempt to dereference a dangling pointer when it is destroyed, which will result in a crash.
References juce::ListenerList< ListenerClass, ArrayType >::add(), and juce::ListenerList< ListenerClass, ArrayType >::remove().
|
inline |
Calls an invokable object for each listener in the list.
References juce::ListenerList< ListenerClass, ArrayType >::callCheckedExcluding().
Referenced by juce::OpenGLContext::NativeContext::notifyDidResume(), and juce::OpenGLContext::NativeContext::notifyWillPause().
|
inline |
Calls a specific listener method for each listener in the list.
References juce::ListenerList< ListenerClass, ArrayType >::callCheckedExcluding().
|
inline |
Calls an invokable object for each listener in the list, additionally checking the bail-out checker before each call.
See the class description for info about writing a bail-out checker.
References juce::ListenerList< ListenerClass, ArrayType >::callCheckedExcluding().
|
inline |
Calls a specific listener method for each listener in the list, additionally checking the bail-out checker before each call.
See the class description for info about writing a bail-out checker.
References juce::ListenerList< ListenerClass, ArrayType >::callCheckedExcluding().
|
inline |
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.
See the class description for info about writing a bail-out checker.
References juce::ListenerList< ListenerClass, ArrayType >::Iterator::end, juce::ListenerList< ListenerClass, ArrayType >::initialised(), juce::GenericScopedTryLock< LockType >::isLocked(), juce::ListenerList< ListenerClass, ArrayType >::iterators, jassert, and juce::ListenerList< ListenerClass, ArrayType >::listeners.
Referenced by juce::ListenerList< ListenerClass, ArrayType >::call(), juce::ListenerList< ListenerClass, ArrayType >::call(), juce::ListenerList< ListenerClass, ArrayType >::callChecked(), juce::ListenerList< ListenerClass, ArrayType >::callChecked(), juce::ListenerList< ListenerClass, ArrayType >::callCheckedExcluding(), juce::ListenerList< ListenerClass, ArrayType >::callExcluding(), and juce::ListenerList< ListenerClass, ArrayType >::callExcluding().
|
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.
References juce::ListenerList< ListenerClass, ArrayType >::callCheckedExcluding().
|
inline |
Calls an invokable object for each listener in the list, except for the listener specified by listenerToExclude.
References juce::ListenerList< ListenerClass, ArrayType >::callCheckedExcluding().
|
inline |
Calls a specific listener method for each listener in the list, except for the listener specified by listenerToExclude.
References juce::ListenerList< ListenerClass, ArrayType >::callCheckedExcluding().
|
inline |
Clears the list.
If the ListenerList is cleared during a callback, it is guaranteed that no more listeners will be called.
References juce::ListenerList< ListenerClass, ArrayType >::initialised(), juce::ListenerList< ListenerClass, ArrayType >::iterators, and juce::ListenerList< ListenerClass, ArrayType >::listeners.
Referenced by juce::ListenerList< ListenerClass, ArrayType >::~ListenerList().
|
inlinenoexcept |
Returns true if the specified listener has been added to the list.
References juce::ListenerList< ListenerClass, ArrayType >::initialised(), and juce::ListenerList< ListenerClass, ArrayType >::listeners.
|
inlinenoexcept |
Returns the raw array of listeners.
Any attempt to mutate the array may result in undefined behaviour.
If the array uses a mutex/CriticalSection, reading from the array without first obtaining the lock may potentially result in undefined behaviour.
References juce::ListenerList< ListenerClass, ArrayType >::initialiseIfNeeded(), and juce::ListenerList< ListenerClass, ArrayType >::listeners.
|
inlineprivatenoexcept |
References juce::ListenerList< ListenerClass, ArrayType >::initialised, and juce::ListenerList< ListenerClass, ArrayType >::state.
Referenced by juce::ListenerList< ListenerClass, ArrayType >::callCheckedExcluding(), juce::ListenerList< ListenerClass, ArrayType >::clear(), juce::ListenerList< ListenerClass, ArrayType >::contains(), juce::ListenerList< ListenerClass, ArrayType >::initialiseIfNeeded(), juce::ListenerList< ListenerClass, ArrayType >::isEmpty(), juce::ListenerList< ListenerClass, ArrayType >::remove(), and juce::ListenerList< ListenerClass, ArrayType >::size().
|
inlineprivatenoexcept |
References juce::ListenerList< ListenerClass, ArrayType >::initialised, juce::ListenerList< ListenerClass, ArrayType >::initialised(), juce::ListenerList< ListenerClass, ArrayType >::initialising, juce::ListenerList< ListenerClass, ArrayType >::iterators, juce::ListenerList< ListenerClass, ArrayType >::listeners, juce::ListenerList< ListenerClass, ArrayType >::state, and juce::ListenerList< ListenerClass, ArrayType >::uninitialised.
Referenced by juce::ListenerList< ListenerClass, ArrayType >::add(), and juce::ListenerList< ListenerClass, ArrayType >::getListeners().
|
inlinenoexcept |
Returns true if no listeners are registered, false otherwise.
References juce::ListenerList< ListenerClass, ArrayType >::initialised(), and juce::ListenerList< ListenerClass, ArrayType >::listeners.
|
inline |
Removes a listener from the list.
If the listener wasn't in the list, this has no effect.
If a Listener is removed during a callback, it is guaranteed not to be called if it hasn't already been called.
References juce::end(), juce::ListenerList< ListenerClass, ArrayType >::initialised(), juce::ListenerList< ListenerClass, ArrayType >::iterators, jassert, and juce::ListenerList< ListenerClass, ArrayType >::listeners.
Referenced by juce::ListenerList< ListenerClass, ArrayType >::addScoped(), and juce::OpenGLContext::NativeContext::removeListener().
|
inlinenoexcept |
Returns the number of registered listeners.
References juce::ListenerList< ListenerClass, ArrayType >::initialised(), and juce::ListenerList< ListenerClass, ArrayType >::listeners.
|
private |
|
private |
Referenced by juce::ListenerList< ListenerClass, ArrayType >::add(), juce::ListenerList< ListenerClass, ArrayType >::callCheckedExcluding(), juce::ListenerList< ListenerClass, ArrayType >::clear(), juce::ListenerList< ListenerClass, ArrayType >::contains(), juce::ListenerList< ListenerClass, ArrayType >::getListeners(), juce::ListenerList< ListenerClass, ArrayType >::initialiseIfNeeded(), juce::ListenerList< ListenerClass, ArrayType >::isEmpty(), juce::ListenerList< ListenerClass, ArrayType >::remove(), and juce::ListenerList< ListenerClass, ArrayType >::size().
|
private |