Loading...
Searching...
No Matches
LightweightListenerList< ListenerClass > Class Template Reference

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.
 

Detailed Description

template<typename ListenerClass>
class LightweightListenerList< ListenerClass >

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.

See also
ListenerList, ThreadSafeListenerList

Member Typedef Documentation

◆ DummyBailOutChecker

template<typename ListenerClass >
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.

◆ ThisType

template<typename ListenerClass >
using LightweightListenerList< ListenerClass >::ThisType = LightweightListenerList<ListenerClass>

◆ ListenerType

template<typename ListenerClass >
using LightweightListenerList< ListenerClass >::ListenerType = ListenerClass

Constructor & Destructor Documentation

◆ LightweightListenerList()

template<typename ListenerClass >
LightweightListenerList< ListenerClass >::LightweightListenerList ( )
default

Creates an empty list.

◆ ~LightweightListenerList()

template<typename ListenerClass >
LightweightListenerList< ListenerClass >::~LightweightListenerList ( )

Destructor.

References jassert.

Member Function Documentation

◆ add()

template<typename ListenerClass >
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.

See also
remove

References jassert, and jassertfalse.

Referenced by LightweightListenerList< ListenerClass >::addScoped().

◆ remove()

template<typename ListenerClass >
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().

◆ addScoped()

template<typename ListenerClass >
ErasedScopeGuard LightweightListenerList< ListenerClass >::addScoped ( ListenerClass & listenerToAdd)
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().

◆ size()

template<typename ListenerClass >
int LightweightListenerList< ListenerClass >::size ( ) const
nodiscardnoexcept

Returns the number of registered listeners.

◆ isEmpty()

template<typename ListenerClass >
bool LightweightListenerList< ListenerClass >::isEmpty ( ) const
nodiscardnoexcept

Returns true if no listeners are registered, false otherwise.

◆ clear()

template<typename ListenerClass >
void LightweightListenerList< ListenerClass >::clear ( )

Clears the list.

If you need to clear the list during a callback, use the ListenerList type.

References jassert.

◆ contains()

template<typename ListenerClass >
bool LightweightListenerList< ListenerClass >::contains ( ListenerClass * listener) const
nodiscardnoexcept

Returns true if the specified listener has been added to the list.

◆ call() [1/2]

template<typename ListenerClass >
template<typename Callback >
void LightweightListenerList< ListenerClass >::call ( Callback && callback) const

Calls an invokable object for each listener in the list.

References LightweightListenerList< ListenerClass >::callCheckedExcluding().

◆ callExcluding() [1/2]

template<typename ListenerClass >
template<typename Callback >
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().

◆ callChecked() [1/2]

template<typename ListenerClass >
template<typename Callback , typename BailOutCheckerType >
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().

◆ callCheckedExcluding() [1/2]

template<typename ListenerClass >
template<typename Callback , typename BailOutCheckerType >
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().

◆ call() [2/2]

template<typename ListenerClass >
template<typename... MethodArgs, typename... Args>
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().

◆ callExcluding() [2/2]

template<typename ListenerClass >
template<typename... MethodArgs, typename... Args>
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().

◆ callChecked() [2/2]

template<typename ListenerClass >
template<typename BailOutCheckerType , typename... MethodArgs, typename... Args>
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().

◆ callCheckedExcluding() [2/2]

template<typename ListenerClass >
template<typename BailOutCheckerType , typename... MethodArgs, typename... Args>
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().


The documentation for this class was generated from the following file:
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram