Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
ObservablePool.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2022 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* ObserverPool.h (C) 2000-2022 */
9/* */
10/* Liste d'observables. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_OBSERVABLEPOOL_H
13#define ARCANE_OBSERVABLEPOOL_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/FatalErrorException.h"
18
19#include "arcane/Observable.h"
20#include "arcane/Observer.h"
21
22#include <map>
23
24/*---------------------------------------------------------------------------*/
25/*---------------------------------------------------------------------------*/
26
27namespace Arcane
28{
29
30/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
32
33class IObservable;
34
35/*---------------------------------------------------------------------------*/
36/*---------------------------------------------------------------------------*/
43template<typename KeyType>
45{
46 public:
47
48 typedef std::map<KeyType,IObservable*> ObservableListType;
49
50 public:
51
56 {
57 for( const auto& x : m_observables ){
58 IObservable* o = x.second;
60 delete o;
61 }
62 }
63
64 public:
65
66 void add(const KeyType& key)
67 {
68 IObservable* x = _getIfExists(key);
69 if (x)
70 ARCANE_FATAL("Observable with current key already exists");
71 m_observables.insert(std::make_pair(key,new Observable()));
72 }
73
74 IObservable* operator[](const KeyType& key)
75 {
76 IObservable* x = _getIfExists(key);
77 if (!x)
78 ARCANE_FATAL("No observable with current key exists");
79 return x;
80 }
81
82 protected:
83
84 private:
85
86 ObservableListType m_observables;
87
88 IObservable* _getIfExists(const KeyType& key) const
89 {
90 auto x = m_observables.find(key);
91 if (x!=m_observables.end())
92 return x->second;
93 return nullptr;
94 }
95};
96
97/*---------------------------------------------------------------------------*/
98/*---------------------------------------------------------------------------*/
99
100} // End namespace Arcane
101
102/*---------------------------------------------------------------------------*/
103/*---------------------------------------------------------------------------*/
104
105#endif
106
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Interface d'un observable.
virtual void detachAllObservers()=0
Détache tous les observeurs associés à cette instance.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
Liste d'observables.
~ObservablePool()
Libère les ressources.
ObservablePool()
Constructeur.
ObservableListType m_observables
Liste des observables.
Classe de base d'un observable.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-