Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
CaseOptionExtended.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/* CaseOptionExtended.h (C) 2000-2023 */
9/* */
10/* Option for the dataset of type 'Extended'. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CASEOPTIONEXTENDED_H
13#define ARCANE_CASEOPTIONEXTENDED_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/Array.h"
18
19#include "arcane/core/CaseOptionSimple.h"
20
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24namespace Arcane
25{
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
34class ARCANE_CORE_EXPORT CaseOptionExtended
35: public CaseOptionSimple
36{
37 public:
38
39 CaseOptionExtended(const CaseOptionBuildInfo& cob, const String& type_name)
40 : CaseOptionSimple(cob)
41 , m_type_name(type_name)
42 {}
43
44 public:
45
46 void print(const String& lang, std::ostream& o) const override;
47 ICaseFunction* function() const override { return 0; }
48 void updateFromFunction(Real /*current_time*/, Integer /*current_iteration*/) override {}
49 void visit(ICaseDocumentVisitor* visitor) const override;
50
57 void setDefaultValue(const String& def_value);
58
59 protected:
60
61 virtual bool _tryToConvert(const String& s) = 0;
62
63 void _search(bool is_phase1) override;
64 bool _allowPhysicalUnit() override { return false; }
65
66 String _typeName() const { return m_type_name; }
67
68 private:
69
72};
73
74/*---------------------------------------------------------------------------*/
75/*---------------------------------------------------------------------------*/
76
92#ifndef SWIG
93template <class T>
94class CaseOptionExtendedT
95: public CaseOptionExtended
96{
97 public:
98
99 CaseOptionExtendedT(const CaseOptionBuildInfo& cob, const String& type_name)
100 : CaseOptionExtended(cob, type_name)
101 {}
102
103 public:
104
106 operator const T&() const { return value(); }
107
109 const T& value() const
110 {
111 ARCANE_CASEOPTION_CHECK_IS_INITIALIZED;
112 return m_value;
113 }
114
116 const T& operator()() const { return value(); }
117
119 const T& valueIfPresentOrArgument(const T& arg_value)
120 {
121 ARCANE_CASEOPTION_CHECK_IS_INITIALIZED;
122 return isPresent() ? m_value : arg_value;
123 }
124
125 protected:
126
127 virtual bool _tryToConvert(const String& s)
128 {
129 // The _caseOptionConvert() function must be declared before
130 // the instantiation of this template. Normally, the automatic config generator
131 // performs this operation.
132 return _caseOptionConvert(*this, s, m_value);
133 }
134
135 private:
136
138};
139#endif
140
141/*---------------------------------------------------------------------------*/
142/*---------------------------------------------------------------------------*/
143
148class ARCANE_CORE_EXPORT CaseOptionMultiExtended
149: public CaseOptionBase
150{
151 public:
152
153 CaseOptionMultiExtended(const CaseOptionBuildInfo& cob, const String& type_name)
154 : CaseOptionBase(cob)
155 , m_type_name(type_name)
156 {}
157 ~CaseOptionMultiExtended() {}
158
159 public:
160
161 void print(const String& lang, std::ostream& o) const override;
162 ICaseFunction* function() const override { return 0; }
163 void updateFromFunction(Real /*current_time*/, Integer /*current_iteration*/) override {}
164 void visit(ICaseDocumentVisitor* visitor) const override;
165
166 protected:
167
168 virtual bool _tryToConvert(const String& s, Integer pos) = 0;
169 virtual void _allocate(Integer size) = 0;
170 virtual bool _allowPhysicalUnit() { return false; }
171 virtual Integer _nbElem() const = 0;
172 String _typeName() const { return m_type_name; }
173 void _search(bool is_phase1) override;
174
175 private:
176
179};
180
181/*---------------------------------------------------------------------------*/
182/*---------------------------------------------------------------------------*/
183
190#ifndef SWIG
191template <class T>
192class CaseOptionMultiExtendedT
193: public CaseOptionMultiExtended
194, public ArrayView<T>
195{
196 public:
197
198 typedef T Type;
199
200 public:
201
202 CaseOptionMultiExtendedT(const CaseOptionBuildInfo& cob, const String& type_name)
203 : CaseOptionMultiExtended(cob, type_name)
204 {}
205 virtual ~CaseOptionMultiExtendedT() {} // delete[] _ptr(); }
206
207 public:
208 protected:
209
210 bool _tryToConvert(const String& s, Integer pos) override
211 {
212 // The _caseOptionConvert() function must be declared before
213 // the instantiation of this template. Normally, the automatic config generator
214 // of options (axl2cc) performs this operation.
215 T& value = this->operator[](pos);
216 return _caseOptionConvert(*this, s, value);
217 }
218 void _allocate(Integer size) override
219 {
220 m_values.resize(size);
221 ArrayView<T>* view = this;
222 *view = m_values.view();
223 }
224 //virtual const void* _elemPtr(Integer i) const { return this->begin()+i; }
225 virtual Integer _nbElem() const override { return m_values.size(); }
226
227 private:
228
229 UniqueArray<T> m_values;
230};
231#endif
232
233/*---------------------------------------------------------------------------*/
234/*---------------------------------------------------------------------------*/
235
236} // End namespace Arcane
237
238/*---------------------------------------------------------------------------*/
239/*---------------------------------------------------------------------------*/
240
241#endif
constexpr ArrayView() noexcept
Constructs an empty view.
constexpr reference operator[](Integer i)
i-th element of the array.
constexpr Integer size() const noexcept
Returns the size of the array.
Information for building a dataset option.
const T & value() const
Option value.
const T & valueIfPresentOrArgument(const T &arg_value)
Returns the value of the option if isPresent()==true or otherwise arg_value.
const T & operator()() const
Option value.
T m_value
Value of the option.
void updateFromFunction(Real, Integer) override
Updates the option value from a function.
String m_type_name
Name of the option type.
ICaseFunction * function() const override
Returns the function linked to this option or nullptr if none exists.
String m_value
Value of the option in unicode string format.
void print(const String &lang, std::ostream &o) const override
Prints the option value in the language lang, to the stream o.
Option for the extended list of types dataset.
ICaseFunction * function() const override
Returns the function linked to this option or nullptr if none exists.
String m_type_name
Name of the option type.
void updateFromFunction(Real, Integer) override
Updates the option value from a function.
UniqueArray< String > m_values
Values in unicode string format.
void print(const String &lang, std::ostream &o) const override
Prints the option value in the language lang, to the stream o.
bool isPresent() const
Returns true if the option is present.
Visitor interface for a dataset option.
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 --
Int32 Integer
Type representing an integer.
double Real
Type representing a real number.