JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | List of all members
juce::ListenerList< ListenerClass, ArrayType > Class Template Reference

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...
 

Public Types

using ThisType = ListenerList< ListenerClass, ArrayType >
 
using ListenerType = ListenerClass
 

Public Member Functions

 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 ArrayTypegetListeners () 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.
 

Detailed Description

template<class ListenerClass, class 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.

Use a ListenerList to manage a set of objects which need a callback, and you can invoke a member function by simply calling call(), callChecked(), or callExcluding().

E.g.

{
public:
void myCallbackMethod (int foo, bool bar);
};
listeners.add (someCallbackObjects...);
// This will invoke myCallbackMethod (1234, true) on each of the objects
// in the list...
listeners.call ([] (MyListenerType& l) { l.myCallbackMethod (1234, true); });
Holds a set of objects and can invoke a member function callback on each object in the set with a sin...
void call(Callback &&callback)
Calls an invokable object for each listener in the list.
void add(ListenerClass *listenerToAdd)
Adds a listener to the list.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88

It is safe to add listeners, remove listeners, clear the listeners, and delete the ListenerList itself during any listener callback.

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.

By default a ListenerList is not thread safe. If thread-safety is required, you can provide a thread-safe Array type as the second type parameter e.g.

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.

@tags{Core}

Definition at line 80 of file juce_ListenerList.h.

Member Typedef Documentation

◆ ListenerType

template<class ListenerClass , class ArrayType = Array<ListenerClass*>>
using juce::ListenerList< ListenerClass, ArrayType >::ListenerType = ListenerClass

Definition at line 322 of file juce_ListenerList.h.

◆ ThisType

Definition at line 321 of file juce_ListenerList.h.

Constructor & Destructor Documentation

◆ ~ListenerList()

Destructor.

Definition at line 88 of file juce_ListenerList.h.

Member Function Documentation

◆ add()

template<class ListenerClass , class ArrayType = Array<ListenerClass*>>
void juce::ListenerList< ListenerClass, ArrayType >::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 a Listener is added during a callback, it is guaranteed not to be called in the same iteration.

See also
remove

Definition at line 100 of file juce_ListenerList.h.

◆ addScoped()

template<class ListenerClass , class ArrayType = Array<ListenerClass*>>
ErasedScopeGuard juce::ListenerList< ListenerClass, ArrayType >::addScoped ( ListenerClass listenerToAdd)

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.

Definition at line 138 of file juce_ListenerList.h.

◆ call() [1/2]

template<class ListenerClass , class ArrayType = Array<ListenerClass*>>
template<typename Callback >
void juce::ListenerList< ListenerClass, ArrayType >::call ( Callback &&  callback)

Calls an invokable object for each listener in the list.

Definition at line 182 of file juce_ListenerList.h.

◆ call() [2/2]

template<class ListenerClass , class ArrayType = Array<ListenerClass*>>
template<typename... MethodArgs, typename... Args>
void juce::ListenerList< ListenerClass, ArrayType >::call ( void(ListenerClass::*)(MethodArgs...)  callbackFunction,
Args &&...  args 
)

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

Definition at line 255 of file juce_ListenerList.h.

◆ callChecked() [1/2]

template<class ListenerClass , class ArrayType = Array<ListenerClass*>>
template<typename Callback , typename BailOutCheckerType >
void juce::ListenerList< ListenerClass, ArrayType >::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.

See the class description for info about writing a bail-out checker.

Definition at line 207 of file juce_ListenerList.h.

◆ callChecked() [2/2]

template<class ListenerClass , class ArrayType = Array<ListenerClass*>>
template<typename BailOutCheckerType , typename... MethodArgs, typename... Args>
void juce::ListenerList< ListenerClass, ArrayType >::callChecked ( const BailOutCheckerType bailOutChecker,
void(ListenerClass::*)(MethodArgs...)  callbackFunction,
Args &&...  args 
)

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.

Definition at line 283 of file juce_ListenerList.h.

◆ callCheckedExcluding() [1/2]

template<class ListenerClass , class ArrayType = Array<ListenerClass*>>
template<typename Callback , typename BailOutCheckerType >
void juce::ListenerList< ListenerClass, ArrayType >::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.

See the class description for info about writing a bail-out checker.

Definition at line 221 of file juce_ListenerList.h.

◆ callCheckedExcluding() [2/2]

template<class ListenerClass , class ArrayType = Array<ListenerClass*>>
template<typename BailOutCheckerType , typename... MethodArgs, typename... Args>
void juce::ListenerList< ListenerClass, ArrayType >::callCheckedExcluding ( ListenerClass listenerToExclude,
const BailOutCheckerType bailOutChecker,
void(ListenerClass::*)(MethodArgs...)  callbackFunction,
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.

See the class description for info about writing a bail-out checker.

Definition at line 300 of file juce_ListenerList.h.

◆ callExcluding() [1/2]

template<class ListenerClass , class ArrayType = Array<ListenerClass*>>
template<typename Callback >
void juce::ListenerList< ListenerClass, ArrayType >::callExcluding ( ListenerClass listenerToExclude,
Callback &&  callback 
)

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

Definition at line 193 of file juce_ListenerList.h.

◆ callExcluding() [2/2]

template<class ListenerClass , class ArrayType = Array<ListenerClass*>>
template<typename... MethodArgs, typename... Args>
void juce::ListenerList< ListenerClass, ArrayType >::callExcluding ( ListenerClass listenerToExclude,
void(ListenerClass::*)(MethodArgs...)  callbackFunction,
Args &&...  args 
)

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

Definition at line 267 of file juce_ListenerList.h.

◆ clear()

template<class ListenerClass , class ArrayType = Array<ListenerClass*>>
void juce::ListenerList< ListenerClass, ArrayType >::clear ( )

Clears the list.

If the ListenerList is cleared during a callback, it is guaranteed that no more listeners will be called.

Definition at line 155 of file juce_ListenerList.h.

◆ contains()

template<class ListenerClass , class ArrayType = Array<ListenerClass*>>
bool juce::ListenerList< ListenerClass, ArrayType >::contains ( ListenerClass listener) const
noexcept

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

Definition at line 166 of file juce_ListenerList.h.

◆ getListeners()

template<class ListenerClass , class ArrayType = Array<ListenerClass*>>
const ArrayType & juce::ListenerList< ListenerClass, ArrayType >::getListeners ( ) const
noexcept

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.

See also
add, remove, clear, contains

Definition at line 177 of file juce_ListenerList.h.

◆ isEmpty()

template<class ListenerClass , class ArrayType = Array<ListenerClass*>>
bool juce::ListenerList< ListenerClass, ArrayType >::isEmpty ( ) const
noexcept

Returns true if no listeners are registered, false otherwise.

Definition at line 148 of file juce_ListenerList.h.

◆ remove()

template<class ListenerClass , class ArrayType = Array<ListenerClass*>>
void juce::ListenerList< ListenerClass, ArrayType >::remove ( ListenerClass listenerToRemove)

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.

Definition at line 114 of file juce_ListenerList.h.

◆ size()

template<class ListenerClass , class ArrayType = Array<ListenerClass*>>
int juce::ListenerList< ListenerClass, ArrayType >::size ( ) const
noexcept

Returns the number of registered listeners.

Definition at line 145 of file juce_ListenerList.h.


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