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 |
Iterates the listeners in a ListenerList. More... | |
Public Types | |
using | ListenerType = ListenerClass |
using | ThisType = ListenerList< ListenerClass, ArrayType > |
Public Member Functions | |
ListenerList ()=default | |
Creates an empty list. More... | |
~ListenerList ()=default | |
Destructor. More... | |
void | add (ListenerClass *listenerToAdd) |
Adds a listener to the list. More... | |
template<typename Callback > | |
void | call (Callback &&callback) |
Calls a member function on each listener in the list, with multiple parameters. More... | |
template<typename Callback , typename BailOutCheckerType > | |
void | callChecked (const BailOutCheckerType &bailOutChecker, Callback &&callback) |
Calls a member function on each listener in the list, with 1 parameter and a bail-out-checker. More... | |
template<typename Callback , typename BailOutCheckerType > | |
void | callCheckedExcluding (ListenerClass *listenerToExclude, const BailOutCheckerType &bailOutChecker, Callback &&callback) |
Calls a member function, with 1 parameter, on all but the specified listener in the list with a bail-out-checker. More... | |
template<typename Callback > | |
void | callExcluding (ListenerClass *listenerToExclude, Callback &&callback) |
Calls a member function with 1 parameter, on all but the specified listener in the list. More... | |
void | clear () |
Clears the list. More... | |
bool | contains (ListenerClass *listener) const noexcept |
Returns true if the specified listener has been added to the list. More... | |
const ArrayType & | getListeners () const noexcept |
Returns the raw array of listeners. More... | |
bool | isEmpty () const noexcept |
Returns true if no listeners are registered, false otherwise. More... | |
void | remove (ListenerClass *listenerToRemove) |
Removes a listener from the list. More... | |
int | size () const noexcept |
Returns the number of registered listeners. More... | |
Private Attributes | |
ArrayType | listeners |
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() or callChecked().
E.g.
If you add or remove listeners from the list during one of the callbacks - i.e. while it's in the middle of iterating the listeners, then it's guaranteed that no listeners will be mistakenly called after they've been removed, but it may mean that some of the listeners could be called more than once, or not at all, depending on the list's order.
Sometimes, there's a chance that invoking one of the callbacks might result in the list itself being deleted while it's still iterating - to survive this situation, you can use callChecked() instead of call(), passing it a local object to act as a "BailOutChecker". The BailOutChecker must implement a method of the form "bool shouldBailOut()", and the list will check this after each callback to determine whether it should abort the operation. For an example of a bail-out checker, see the Component::BailOutChecker class, which can be used to check when a Component has been deleted. See also ListenerList::DummyBailOutChecker, which is a dummy checker that always returns false.
@tags{Core}
using juce::ListenerList< ListenerClass, ArrayType >::ListenerType = ListenerClass |
using juce::ListenerList< ListenerClass, ArrayType >::ThisType = ListenerList<ListenerClass, ArrayType> |
|
default |
Creates an empty list.
|
default |
Destructor.
|
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.
|
inline |
Calls a member function on each listener in the list, with multiple parameters.
|
inline |
Calls a member function on each listener in the list, with 1 parameter and a bail-out-checker.
See the class description for info about writing a bail-out checker.
|
inline |
Calls a member function, with 1 parameter, on all but the specified listener in the list with a bail-out-checker.
This can be useful if the caller is also a listener and needs to exclude itself. See the class description for info about writing a bail-out checker.
|
inline |
Calls a member function with 1 parameter, on all but the specified listener in the list.
This can be useful if the caller is also a listener and needs to exclude itself.
|
inline |
Clears the list.
|
inlinenoexcept |
Returns true if the specified listener has been added to the list.
|
inlinenoexcept |
Returns the raw array of listeners.
|
inlinenoexcept |
Returns true if no listeners are registered, false otherwise.
|
inline |
Removes a listener from the list.
If the listener wasn't in the list, this has no effect.
|
inlinenoexcept |
Returns the number of registered listeners.
|
private |
Referenced by juce::ListenerList< juce::TextEditor::Listener >::add(), juce::ListenerList< juce::TextEditor::Listener >::call(), juce::ListenerList< juce::TextEditor::Listener >::callChecked(), juce::ListenerList< juce::TextEditor::Listener >::callCheckedExcluding(), juce::ListenerList< juce::TextEditor::Listener >::callExcluding(), juce::ListenerList< juce::TextEditor::Listener >::clear(), juce::ListenerList< juce::TextEditor::Listener >::contains(), juce::ListenerList< juce::TextEditor::Listener >::getListeners(), juce::ListenerList< juce::TextEditor::Listener >::isEmpty(), juce::ListenerList< juce::TextEditor::Listener >::remove(), and juce::ListenerList< juce::TextEditor::Listener >::size().