Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
Arcane::EventObservable< Args > Class Template Reference

Base class for an event handler. More...

#include </__w/arcaneframework.github.io/arcaneframework.github.io/framework/arccore/src/common/arccore/common/Event.h>

Inheritance diagram for Arcane::EventObservable< Args >:
Collaboration diagram for Arcane::EventObservable< Args >:

Public Types

typedef EventObserver< Args... > ObserverType

Public Member Functions

void attach (ObserverType *o)
 Attaches the observer o to this observable.
void detach (ObserverType *o)
 Detaches the observer o from this observable.
template<typename Lambda>
void attach (EventObserverPool &pool, const Lambda &lambda)
 Adds an observer using the lambda lambda and stores a reference in pool.
void notify (Args... args)
 Calls the observers associated with this observable.
Public Member Functions inherited from Arcane::EventObservableBase
 EventObservableBase (const EventObservableBase &)=delete
 EventObservableBase (EventObservableBase &&)=delete
EventObservableBase & operator= (const EventObservableBase &)=delete
EventObservableBase & operator= (EventObservableBase &&)=delete
bool hasObservers () const
void detachAllObservers ()

Additional Inherited Members

Protected Member Functions inherited from Arcane::EventObservableBase
void _attachObserver (EventObserverBase *obs, bool is_auto_destroy)
void _detachObserver (EventObserverBase *obs)
ConstArrayView< EventObserverBase * > _observers () const

Detailed Description

template<typename... Args>
class Arcane::EventObservable< Args >

Base class for an event handler.

Instances of this class cannot be copied.

This class allows registering a list of observers that can be notified when notify() is called. Args contains the list of notification parameters.

It is possible to add an observer via the attach() method. If the observer is a lambda function, it is necessary to specify an instance of EventObserverPool to manage the lifetime of the lambda, which will then be the same as that of the associated EventObserverPool.

EventObservable<int,double> observable;
observable.attach(pool,[](int a,double b) { ... });
std::function<int,double> f2(...);
auto o = new EventObserver<int,double>(f2);
observable.attach(o);
observable.notify(1,3.2);
void attach(ObserverType *o)
Attaches the observer o to this observable.
void notify(Args... args)
Calls the observers associated with this observable.

Definition at line 194 of file arccore/src/common/arccore/common/Event.h.

Member Typedef Documentation

◆ ObserverType

template<typename... Args>
typedef EventObserver<Args...> Arcane::EventObservable< Args >::ObserverType

Definition at line 199 of file arccore/src/common/arccore/common/Event.h.

Member Function Documentation

◆ attach() [1/2]

template<typename... Args>
template<typename Lambda>
void Arcane::EventObservable< Args >::attach ( EventObserverPool & pool,
const Lambda & lambda )
inline

Adds an observer using the lambda lambda and stores a reference in pool.

Definition at line 226 of file arccore/src/common/arccore/common/Event.h.

◆ attach() [2/2]

template<typename... Args>
void Arcane::EventObservable< Args >::attach ( ObserverType * o)
inline

Attaches the observer o to this observable.

An exception is thrown if the observer is already attached to an observable.

Definition at line 212 of file arccore/src/common/arccore/common/Event.h.

◆ detach()

template<typename... Args>
void Arcane::EventObservable< Args >::detach ( ObserverType * o)
inline

Detaches the observer o from this observable.

An exception is thrown if the observer is not attached to this observable.

Definition at line 219 of file arccore/src/common/arccore/common/Event.h.

◆ notify()

template<typename... Args>
void Arcane::EventObservable< Args >::notify ( Args... args)
inline

Calls the observers associated with this observable.

Definition at line 234 of file arccore/src/common/arccore/common/Event.h.


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