15#include "arcane/utils/UniqueArray.h"
16#include "arcane/utils/FatalErrorException.h"
42 void rebuildOberversArray()
44 m_observers_array.clear();
46 for(
auto o : m_observers )
47 m_observers_array.add(o);
50 std::set<EventObserverBase*> m_auto_destroy_observers;
51 std::set<EventObserverBase*> m_observers;
74 std::cerr <<
"ERROR: Exception launched during call to ~EventObservableBase().\n";
82void EventObservableBase::
83_attachObserver(EventObserverBase* obs,
bool is_auto_destroy)
86 if (m_p->m_observers.find(obs)!=m_p->m_observers.end())
87 ARCANE_FATAL(
"Observer is already attached to this observable");
88 obs->_notifyAttach(
this);
89 m_p->m_observers.insert(obs);
90 m_p->rebuildOberversArray();
92 m_p->m_auto_destroy_observers.insert(obs);
98void EventObservableBase::
99_detachObserver(EventObserverBase* obs)
105 for(
auto o : m_p->m_observers )
107 m_p->m_observers.erase(o);
114 ARCANE_FATAL(
"observer is not registered to this observable");
115 obs->_notifyDetach();
116 m_p->rebuildOberversArray();
122ConstArrayView<EventObserverBase*> EventObservableBase::
125 return m_p->m_observers_array;
131void EventObservableBase::
134 for(
auto o : m_p->m_observers )
136 m_p->m_observers.clear();
137 for(
auto o : m_p->m_auto_destroy_observers )
144bool EventObservableBase::
147 return (m_p->m_observers.size()!=0);
158~EventObserverBase() ARCANE_NOEXCEPT_FALSE
161 m_observable->_detachObserver(
this);
167void EventObserverBase::
171 ARCANE_FATAL(
"EventObserver is not attached to an EventObservable");
172 m_observable =
nullptr;
178void EventObserverBase::
179_notifyAttach(EventObservableBase* obs)
182 ARCANE_FATAL(
"EventObserver is already attached to an EventObservable");
204 for(
auto o : m_observers )
215 m_observers.add(
obs);
231 std::cout <<
"THIS_IS_MY FUNC XA=" << a <<
" B=" <<
b <<
'\n';
233 void operator()(
int a,
int b)
235 std::cout <<
"THIS_IS OPERATOR() FUNC XA=" << a <<
" B=" << b <<
'\n';
239extern "C++" ARCANE_UTILS_EXPORT
void
242 using std::placeholders::_1;
243 using std::placeholders::_2;
246 auto func = [&](
int a,
int b){
247 std::cout <<
"XA=" << a <<
" B=" << b <<
" f=" << f <<
'\n';
250 auto func2 = [&](
int a,
int b){
251 std::cout <<
"FUNC2: XA=" << a <<
" B=" << b <<
" f=" << f <<
'\n';
254 EventObserver<int,int> x2(func);
256 EventObservable<int,int> xevent;
257 EventObserverPool pool;
259 EventObserver<int,int> xobserver;
262 std::function<void(
int,
int)> kk( std::bind( &TestMemberCall::my_func, tmc, _1, _2 ) );
265 EventObserver<int,int> x4(kk);
266 EventObserver<int,int> x3(tmc);
270 xevent.attach(&xobserver);
274 xevent.attach(pool,func2);
276 std::cout <<
"(After) F=" << f <<
'\n';
280 EventObserver<int,int>* eo1 =
nullptr;
281 EventObservable<int,int> xevent;
283 eo1 =
new EventObserver<int,int>( std::bind( &TestMemberCall::my_func, tmc, _1, _2 ) );
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Fichier contenant les mécanismes de gestion des évènements.
Classe de base d'un observateur d'évènement.
void clear()
Supprime tous les observateurs associés à cette instance.
void add(EventObserverBase *x)
Ajoute l'observateur x.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
Integer arcaneCheckArraySize(unsigned long long size)
Vérifie que size peut être converti dans un 'Integer' pour servir de taille à un tableau....