Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
CaseOptionServiceImpl.h
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/* CaseOptionServiceImpl.h (C) 2000-2025 */
9/* */
10/* Implementation of a dataset option using a service. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_CASEOPTIONSERVICEIMPL_H
13#define ARCANE_CORE_CASEOPTIONSERVICEIMPL_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/Functor.h"
18
19#include "arcane/core/CaseOptions.h"
20#include "arcane/core/CaseOptionsMulti.h"
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
31class IService;
33
34/*---------------------------------------------------------------------------*/
35/*---------------------------------------------------------------------------*/
36
37/*!
38 * \brief Interface of a service instance container.
39 * \todo: add reference counter
40 */
41class ARCANE_CORE_EXPORT ICaseOptionServiceContainer
42{
43 public:
44
45 virtual ~ICaseOptionServiceContainer() = default;
46
47 public:
48
49 virtual bool tryCreateService(Integer index, Internal::IServiceFactory2* factory, const ServiceBuildInfoBase& sbi) = 0;
50 virtual bool hasInterfaceImplemented(Internal::IServiceFactory2*) const = 0;
51 //! Allocates an array for \a size elements
52 virtual void allocate(Integer size) = 0;
53 //! Returns the number of elements in the array.
54 virtual Integer nbElem() const = 0;
55};
56
57/*---------------------------------------------------------------------------*/
58/*---------------------------------------------------------------------------*/
59
60/*!
61 * \internal
62 * \ingroup CaseOption
63 * \brief Base class for implementing options using services.
64 *
65 * This class is internal to Arcane. The class to use is 'CaseOptionService'.
66 */
67class ARCANE_CORE_EXPORT CaseOptionServiceImpl
68: public CaseOptions
69{
70 public:
71
72 CaseOptionServiceImpl(const CaseOptionBuildInfo& cob, bool allow_null, bool is_optional);
73
74 public:
75
76 void read(eCaseOptionReadPhase phase) override;
77 String serviceName() const { return m_service_name; }
78 bool isOptional() const { return m_is_optional; }
79
80 //! Returns the valid implementation names for this service in \a names
81 virtual void getAvailableNames(StringArray& names) const;
82 void visit(ICaseDocumentVisitor* visitor) const override;
83
84 void setDefaultValue(const String& def_value);
85 void addDefaultValue(const String& category, const String& value);
86
87 /*!
88 * \brief Positions the instance container.
89 *
90 * \a container remains the property of the caller, who must manage
91 * its lifetime.
92 */
94
95 void setMeshName(const String& mesh_name) { m_mesh_name = mesh_name; }
96 String meshName() const { return m_mesh_name; }
97
98 protected:
99
100 virtual void print(const String& lang, std::ostream& o) const;
101
102 protected:
103
104 String _defaultValue() const { return m_default_value; }
105
106 private:
107
108 String m_name;
109 String m_default_value;
110 String m_service_name;
111 String m_mesh_name;
112 XmlNode m_element; //!< Option element
113 bool m_allow_null;
114 bool m_is_optional;
115 bool m_is_override_default;
116 //! List of default values by category.
117 StringDictionary m_default_values;
118 ICaseOptionServiceContainer* m_container;
119
120 private:
121
122 void _readPhase1();
123};
124
125/*---------------------------------------------------------------------------*/
126/*---------------------------------------------------------------------------*/
127
128/*!
129 * \internal
130 * \brief Base class for a service option that can appear multiple times.
131 *
132 * You must call setContainer() to position a container
133 * before using this class.
134 */
135class ARCANE_CORE_EXPORT CaseOptionMultiServiceImpl
136: public CaseOptionsMulti
137{
138 public:
139
140 CaseOptionMultiServiceImpl(const CaseOptionBuildInfo& cob, bool allow_null);
141 ~CaseOptionMultiServiceImpl();
142
143 public:
144
145 //! Returns the valid implementation names for this service in \a names
146 void getAvailableNames(StringArray& names) const;
147 //! Name of the nth service
149 {
150 return m_services_name[index];
151 }
152
153 void multiAllocate(const XmlNodeList&) override;
154 void visit(ICaseDocumentVisitor* visitor) const override;
155
156 /*!
157 * \brief Positions the instance container.
158 *
159 * \a container remains the property of the caller, who must manage
160 * its lifetime.
161 */
162 void setContainer(ICaseOptionServiceContainer* container);
163
164 void setMeshName(const String& mesh_name) { m_mesh_name = mesh_name; }
165 String meshName() const { return m_mesh_name; }
166
167 public:
168
169 void _setNotifyAllocateFunctor(IFunctor* f)
170 {
171 m_notify_functor = f;
172 }
173
174 protected:
175
176 String _defaultValue() const { return m_default_value; }
177
178 protected:
179
180 bool m_allow_null;
181 String m_default_value;
182 String m_mesh_name;
183 IFunctor* m_notify_functor;
184 ICaseOptionServiceContainer* m_container;
185 //! List of allocated options that must be deleted.
187 //! Service names for each occurrence
189};
190
191/*---------------------------------------------------------------------------*/
192/*---------------------------------------------------------------------------*/
193
194} // End namespace Arcane
195
196/*---------------------------------------------------------------------------*/
197/*---------------------------------------------------------------------------*/
198
199#endif
String serviceName(Integer index) const
Name of the nth service.
UniqueArray< String > m_services_name
Service names for each occurrence.
UniqueArray< ReferenceCounter< ICaseOptions > > m_allocated_options
List of allocated options that must be deleted.
void getAvailableNames(StringArray &names) const
Returns the valid implementation names for this service in names.
void setContainer(ICaseOptionServiceContainer *container)
Positions the instance container.
void read(eCaseOptionReadPhase phase) override
Performs the reading of the read_phase phase of the options.
void visit(ICaseDocumentVisitor *visitor) const override
Applies the visitor to this option.
virtual void getAvailableNames(StringArray &names) const
Returns the valid implementation names for this service in names.
CaseOptions(ICaseMng *cm, const String &name)
Constructs an options set.
Visitor interface for a dataset option.
Interface of a service instance container.
virtual void allocate(Integer size)=0
Allocates an array for size elements.
virtual Integer nbElem() const =0
Returns the number of elements in the array.
Interface of a service.
Definition IService.h:40
Information for creating a service.
1D data vector with value semantics (STL style).
List of nodes of a DOM tree.
Definition XmlNodeList.h:36
Node of a DOM tree.
Definition XmlNode.h:51
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Array< String > StringArray
Dynamic one-dimensional array of strings.
Definition UtilsTypes.h:145
eCaseOptionReadPhase
Reading phases.
Int32 Integer
Type representing an integer.