Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
ModuleMng.cc
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/* ModuleMng.cc (C) 2000-2019 */
9/* */
10/* Classe gérant l'ensemble des modules. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/ArcanePrecomp.h"
15
16#include "arcane/utils/Iostream.h"
17#include "arcane/utils/List.h"
18#include "arcane/utils/Deleter.h"
19#include "arcane/utils/String.h"
20#include "arcane/utils/ITraceMng.h"
21#include "arcane/utils/FatalErrorException.h"
22#include "arcane/utils/Ref.h"
23
24#include "arcane/IModuleMng.h"
25#include "arcane/IModule.h"
26
27#include <map>
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
32namespace Arcane
33{
34
35/*---------------------------------------------------------------------------*/
36/*---------------------------------------------------------------------------*/
41: public IModuleMng
42{
43 public:
44
46 ~ModuleMng();
47
48 void addModule(Ref<IModule>) override;
49 void removeModule(Ref<IModule>) override;
50 void dumpList(std::ostream&) override;
51 ModuleCollection modules() const override { return m_modules; }
52 void removeAllModules() override;
53 bool isModuleActive(const String& name) override;
54 IModule* findModule(const String& name) override;
55
56 private:
57
59 std::map<String,Ref<IModule>> m_modules_map;
60 IModule* _findModule(const String& name);
61};
62
63/*---------------------------------------------------------------------------*/
64/*---------------------------------------------------------------------------*/
65
66extern "C++" IModuleMng*
67arcaneCreateModuleMng(ISubDomain* sd)
68{
69 return new ModuleMng(sd);
70}
71
72/*---------------------------------------------------------------------------*/
73/*---------------------------------------------------------------------------*/
74
75ModuleMng::
76ModuleMng([[maybe_unused]] ISubDomain* sd)
77{
78}
79
80/*---------------------------------------------------------------------------*/
81/*---------------------------------------------------------------------------*/
90
91/*---------------------------------------------------------------------------*/
92/*---------------------------------------------------------------------------*/
93
96{
98 m_modules_map.clear();
99}
100
101/*---------------------------------------------------------------------------*/
102/*---------------------------------------------------------------------------*/
103
106{
107 const String& module_name = module->name();
108 auto iter = m_modules_map.find(module_name);
109 if (iter!=m_modules_map.end())
110 ARCANE_FATAL("A module named '{0}' is already registered",module_name);
111 m_modules.add(module.get());
112 m_modules_map.insert(std::make_pair(module_name,module));
113}
114
115/*---------------------------------------------------------------------------*/
116/*---------------------------------------------------------------------------*/
117
120{
121 const String& module_name = module->name();
122 auto iter = m_modules_map.find(module_name);
123 m_modules_map.erase(iter);
124
125 m_modules.remove(module.get());
126}
127
128/*---------------------------------------------------------------------------*/
129/*---------------------------------------------------------------------------*/
130
132dumpList(std::ostream& o)
133{
134 o << "** ModuleMng::dump_list: " << m_modules.count();
135 o << '\n';
136 for( ModuleList::Enumerator i(m_modules); ++i; ){
137 o << "** Module: " << (*i)->name();
138 o << '\n';
139 }
140}
141
142/*---------------------------------------------------------------------------*/
143/*---------------------------------------------------------------------------*/
144
146isModuleActive(const String& name)
147{
148 IModule* module = _findModule(name);
149 if (!module)
150 return false;
151 return !module->disabled();
152}
153
154/*---------------------------------------------------------------------------*/
155/*---------------------------------------------------------------------------*/
156
158findModule(const String& name)
159{
160 return _findModule(name);
161}
162
163/*---------------------------------------------------------------------------*/
164/*---------------------------------------------------------------------------*/
165
166IModule* ModuleMng::
167_findModule(const String& name)
168{
169 auto iter = m_modules_map.find(name);
170 if (iter!=m_modules_map.end())
171 return iter->second.get();
172 return nullptr;
173}
174
175/*---------------------------------------------------------------------------*/
176/*---------------------------------------------------------------------------*/
177
178} // End namespace Arcane
179
180/*---------------------------------------------------------------------------*/
181/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
void clear()
Supprime tous les éléments de la collection.
Definition Collection.h:68
Integer count() const
Nombre d'éléments de la collection.
Definition Collection.h:70
Interface du gestionnaire de modules.
Definition IModuleMng.h:39
Interface d'un module.
Definition IModule.h:39
Interface du gestionnaire d'un sous-domaine.
Definition ISubDomain.h:74
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
Gestionnaire des modules.
Definition ModuleMng.cc:42
bool isModuleActive(const String &name) override
Indique si le module de nom name est actif.
Definition ModuleMng.cc:146
IModule * findModule(const String &name) override
Retourne l'instance du module de nom name.
Definition ModuleMng.cc:158
void addModule(Ref< IModule >) override
Ajoute le module m au gestionnaire.
Definition ModuleMng.cc:105
ModuleList m_modules
Liste des modules.
Definition ModuleMng.cc:58
void removeAllModules() override
Supprime et détruit les modules gérés par ce gestionnaire.
Definition ModuleMng.cc:95
void removeModule(Ref< IModule >) override
Supprime le module m.
Definition ModuleMng.cc:119
void dumpList(std::ostream &) override
Affiche la liste des modules du gestionnaire sur un flux o.
Definition ModuleMng.cc:132
ModuleCollection modules() const override
Liste des modules.
Definition ModuleMng.cc:51
Chaîne de caractères unicode.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-