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