14#include "arcane/utils/ValueConvert.h"
15#include "arcane/utils/String.h"
16#include "arcane/utils/NotSupportedException.h"
18#include "arcane/datatype/SmallVariant.h"
20#include "arcane/CaseTableParams.h"
48 virtual void value(Integer
id, Real& v)
const = 0;
49 virtual void value(Integer
id, Integer& v)
const = 0;
54 virtual void removeValue(Integer
id) = 0;
55 virtual void toString(Integer
id,
String& str)
const = 0;
59 const SmallVariant& param(Integer
id)
const {
return (*m_param_list)[id]; }
61 SmallVariant& param(Integer
id) {
return (*m_param_list)[id]; }
63 Params& params() {
return *m_param_list; }
65 Integer nbElement()
const {
return m_param_list->
size(); }
90 void value(Integer
id, Real& v)
const override;
91 void value(Integer
id, Integer& v)
const override;
96 void removeValue(Integer
id)
override;
97 void toString(Integer
id,
String& str)
const override;
101 bool _checkConvert(Integer
id,
const String& str, Type& value)
const;
110value(Integer
id, Real& v)
const
112 v = (
Real)(asType(param(
id)));
114template <
class Type>
void CFParamSetterT<Type>::
117 v = Convert::toInteger(asType(param(
id)));
119template <
class Type>
void CFParamSetterT<Type>::
120toString(
Integer id, String& s)
const
122 s = String::fromNumber(asType(param(
id)));
125template <
class Type> CaseTable::eError CFParamSetterT<Type>::
128 return _setIfValid(
id, (Type)(Convert::toDouble(v)));
131template <
class Type> CaseTable::eError CFParamSetterT<Type>::
134 return _setIfValid(
id, (Type)(v));
137template <
class Type> CaseTable::eError CFParamSetterT<Type>::
138setValue(
Integer id,
const String& s)
140 Type avalue = Type();
141 if (_checkConvert(
id, s, avalue))
142 return CaseTable::ErrCanNotConvertParamToRightType;
143 return _setIfValid(
id, avalue);
146template <
class Type> CaseTable::eError CFParamSetterT<Type>::
147appendValue(
const String& s)
149 Type avalue = Type();
151 if (_checkConvert(
id, s, avalue))
152 return CaseTable::ErrCanNotConvertParamToRightType;
153 CaseTable::eError err = _checkValid(
id, avalue);
154 if (err == CaseTable::ErrNo) {
156 v.setValueAll(avalue);
162template <
class Type>
void CFParamSetterT<Type>::
165 params().remove(index);
168template <
class Type> CaseTable::eError CFParamSetterT<Type>::
169_setIfValid(
Integer id, Type avalue)
171 CaseTable::eError err = _checkValid(
id, avalue);
172 if (err == CaseTable::ErrNo)
173 param(
id).setValueAll(avalue);
177template <
class Type>
bool CFParamSetterT<Type>::
178_checkConvert(
Integer id,
const String& str, Type& avalue)
const
183 if (builtInGetValue(avalue, str))
189template <
class Type> CaseTable::eError CFParamSetterT<Type>::
190_checkValid(
Integer id, Type avalue)
const
192 Integer nb_param = nbElement();
194 if (nb_param != 0 &&
id > 0) {
195 Type previous_value = asType(param(
id - 1));
196 if (avalue < previous_value)
197 return CaseTable::ErrNotGreaterThanPrevious;
201 if (nb_param != 0 && (
id + 1) < nb_param) {
202 Type next_value = asType(param(
id + 1));
203 if (avalue > next_value)
204 return CaseTable::ErrNotLesserThanNext;
207 return CaseTable::ErrNo;
240CaseTableParams::Impl::
251CaseTableParams::Impl::
260void CaseTableParams::Impl::
273 m_setter =
new CFParamSetterT<Real>(&m_param_list);
275 m_setter =
new CFParamSetterT<Integer>(&m_param_list);
277 ARCANE_THROW(NotSupportedException,
"Invalid type '{0}'", (
int)type);
300bool CaseTableParams::
309 return m_p->m_param_list.
size();
312void CaseTableParams::
313value(Integer
id, Real& v)
const
315 m_p->m_setter->value(
id, v);
318void CaseTableParams::
319value(Integer
id, Integer& v)
const
321 m_p->m_setter->value(
id, v);
325appendValue(
const String& avalue)
327 return m_p->m_setter->appendValue(avalue);
331setValue(Integer
id,
const String& avalue)
333 return m_p->m_setter->setValue(
id, avalue);
337setValue(Integer
id, Real v)
339 return m_p->m_setter->setValue(
id, v);
343setValue(Integer
id, Integer v)
345 return m_p->m_setter->setValue(
id, v);
348void CaseTableParams::
349removeValue(Integer
id)
351 m_p->m_setter->removeValue(
id);
354void CaseTableParams::
355toString(Integer
id, String& str)
const
357 m_p->m_setter->toString(
id, str);
360void CaseTableParams::
363 m_p->setType(new_type);
371 template <
typename T>
376 bool operator()(
const SmallVariant& a,
const SmallVariant& b)
const
390template <
typename T>
void CaseTableParams::
396 const Int32 max_end = nbElement();
401 ConstArrayView<SmallVariant> params = m_p->m_param_list;
402 auto iter = std::lower_bound(params.begin(), params.end(), v2, comp);
403 Int32 pos =
static_cast<Int32>(iter - params.begin());
408 begin = std::clamp(begin, 0, max_end);
409 end = std::clamp(end, 0, max_end);
415void CaseTableParams::
416getRange(Real v,
Int32& begin,
Int32& end)
const
418 _getRange(v, begin, end);
424void CaseTableParams::
425getRange(Integer v,
Int32& begin,
Int32& end)
const
427 _getRange(v, begin, end);
433template class CFParamSetterT<Real>;
434template class CFParamSetterT<Integer>;
#define ARCANE_THROW(exception_class,...)
Macro pour envoyer une exception avec formattage.
eError
Type des erreurs retournées par la classe.
eParamType
Type d'un paramètre d'une fonction.
@ ParamUnknown
Type de paramètre inconnu.
@ ParamReal
Paramètre de type Real.
@ ParamInteger
Paramètre de type Integer.
Classe gérant un type polymorphe.
Integer size() const
Nombre d'éléments du vecteur.
Référence à une instance.
Chaîne de caractères unicode.
Vecteur 1D de données avec sémantique par valeur (style STL).
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
double Real
Type représentant un réel.
Int32 Integer
Type représentant un entier.