Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
CaseOptionEnum.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/* CaseOptionEnum.h (C) 2000-2023 */
9/* */
10/* Enumerated data set option. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CASEOPTIONENUM_H
13#define ARCANE_CASEOPTIONENUM_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/core/CaseOptionSimple.h"
18
19/*---------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
22namespace Arcane
23{
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
33class ARCANE_CORE_EXPORT CaseOptionName
34{
35 public:
36
38 CaseOptionName(const String& true_name);
42 virtual ~CaseOptionName();
43
44 public:
45
50 String name(const String& lang) const;
52 String trueName() const { return m_true_name; }
61 void addAlternativeNodeName(const String& lang, const String& tname);
62
63 private:
64
67};
68
69/*---------------------------------------------------------------------------*/
70/*---------------------------------------------------------------------------*/
71
76class ARCANE_CORE_EXPORT CaseOptionEnumValue
77: public CaseOptionName
78{
79 public:
80
81 CaseOptionEnumValue(const String& name, int value);
83 CaseOptionEnumValue(const CaseOptionEnumValue& rhs);
84 ~CaseOptionEnumValue();
85
86 public:
87
88 int value() const { return m_value; }
89
90 private:
91
92 int m_value;
93};
94
95/*---------------------------------------------------------------------------*/
96/*---------------------------------------------------------------------------*/
97
102class ARCANE_CORE_EXPORT CaseOptionEnumValues
103{
104 public:
105
108
109 public:
110
114
115 public:
116
123 void addEnumValue(CaseOptionEnumValue* value, bool do_clone);
124
126 Integer nbEnumValue() const;
127
130
140 bool valueOfName(const String& name, const String& lang, int& value) const;
141
143 String nameOfValue(int value, const String& lang) const;
144
148 void getValidNames(const String& lang, StringArray& names) const;
149
150 private:
151
153};
154
155/*---------------------------------------------------------------------------*/
156/*---------------------------------------------------------------------------*/
157
162class ARCANE_CORE_EXPORT CaseOptionEnum
163: public CaseOptionSimple
164{
165 public:
166
167 CaseOptionEnum(const CaseOptionBuildInfo& cob, const String& type_name);
168 ~CaseOptionEnum();
169
170 public:
171
172 virtual void print(const String& lang, std::ostream& o) const;
173 virtual void updateFromFunction(Real current_time, Integer current_iteration)
174 {
175 _updateFromFunction(current_time, current_iteration);
176 }
177
178 void addEnumValue(CaseOptionEnumValue* value, bool do_clone)
179 {
180 m_enum_values->addEnumValue(value, do_clone);
181 }
182 CaseOptionEnumValues* enumValues() const { return m_enum_values; }
183
184 virtual void visit(ICaseDocumentVisitor* visitor) const;
185
186 int enumValueAsInt() const { return _optionValue(); }
187
188 public:
189 protected:
190
191 virtual void _search(bool is_phase1);
192 virtual bool _allowPhysicalUnit() { return false; }
193
195 virtual void _setOptionValue(int v) = 0;
197 virtual int _optionValue() const = 0;
198
199 protected:
200
201 void _setEnumDefaultValue(int def_value);
202
203 private:
204
206 CaseOptionEnumValues* m_enum_values;
207 void _updateFromFunction(Real current_time, Integer current_iteration);
208};
209
210/*---------------------------------------------------------------------------*/
211/*---------------------------------------------------------------------------*/
212
219template <class EnumType>
220class CaseOptionEnumT
221: public CaseOptionEnum
222{
223 public:
224
225 CaseOptionEnumT(const CaseOptionBuildInfo& cob, const String& type_name)
226 : CaseOptionEnum(cob, type_name)
227 , m_value(EnumType())
228 {}
229
230 public:
231
233 EnumType value() const
234 {
235 ARCANE_CASEOPTION_CHECK_IS_INITIALIZED;
236 return m_value;
237 }
238
240 operator EnumType() const { return value(); }
241
243 EnumType operator()() const { return value(); }
244
251 void setDefaultValue(EnumType def_value)
252 {
253 _setEnumDefaultValue(static_cast<int>(def_value));
254 }
255
257 EnumType valueIfPresentOrArgument(EnumType arg_value)
258 {
259 ARCANE_CASEOPTION_CHECK_IS_INITIALIZED;
260 return isPresent() ? m_value : arg_value;
261 }
262
263 private:
264
265 EnumType m_value;
266
267 public:
268 protected:
269
270 virtual void _setOptionValue(int i)
271 {
272 m_value = static_cast<EnumType>(i);
273 }
274 virtual int _optionValue() const
275 {
276 return static_cast<int>(m_value);
277 }
278};
279
280/*---------------------------------------------------------------------------*/
281/*---------------------------------------------------------------------------*/
282
287class ARCANE_CORE_EXPORT CaseOptionMultiEnum
288: public CaseOptionBase
289{
290 public:
291 public:
292
293 CaseOptionMultiEnum(const CaseOptionBuildInfo& cob, const String& type_name);
294 ~CaseOptionMultiEnum();
295
296 public:
297
298 virtual void print(const String& lang, std::ostream& o) const;
299 virtual ICaseFunction* function() const { return 0; }
300 virtual void updateFromFunction(Real /*current_time*/, Integer /*current_iteration*/) {}
301
302 void addEnumValue(CaseOptionEnumValue* value, bool do_clone)
303 {
304 m_enum_values->addEnumValue(value, do_clone);
305 }
306
307 CaseOptionEnumValues* enumValues() const { return m_enum_values; }
308
309 virtual void visit(ICaseDocumentVisitor* visitor) const;
310
311 protected:
312
313 virtual void _search(bool is_phase1);
314 virtual bool _allowPhysicalUnit() { return false; }
315
317 virtual void _allocate(Integer size) = 0;
319 virtual Integer _nbElem() const = 0;
323 virtual void _setOptionValue(Integer index, int v) = 0;
325 virtual int _optionValue(Integer index) const = 0;
326
327 private:
328
330 CaseOptionEnumValues* m_enum_values;
331};
332
333/*---------------------------------------------------------------------------*/
334/*---------------------------------------------------------------------------*/
335
340template <class T>
341class CaseOptionMultiEnumT
342: public CaseOptionMultiEnum
343, public ArrayView<T>
344{
345 public:
346
347 typedef T Type;
348
349 public:
350
351 CaseOptionMultiEnumT(const CaseOptionBuildInfo& cob, const String type_name)
352 : CaseOptionMultiEnum(cob, type_name)
353 {}
354
355 protected:
356
357 virtual void _allocate(Integer size)
358 {
359 m_values.resize(size);
360 ArrayView<T>* view = this;
361 *view = m_values.view();
362 }
363 virtual Integer _nbElem() const
364 {
365 return this->size();
366 }
367 virtual void _setOptionValue(Integer index, int v)
368 {
369 (*this)[index] = static_cast<T>(v);
370 }
371 virtual int _optionValue(Integer index) const
372 {
373 return static_cast<int>((*this)[index]);
374 }
375
376 private:
377
378 UniqueArray<T> m_values;
379};
380
381/*---------------------------------------------------------------------------*/
382/*---------------------------------------------------------------------------*/
383
384} // End namespace Arcane
385
386/*---------------------------------------------------------------------------*/
387/*---------------------------------------------------------------------------*/
388
389#endif
constexpr ArrayView() noexcept
Constructs an empty view.
constexpr Integer size() const noexcept
Returns the size of the array.
Information for building a dataset option.
EnumType value() const
Option value.
EnumType operator()() const
Option value.
void setDefaultValue(EnumType def_value)
Sets the default value of the option.
EnumType m_value
Option value.
virtual void _setOptionValue(int i)
Sets the option value to v.
EnumType valueIfPresentOrArgument(EnumType arg_value)
Returns the option value if isPresent()==true, otherwise arg_value.
virtual int _optionValue() const
Returns the option value.
Name and value of a data set enumeration.
Set of values for an enumeration.
String nameOfValue(int value, const String &lang) const
Returns the name corresponding to the value value for the language lang.
CaseOptionEnumValues()
Constructs the instance.
UniqueArray< CaseOptionEnumValue * > EnumValueList
Type of the value list.
void getValidNames(const String &lang, StringArray &names) const
Fills names with valid names for the language lang.
EnumValueList * m_enum_values
Enumeration values.
bool valueOfName(const String &name, const String &lang, int &value) const
Returns the value of the enumeration having the name name.
Integer nbEnumValue() const
Returns the number of enumeration values.
CaseOptionEnumValue * enumValue(Integer index) const
Returns the i-th value.
void addEnumValue(CaseOptionEnumValue *value, bool do_clone)
Adds the enumeration value value. The instance becomes the owner of value, which is destroyed when it...
virtual void print(const String &lang, std::ostream &o) const
Prints the option value in the language lang, to the stream o.
virtual void _setOptionValue(int v)=0
Sets the option value to v.
virtual void updateFromFunction(Real current_time, Integer current_iteration)
Updates the option value from a function.
virtual int _optionValue() const =0
Returns the option value.
String m_type_name
Enumeration name.
virtual void _setOptionValue(Integer index, int v)
virtual Integer _nbElem() const
Returns the number of elements in the array.
virtual int _optionValue(Integer index) const
Returns the enumeration value for index index.
virtual void _allocate(Integer size)
Allocates an array for size elements.
virtual Integer _nbElem() const =0
Returns the number of elements in the array.
String m_type_name
Enumeration name.
virtual void print(const String &lang, std::ostream &o) const
Prints the option value in the language lang, to the stream o.
virtual void _allocate(Integer size)=0
Allocates an array for size elements.
virtual ICaseFunction * function() const
Returns the function linked to this option or nullptr if none exists.
virtual void updateFromFunction(Real, Integer)
Updates the option value from a function.
virtual int _optionValue(Integer index) const =0
Returns the enumeration value for index index.
virtual void _setOptionValue(Integer index, int v)=0
String name(const String &lang) const
returns the name of the option in the language lang. If no translation is available in the language l...
CaseOptionName(const String &true_name)
Constructs a name option true_name.
String trueName() const
Returns the true name (non-translated) of the option.
StringDictionary * m_translations
Translations.
String m_true_name
Option name.
bool isPresent() const
Returns true if the option is present.
Interface of a dataset function.
1D data vector with value semantics (STL style).
-- 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
Int32 Integer
Type representing an integer.
double Real
Type representing a real number.