14#include "arcane/CaseOptionSimple.h"
16#include "arcane/utils/ValueConvert.h"
17#include "arcane/utils/ITraceMng.h"
18#include "arcane/utils/FatalErrorException.h"
20#include "arcane/core/CaseOptionException.h"
21#include "arcane/core/CaseOptionBuildInfo.h"
22#include "arcane/core/XmlNodeList.h"
23#include "arcane/core/ICaseFunction.h"
24#include "arcane/core/ICaseMng.h"
25#include "arcane/core/ICaseDocument.h"
26#include "arcane/core/CaseNodeNames.h"
27#include "arcane/core/CaseOptionError.h"
28#include "arcane/core/IPhysicalUnitConverter.h"
29#include "arcane/core/IPhysicalUnitSystem.h"
30#include "arcane/core/IStandardFunction.h"
31#include "arcane/core/ICaseDocumentVisitor.h"
42template<
typename T>
void
43_copyCaseOptionValue(T& out,
const T& in);
45template<>
void _copyCaseOptionValue(String& out,
const String& in) { out = in; }
46template<>
void _copyCaseOptionValue(
bool& out,
const bool& in) { out = in; }
47template<>
void _copyCaseOptionValue(
Real& out,
const Real& in) { out = in; }
48template<>
void _copyCaseOptionValue(
Int16& out,
const Int16& in) { out = in; }
49template<>
void _copyCaseOptionValue(
Int32& out,
const Int32& in) { out = in; }
50template<>
void _copyCaseOptionValue(
Int64& out,
const Int64& in) { out = in; }
51template<>
void _copyCaseOptionValue(Real2& out,
const Real2& in) { out = in; }
52template<>
void _copyCaseOptionValue(Real3& out,
const Real3& in) { out = in; }
53template<>
void _copyCaseOptionValue(Real2x2& out,
const Real2x2& in) { out = in; }
54template<>
void _copyCaseOptionValue(Real3x3& out,
const Real3x3& in) { out = in; }
56template<
typename T>
void
57_copyCaseOptionValue(UniqueArray<T>& out,
const Array<T>& in)
62template<
typename T>
void
63_copyCaseOptionValue(UniqueArray<T>& out,
const UniqueArray<T>& in)
68template<
typename T>
void
69_copyCaseOptionValue(Array<T>& out,
const Array<T>& in)
78CaseOptionSimple(
const CaseOptionBuildInfo& cob)
80, m_is_optional(cob.isOptional())
81, m_has_valid_value(true)
89CaseOptionSimple(
const CaseOptionBuildInfo& cob,
const String& physical_unit)
91, m_is_optional(cob.isOptional())
92, m_has_valid_value(true)
93, m_default_physical_unit(physical_unit)
103 delete m_unit_converter;
109void CaseOptionSimple::
110_search(
bool is_phase1)
116 const String& velem_name = name();
117 XmlNodeList velems = rootElement().children(velem_name);
119 Integer nb_elem = velems.size();
120 ICaseDocumentFragment* doc = caseDocumentFragment();
124 CaseOptionError::addWarning(doc,A_FUNCINFO,velem.xpathFullName(),
125 String::format(
"Only one token of the element is allowed (nb_occur={0})",
133 _searchFunction(velem);
135 String physical_unit = m_element.attrValue(
"unit");
136 if (!physical_unit.null()){
137 _setPhysicalUnit(physical_unit);
138 if (_allowPhysicalUnit()){
140 m_unit_converter = caseMng()->physicalUnitSystem()->createConverter(physical_unit,defaultPhysicalUnit());
143 CaseOptionError::addError(doc,A_FUNCINFO,velem.xpathFullName(),
144 String::format(
"Usage of a physic unit ('{0}') is not allowed for this kind of option",
152void CaseOptionSimple::
153_setPhysicalUnit(
const String& value)
155 m_physical_unit = value;
164 return m_physical_unit;
170void CaseOptionSimple::
177 String fname = caseDocumentFragment()->caseNodeNames()->function_ref;
179 if (func_name.
null())
186 <<
">: no function named <" << func_name <<
">";
190 IStandardFunction* sf =
dynamic_cast<IStandardFunction*
>(func);
192 msg->
info() <<
"Use standard function: " << func_name;
193 m_standard_function = sf;
196 msg->
info() <<
"Use function: " << func_name;
204void CaseOptionSimple::
205_setChangedSinceLastIteration(
bool has_changed)
207 m_changed_since_last_iteration = has_changed;
213bool CaseOptionSimple::
214hasChangedSinceLastIteration()
const
216 return m_changed_since_last_iteration;
225 if (!m_element.null())
226 return m_element.xpathFullName();
227 String fn = rootElement().xpathFullName() +
"/" + name();
235defaultPhysicalUnit()
const
237 return m_default_physical_unit;
243void CaseOptionSimple::
264template<
typename DataType>
static void
268 ARCANE_UNUSED(value);
281_checkPhysicalConvert(IPhysicalUnitConverter* converter,RealUniqueArray& values)
285 RealUniqueArray input_values(values);
290template<
typename DataType>
static bool
291_allowConvert(
const DataType& value)
293 ARCANE_UNUSED(value);
298_allowConvert(
const Real& value)
300 ARCANE_UNUSED(value);
305_allowConvert(
const RealUniqueArray& value)
307 ARCANE_UNUSED(value);
314template<
typename T> CaseOptionSimpleT<T>::
315CaseOptionSimpleT(
const CaseOptionBuildInfo& cob)
316: CaseOptionSimple(cob)
318 _copyCaseOptionValue(m_value,
Type());
324template<
typename T> CaseOptionSimpleT<T>::
325CaseOptionSimpleT(
const CaseOptionBuildInfo& cob,
const String& physical_unit)
326: CaseOptionSimple(cob,physical_unit)
328 _copyCaseOptionValue(m_value,
Type());
334template<
typename T>
bool CaseOptionSimpleT<T>::
337 using Type =
typename CaseOptionTraitsT<T>::ContainerType;
338 return _allowConvert(
Type());
347template<
typename Type>
351 static String collapse(
const String& str)
353 return String::collapseWhiteSpace(str);
357class StringCollapser<String>
360 static String collapse(
const String& str)
387 String str_val = (_element().null()) ? _defaultValue() : _element().value();
391 CaseOptionError::addOptionNotFoundError(
doc,A_FUNCINFO,
392 name(),rootElement());
398 _setHasValidValue(has_valid_value);
399 if (has_valid_value){
401 str_val = StringCollapser<Type>::collapse(str_val);
402 bool is_bad = builtInGetValue(val,str_val);
405 CaseOptionError::addInvalidTypeError(doc,A_FUNCINFO,
406 name(),rootElement(),str_val,typeToName(val));
409 _checkPhysicalConvert(physicalUnitConverter(),val);
426 if (_isInitialized())
442class FunctionConverterT
449 ARCANE_UNUSED(value);
455class FunctionConverterT<
Real>
458 void convert(ICaseFunction& tbl,
Real t,
Real& value)
459 { tbl.value(t,value); }
463class FunctionConverterT<Real3>
466 void convert(ICaseFunction& tbl,
Real t,Real3& value)
467 { tbl.value(t,value); }
471class FunctionConverterT<bool>
474 void convert(ICaseFunction& tbl,
Real t,
bool& value)
475 { tbl.value(t,value); }
479class FunctionConverterT<
Integer>
482 void convert(ICaseFunction& tbl,
Real t,Integer& value)
483 { tbl.value(t,value); }
487class FunctionConverterT<String>
490 void convert(ICaseFunction& tbl,
Real t,String& value)
491 { tbl.value(t,value); }
497template<
typename ParamType,
typename ValueType>
498class ComputeFunctionValue
501 static void convert(ICaseFunction* func,ParamType t,ValueType& new_value)
503 FunctionConverterT<ValueType>().convert(*func,t,new_value);
519 _checkPhysicalConvert(physicalUnitConverter(),
new_value);
534 _checkPhysicalConvert(physicalUnitConverter(),
new_value);
545 _checkIsInitialized();
550 switch(
func->paramType()){
551 case ICaseFunction::ParamReal:
554 case ICaseFunction::ParamInteger:
557 case ICaseFunction::ParamUnknown:
560 _checkPhysicalConvert(physicalUnitConverter(),
new_value);
561 this->_setChangedSinceLastIteration(m_value!=
new_value);
574 _checkIsInitialized();
596template<
typename T> CaseOptionMultiSimpleT<T>::
597CaseOptionMultiSimpleT(
const CaseOptionBuildInfo& cob,
599: CaseOptionMultiSimple(cob)
606template<
typename T> CaseOptionMultiSimpleT<T>::
607~CaseOptionMultiSimpleT()
609 const T* avalue = m_view.data();
616template<
typename T>
bool CaseOptionMultiSimpleT<T>::
619 using Type =
typename CaseOptionTraitsT<T>::ContainerType;
620 return _allowConvert(
Type());
641 _checkMinMaxOccurs(
asize);
647 using Type =
typename CaseOptionTraitsT<T>::ContainerType;
653 for( Integer i=0; i<
asize; ++i ){
660 name(),rootElement());
666 name(),rootElement(),
str_val,typeToName(
val));
680 for( Integer i=0; i<this->size(); ++i )
681 o << this->_ptr()[i] <<
" ";
700 ComputeFunctionValue<Real,String>::convert(
func,
t,v);
707String CaseOptionSimple::
708_convertFunctionIntegerToString(ICaseFunction* func,Integer t)
711 ComputeFunctionValue<Integer,String>::convert(func,t,v);
718template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<Real>;
719template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<Real2>;
720template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<Real3>;
721template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<Real2x2>;
722template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<Real3x3>;
723template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<bool>;
724template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<Int16>;
725template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<Int32>;
726template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<Int64>;
727template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<String>;
729template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<RealArray>;
730template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<Real2Array>;
731template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<Real3Array>;
732template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<Real2x2Array>;
733template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<Real3x3Array>;
734template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<BoolArray>;
735template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<Int16Array>;
736template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<Int32Array>;
737template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<Int64Array>;
738template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<StringArray>;
740template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<Real>;
741template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<Real2>;
742template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<Real3>;
743template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<Real2x2>;
744template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<Real3x3>;
745template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<bool>;
746template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<Int16>;
747template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<Int32>;
748template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<Int64>;
749template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<String>;
751template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<RealArray>;
752template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<Real2Array>;
753template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<Real3Array>;
754template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<Real2x2Array>;
755template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<Real3x3Array>;
756template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<BoolArray>;
757template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<Int16Array>;
758template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<Int32Array>;
759template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<Int64Array>;
760template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<StringArray>;
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Informations pour construire une option de jeu de données.
static void addInvalidTypeError(ICaseDocumentFragment *document, const TraceInfo &where, const String &node_name, const XmlNode &parent, const String &value, const String &expected_type)
Erreur lorsqu'une valeur d'une jeu de données n'est pas du bon type. Cette erreur est collective.
static void addOptionNotFoundError(ICaseDocumentFragment *document, const TraceInfo &where, const String &node_name, const XmlNode &parent)
Erreur lorsqu'une option du jeu de données n'est pas trouvée. Cette erreur est collective.
Exception en rapport avec le jeu de données.
Option du jeu de données de type liste de types simples (réel, entier, booléen, .....
typename CaseOptionTraitsT< T >::ContainerType Type
Type de la valeur de l'option.
typename CaseOptionTraitsT< T >::ArrayViewType ArrayViewType
Type de la vue sur les valeurs de l'option.
void print(const String &lang, std::ostream &o) const override
Imprime la valeur de l'option dans le langage lang,sur le flot o.
void visit(ICaseDocumentVisitor *visitor) const override
Applique le visiteur sur cette option.
void _search(bool is_phase1) override
Cherche la valeur de l'option dans le jeu de donnée.
Option du jeu de données de type simple (réel, entier, booléen, ...)
CaseOptionTraitsT< T >::ContainerType Type
Type de l'option.
Interface d'une partie d'un jeu de données.
Interface du visiteur pour une option du jeu de données.
Interface d'une fonction du jeu de données.
Interface d'un convertisseur d'unité.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Liste de noeuds d'un arbre DOM.
Interface du gestionnaire de traces.
virtual TraceMessage info()=0
Flot pour un message d'information.
Chaîne de caractères unicode.
bool null() const
Retourne true si la chaîne est nulle.
TraceMessage pfatal() const
Flot pour un message d'erreur fatale en parallèle.
ITraceMng * traceMng() const
Gestionnaire de trace.
TraceMessageDbg debug(Trace::eDebugLevel=Trace::Medium) const
Flot pour un message de debug.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
bool builtInPutValue(const String &v, String &s)
Converti la valeur v dans la chaîne s.
Int32 Integer
Type représentant un entier.