Arcane  v4.1.2.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
CaseOptionSimple.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2025 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/* CaseOptionSimple.cc (C) 2000-2025 */
9/* */
10/* Option du jeu de données de type simple . */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/CaseOptionSimple.h"
15
16#include "arcane/utils/ValueConvert.h"
17#include "arcane/utils/ITraceMng.h"
18#include "arcane/utils/FatalErrorException.h"
19#include "arcane/utils/StringBuilder.h"
20#include "arcane/utils/internal/ParameterCaseOption.h"
21
22#include "arcane/core/CaseOptionException.h"
23#include "arcane/core/CaseOptionBuildInfo.h"
24#include "arcane/core/XmlNodeList.h"
25#include "arcane/core/ICaseFunction.h"
26#include "arcane/core/ICaseMng.h"
27#include "arcane/core/ICaseDocument.h"
28#include "arcane/core/CaseNodeNames.h"
29#include "arcane/core/CaseOptionError.h"
30#include "arcane/core/IPhysicalUnitConverter.h"
31#include "arcane/core/IPhysicalUnitSystem.h"
32#include "arcane/core/IStandardFunction.h"
33#include "arcane/core/ICaseDocumentVisitor.h"
34#include "arcane/core/internal/StringVariableReplace.h"
35#include "arcane/core/internal/ICaseMngInternal.h"
36
37/*---------------------------------------------------------------------------*/
38/*---------------------------------------------------------------------------*/
39
40namespace Arcane
41{
42
43/*---------------------------------------------------------------------------*/
44/*---------------------------------------------------------------------------*/
45
46template<typename T> void
47_copyCaseOptionValue(T& out,const T& in);
48
49template<> void _copyCaseOptionValue(String& out,const String& in) { out = in; }
50template<> void _copyCaseOptionValue(bool& out,const bool& in) { out = in; }
51template<> void _copyCaseOptionValue(Real& out,const Real& in) { out = in; }
52template<> void _copyCaseOptionValue(Int16& out,const Int16& in) { out = in; }
53template<> void _copyCaseOptionValue(Int32& out,const Int32& in) { out = in; }
54template<> void _copyCaseOptionValue(Int64& out,const Int64& in) { out = in; }
55template<> void _copyCaseOptionValue(Real2& out,const Real2& in) { out = in; }
56template<> void _copyCaseOptionValue(Real3& out,const Real3& in) { out = in; }
57template<> void _copyCaseOptionValue(Real2x2& out,const Real2x2& in) { out = in; }
58template<> void _copyCaseOptionValue(Real3x3& out,const Real3x3& in) { out = in; }
59
60template<typename T> void
61_copyCaseOptionValue(UniqueArray<T>& out,const Array<T>& in)
62{
63 out.copy(in);
64}
65
66template<typename T> void
67_copyCaseOptionValue(UniqueArray<T>& out,const UniqueArray<T>& in)
68{
69 out.copy(in);
70}
71
72template<typename T> void
73_copyCaseOptionValue(Array<T>& out,const Array<T>& in)
74{
75 out.copy(in);
76}
77
78/*---------------------------------------------------------------------------*/
79/*---------------------------------------------------------------------------*/
80
81CaseOptionSimple::
82CaseOptionSimple(const CaseOptionBuildInfo& cob)
83: CaseOptionBase(cob)
84, m_is_optional(cob.isOptional())
85, m_has_valid_value(true)
86{
87}
88
89/*---------------------------------------------------------------------------*/
90/*---------------------------------------------------------------------------*/
91
92CaseOptionSimple::
93CaseOptionSimple(const CaseOptionBuildInfo& cob,const String& physical_unit)
94: CaseOptionBase(cob)
95, m_is_optional(cob.isOptional())
96, m_has_valid_value(true)
97, m_default_physical_unit(physical_unit)
98{
99}
100
101/*---------------------------------------------------------------------------*/
102/*---------------------------------------------------------------------------*/
103
104CaseOptionSimple::
105~CaseOptionSimple()
106{
107 delete m_unit_converter;
108}
109
110/*---------------------------------------------------------------------------*/
111/*---------------------------------------------------------------------------*/
112
113void CaseOptionSimple::
114_search(bool is_phase1)
115{
116 if (!is_phase1)
117 return;
118
119 //ITraceMng* msg = caseMng()->traceMng();
120 const String& velem_name = name();
121 XmlNodeList velems = rootElement().children(velem_name);
122 XmlNode velem;
123 Integer nb_elem = velems.size();
124 ICaseDocumentFragment* doc = caseDocumentFragment();
125 if (nb_elem>=1){
126 velem = velems[0];
127 if (nb_elem>=2){
128 CaseOptionError::addWarning(doc,A_FUNCINFO,velem.xpathFullName(),
129 String::format("Only one token of the element is allowed (nb_occur={0})",
130 nb_elem));
131 }
132 }
133
134 // Liste des options de la ligne de commande.
135 {
136 const ParameterListWithCaseOption& params = caseMng()->_internalImpl()->parameters();
137 const ParameterCaseOption pco{ params.getParameterCaseOption(doc->language()) };
138
139 String reference_input = pco.getParameterOrNull(String::format("{0}/{1}", rootElement().xpathFullName(), velem_name), 1, false);
140 if (!reference_input.null()) {
141 // Si l'utilisateur a spécifié une option qui n'est pas présente dans le
142 // jeu de données, on doit la créer.
143 if (velem.null()) {
144 velem = rootElement().createElement(name());
145 }
146 velem.setValue(reference_input);
147 }
148 if (!velem.null()) {
149 velem.setValue(StringVariableReplace::replaceWithCmdLineArgs(params, velem.value(), true));
150 }
151 }
152
153 m_element = velem;
154 m_function = 0;
155
156 _searchFunction(velem);
157
158 String physical_unit = m_element.attrValue("unit");
159 if (!physical_unit.null()){
160 _setPhysicalUnit(physical_unit);
161 if (_allowPhysicalUnit()){
162 //TODO: VERIFIER QU'IL Y A UNE DEFAULT_PHYSICAL_UNIT.
163 m_unit_converter = caseMng()->physicalUnitSystem()->createConverter(physical_unit,defaultPhysicalUnit());
164 }
165 else
166 CaseOptionError::addError(doc,A_FUNCINFO,velem.xpathFullName(),
167 String::format("Usage of a physic unit ('{0}') is not allowed for this kind of option",
168 physical_unit));
169 }
170}
171
172/*---------------------------------------------------------------------------*/
173/*---------------------------------------------------------------------------*/
174
175void CaseOptionSimple::
176_setPhysicalUnit(const String& value)
177{
178 m_physical_unit = value;
179}
180
181/*---------------------------------------------------------------------------*/
182/*---------------------------------------------------------------------------*/
183
184String CaseOptionSimple::
185physicalUnit() const
186{
187 return m_physical_unit;
188}
189
190/*---------------------------------------------------------------------------*/
191/*---------------------------------------------------------------------------*/
192
193void CaseOptionSimple::
194_searchFunction(XmlNode& velem)
195{
196 if (velem.null())
197 return;
198
199 // Recherche une éventuelle fonction associée
200 String fname = caseDocumentFragment()->caseNodeNames()->function_ref;
201 String func_name = velem.attrValue(fname);
202 if (func_name.null())
203 return;
204
205 ICaseFunction* func = caseMng()->findFunction(func_name);
206 ITraceMng* msg = caseMng()->traceMng();
207 if (!func){
208 msg->pfatal() << "In element <" << velem.name()
209 << ">: no function named <" << func_name << ">";
210 }
211
212 // Recherche s'il s'agit d'une fonction standard
213 IStandardFunction* sf = dynamic_cast<IStandardFunction*>(func);
214 if (sf){
215 msg->info() << "Use standard function: " << func_name;
216 m_standard_function = sf;
217 }
218 else{
219 msg->info() << "Use function: " << func_name;
220 m_function = func;
221 }
222}
224/*---------------------------------------------------------------------------*/
225/*---------------------------------------------------------------------------*/
226
227void CaseOptionSimple::
228_setChangedSinceLastIteration(bool has_changed)
229{
230 m_changed_since_last_iteration = has_changed;
231}
232
233/*---------------------------------------------------------------------------*/
234/*---------------------------------------------------------------------------*/
235
236bool CaseOptionSimple::
237hasChangedSinceLastIteration() const
238{
239 return m_changed_since_last_iteration;
240}
241
242/*---------------------------------------------------------------------------*/
243/*---------------------------------------------------------------------------*/
244
245String CaseOptionSimple::
246xpathFullName() const
247{
248 if (!m_element.null())
249 return m_element.xpathFullName();
250 String fn = rootElement().xpathFullName() + "/" + name();
251 return fn;
252}
253
254/*---------------------------------------------------------------------------*/
255/*---------------------------------------------------------------------------*/
256
257String CaseOptionSimple::
258defaultPhysicalUnit() const
259{
260 return m_default_physical_unit;
261}
262
263/*---------------------------------------------------------------------------*/
264/*---------------------------------------------------------------------------*/
265
266void CaseOptionSimple::
267visit(ICaseDocumentVisitor* visitor) const
268{
269 visitor->applyVisitor(this);
270}
271
272/*---------------------------------------------------------------------------*/
273/*---------------------------------------------------------------------------*/
274
275/*---------------------------------------------------------------------------*/
276/*---------------------------------------------------------------------------*/
277/*
278 * Prise en compte du système d'unité mais uniquement pour
279 * les options de type 'Real' ou 'RealArray'.
280 * TODO: voir si c'est intéressant pour les autres types
281 * comme Real2, Real3.
282 * Pour les types intégraux comme 'Integer', il ne vaut mieux
283 * pas supporter les conversions car cela risque de faire des valeurs
284 * trop grandes ou nulle si la conversion donne un nombre inférieur à 1
285 * (par exemple, 5 centimètres convertie en mètre donne 0).
286 */
287template<typename DataType> static void
288_checkPhysicalConvert(IPhysicalUnitConverter* converter,DataType& value)
289{
290 ARCANE_UNUSED(converter);
291 ARCANE_UNUSED(value);
292}
293
294static void
295_checkPhysicalConvert(IPhysicalUnitConverter* converter,Real& value)
296{
297 if (converter){
298 Real new_value = converter->convert(value);
299 value = new_value;
300 }
301}
302
303static void
304_checkPhysicalConvert(IPhysicalUnitConverter* converter,RealUniqueArray& values)
305{
306 if (converter){
307 //TODO utiliser tableau local pour eviter allocation
308 RealUniqueArray input_values(values);
309 converter->convert(input_values,values);
310 }
311}
312
313template<typename DataType> static bool
314_allowConvert(const DataType& value)
315{
316 ARCANE_UNUSED(value);
317 return false;
318}
319
320static bool
321_allowConvert(const Real& value)
322{
323 ARCANE_UNUSED(value);
324 return true;
325}
326
327static bool
328_allowConvert(const RealUniqueArray& value)
329{
330 ARCANE_UNUSED(value);
331 return true;
332}
333
334/*---------------------------------------------------------------------------*/
335/*---------------------------------------------------------------------------*/
336
337template<typename T> CaseOptionSimpleT<T>::
338CaseOptionSimpleT(const CaseOptionBuildInfo& cob)
339: CaseOptionSimple(cob)
340{
341 _copyCaseOptionValue(m_value,Type());
342}
343
344/*---------------------------------------------------------------------------*/
345/*---------------------------------------------------------------------------*/
346
347template<typename T> CaseOptionSimpleT<T>::
348CaseOptionSimpleT(const CaseOptionBuildInfo& cob,const String& physical_unit)
349: CaseOptionSimple(cob,physical_unit)
350{
351 _copyCaseOptionValue(m_value,Type());
352}
353
354/*---------------------------------------------------------------------------*/
355/*---------------------------------------------------------------------------*/
356
357template<typename T> bool CaseOptionSimpleT<T>::
359{
360 using Type = typename CaseOptionTraitsT<T>::ContainerType;
361 return _allowConvert(Type());
362}
363
364namespace
365{
366// Cette classe a pour but de supprimer les blancs en début et fin de
367// chaîne sauf si \a Type est une 'String'.
368// Si le type attendu n'est pas une 'String', on considère que les blancs
369// en début et fin ne sont pas significatifs.
370template<typename Type>
371class StringCollapser
372{
373 public:
374 static String collapse(const String& str)
375 {
376 return String::collapseWhiteSpace(str);
377 }
378};
379template<>
380class StringCollapser<String>
381{
382 public:
383 static String collapse(const String& str)
384 {
385 return str;
386 }
387};
388}
389
390/*---------------------------------------------------------------------------*/
391/*---------------------------------------------------------------------------*/
392/*!
393 * \brief Cherche la valeur de l'option dans le jeu de données.
394 *
395 * La valeur trouvée est stockée dans \a m_value.
396 *
397 * Si la valeur n'est pas présente dans le jeu de données, regarde s'il
398 * existe une valeur par défaut et utilise cette dernière.
399 */
400template<typename T> void CaseOptionSimpleT<T>::
401_search(bool is_phase1)
402{
403 CaseOptionSimple::_search(is_phase1);
404 if (!is_phase1)
405 return;
407
408 // Si l'option n'est pas présente dans le jeu de données, on prend
409 // l'option par défaut, sauf si l'option est facultative
410 String str_val = (_element().null()) ? _defaultValue() : _element().value();
411 bool has_valid_value = true;
412 if (str_val.null()){
413 if (!isOptional()){
415 name(),rootElement());
416 return;
417 }
418 else
419 has_valid_value = false;
420 }
421 _setHasValidValue(has_valid_value);
422 if (has_valid_value){
423 Type val = Type();
424 str_val = StringCollapser<Type>::collapse(str_val);
425 bool is_bad = builtInGetValue(val,str_val);
426 //cerr << "** TRY CONVERT " << str_val << ' ' << val << ' ' << is_bad << endl;
427 if (is_bad){
429 name(),rootElement(),str_val,typeToName(val));
430 return;
431 }
432 _checkPhysicalConvert(physicalUnitConverter(),val);
433 m_value = val;
434 }
435 _setIsInitialized();
436}
437
438/*---------------------------------------------------------------------------*/
439/*---------------------------------------------------------------------------*/
440
441template<typename T> void CaseOptionSimpleT<T>::
442setDefaultValue(const Type& def_value)
443{
444 // Si on a une valeur donnée par l'utilisateur, on ne fait rien.
445 if (isPresent())
446 return;
447
448 // Valeur déjà initialisée. Dans ce cas on remplace aussi la valeur actuelle.
449 if (_isInitialized())
450 m_value = def_value;
451
452 String s;
453 bool is_bad = builtInPutValue(def_value,s);
454 if (is_bad)
455 ARCANE_FATAL("Can not set default value");
456 _setDefaultValue(s);
457}
458
459/*---------------------------------------------------------------------------*/
460/*---------------------------------------------------------------------------*/
461
462namespace
463{
464template<typename T>
465class FunctionConverterT
466{
467 public:
468 void convert(ICaseFunction& tbl,Real t,T& value)
469 {
470 ARCANE_UNUSED(tbl);
471 ARCANE_UNUSED(t);
472 ARCANE_UNUSED(value);
473 throw CaseOptionException("FunctionConverter","Invalid type");
474 }
475};
476
477template<>
478class FunctionConverterT<Real>
479{
480 public:
481 void convert(ICaseFunction& tbl,Real t,Real& value)
482 { tbl.value(t,value); }
483};
484
485template<>
486class FunctionConverterT<Real3>
487{
488 public:
489 void convert(ICaseFunction& tbl,Real t,Real3& value)
490 { tbl.value(t,value); }
491};
492
493template<>
494class FunctionConverterT<bool>
495{
496 public:
497 void convert(ICaseFunction& tbl,Real t,bool& value)
498 { tbl.value(t,value); }
499};
500
501template<>
502class FunctionConverterT<Integer>
503{
504 public:
505 void convert(ICaseFunction& tbl,Real t,Integer& value)
506 { tbl.value(t,value); }
507};
508
509template<>
510class FunctionConverterT<String>
511{
512 public:
513 void convert(ICaseFunction& tbl,Real t,String& value)
514 { tbl.value(t,value); }
515};
516
517/*---------------------------------------------------------------------------*/
518/*---------------------------------------------------------------------------*/
519
520template<typename ParamType,typename ValueType>
521class ComputeFunctionValue
522{
523 public:
524 static void convert(ICaseFunction* func,ParamType t,ValueType& new_value)
525 {
526 FunctionConverterT<ValueType>().convert(*func,t,new_value);
527 }
528};
529
530} // namespace
531
532/*---------------------------------------------------------------------------*/
533/*---------------------------------------------------------------------------*/
534
536valueAtParameter(Real t) const
537{
538 ICaseFunction* func = function();
539 Type new_value(m_value);
540 if (func){
541 ComputeFunctionValue<Real,T>::convert(func,t,new_value);
542 _checkPhysicalConvert(physicalUnitConverter(),new_value);
543 }
544 return new_value;
545}
546
547/*---------------------------------------------------------------------------*/
548/*---------------------------------------------------------------------------*/
549
552{
553 ICaseFunction* func = function();
554 Type new_value(m_value);
555 if (func){
556 ComputeFunctionValue<Integer,T>::convert(func,t,new_value);
557 _checkPhysicalConvert(physicalUnitConverter(),new_value);
558 }
559 return new_value;
560}
561
562/*---------------------------------------------------------------------------*/
563/*---------------------------------------------------------------------------*/
564
565template<typename T> void CaseOptionSimpleT<T>::
566updateFromFunction(Real current_time,Integer current_iteration)
567{
568 _checkIsInitialized();
569 ICaseFunction* func = function();
570 if (!func)
571 return;
572 Type new_value(m_value);
573 switch(func->paramType()){
575 ComputeFunctionValue<Real,T>::convert(func,current_time,new_value);
576 break;
578 ComputeFunctionValue<Integer,T>::convert(func,current_iteration,new_value);
579 break;
581 break;
582 }
583 _checkPhysicalConvert(physicalUnitConverter(),new_value);
584 this->_setChangedSinceLastIteration(m_value!=new_value);
585 ITraceMng* msg = caseMng()->traceMng();
586 msg->debug() << "New value for option <" << name() << "> " << new_value;
587 _copyCaseOptionValue(m_value,new_value);
588}
589
590/*---------------------------------------------------------------------------*/
591/*---------------------------------------------------------------------------*/
592
593template<typename T> void CaseOptionSimpleT<T>::
594print(const String& lang,std::ostream& o) const
595{
596 ARCANE_UNUSED(lang);
597 _checkIsInitialized();
598 if (hasValidValue())
599 o << m_value;
600 else
601 o << "undefined";
602}
603
604/*---------------------------------------------------------------------------*/
605/*---------------------------------------------------------------------------*/
606
607/*---------------------------------------------------------------------------*/
608/*---------------------------------------------------------------------------*/
609
610template<typename T> CaseOptionMultiSimpleT<T>::
613{
614}
615
616/*---------------------------------------------------------------------------*/
617/*---------------------------------------------------------------------------*/
618
619template<typename T> CaseOptionMultiSimpleT<T>::
620CaseOptionMultiSimpleT(const CaseOptionBuildInfo& cob,
621 const String& /*physical_unit*/)
622: CaseOptionMultiSimple(cob)
623{
624}
625
626/*---------------------------------------------------------------------------*/
627/*---------------------------------------------------------------------------*/
628
629template<typename T> CaseOptionMultiSimpleT<T>::
631{
632 const T* avalue = m_view.data();
633 delete[] avalue;
634}
635
636/*---------------------------------------------------------------------------*/
637/*---------------------------------------------------------------------------*/
638
639template<typename T> bool CaseOptionMultiSimpleT<T>::
641{
642 using Type = typename CaseOptionTraitsT<T>::ContainerType;
643 return _allowConvert(Type());
644}
645
646/*---------------------------------------------------------------------------*/
647/*---------------------------------------------------------------------------*/
648/*!
649 * \brief Cherche la valeur de l'option dans le jeu de donnée.
650 *
651 * La valeur trouvée est stockée dans \a m_value.
652 *
653 * Si la valeur n'est pas présente dans le jeu de donnée, regarde s'il
654 * existe une valeur par défaut et utilise cette dernière.
655 */
656template <typename T>
658_search(bool is_phase1)
659{
660 if (!is_phase1)
661 return;
662
663 const ParameterListWithCaseOption& params = caseMng()->_internalImpl()->parameters();
664 const ParameterCaseOption pco{ params.getParameterCaseOption(caseDocumentFragment()->language()) };
665
666 String full_xpath = String::format("{0}/{1}", rootElement().xpathFullName(), name());
667 // !!! En XML, on commence par 1 et non 0.
668 UniqueArray<Integer> option_in_param;
669 pco.indexesInParam(full_xpath, option_in_param, false);
670
671 XmlNodeList elem_list = rootElement().children(name());
672 Integer asize = elem_list.size();
673
674 bool is_optional = isOptional();
675
676 if (asize == 0 && option_in_param.empty() && is_optional) {
677 return;
678 }
679
680 Integer min_occurs = minOccurs();
681 Integer max_occurs = maxOccurs();
682
683 Integer max_in_param = 0;
684
685 if (!option_in_param.empty()) {
686 max_in_param = option_in_param[0];
687 for (Integer index : option_in_param) {
688 if (index > max_in_param)
689 max_in_param = index;
690 }
691 if (max_occurs >= 0) {
692 if (max_in_param > max_occurs) {
693 StringBuilder msg = "Bad number of occurences in command line (greater than max)";
694 msg += " index_max_in_param=";
695 msg += max_in_param;
696 msg += " max_occur=";
697 msg += max_occurs;
698 msg += " option=";
699 msg += full_xpath;
700 throw CaseOptionException(A_FUNCINFO, msg.toString(), true);
701 }
702 }
703 }
704
705 if (max_occurs >= 0) {
706 if (asize > max_occurs) {
707 StringBuilder msg = "Bad number of occurences (greater than max)";
708 msg += " nb_occur=";
709 msg += asize;
710 msg += " max_occur=";
711 msg += max_occurs;
712 msg += " option=";
713 msg += full_xpath;
714 throw CaseOptionException(A_FUNCINFO, msg.toString(), true);
715 }
716 }
717 // Il y aura toujours au moins min_occurs options.
718 // S'il n'y a pas assez l'options dans le jeu de données et dans les paramètres de la
719 // ligne de commande, on ajoute des services par défaut (si pas de défaut, il y aura un plantage).
720 Integer final_size = std::max(asize, std::max(min_occurs, max_in_param));
721
722 const Type* old_value = m_view.data();
723 delete[] old_value;
724 using Type = typename CaseOptionTraitsT<T>::ContainerType;
725 Type* ptr_value = new Type[final_size];
726 m_view = ArrayViewType(final_size, ptr_value);
727 this->_setArray(ptr_value, final_size);
728
729 // D'abord, on aura les options du jeu de données : comme on ne peut pas définir un indice
730 // pour les options dans le jeu de données, elles seront forcément au début et seront contigües.
731 // Puis, s'il manque des options pour atteindre le min_occurs, on ajoute des options par défaut.
732 // S'il n'y a pas d'option par défaut, il y aura une exception.
733 // Enfin, l'utilisateur peut avoir ajouté des options à partir de la ligne de commande. On les ajoute alors.
734 // Si l'utilisateur souhaite modifier des valeurs du jeu de données à partir de la ligne de commande, on
735 // remplace les options au fur et à mesure de la lecture.
736 for (Integer i = 0; i < final_size; ++i) {
737 String str_val;
738
739 // Partie paramètres de la ligne de commande.
740 if (option_in_param.contains(i + 1)) {
741 str_val = pco.getParameterOrNull(full_xpath, i + 1, false);
742 }
743
744 // Partie jeu de données.
745 else if (i < asize) {
746 XmlNode velem = elem_list[i];
747 if (!velem.null()) {
748 str_val = velem.value();
749 }
750 }
751
752 // Valeur par défaut.
753 if (str_val.null()) {
754 str_val = _defaultValue();
755 }
756 else {
757 // Dans un else : Le remplacement de symboles ne s'applique pas pour les valeurs par défault du .axl.
758 str_val = StringVariableReplace::replaceWithCmdLineArgs(params, str_val, true);
759 }
760
761 // Maintenant, ce plantage concerne aussi le cas où il n'y a pas de valeurs par défaut et qu'il n'y a
762 // pas assez d'options pour atteindre le min_occurs.
763 if (str_val.null())
765 name(), rootElement());
766 Type val = Type();
767 str_val = StringCollapser<Type>::collapse(str_val);
768 bool is_bad = builtInGetValue(val, str_val);
769 if (is_bad)
771 name(), rootElement(), str_val, typeToName(val));
772 //throw CaseOptionException("get_value",name(),rootElement(),str_val,typeToName(val));
773 //ptr_value[i] = val;
774 _copyCaseOptionValue(ptr_value[i], val);
775 }
776}
777
778/*---------------------------------------------------------------------------*/
779/*---------------------------------------------------------------------------*/
780
781template<typename T> void CaseOptionMultiSimpleT<T>::
782print(const String& lang,std::ostream& o) const
783{
784 ARCANE_UNUSED(lang);
785 for( Integer i=0; i<this->size(); ++i )
786 o << this->_ptr()[i] << " ";
787}
788
789/*---------------------------------------------------------------------------*/
790/*---------------------------------------------------------------------------*/
791
792template<typename T> void CaseOptionMultiSimpleT<T>::
793visit(ICaseDocumentVisitor* visitor) const
794{
795 visitor->applyVisitor(this);
796}
797
798/*---------------------------------------------------------------------------*/
799/*---------------------------------------------------------------------------*/
800
801String CaseOptionSimple::
802_convertFunctionRealToString(ICaseFunction* func,Real t)
803{
804 String v;
805 ComputeFunctionValue<Real,String>::convert(func,t,v);
806 return v;
807}
808
809/*---------------------------------------------------------------------------*/
810/*---------------------------------------------------------------------------*/
811
812String CaseOptionSimple::
813_convertFunctionIntegerToString(ICaseFunction* func,Integer t)
814{
815 String v;
816 ComputeFunctionValue<Integer,String>::convert(func,t,v);
817 return v;
818}
819
820/*---------------------------------------------------------------------------*/
821/*---------------------------------------------------------------------------*/
822
823template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<Real>;
824template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<Real2>;
825template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<Real3>;
826template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<Real2x2>;
827template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<Real3x3>;
828template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<bool>;
829template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<Int16>;
830template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<Int32>;
831template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<Int64>;
832template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<String>;
833
834template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<RealArray>;
835template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<Real2Array>;
836template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<Real3Array>;
837template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<Real2x2Array>;
838template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<Real3x3Array>;
839template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<BoolArray>;
840template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<Int16Array>;
841template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<Int32Array>;
842template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<Int64Array>;
843template class ARCANE_TEMPLATE_EXPORT CaseOptionSimpleT<StringArray>;
844
845template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<Real>;
846template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<Real2>;
847template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<Real3>;
848template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<Real2x2>;
849template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<Real3x3>;
850template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<bool>;
851template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<Int16>;
852template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<Int32>;
853template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<Int64>;
854template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<String>;
855
856template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<RealArray>;
857template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<Real2Array>;
858template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<Real3Array>;
859template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<Real2x2Array>;
860template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<Real3x3Array>;
861template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<BoolArray>;
862template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<Int16Array>;
863template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<Int32Array>;
864template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<Int64Array>;
865template class ARCANE_TEMPLATE_EXPORT CaseOptionMultiSimpleT<StringArray>;
866
867/*---------------------------------------------------------------------------*/
868/*---------------------------------------------------------------------------*/
869
870} // End namespace Arcane
871
872/*---------------------------------------------------------------------------*/
873/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
bool empty() const
Capacité (nombre d'éléments alloués) du vecteur.
bool contains(ConstReferenceType v) const
Vrai si le tableau contient l'élément de valeur v.
constexpr pointer _ptr() noexcept
Retourne un pointeur sur le tableau.
constexpr const_pointer data() const noexcept
Pointeur sur le début de la vue.
void _setArray(pointer v, Integer s) noexcept
Modifie le pointeur et la taille du tableau.
Classe de base des vecteurs 1D de données.
Classe de base d'une option du jeu de donnée.
String name() const
Retourne le nom de l'option correspondant au langage du jeu de données.
String _defaultValue() const
Retourne la valeur par défaut de l'option ou 0 s'il n'y en a pas.
ICaseMng * caseMng() const
Gestionnaire de cas.
ICaseDocumentFragment * caseDocumentFragment() const
Retourne le document associé à cette option.
bool isOptional() const
Permet de savoir si une option est optionnelle.
Integer maxOccurs() const
Nombre maximum d'occurences (pour une option multiple) (-1 == unbounded)
XmlNode rootElement() const
Retourne l'élément racine du DOM.
Integer minOccurs() const
Nombre minimum d'occurences (pour une option multiple)
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, ...)
virtual void _search(bool is_phase1)
Cherche la valeur de l'option dans le jeu de données.
Type valueAtParameter(Real t) const
Retourne la valeur de l'option pour le paramètre réel t.
CaseOptionTraitsT< T >::ContainerType Type
Type de l'option.
virtual void print(const String &lang, std::ostream &o) const
Imprime la valeur de l'option dans le langage lang,sur le flot o.
virtual void updateFromFunction(Real current_time, Integer current_iteration)
void setDefaultValue(const Type &def_value)
Positionne la valeur par défaut de l'option.
Classe de base des options simples (uniquement une valeur).
bool hasValidValue() const
Indique si l'option a une valeur invalide.
ICaseFunction * function() const override
Fonction associée à cette option (0 si aucune).
bool isOptional() const
Indique si l'option est facultative.
IPhysicalUnitConverter * physicalUnitConverter() const
Convertisseur d'unité physique.
bool isPresent() const
Retourne true si l'option est présente.
Interface du visiteur pour une option du jeu de données.
@ ParamUnknown
Type de paramètre inconnu.
@ ParamReal
Paramètre de type Real.
@ ParamInteger
Paramètre de type Integer.
virtual eParamType paramType() const =0
Type du paramètre de la fonction.
virtual Real convert(Real value)=0
Retourne la valeur convertie de value.
Interface du gestionnaire de traces.
virtual TraceMessage pfatal()=0
Flot pour un message d'erreur fatale parallèle.
virtual TraceMessage info()=0
Flot pour un message d'information.
virtual TraceMessageDbg debug(Trace::eDebugLevel=Trace::Medium)=0
Flot pour un message de debug.
Classe gérant un vecteur de réel de dimension 2.
Definition Real2.h:121
Classe gérant une matrice de réel de dimension 2x2.
Definition Real2x2.h:53
Classe gérant un vecteur de réel de dimension 3.
Definition Real3.h:132
Classe gérant une matrice de réel de dimension 3x3.
Definition Real3x3.h:66
Constructeur de chaîne de caractère unicode.
String toString() const
Retourne la chaîne de caractères construite.
Chaîne de caractères unicode.
bool null() const
Retourne true si la chaîne est nulle.
Definition String.cc:305
static String collapseWhiteSpace(const String &rhs)
Effectue une normalisation des caractères espaces.
Definition String.cc:453
Vecteur 1D de données avec sémantique par valeur (style STL).
Liste de noeuds d'un arbre DOM.
Definition XmlNodeList.h:35
Noeud d'un arbre DOM.
Definition XmlNode.h:51
String attrValue(const String &name, bool throw_exception=false) const
Valeur de l'attribut name.
Definition XmlNode.cc:225
String value() const
Valeur du noeud.
Definition XmlNode.cc:199
bool null() const
Vrai si le noeud est nul.
Definition XmlNode.h:294
String name() const
Nom du noeud.
Definition XmlNode.cc:132
-*- 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.
std::int64_t Int64
Type entier signé sur 64 bits.
Int32 Integer
Type représentant un entier.
UniqueArray< Real > RealUniqueArray
Tableau dynamique à une dimension de réels.
Definition UtilsTypes.h:349
std::int16_t Int16
Type entier signé sur 16 bits.
double Real
Type représentant un réel.
std::int32_t Int32
Type entier signé sur 32 bits.