Arcane  v3.14.10.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
utils/Observable.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/* Observable.h (C) 2000-2021 */
9/* */
10/* Observable. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_UTILS_OBSERVABLE_H
13#define ARCANE_UTILS_OBSERVABLE_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/Array.h"
18#include "arcane/utils/IObservable.h"
19#include "arcane/utils/IObserver.h"
20
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24namespace Arcane
25{
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29/*!
30 * \ingroup Core
31 * \brief Classe de base d'un observable.
32 *
33 * Un observable ne peut pas être copié.
34 */
35class ARCANE_UTILS_EXPORT Observable
36: public IObservable
37{
38 public:
39
40 virtual ~Observable(); //!< Libère les ressources
41
42 public:
43
44 Observable() : m_is_destroyed(false) {}
45
46 public:
47
48 Observable(const Observable& rhs) = delete;
49 void operator=(const Observable& rhs) = delete;
50
51 public:
52
53 void destroy() override;
54 void attachObserver(IObserver* obs) override;
55 void detachObserver(IObserver* obs) override;
56 void notifyAllObservers() override;
57 bool hasObservers() const override;
58 bool isDestroyed() const override;
59 void detachAllObservers() override;
60
61 protected:
62
63 void _detachAllObservers();
64
65 private:
66
67 bool m_is_destroyed;
68 UniqueArray<IObserver*> m_observers;
69};
70
71/*---------------------------------------------------------------------------*/
72/*---------------------------------------------------------------------------*/
73/*!
74 * \brief Observable qui appelle automatiquement
75 * IObservable::detachAllObservers() dans le destructeur.
76 */
77class ARCANE_UTILS_EXPORT AutoDetachObservable
78: public Observable
79{
80 public:
83};
84
85/*---------------------------------------------------------------------------*/
86/*---------------------------------------------------------------------------*/
87
88} // End namespace Arcane
89
90/*---------------------------------------------------------------------------*/
91/*---------------------------------------------------------------------------*/
92
93#endif
94
Observable qui appelle automatiquement IObservable::detachAllObservers() dans le destructeur.
Interface d'un observable.
Classe de base d'un observable.
Vecteur 1D de données avec sémantique par valeur (style STL).
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-