Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
CaseOptionBase.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/* CaseOptionBase.h (C) 2000-2025 */
9/* */
10/* Base class for a data set option. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CASEOPTIONBASE_H
13#define ARCANE_CASEOPTIONBASE_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/String.h"
18
19#include "arcane/core/XmlNode.h"
20
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24namespace Arcane
25{
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
31class ICaseDocument;
33class ICaseMng;
34class ICaseOptionList;
35class ISubDomain;
36class ICaseFunction;
39
40/*---------------------------------------------------------------------------*/
41/*---------------------------------------------------------------------------*/
42
43/*!
44 * \brief Base class for a data set option.
45 *
46 * \ingroup CaseOption
47 *
48 * Links the option with the name \a m_name to the corresponding DOM node.
49 */
50class ARCANE_CORE_EXPORT CaseOptionBase
51{
52 protected:
53
54 CaseOptionBase(const CaseOptionBuildInfo& cob);
55
56 public:
57
58 virtual ~CaseOptionBase();
59
60 public:
61
62 //! Returns the true name (untranslated) of the option.
63 String trueName() const;
64
65 //! Returns the option name corresponding to the data set language.
66 String name() const;
67
68 //! Name of the option in the language \a lang. Returns \a name() if no translation exists.
69 String translatedName(const String& lang) const;
70
71 //! Retrieves the value from the configuration file for the variable
72 void search(bool is_phase1);
73
74 //! Prints the option value in the language \a lang, to the stream \a o
75 virtual void print(const String& lang, std::ostream& o) const = 0;
76
77 //! Case manager
78 ICaseMng* caseMng() const;
79
80 //! Parent OptionList
82
83 //! Trace manager
84 ITraceMng* traceMng() const;
85
86 //! Sub-domain manager
87 ARCCORE_DEPRECATED_2019("Do not use subDomain(). Try to get subDomain from an other way.")
88 ISubDomain* subDomain() const;
89
90 //! Returns the document manager
91 ARCANE_DEPRECATED_REASON("Y2023: use caseMng()->caseDocument() instead.")
93
94 //! Returns the document associated with this option
96
97 //! Positions the root element at \a root_element
98 void setRootElement(const XmlNode& root_element);
99
100 //! Returns the root element of the DOM
101 XmlNode rootElement() const;
102
103 //! Returns the function linked to this option or `nullptr` if none exists
104 virtual ICaseFunction* function() const = 0;
105
106 //! Minimum number of occurrences (for a multiple option)
107 Integer minOccurs() const;
108
109 //! Maximum number of occurrences (for a multiple option) (-1 == unbounded)
110 Integer maxOccurs() const;
111
112 //! Allows knowing if an option is optional.
113 bool isOptional() const;
114
115 /*! \brief Updates the option value from a function.
116 *
117 * If the option is not linked to a workflow table, it does nothing.
118 * Otherwise, it uses \a current_time or \a current_iteration depending on the function parameter type to calculate the new
119 * option value. This value will then be normally accessible via
120 * the operator() method.
121 */
122 virtual void updateFromFunction(Real current_time, Integer current_iteration) = 0;
123
124 /*!
125 \brief Adds a translation for the option name.
126 *
127 Adds the option name \a name corresponding to the language \a lang.
128 If a translation already exists for this language, it is replaced by
129 this one.
130 */
131 void addAlternativeNodeName(const String& lang, const String& name);
132
133 //! Adds the default value \a value to the category \a category
134 void addDefaultValue(const String& category, const String& value);
135
136 //! Applies the visitor to this option
137 virtual void visit(ICaseDocumentVisitor* visitor) const = 0;
138
139 //! Throws an exception if the option has not been initialized.
140 void checkIsInitialized() const { _checkIsInitialized(); }
141
142 protected:
143
144 //! Returns the default value of the option or 0 if none exists
145 String _defaultValue() const;
146
147 void _setDefaultValue(const String& def_value);
148
149 protected:
150
151 virtual void _search(bool is_phase1) = 0;
152 void _setIsInitialized();
153 bool _isInitialized() const;
154 void _checkIsInitialized() const;
155 void _checkMinMaxOccurs(Integer nb_occur);
156 String _xpathFullName() const;
157
158 private:
159
160 CaseOptionBasePrivate* m_p; //!< Implementation.
161
162 private:
163
164 void _setTranslatedName();
165 void _setCategoryDefaultValue();
166 /*! \brief Copy constructor.
167 *
168 * The copy constructor is private because the option should not be
169 * copied, notably due to the ICaseFunction which is unique.
170 */
171 CaseOptionBase(const CaseOptionBase& from) = delete;
172 //! Copy assignment operator
173 CaseOptionBase& operator=(const CaseOptionBase& from) = delete;
174};
175
176/*---------------------------------------------------------------------------*/
177/*---------------------------------------------------------------------------*/
178
179} // End namespace Arcane
180
181/*---------------------------------------------------------------------------*/
182/*---------------------------------------------------------------------------*/
183
184#endif
Base class for a data set option.
String name() const
Returns the option name corresponding to the data set language.
String translatedName(const String &lang) const
Name of the option in the language lang. Returns name() if no translation exists.
void addDefaultValue(const String &category, const String &value)
Adds the default value value to the category category.
ICaseDocument * caseDocument() const
Returns the document manager.
virtual void visit(ICaseDocumentVisitor *visitor) const =0
Applies the visitor to this option.
void search(bool is_phase1)
Retrieves the value from the configuration file for the variable.
void checkIsInitialized() const
Throws an exception if the option has not been initialized.
ICaseMng * caseMng() const
Case manager.
ICaseDocumentFragment * caseDocumentFragment() const
Returns the document associated with this option.
void addAlternativeNodeName(const String &lang, const String &name)
Adds a translation for the option name.
void setRootElement(const XmlNode &root_element)
Positions the root element at root_element.
bool isOptional() const
Allows knowing if an option is optional.
Integer maxOccurs() const
Maximum number of occurrences (for a multiple option) (-1 == unbounded).
XmlNode rootElement() const
Returns the root element of the DOM.
virtual ICaseFunction * function() const =0
Returns the function linked to this option or nullptr if none exists.
virtual void updateFromFunction(Real current_time, Integer current_iteration)=0
Updates the option value from a function.
ITraceMng * traceMng() const
Trace manager.
ISubDomain * subDomain() const
Sub-domain manager.
String trueName() const
Returns the true name (untranslated) of the option.
ICaseOptionList * parentOptionList() const
Parent OptionList.
Integer minOccurs() const
Minimum number of occurrences (for a multiple option).
virtual void print(const String &lang, std::ostream &o) const =0
Prints the option value in the language lang, to the stream o.
Visitor interface for a dataset option.
Case manager interface.
Definition ICaseMng.h:57
Interface of the subdomain manager.
Definition ISubDomain.h:75
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.