Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
ServiceRegisterer.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/* ServiceRegisterer.cc (C) 2000-2018 */
9/* */
10/* Register containing the list of service implementations. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/ArcanePrecomp.h"
15
16#include "arcane/utils/Iostream.h"
17
18#include "arcane/core/ServiceRegisterer.h"
19
20#include <stdlib.h>
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
31static ServiceRegisterer* global_arcane_first_service = nullptr;
32static Integer global_arcane_nb_service = 0;
33
34/*---------------------------------------------------------------------------*/
35/*---------------------------------------------------------------------------*/
36
38ServiceRegisterer(ServiceInfoWithPropertyCreateFunc func,
39 const ServiceProperty& properties) ARCANE_NOEXCEPT
40: m_module_factory_with_property_functor(nullptr)
41, m_info_function_with_property(func)
42, m_name(properties.name())
43, m_service_property(properties)
44, m_module_property(properties.name())
45, m_previous(nullptr)
46, m_next(nullptr)
47{
48 _init();
49}
50
51/*---------------------------------------------------------------------------*/
52/*---------------------------------------------------------------------------*/
53
55ServiceRegisterer(ModuleFactoryWithPropertyFunc func,
56 const ModuleProperty& properties) ARCANE_NOEXCEPT
57: m_module_factory_with_property_functor(func)
58, m_info_function_with_property(nullptr)
59, m_name(properties.name())
60, m_service_property(ServiceProperty(properties.name(), 0))
61, m_module_property(properties)
62, m_previous(nullptr)
63, m_next(nullptr)
64{
65 _init();
66}
67
68/*---------------------------------------------------------------------------*/
69/*---------------------------------------------------------------------------*/
70
71void ServiceRegisterer::
72_init()
73{
74 if (global_arcane_first_service == nullptr) {
75 global_arcane_first_service = this;
76 setPreviousService(nullptr);
77 setNextService(nullptr);
78 }
79 else {
80 ServiceRegisterer* next = global_arcane_first_service->nextService();
81 setNextService(global_arcane_first_service);
82 global_arcane_first_service = this;
83 if (next)
84 next->setPreviousService(this);
85 }
86 ++global_arcane_nb_service;
87
88 { // Check integrity
89 ServiceRegisterer* p = global_arcane_first_service;
90 Integer count = global_arcane_nb_service;
91 while (p && count > 0) {
92 p = p->nextService();
93 --count;
94 }
95 if (p) {
96 cout << "Arcane Fatal Error: Service '" << m_name << "' conflict in service registration" << std::endl;
97 exit(1);
98 }
99 else if (count > 0) {
100 cout << "Arcane Fatal Error: Service '" << m_name << "' breaks service registration (inconsistent shortcut)" << std::endl;
101 exit(1);
102 }
103 }
104}
105
106/*---------------------------------------------------------------------------*/
107/*---------------------------------------------------------------------------*/
108
111{
112 return global_arcane_first_service;
113}
114
115/*---------------------------------------------------------------------------*/
116/*---------------------------------------------------------------------------*/
117
119nbService()
120{
121 return global_arcane_nb_service;
122}
123
124/*---------------------------------------------------------------------------*/
125/*---------------------------------------------------------------------------*/
126
127} // namespace Arcane
128
129/*---------------------------------------------------------------------------*/
130/*---------------------------------------------------------------------------*/
Module creation properties.
Service creation properties.
Service and module registrar.
static ServiceRegisterer * firstService()
Access to the first element of the service registrar chain.
ServiceRegisterer * nextService() const
Next service (0 if the last).
static Integer nbService()
Number of service registrars in the chain.
ServiceRegisterer(ServiceInfoWithPropertyCreateFunc func, const ServiceProperty &properties) ARCANE_NOEXCEPT
Creates a registrar for the service name and the function func.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.