Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
CaseOptionSimple.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/* CaseOptionSimple.h (C) 2000-2025 */
9/* */
10/* Simple data set option. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CASEOPTIONSIMPLE_H
13#define ARCANE_CASEOPTIONSIMPLE_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/core/ICaseOptions.h"
18#include "arcane/core/CaseOptionBase.h"
19
20/*---------------------------------------------------------------------------*/
21/*---------------------------------------------------------------------------*/
22
23namespace Arcane
24{
25
29
30/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
32
33#ifdef ARCANE_CHECK
34#define ARCANE_CASEOPTION_CHECK_IS_INITIALIZED _checkIsInitialized()
35#else
36#define ARCANE_CASEOPTION_CHECK_IS_INITIALIZED
37#endif
38
39/*---------------------------------------------------------------------------*/
40/*---------------------------------------------------------------------------*/
41
42template <typename Type>
44{
45 public:
46
47 using ContainerType = Type;
48 using ReferenceType = Type&;
49 using ConstReferenceType = const Type&;
50 using ArrayViewType = ArrayView<Type>;
51 using ConstArrayViewType = ConstArrayView<Type>;
52};
53
54/*---------------------------------------------------------------------------*/
55/*---------------------------------------------------------------------------*/
56
64template <typename Type>
66{
67 public:
68
69 using ContainerType = UniqueArray<Type>;
70 using ReferenceType = const Array<Type>&;
71 using ConstReferenceType = const Array<Type>&;
72 using ArrayViewType = ConstArrayView<ContainerType>;
73 using ConstArrayViewType = ConstArrayView<ContainerType>;
74};
75
76/*---------------------------------------------------------------------------*/
77/*---------------------------------------------------------------------------*/
78
83class ARCANE_CORE_EXPORT CaseOptionSimple
84: public CaseOptionBase
85{
86 public:
87
88 explicit CaseOptionSimple(const CaseOptionBuildInfo& cob);
89 CaseOptionSimple(const CaseOptionBuildInfo& cob, const String& physical_unit);
90 ~CaseOptionSimple();
91
92 public:
93
95 bool isPresent() const { return !m_element.null(); }
96
103 ARCANE_DEPRECATED_LONG_TERM("Y2022: Do not access XML item from option")
104 XmlNode element() const { return m_element; }
105
112 ICaseFunction* function() const override { return m_function; }
128 bool hasChangedSinceLastIteration() const;
130 String xpathFullName() const;
135 String defaultPhysicalUnit() const;
137 String physicalUnit() const;
151 bool isOptional() const { return m_is_optional; }
152
159 bool hasValidValue() const { return m_has_valid_value; }
160
161 void visit(ICaseDocumentVisitor* visitor) const override;
162
163 protected:
164
165 void _search(bool is_phase1) override;
166 virtual bool _allowPhysicalUnit() = 0;
167 void _setChangedSinceLastIteration(bool has_changed);
168 void _searchFunction(XmlNode& velem);
169 void _setPhysicalUnit(const String& value);
170 void _setHasValidValue(bool v) { m_has_valid_value = v; }
171 XmlNode _element() const { return m_element; }
172
173 static String _convertFunctionRealToString(ICaseFunction* func, Real t);
174 static String _convertFunctionIntegerToString(ICaseFunction* func, Integer t);
175
176 private:
177
183 bool m_changed_since_last_iteration = false;
184 bool m_is_optional = false;
185 bool m_has_valid_value = false;
186 String m_default_physical_unit;
187 String m_physical_unit;
188};
189
190/*---------------------------------------------------------------------------*/
191/*---------------------------------------------------------------------------*/
192
209template <class T>
210class CaseOptionSimpleT
211: public CaseOptionSimple
212{
213 public:
214
215 typedef CaseOptionSimpleT<T> ThatClass;
216#ifndef SWIG
217 typedef typename CaseOptionTraitsT<T>::ContainerType Type;
218#else
219 typedef T Type;
220#endif
221 public:
222
223 ARCANE_CORE_EXPORT CaseOptionSimpleT(const CaseOptionBuildInfo& cob);
224 ARCANE_CORE_EXPORT CaseOptionSimpleT(const CaseOptionBuildInfo& cob, const String& physical_unit);
225
226 public:
227
228 ARCANE_CORE_EXPORT virtual void print(const String& lang, std::ostream& o) const;
229
231 const Type& value() const
232 {
233 ARCANE_CASEOPTION_CHECK_IS_INITIALIZED;
234 return m_value;
235 }
236
238 operator const Type&() const { return value(); }
239
241 ARCANE_CORE_EXPORT Type valueAtParameter(Real t) const;
242
244 ARCANE_CORE_EXPORT Type valueAtParameter(Integer t) const;
245
247 //const Type& operator()() const { return value(); }
248 const Type& operator()() const { return value(); }
249
250#ifdef ARCANE_DOTNET
251 operator ThatClass*() { return this; }
252 operator const ThatClass*() const { return this; }
253 const ThatClass* operator->() const { return this; }
254 static Real castTo__Arcane_Real(const ThatClass& v)
255 {
256 return (Real)(v);
257 }
258#endif
259
261 ARCANE_DEPRECATED Type operator()(Real t) const
262 {
263 return valueAtParameter(t);
264 }
265
267 ARCANE_DEPRECATED Type operator()(Integer t) const
268 {
269 return valueAtParameter(t);
270 }
271
276 ARCANE_CORE_EXPORT virtual void updateFromFunction(Real current_time, Integer current_iteration);
277
285 ARCANE_CORE_EXPORT void setDefaultValue(const Type& def_value);
286
288 const Type& valueIfPresentOrArgument(const Type& arg_value)
289 {
290 ARCANE_CASEOPTION_CHECK_IS_INITIALIZED;
291 return isPresent() ? m_value : arg_value;
292 }
293
294 protected:
295
296 ARCANE_CORE_EXPORT virtual void _search(bool is_phase1);
297 ARCANE_CORE_EXPORT virtual bool _allowPhysicalUnit();
298
299 private:
300
302};
303
304/*---------------------------------------------------------------------------*/
305/*---------------------------------------------------------------------------*/
306
307class ARCANE_CORE_EXPORT CaseOptionMultiSimple
308: public CaseOptionBase
309{
310 public:
311
312 CaseOptionMultiSimple(const CaseOptionBuildInfo& cob)
313 : CaseOptionBase(cob)
314 {}
315};
316
317/*---------------------------------------------------------------------------*/
318/*---------------------------------------------------------------------------*/
319
328#ifndef SWIG
329template <class T>
330class CaseOptionMultiSimpleT
331: public CaseOptionMultiSimple
332#ifdef ARCANE_HAS_PRIVATE_CASEOPTIONSMULTISIMPLE_BASE_CLASS
333, private ArrayView<T>
334#else
335, public ArrayView<T>
336#endif
337{
338 public:
339
341 using Type = typename CaseOptionTraitsT<T>::ContainerType;
342 using ReferenceType = typename CaseOptionTraitsT<T>::ReferenceType;
343 using ConstReferenceType = typename CaseOptionTraitsT<T>::ConstReferenceType;
345 using ArrayViewType = typename CaseOptionTraitsT<T>::ArrayViewType;
347 using ConstArrayViewType = typename CaseOptionTraitsT<T>::ConstArrayViewType;
348
349 public:
350
351 ARCANE_CORE_EXPORT CaseOptionMultiSimpleT(const CaseOptionBuildInfo& cob);
352 ARCANE_CORE_EXPORT CaseOptionMultiSimpleT(const CaseOptionBuildInfo& cob, const String& physical_unit);
353 ARCANE_CORE_EXPORT ~CaseOptionMultiSimpleT();
354
355 public:
356
357 ARCCORE_DEPRECATED_2021("Use view() instead")
358 ArrayView<T> operator()()
359 {
360 return *this;
361 }
362 ARCCORE_DEPRECATED_2021("Use view() instead")
363 const ArrayView<T> operator()() const
364 {
365 return *this;
366 }
367
369 ARCCORE_DEPRECATED_2021("Use view() instead")
370 operator ArrayView<T>()
371 {
372 ArrayView<T>* v = this;
373 return *v;
374 }
375
377 ARCCORE_DEPRECATED_2021("Use view() instead")
378 operator ConstArrayView<T>() const
379 {
380 const ArrayView<T>* v = this;
381 return *v;
382 }
383
386 {
387 return m_view;
388 }
389
391 {
392 return m_view;
393 }
394
395 ConstReferenceType operator[](Integer i) const { return m_view[i]; }
396 ReferenceType operator[](Integer i) { return m_view[i]; }
397
398 public:
399
400 ARCANE_CORE_EXPORT void print(const String& lang, std::ostream& o) const override;
401 ICaseFunction* function() const override { return 0; }
402 void updateFromFunction(Real, Integer) override {}
403
404 ConstArrayView<T> values() const
405 {
406 const ArrayView<T>* v = this;
407 return *v;
408 }
409 const T& value(Integer index) const { return this->operator[](index); }
410 Integer size() const { return ArrayView<T>::size(); }
411 ARCANE_CORE_EXPORT void visit(ICaseDocumentVisitor* visitor) const override;
412 bool isPresent() const { return !m_view.empty(); }
413
414 protected:
415
416 void _search(bool is_phase1) override;
417 virtual bool _allowPhysicalUnit();
418
419 private:
420
421 ArrayViewType m_view;
422};
423#endif
424
425/*---------------------------------------------------------------------------*/
426/*---------------------------------------------------------------------------*/
427
428typedef CaseOptionSimpleT<Real> CaseOptionReal;
429typedef CaseOptionSimpleT<Real2> CaseOptionReal2;
430typedef CaseOptionSimpleT<Real3> CaseOptionReal3;
431typedef CaseOptionSimpleT<Real2x2> CaseOptionReal2x2;
432typedef CaseOptionSimpleT<Real3x3> CaseOptionReal3x3;
433typedef CaseOptionSimpleT<bool> CaseOptionBool;
434typedef CaseOptionSimpleT<Integer> CaseOptionInteger;
435typedef CaseOptionSimpleT<Int32> CaseOptionInt32;
436typedef CaseOptionSimpleT<Int64> CaseOptionInt64;
437typedef CaseOptionSimpleT<String> CaseOptionString;
438
439typedef CaseOptionSimpleT<RealArray> CaseOptionRealArray;
440typedef CaseOptionSimpleT<Real2Array> CaseOptionReal2Array;
441typedef CaseOptionSimpleT<Real3Array> CaseOptionReal3Array;
442typedef CaseOptionSimpleT<Real2x2Array> CaseOptionReal2x2Array;
443typedef CaseOptionSimpleT<Real3x3Array> CaseOptionReal3x3Array;
444typedef CaseOptionSimpleT<BoolArray> CaseOptionBoolArray;
445typedef CaseOptionSimpleT<IntegerArray> CaseOptionIntegerArray;
446typedef CaseOptionSimpleT<Int32Array> CaseOptionInt32Array;
447typedef CaseOptionSimpleT<Int64Array> CaseOptionInt64Array;
448typedef CaseOptionSimpleT<StringArray> CaseOptionStringArray;
449
450/*---------------------------------------------------------------------------*/
451/*---------------------------------------------------------------------------*/
452
453} // End namespace Arcane
454
455/*---------------------------------------------------------------------------*/
456/*---------------------------------------------------------------------------*/
457
458#endif
Modifiable view of an array of type T.
constexpr ArrayView() noexcept
Constructs an empty view.
constexpr Integer size() const noexcept
Returns the size of the array.
Base class for 1D data vectors.
Information for building a dataset option.
typename CaseOptionTraitsT< T >::ConstArrayViewType ConstArrayViewType
Type of the constant view on the option values.
ConstArrayViewType view() const
Constant view on the option elements.
typename CaseOptionTraitsT< T >::ContainerType Type
Type of the option value.
typename CaseOptionTraitsT< T >::ArrayViewType ArrayViewType
Type of the view on the option values.
void updateFromFunction(Real, Integer) override
Updates the option value from a function.
void print(const String &lang, std::ostream &o) const override
Prints the option value in the language lang, to the stream o.
ICaseFunction * function() const override
Returns the function linked to this option or nullptr if none exists.
void visit(ICaseDocumentVisitor *visitor) const override
Applies the visitor to this option.
void _search(bool is_phase1) override
Searches for the option value in the dataset.
ArrayViewType view()
View on the option elements.
Simple data set option (real, integer, boolean, ...).
const Type & valueIfPresentOrArgument(const Type &arg_value)
Returns the value of the option if isPresent()==true or otherwise arg_value.
virtual void _search(bool is_phase1)
Searches for the option value in the data set.
ARCANE_DEPRECATED Type operator()(Real t) const
Returns the value of the option for the real parameter t.
Type valueAtParameter(Real t) const
Returns the value of the option for the real parameter t.
CaseOptionTraitsT< T >::ContainerType Type
Option type.
virtual void print(const String &lang, std::ostream &o) const
Prints the option value in the language lang, to the stream o.
Type valueAtParameter(Integer t) const
Returns the value of the option for the integer parameter t.
const Type & value() const
Returns the value of the option.
const Type & operator()() const
Returns the value of the option.
ARCANE_DEPRECATED Type operator()(Integer t) const
Returns the value of the option for the integer parameter t.
virtual void updateFromFunction(Real current_time, Integer current_iteration)
void setDefaultValue(const Type &def_value)
Sets the default value of the option.
IStandardFunction * m_standard_function
XmlNode m_element
Option element.
bool hasValidValue() const
Indicates if the option has an invalid value.
ICaseFunction * function() const override
Function associated with this option (0 if none).
IPhysicalUnitConverter * m_unit_converter
Unit converter (nullptr if not needed). Valid only for 'Real' options.
bool isOptional() const
Indicates if the option is optional.
virtual IStandardFunction * standardFunction() const
Standard function associated with this option (0 if none).
ARCANE_DEPRECATED_LONG_TERM("Y2022: Do not access XML item from option") XmlNode element() const
Returns the element of the option.
ICaseFunction * m_function
Associated function (or nullptr).
IPhysicalUnitConverter * physicalUnitConverter() const
Physical unit converter.
bool isPresent() const
Returns true if the option is present.
Constant view of an array of type T.
Visitor interface for a dataset option.
Interface of a dataset function.
Interface of a unit converter.
Interface managing a standard function.
1D data vector with value semantics (STL style).
Node of a DOM tree.
Definition XmlNode.h:51
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
double Real
Type representing a real number.
Type
Type of JSON value.
Definition rapidjson.h:730