JUCE v8.0.9
JUCE API
 
Loading...
Searching...
No Matches
juce::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>

Inheritance diagram for juce::LightweightListenerList< ListenerClass >:
Collaboration diagram for juce::LightweightListenerList< ListenerClass >:

Public Types

using DummyBailOutChecker = typename ListenerList< ListenerClass >::DummyBailOutChecker
 A dummy bail-out checker that always returns false.
 
using ListenerType = ListenerClass
 
using ThisType = LightweightListenerList< ListenerClass >
 

Public Member Functions

 LightweightListenerList ()=default
 Creates an empty list.
 
 ~LightweightListenerList ()
 Destructor.
 
void add (ListenerClass *listenerToAdd)
 Adds a listener to the list.
 
ErasedScopeGuard addScoped (ListenerClass &listenerToAdd)
 Adds a listener that will be automatically removed when the Guard is destroyed.
 
template<typename Callback >
void call (Callback &&callback) const
 Calls an invokable object for each listener in the list.
 
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 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 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 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 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.
 
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... 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.
 
void clear ()
 Clears the list.
 
bool contains (ListenerClass *listener) const noexcept
 Returns true if the specified listener has been added to the list.
 
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 Attributes

Array< ListenerClass * > listeners
 

Detailed Description

template<typename ListenerClass>
class juce::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

@tags{Core}

Member Typedef Documentation

◆ DummyBailOutChecker

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

◆ ListenerType

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

◆ ThisType

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

Constructor & Destructor Documentation

◆ LightweightListenerList()

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

Creates an empty list.

◆ ~LightweightListenerList()

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

Destructor.

References jassert.

Member Function Documentation

◆ add()

template<typename ListenerClass >
void juce::LightweightListenerList< ListenerClass >::add ( ListenerClass *  listenerToAdd)
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 you need to add a Listener during a callback, use the ListenerList type.

See also
remove

References juce::Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::addIfNotAlreadyThere(), jassert, jassertfalse, and juce::LightweightListenerList< ListenerClass >::listeners.

Referenced by juce::detail::CallbackListenerList< Args >::addListener(), and juce::LightweightListenerList< ListenerClass >::addScoped().

◆ addScoped()

template<typename ListenerClass >
ErasedScopeGuard juce::LightweightListenerList< ListenerClass >::addScoped ( ListenerClass &  listenerToAdd)
inline

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 juce::LightweightListenerList< ListenerClass >::add(), and juce::LightweightListenerList< ListenerClass >::remove().

◆ call() [1/2]

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

Calls an invokable object for each listener in the list.

References juce::LightweightListenerList< ListenerClass >::callCheckedExcluding().

Referenced by juce::detail::CallbackListenerList< Args >::call().

◆ call() [2/2]

template<typename ListenerClass >
template<typename... MethodArgs, typename... Args>
void juce::LightweightListenerList< ListenerClass >::call ( void(ListenerClass::*)(MethodArgs...)  callbackFunction,
Args &&...  args 
) const
inline

Calls a specific listener method for each listener in the list.

References juce::LightweightListenerList< ListenerClass >::callCheckedExcluding().

◆ callChecked() [1/2]

template<typename ListenerClass >
template<typename Callback , typename BailOutCheckerType >
void juce::LightweightListenerList< ListenerClass >::callChecked ( const BailOutCheckerType &  bailOutChecker,
Callback &&  callback 
) const
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::LightweightListenerList< ListenerClass >::callCheckedExcluding().

◆ callChecked() [2/2]

template<typename ListenerClass >
template<typename BailOutCheckerType , typename... MethodArgs, typename... Args>
void juce::LightweightListenerList< ListenerClass >::callChecked ( const BailOutCheckerType &  bailOutChecker,
void(ListenerClass::*)(MethodArgs...)  callbackFunction,
Args &&...  args 
) const
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::LightweightListenerList< ListenerClass >::callCheckedExcluding().

◆ callCheckedExcluding() [1/2]

template<typename ListenerClass >
template<typename Callback , typename BailOutCheckerType >
void juce::LightweightListenerList< ListenerClass >::callCheckedExcluding ( ListenerClass *  listenerToExclude,
const BailOutCheckerType &  bailOutChecker,
Callback &&  callback 
) const
inline

◆ callCheckedExcluding() [2/2]

template<typename ListenerClass >
template<typename BailOutCheckerType , typename... MethodArgs, typename... Args>
void juce::LightweightListenerList< ListenerClass >::callCheckedExcluding ( ListenerClass *  listenerToExclude,
const BailOutCheckerType &  bailOutChecker,
void(ListenerClass::*)(MethodArgs...)  callbackFunction,
Args &&...  args 
) const
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::LightweightListenerList< ListenerClass >::callCheckedExcluding().

◆ callExcluding() [1/2]

template<typename ListenerClass >
template<typename Callback >
void juce::LightweightListenerList< ListenerClass >::callExcluding ( ListenerClass *  listenerToExclude,
Callback &&  callback 
) const
inline

Calls an invokable object for each listener in the list, except for the listener specified by listenerToExclude.

References juce::LightweightListenerList< ListenerClass >::callCheckedExcluding().

◆ callExcluding() [2/2]

template<typename ListenerClass >
template<typename... MethodArgs, typename... Args>
void juce::LightweightListenerList< ListenerClass >::callExcluding ( ListenerClass *  listenerToExclude,
void(ListenerClass::*)(MethodArgs...)  callbackFunction,
Args &&...  args 
) const
inline

Calls a specific listener method for each listener in the list, except for the listener specified by listenerToExclude.

References juce::LightweightListenerList< ListenerClass >::callCheckedExcluding().

◆ clear()

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

◆ contains()

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

◆ isEmpty()

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

◆ remove()

template<typename ListenerClass >
void juce::LightweightListenerList< ListenerClass >::remove ( ListenerClass *  listenerToRemove)
inline

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, juce::LightweightListenerList< ListenerClass >::listeners, and juce::Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::removeFirstMatchingValue().

Referenced by juce::detail::CallbackListenerList< Args >::addListener(), and juce::LightweightListenerList< ListenerClass >::addScoped().

◆ size()

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

Member Data Documentation

◆ listeners


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