Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
ServiceInfo.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/* ServiceInfo.cc (C) 2000-2019 */
9/* */
10/* Information about a service. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/ArcanePrecomp.h"
15
16#include "arcane/utils/List.h"
17#include "arcane/utils/VersionInfo.h"
18#include "arcane/utils/String.h"
19#include "arcane/utils/StringBuilder.h"
20
21#include "arcane/core/ServiceInfo.h"
23#include "arcane/core/StringDictionary.h"
24#include "arcane/core/IBase.h"
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29namespace Arcane::Internal
30{
31
32/*---------------------------------------------------------------------------*/
33/*---------------------------------------------------------------------------*/
34
35class ServiceInfoPrivate
36{
37 public:
38
39 ServiceInfoPrivate(const String& local_name, const VersionInfo& version,
40 Integer valid_dimension);
41 ~ServiceInfoPrivate();
42
43 public:
44
45 List<IServiceFactory2*> factories() { return m_factories; }
46 void addFactory(IServiceFactory2* factory)
47 {
48 m_factories.add(factory);
49 m_ref_factories.add(ReferenceCounter<IServiceFactory2>(factory));
50 }
51
52 public:
53
54 String m_namespace_uri;
55 String m_local_name;
56 VersionInfo m_version;
57 Integer m_valid_dimension;
58 StringList m_implemented_interfaces;
59 String m_case_options_file_name;
60
61 private:
62
63 List<IServiceFactory2*> m_factories;
65
66 public:
67
68 ISingletonServiceFactory* m_singleton_factory;
69 StringDictionary m_tag_names;
70 String m_default_tag_name;
71 Real m_axl_version;
72 IServiceFactoryInfo* m_factory_info;
73 FileContent m_axl_content;
74 int m_usage_type;
75};
76
77/*---------------------------------------------------------------------------*/
78/*---------------------------------------------------------------------------*/
79
80ServiceInfoPrivate::
81ServiceInfoPrivate(const String& local_name, const VersionInfo& version,
82 Integer valid_dimension)
83: m_namespace_uri(arcaneNamespaceURI())
84, m_local_name(local_name)
85, m_version(version)
86, m_valid_dimension(valid_dimension)
87, m_singleton_factory(nullptr)
88, m_axl_version(0.0)
89, m_factory_info(nullptr)
90, m_usage_type(ST_None)
91{
92 m_default_tag_name = local_name.clone();
93 m_default_tag_name = m_default_tag_name.lower();
94}
95
96/*---------------------------------------------------------------------------*/
97/*---------------------------------------------------------------------------*/
98
99ServiceInfoPrivate::
100~ServiceInfoPrivate()
101{
102 delete m_singleton_factory;
103}
104
105/*---------------------------------------------------------------------------*/
106/*---------------------------------------------------------------------------*/
107
108/*---------------------------------------------------------------------------*/
109/*---------------------------------------------------------------------------*/
110
112ServiceInfo(const String& local_name, const VersionInfo& version,
113 Integer valid_dimension)
114: m_p(new ServiceInfoPrivate(local_name, version, valid_dimension))
115{
116}
117
118/*---------------------------------------------------------------------------*/
119/*---------------------------------------------------------------------------*/
120
123{
124 delete m_p;
125}
126
127/*---------------------------------------------------------------------------*/
128/*---------------------------------------------------------------------------*/
129
131namespaceURI() const
132{
133 return m_p->m_namespace_uri;
134}
135
136/*---------------------------------------------------------------------------*/
137/*---------------------------------------------------------------------------*/
138
140localName() const
141{
142 return m_p->m_local_name;
143}
144
145/*---------------------------------------------------------------------------*/
146/*---------------------------------------------------------------------------*/
147
149version() const
150{
151 return m_p->m_version;
152}
153
154/*---------------------------------------------------------------------------*/
155/*---------------------------------------------------------------------------*/
156
158allowDimension(Integer n) const
159{
160 if (n == 3 && (m_p->m_valid_dimension & Dim3))
161 return true;
162 if (n == 2 && (m_p->m_valid_dimension & Dim2))
163 return true;
164 if (n == 1 && (m_p->m_valid_dimension & Dim1))
165 return true;
166 return false;
167}
168
169/*---------------------------------------------------------------------------*/
170/*---------------------------------------------------------------------------*/
171
174{
175 if (m_p->m_implemented_interfaces.contains(name))
176 return;
177 m_p->m_implemented_interfaces.add(name);
178}
179
180/*---------------------------------------------------------------------------*/
181/*---------------------------------------------------------------------------*/
182
185{
186 return m_p->m_implemented_interfaces;
187}
188
189/*---------------------------------------------------------------------------*/
190/*---------------------------------------------------------------------------*/
191
194{
195 return m_p->m_case_options_file_name;
196}
197
198/*---------------------------------------------------------------------------*/
199/*---------------------------------------------------------------------------*/
200
201void ServiceInfo::
202setCaseOptionsFileName(const String& fn)
203{
204 m_p->m_case_options_file_name = fn;
205}
206
207/*---------------------------------------------------------------------------*/
208/*---------------------------------------------------------------------------*/
209
210void ServiceInfo::
211addFactory(IServiceFactory2* factory)
212{
213 m_p->addFactory(factory);
214}
215
216/*---------------------------------------------------------------------------*/
217/*---------------------------------------------------------------------------*/
218
220factories() const
221{
222 return m_p->factories();
223}
224
225/*---------------------------------------------------------------------------*/
226/*---------------------------------------------------------------------------*/
227
229singletonFactory() const
230{
231 return m_p->m_singleton_factory;
232}
233
234/*---------------------------------------------------------------------------*/
235/*---------------------------------------------------------------------------*/
236
237void ServiceInfo::
238setSingletonFactory(ISingletonServiceFactory* f)
239{
240 delete m_p->m_singleton_factory;
241 m_p->m_singleton_factory = f;
242}
243
244/*---------------------------------------------------------------------------*/
245/*---------------------------------------------------------------------------*/
246
248tagName(const String& lang) const
249{
250 String v = m_p->m_tag_names.find(lang);
251 if (v.null())
252 v = m_p->m_default_tag_name;
253 return v;
254}
255
256/*---------------------------------------------------------------------------*/
257/*---------------------------------------------------------------------------*/
258
259void ServiceInfo::
260setDefaultTagName(const String& value)
261{
262 m_p->m_default_tag_name = value;
263}
264
265/*---------------------------------------------------------------------------*/
266/*---------------------------------------------------------------------------*/
267
268void ServiceInfo::
269setTagName(const String& value, const String& lang)
270{
271 m_p->m_tag_names.add(lang, value);
272}
273
274/*---------------------------------------------------------------------------*/
275/*---------------------------------------------------------------------------*/
276
278axlVersion() const
279{
280 return m_p->m_axl_version;
281}
282
283/*---------------------------------------------------------------------------*/
284/*---------------------------------------------------------------------------*/
285
286void ServiceInfo::
287setAxlVersion(Real v) const
288{
289 m_p->m_axl_version = v;
290}
291
292/*---------------------------------------------------------------------------*/
293/*---------------------------------------------------------------------------*/
294
296factoryInfo() const
297{
298 return m_p->m_factory_info;
299}
300
301/*---------------------------------------------------------------------------*/
302/*---------------------------------------------------------------------------*/
303
304void ServiceInfo::
305setFactoryInfo(IServiceFactoryInfo* sfi)
306{
307 m_p->m_factory_info = sfi;
308}
309
310void ServiceInfo::
311setAxlContent(const FileContent& file_content)
312{
313 m_p->m_axl_content = file_content;
314}
315
317axlContent() const
318{
319 return m_p->m_axl_content;
320}
321
322/*---------------------------------------------------------------------------*/
323/*---------------------------------------------------------------------------*/
324
326usageType() const
327{
328 return m_p->m_usage_type;
329}
330
331/*---------------------------------------------------------------------------*/
332/*---------------------------------------------------------------------------*/
333
334ServiceInfo* ServiceInfo::
335create(const ServiceProperty& sp, const char* filename, int lineno)
336{
337 ARCANE_UNUSED(filename);
338 ARCANE_UNUSED(lineno);
339 //TODO: use the 'filename' and 'lineno' info.
340
341 // Attention to properly copy the string from sp because it is a const char*.
342 String name = std::string_view(sp.name());
343 ServiceInfo* si = new ServiceInfo(name, VersionInfo("0.0"), IServiceInfo::Dim2 | IServiceInfo::Dim3);
345 si->setFactoryInfo(sfi);
346 sfi->initProperties(sp.properties());
347 si->m_p->m_usage_type = sp.type();
348 return si;
349}
350
351/*---------------------------------------------------------------------------*/
352/*---------------------------------------------------------------------------*/
353
354ServiceInfo* ServiceInfo::
355create(const String& name, int service_type)
356{
357 ServiceProperty sp(name.localstr(), service_type);
358 return create(sp, "none", 0);
359}
360
361/*---------------------------------------------------------------------------*/
362/*---------------------------------------------------------------------------*/
363
364} // End namespace Arcane::Internal
365
366/*---------------------------------------------------------------------------*/
367/*---------------------------------------------------------------------------*/
This file contains the various service factories and macros for registering services.
Description and content of a file.
Definition FileContent.h:33
Information about a service factory.
Information about the manufacturing of a service or a module.
Information about a service.
Definition ServiceInfo.h:51
ServiceInfo(const String &local_name, const VersionInfo &version, Integer valid_dimension)
Constructor.
const FileContent & axlContent() const override
Content of the AXL file associated with this service or module.
~ServiceInfo() override
Destructor.
String localName() const override
Local part of the service name.
String namespaceURI() const override
Service name namespace.
bool allowDimension(Integer n) const override
Indicates if the service is usable in dimension n.
VersionInfo version() const override
Service version.
StringCollection implementedInterfaces() const override
List of names of classes implemented by this service.
ServiceFactory2Collection factories() const override
List of service factories.
void addImplementedInterface(const String &name) override
Adds the name interface name to the interfaces implemented by this service.
ISingletonServiceFactory * singletonFactory() const override
Factory for singleton services (nullptr if not supported).
int usageType() const override
Indicates where the service can be used.
const String & caseOptionsFileName() const override
Name of the file containing the dataset (null if none).
IServiceFactoryInfo * factoryInfo() const override
Info on the factories available for this service.
Real axlVersion() const override
Version of the axl file describing this service.
String tagName(const String &lang) const override
Name of the service XML element for the language lang. If lang is null, returns the default name.
Implementation of a collection of elements in vector form.
Encapsulation of a pointer with a reference counter.
Service creation properties.
const char * name() const
Service name.
eServiceFactoryProperties properties() const
Service properties (combination of eServiceFactoryProperties).
int type() const
Service type (combination of eServiceType).
void add(const String &key, const String &value)
Adds the (key, value) pair to the dictionary.
bool null() const
Returns true if the string is null.
Definition String.cc:306
String clone() const
Clones this string.
Definition String.cc:414
String lower() const
Transforms all characters in the string to lowercase.
Definition String.cc:480
const char * localstr() const
Returns the conversion of the instance into UTF-8 encoding.
Definition String.cc:229
1D data vector with value semantics (STL style).
Information about a version.
Definition VersionInfo.h:47
Internal types of Arcane.
Int32 Integer
Type representing an integer.
Collection< String > StringCollection
Collection of strings.
Definition UtilsTypes.h:506
Collection< Internal::IServiceFactory2 * > ServiceFactory2Collection
Collection of service factories.
List< String > StringList
Unicode string list.
Definition UtilsTypes.h:509
double Real
Type representing a real number.