Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
CaseTable.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/* CaseTable.h (C) 2000-2025 */
9/* */
10/* Class managing a lookup table. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_CASETABLE_H
13#define ARCANE_CORE_CASETABLE_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/core/datatype/SmallVariant.h"
18
19#include "arcane/core/CaseFunction.h"
20
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24namespace Arcane
25{
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
30class CaseTableParams;
31
32/*---------------------------------------------------------------------------*/
33/*---------------------------------------------------------------------------*/
34
35/*!
36 * \internal
37 * \brief Data set function.
38 */
39class ARCANE_CORE_EXPORT CaseTable
40: public CaseFunction
41{
42 public:
43
44 /*!
45 * \brief Types of errors returned by the class.
46 */
47 enum eError
48 {
49 ErrNo,
50 //! Indicates that an element index is not valid
52 //! Indicates that converting the parameter to the desired type is impossible
54 //! Indicates that converting the value to the desired type is impossible
56 //! Indicates that the parameter is not greater than the previous one
58 //! Indicates that the parameter is not less than the next one
60 };
61
62 /*! \brief Type of the table curve.
63 */
65 {
66 CurveUnknown = 0, //!< Unknown curve type
67 CurveConstant = 1, //!< Piecewise constant curve
68 CurveLinear = 2 //!< Piecewise linear curve
69 };
70
71 public:
72
73 /*! \brief Constructs a lookup table from the data set.
74 * \param curve_type type of the lookup table curve
75 */
76 CaseTable(const CaseFunctionBuildInfo& info, eCurveType curve_type);
77 virtual ~CaseTable();
78
79 public:
80
81 //! Number of elements in the function
82 virtual Integer nbElement() const;
83
84 //! The i-th value in the string \a str
85 virtual void valueToString(Integer id, String& str) const;
86
87 //! The i-th parameter in the string \a str
88 virtual void paramToString(Integer id, String& param) const;
89
90 /*!
91 * \brief Modifies the parameter of element \a id.
92 *
93 * Uses \a value as the new value for the parameter.
94 * \a value must be convertible to the parameter type.
95 *
96 * \return the error value, ErrNo otherwise.
97 */
98 virtual eError setParam(Integer id, const String& value);
99
100 /*!
101 * \brief Modifies the value of element \a id.
102 *
103 * Uses \a value as the new value.
104 * \a value must be convertible to the value type.
105 *
106 * \return the error value, ErrNo otherwise.
107 */
108 virtual eError setValue(Integer id, const String& value);
109
110 /*! \brief Adds an element to the table.
111 *
112 * Adds the element (param,value) to the table.
113 *
114 * \return the error value, ErrNo otherwise.
115 */
116 virtual eError appendElement(const String& param, const String& value);
117
118 /*!
119 * \brief Inserts a couple (parameter,value) into the function.
120 *
121 * Inserts a couple (parameter,value) identical to the one found at position
122 * \a id. Subsequent parameters are shifted by one position. It is then possible
123 * to modify this couple using the methods setParam() or setValue().
124 *
125 * If \a id is greater than the number of elements in the function, an element
126 * is added to the end with the same value as the last element of
127 * the function.
128 */
129 virtual void insertElement(Integer id);
130
131 /*!
132 * \brief Removes a couple (parameter,value) from the function.
133 *
134 * If \a id is greater than the number of elements in the function, no
135 * operation is performed.
136 */
137 virtual void removeElement(Integer id);
138
139 /*! @name Curve Type */
140 //@{
141 //! Returns the curve type of the function
142 virtual eCurveType curveType() const { return m_curve_type; }
143 //@}
144
145 virtual void setParamType(eParamType type);
146
147 virtual bool checkIfValid() const;
148
149 virtual void value(Real param, Real& v) const;
150 virtual void value(Real param, Integer& v) const;
151 virtual void value(Real param, bool& v) const;
152 virtual void value(Real param, String& v) const;
153 virtual void value(Real param, Real3& v) const;
154 virtual void value(Integer param, Real& v) const;
155 virtual void value(Integer param, Integer& v) const;
156 virtual void value(Integer param, bool& v) const;
157 virtual void value(Integer param, String& v) const;
158 virtual void value(Integer param, Real3& v) const;
159
160 public:
161 private:
162
163 CaseTableParams* m_param_list;
164 UniqueArray<SmallVariant> m_value_list; //!< List of values.
165 eCurveType m_curve_type; //!< Curve type
166 bool m_use_fast_search = true;
167
168 private:
169
170 template <typename U, typename V> void _findValue(U param, V& value) const;
171 template <typename U, typename V> void _findValueAndApplyTransform(U param, V& value) const;
172
173 bool _isValidIndex(Integer index) const;
174 eError _setValue(Integer index, const String& value_str);
175};
176
177/*---------------------------------------------------------------------------*/
178/*---------------------------------------------------------------------------*/
179
180} // namespace Arcane
181
182/*---------------------------------------------------------------------------*/
183/*---------------------------------------------------------------------------*/
184
185#endif
Information to build an instance of CaseFunction.
CaseFunction(const CaseFunctionBuildInfo &info)
Constructs a dataset function.
virtual eCurveType curveType() const
Returns the curve type of the function.
Definition CaseTable.h:142
eCurveType
Type of the table curve.
Definition CaseTable.h:65
@ CurveUnknown
Unknown curve type.
Definition CaseTable.h:66
@ CurveLinear
Piecewise linear curve.
Definition CaseTable.h:68
@ CurveConstant
Piecewise constant curve.
Definition CaseTable.h:67
CaseTable(const CaseFunctionBuildInfo &info, eCurveType curve_type)
Constructs a lookup table from the data set.
Definition CaseTable.cc:46
eError
Types of errors returned by the class.
Definition CaseTable.h:48
@ ErrCanNotConvertParamToRightType
Indicates that converting the parameter to the desired type is impossible.
Definition CaseTable.h:53
@ ErrBadRange
Indicates that an element index is not valid.
Definition CaseTable.h:51
@ ErrNotGreaterThanPrevious
Indicates that the parameter is not greater than the previous one.
Definition CaseTable.h:57
@ ErrNotLesserThanNext
Indicates that the parameter is not less than the next one.
Definition CaseTable.h:59
@ ErrCanNotConvertValueToRightType
Indicates that converting the value to the desired type is impossible.
Definition CaseTable.h:55
Class managing a 3-dimensional real vector.
Definition Real3.h:132
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.