Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
ModuleFactory.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/* ModuleFactory.h (C) 2000-2019 */
9/* */
10/* Manufacture des modules. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_MODULEFACTORY_H
13#define ARCANE_MODULEFACTORY_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/IServiceFactory.h"
18#include "arcane/IModuleFactory.h"
19#include "arcane/ServiceRegisterer.h"
20#include "arcane/ModuleBuildInfo.h"
21#include "arcane/IServiceInfo.h"
22#include "arcane/ModuleProperty.h"
23#include "arcane/ServiceProperty.h"
24
25#include <atomic>
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
30namespace Arcane
31{
32
33/*---------------------------------------------------------------------------*/
34/*---------------------------------------------------------------------------*/
39class ARCANE_CORE_EXPORT ModuleFactory
40: public IModuleFactoryInfo
41{
42 public:
43
54 ~ModuleFactory() override;
55
56 public:
57
58 void addReference() override;
59 void removeReference() override;
60 Ref<IModule> createModule(ISubDomain* parent,const MeshHandle& mesh_handle) override;
61 bool isAutoload() const override { return m_is_autoload; }
62 void initializeModuleFactory(ISubDomain* sub_domain) override;
63 String moduleName() const override { return m_name; }
64 const IServiceInfo* serviceInfo() const override;
65
66 private:
67
68 Ref<IModuleFactory2> m_factory;
69 bool m_is_autoload;
70 String m_name;
71 std::atomic<Int32> m_nb_ref;
72};
73
74/*---------------------------------------------------------------------------*/
75/*---------------------------------------------------------------------------*/
80class ARCANE_CORE_EXPORT ModuleFactory2
81: public IModuleFactory2
82{
83 public:
84
85 ModuleFactory2(IServiceInfo* service_info,const String& name)
86 : m_service_info(service_info), m_name(name)
87 {
88 }
89 ~ModuleFactory2() override;
90
91 String moduleName() const override
92 {
93 return m_name;
94 }
95
96 const IServiceInfo* serviceInfo() const override
97 {
98 return m_service_info;
99 }
100
101 private:
102
103 IServiceInfo* m_service_info;
104 String m_name;
105};
106
107/*---------------------------------------------------------------------------*/
108/*---------------------------------------------------------------------------*/
115template<class ModuleType>
117: public ModuleFactory2
118{
119 public:
120
121 ModuleFactory2T(IServiceInfo* service_info,const String& name)
122 : ModuleFactory2(service_info,name)
123 {
124 }
125
131
133 {
134 ModuleType::staticInitialize(sd);
135 }
136};
137
138/*---------------------------------------------------------------------------*/
139/*---------------------------------------------------------------------------*/
166#define ARCANE_REGISTER_MODULE(class_name,a_module_properties) \
167extern "C++" ARCANE_EXPORT Arcane::IModuleFactoryInfo*\
168ARCANE_JOIN_WITH_LINE(arcaneCreateModuleFactory##class_name) (const Arcane::ModuleProperty& properties) \
169{\
170 const char* module_name = properties.name();\
171 Arcane::ServiceProperty sp(module_name,0);\
172 auto* si = Arcane::Internal::ServiceInfo::create(sp,__FILE__,__LINE__); \
173 Arcane::IModuleFactory2* mf = new Arcane::ModuleFactory2T< class_name >(si,module_name); \
174 return new Arcane::ModuleFactory(Arcane::makeRef(mf), properties.isAutoload()); \
175} \
176Arcane::ServiceRegisterer ARCANE_EXPORT ARCANE_JOIN_WITH_LINE(globalModuleRegisterer##class_name) \
177 (& ARCANE_JOIN_WITH_LINE(arcaneCreateModuleFactory##class_name),a_module_properties)
178
179/*---------------------------------------------------------------------------*/
180/*---------------------------------------------------------------------------*/
187#define ARCANE_REGISTER_AXL_MODULE(class_name,a_module_properties) \
188extern "C++" ARCANE_EXPORT Arcane::IModuleFactoryInfo*\
189ARCANE_JOIN_WITH_LINE(arcaneCreateModuleFactory##class_name) (const Arcane::ModuleProperty& properties) \
190{\
191 const char* module_name = properties.name();\
192 Arcane::ServiceProperty sp(module_name,0);\
193 auto* si = Arcane::Internal::ServiceInfo::create(sp,__FILE__,__LINE__); \
194 class_name :: fillServiceInfo(si); \
195 Arcane::IModuleFactory2* mf = new Arcane::ModuleFactory2T< class_name >(si,module_name); \
196 return new Arcane::ModuleFactory(Arcane::makeRef(mf),properties.isAutoload()); \
197} \
198Arcane::ServiceRegisterer ARCANE_EXPORT ARCANE_JOIN_WITH_LINE(globalModuleRegisterer##class_name) \
199 (& ARCANE_JOIN_WITH_LINE(arcaneCreateModuleFactory##class_name),a_module_properties)
200
201/*---------------------------------------------------------------------------*/
202/*---------------------------------------------------------------------------*/
211#define ARCANE_DEFINE_STANDARD_MODULE(class_name,module_name) \
212 ARCANE_REGISTER_MODULE(class_name,Arcane::ModuleProperty(#module_name))
213
214/*---------------------------------------------------------------------------*/
215/*---------------------------------------------------------------------------*/
216
217} // End namespace Arcane
218
219/*---------------------------------------------------------------------------*/
220/*---------------------------------------------------------------------------*/
221
222#endif
Interface d'une fabrique de module (V2).
Informations sur la fabrique d'un module.
Interface des informations d'un service ou d'un module.
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
Handle sur un maillage.
Definition MeshHandle.h:47
Informations pour construire un module.
Classe template de fabrique de module.
Ref< IModule > createModuleInstance(ISubDomain *sd, const MeshHandle &mesh_handle) override
Créé un module.
void initializeModuleFactory(ISubDomain *sd) override
Initialisation statique du module.
Classe implémentant IModuleFactory2.
String moduleName() const override
Nom du module créé par cette fabrique.
const IServiceInfo * serviceInfo() const override
Informations sur le module pouvant être créé par cette fabrique.
Fabrique d'un module.
String moduleName() const override
Nom du module créé par cette fabrique.
bool isAutoload() const override
Indique si le module et doit être chargé automatiquement.
Chaîne de caractères unicode.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-