Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
ModuleFactory.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 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.cc (C) 2000-2019 */
9/* */
10/* Module manufacturing. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/ArcanePrecomp.h"
15
16#include "arcane/utils/String.h"
17#include "arcane/utils/FatalErrorException.h"
18#include "arcane/utils/TraceInfo.h"
19
20#include "arcane/core/ModuleFactory.h"
21#include "arcane/core/IModuleMng.h"
22#include "arcane/core/IModule.h"
23#include "arcane/core/ISubDomain.h"
24#include "arcane/core/IServiceInfo.h"
25#include "arcane/core/IMesh.h"
26
27#include "arcane/utils/Iostream.h"
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
32namespace Arcane
33{
34
35/*---------------------------------------------------------------------------*/
36/*---------------------------------------------------------------------------*/
37
39ModuleFactory(Ref<IModuleFactory2> factory, bool is_autoload)
40: m_factory(factory)
41, m_is_autoload(is_autoload)
42, m_name(factory->moduleName())
43, m_nb_ref(0)
44{
45 //cerr << "** ADD MODULE FACTORY this=" << this
46 // << " service_info_name=" << m_service_info->localName()
47 // << " autoload=" << is_autoload << '\n';
48}
49
50/*---------------------------------------------------------------------------*/
51/*---------------------------------------------------------------------------*/
52
53ModuleFactory::
54~ModuleFactory()
55{
56}
57
58/*---------------------------------------------------------------------------*/
59/*---------------------------------------------------------------------------*/
60
62createModule(ISubDomain* parent, const MeshHandle& mesh_handle)
63{
64 if (!m_factory)
65 ARCANE_FATAL("Null factory for module named '{0}'", moduleName());
66
67 Ref<IModule> module = m_factory->createModuleInstance(parent, mesh_handle);
68
69 if (!module)
70 ARCANE_FATAL("Can not create module named '{0}'", moduleName());
71
72 parent->checkId("ModuleFactory::createModule", module->name());
73 parent->moduleMng()->addModule(module);
74
75 return module;
76}
77
78/*---------------------------------------------------------------------------*/
79/*---------------------------------------------------------------------------*/
80
83{
84 m_factory->initializeModuleFactory(sub_domain);
85}
86
87/*---------------------------------------------------------------------------*/
88/*---------------------------------------------------------------------------*/
89
91serviceInfo() const
92{
93 return m_factory->serviceInfo();
94}
95
96/*---------------------------------------------------------------------------*/
97/*---------------------------------------------------------------------------*/
98
99void ModuleFactory::
100addReference()
101{
102 ++m_nb_ref;
103}
104
105/*---------------------------------------------------------------------------*/
106/*---------------------------------------------------------------------------*/
107
108void ModuleFactory::
109removeReference()
110{
111 // Decrements and returns the previous value.
112 // If it equals 1, it means there are no more references
113 // to the object and it must be destroyed.
114 Int32 v = std::atomic_fetch_add(&m_nb_ref, -1);
115 if (v == 1)
116 delete this;
117}
118
119/*---------------------------------------------------------------------------*/
120/*---------------------------------------------------------------------------*/
121
122ModuleFactoryReference::
123ModuleFactoryReference(Ref<IModuleFactory2> factory, bool is_autoload)
124: Base(new ModuleFactory(factory, is_autoload))
125{
126}
127
128/*---------------------------------------------------------------------------*/
129/*---------------------------------------------------------------------------*/
130
131/*---------------------------------------------------------------------------*/
132/*---------------------------------------------------------------------------*/
133
134ModuleFactory2::
135~ModuleFactory2()
136{
137 if (m_service_info) {
138 delete m_service_info->factoryInfo();
139 delete m_service_info;
140 }
141}
142
143/*---------------------------------------------------------------------------*/
144/*---------------------------------------------------------------------------*/
145
146} // End namespace Arcane
147
148/*---------------------------------------------------------------------------*/
149/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
virtual void addModule(Ref< IModule > m)=0
Adds module m to the manager.
Interface for service or module information.
Interface of the subdomain manager.
Definition ISubDomain.h:75
virtual IModuleMng * moduleMng()=0
Returns the module manager.
virtual void checkId(const String &where, const String &id)=0
Checks if an identifier is valid.
Handle on a mesh.
Definition MeshHandle.h:48
Module factory.
ModuleFactory(Ref< IModuleFactory2 > factory, bool is_autoload)
Constructs a factory for a module.
Ref< IModule > createModule(ISubDomain *parent, const MeshHandle &mesh_handle) override
Creates a module.
String moduleName() const override
Name of the module created by this factory.
void initializeModuleFactory(ISubDomain *sub_domain) override
If the factory is a one-to-one module, initializes it on the sub-domain sub_domain.
const IServiceInfo * serviceInfo() const override
Information about the module that can be created by this factory.
Reference to an instance.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --