A lightweight version of the ListenerList that doesn't provide any guarantees when mutating the list from a callback, but allows callbacks to be triggered concurrently without a mutex. More...
#include <juce_ListenerList.h>
Public Types | |
using | DummyBailOutChecker = typename ListenerList<ListenerClass>::DummyBailOutChecker |
A dummy bail-out checker that always returns false. | |
using | ThisType = LightweightListenerList<ListenerClass> |
using | ListenerType = ListenerClass |
Public Member Functions | |
LightweightListenerList ()=default | |
Creates an empty list. | |
~LightweightListenerList () | |
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 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. | |
template<typename Callback > | |
void | call (Callback &&callback) const |
Calls an invokable object for each listener in the list. | |
template<typename Callback > | |
void | callExcluding (ListenerClass *listenerToExclude, Callback &&callback) const |
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) const |
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) const |
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) const |
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) const |
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) const |
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) const |
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. | |
A lightweight version of the ListenerList that doesn't provide any guarantees when mutating the list from a callback, but allows callbacks to be triggered concurrently without a mutex.
using LightweightListenerList< ListenerClass >::DummyBailOutChecker = typename ListenerList<ListenerClass>::DummyBailOutChecker |
A dummy bail-out checker that always returns false.
See the class description for info about writing a bail-out checker.
using LightweightListenerList< ListenerClass >::ThisType = LightweightListenerList<ListenerClass> |
using LightweightListenerList< ListenerClass >::ListenerType = ListenerClass |
|
default |
Creates an empty list.
LightweightListenerList< ListenerClass >::~LightweightListenerList | ( | ) |
Destructor.
References jassert.
void LightweightListenerList< ListenerClass >::add | ( | ListenerClass * | listenerToAdd | ) |
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 you need to add a Listener during a callback, use the ListenerList type.
References jassert, and jassertfalse.
Referenced by LightweightListenerList< ListenerClass >::addScoped().
void LightweightListenerList< ListenerClass >::remove | ( | ListenerClass * | listenerToRemove | ) |
Removes a listener from the list.
If the listener wasn't in the list, this has no effect.
If you need to remove a Listener during a callback, use the ListenerList type.
References jassert.
Referenced by LightweightListenerList< ListenerClass >::addScoped().
|
nodiscard |
Adds a listener that will be automatically removed 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 LightweightListenerList< ListenerClass >::add(), and LightweightListenerList< ListenerClass >::remove().
|
nodiscardnoexcept |
Returns the number of registered listeners.
|
nodiscardnoexcept |
Returns true if no listeners are registered, false otherwise.
void LightweightListenerList< ListenerClass >::clear | ( | ) |
Clears the list.
If you need to clear the list during a callback, use the ListenerList type.
References jassert.
|
nodiscardnoexcept |
Returns true if the specified listener has been added to the list.
void LightweightListenerList< ListenerClass >::call | ( | Callback && | callback | ) | const |
Calls an invokable object for each listener in the list.
References LightweightListenerList< ListenerClass >::callCheckedExcluding().
void LightweightListenerList< ListenerClass >::callExcluding | ( | ListenerClass * | listenerToExclude, |
Callback && | callback ) const |
Calls an invokable object for each listener in the list, except for the listener specified by listenerToExclude.
References LightweightListenerList< ListenerClass >::callCheckedExcluding().
void LightweightListenerList< ListenerClass >::callChecked | ( | const BailOutCheckerType & | bailOutChecker, |
Callback && | callback ) const |
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 LightweightListenerList< ListenerClass >::callCheckedExcluding().
void LightweightListenerList< ListenerClass >::callCheckedExcluding | ( | ListenerClass * | listenerToExclude, |
const BailOutCheckerType & | bailOutChecker, | ||
Callback && | callback ) const |
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.
Referenced by LightweightListenerList< ListenerClass >::call(), LightweightListenerList< ListenerClass >::call(), LightweightListenerList< ListenerClass >::callChecked(), LightweightListenerList< ListenerClass >::callChecked(), LightweightListenerList< ListenerClass >::callCheckedExcluding(), LightweightListenerList< ListenerClass >::callExcluding(), and LightweightListenerList< ListenerClass >::callExcluding().
void LightweightListenerList< ListenerClass >::call | ( | void(ListenerClass::* | callbackFunction )(MethodArgs...), |
Args &&... | args ) const |
Calls a specific listener method for each listener in the list.
References LightweightListenerList< ListenerClass >::callCheckedExcluding().
void LightweightListenerList< ListenerClass >::callExcluding | ( | ListenerClass * | listenerToExclude, |
void(ListenerClass::* | callbackFunction )(MethodArgs...), | ||
Args &&... | args ) const |
Calls a specific listener method for each listener in the list, except for the listener specified by listenerToExclude.
References LightweightListenerList< ListenerClass >::callCheckedExcluding().
void LightweightListenerList< ListenerClass >::callChecked | ( | const BailOutCheckerType & | bailOutChecker, |
void(ListenerClass::* | callbackFunction )(MethodArgs...), | ||
Args &&... | args ) const |
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 LightweightListenerList< ListenerClass >::callCheckedExcluding().
void LightweightListenerList< ListenerClass >::callCheckedExcluding | ( | ListenerClass * | listenerToExclude, |
const BailOutCheckerType & | bailOutChecker, | ||
void(ListenerClass::* | callbackFunction )(MethodArgs...), | ||
Args &&... | args ) const |
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 LightweightListenerList< ListenerClass >::callCheckedExcluding().