14#include "arcane/core/CaseOptionService.h"
16#include "arcane/utils/Collection.h"
17#include "arcane/utils/Enumerator.h"
18#include "arcane/utils/NotImplementedException.h"
19#include "arcane/utils/FatalErrorException.h"
20#include "arcane/utils/ApplicationInfo.h"
21#include "arcane/utils/CommandLineArguments.h"
22#include "arcane/utils/StringBuilder.h"
24#include "arcane/core/IApplication.h"
25#include "arcane/core/IServiceFactory.h"
26#include "arcane/core/CaseOptionBuildInfo.h"
27#include "arcane/core/CaseOptionException.h"
28#include "arcane/core/CaseOptionError.h"
29#include "arcane/core/XmlNodeList.h"
30#include "arcane/core/ICaseDocumentVisitor.h"
31#include "arcane/core/ICaseDocument.h"
32#include "arcane/core/ICaseMng.h"
33#include "arcane/core/internal/ICaseOptionListInternal.h"
34#include "arcane/core/internal/StringVariableReplace.h"
35#include "arcane/utils/ParameterCaseOption.h"
57 if (container->hasInterfaceImplemented(sf2)){
58 names.add(sf2->serviceInfo()->localName());
69 bool is_found =
false;
74 if (si->localName()==service_name && container->tryCreateService(index,sf2,sbi)){
75 opt->setCaseServiceInfo(si);
91 m_impl->setMeshName(mesh_name);
100 return m_impl->meshName();
109 m_impl->setMeshName(mesh_name);
118 return m_impl->meshName();
127CaseOptionServiceImpl::
131, m_default_value(cob.defaultValue())
132, m_element(cob.element())
133, m_allow_null(allow_null)
134, m_is_optional(is_optional)
135, m_is_override_default(false)
136, m_container(nullptr)
143void CaseOptionServiceImpl::
144print(
const String& lang,std::ostream& o)
const
156 visitor->beginVisit(
this);
158 visitor->endVisit(
this);
167 m_container = container;
173void CaseOptionServiceImpl::
177 ARCANE_FATAL(
"null 'm_container'. did you called setContainer() method ?");
181 _setTranslatedName();
187 col->
_internalApi()->setRootElementWithParent(m_element);
195 const ParameterList& params = caseMng()->application()->applicationInfo().commandLineArguments().parameters();
196 ICaseDocumentFragment* doc = caseDocumentFragment();
198 const ParameterCaseOption pco{ params.getParameterCaseOption(doc->language()) };
202 String reference_input = pco.getParameterOrNull(element.xpathFullName(),
"@mesh-name", 1);
203 if (!reference_input.null())
204 mesh_name = reference_input;
206 mesh_name = element.attrValue(
"mesh-name");
209 if (mesh_name.null()) {
210 mesh_name = meshName();
214 mesh_name = StringVariableReplace::replaceWithCmdLineArgs(params, mesh_name,
true);
220 <<
" is_optional=" << isOptional()
221 <<
" allow_null=" << m_allow_null
222 <<
" mesh-name=" << mesh_name
231 String reference_input = pco.getParameterOrNull(element.xpathFullName(),
"@name", 1);
232 if (!reference_input.null())
233 str_val = reference_input;
235 str_val = element.attrValue(
"name");
245 if (!m_is_override_default){
246 String category = doc->defaultCategory();
247 if (!category.null()){
248 String v = m_default_values.find(category);
254 str_val = m_default_value;
258 str_val = StringVariableReplace::replaceWithCmdLineArgs(params, str_val,
true);
260 if (str_val.null() && !isOptional()){
264 m_service_name = str_val;
268 bool need_create = col->
isPresent() || !isOptional();
271 m_container->allocate(1);
272 bool is_found = _tryCreateService(m_container,caseMng()->application(),str_val,0,
this);
274 if (!is_found && !m_allow_null){
281 String::format(
"Unable to find a service named '{0}' (valid values:{1})",
282 str_val,valid_names),
true);
293 if (read_phase==eCaseOptionReadPhase::Phase1)
295 CaseOptions::read(read_phase);
301void CaseOptionServiceImpl::
302setDefaultValue(
const String& def_value)
304 if (!m_service_name.
null()){
306 ARCANE_FATAL(
"Can not set default service name because service is already allocated (option='{0}')",
309 m_default_value = def_value;
310 m_is_override_default =
true;
316void CaseOptionServiceImpl::
317addDefaultValue(
const String& category,
const String& value)
319 m_default_values.add(category,value);
328 _getAvailableServiceNames(m_container,caseMng()->application(),names);
337CaseOptionMultiServiceImpl::
339:
CaseOptionsMulti(cob.caseOptionList(),cob.name(),cob.element(),cob.minOccurs(),cob.maxOccurs())
340, m_allow_null(allow_null)
341, m_default_value(cob.defaultValue())
342, m_notify_functor(nullptr)
343, m_container(nullptr)
350CaseOptionMultiServiceImpl::
351~CaseOptionMultiServiceImpl()
361 m_container = container;
372 visitor->beginVisit(
this,index);
374 visitor->endVisit(
this,index);
382void CaseOptionMultiServiceImpl::
386 ARCANE_FATAL(
"null 'm_container'. did you called setContainer() method ?");
393 String full_xpath = String::format(
"{0}/{1}", parent_element.xpathFullName(),
name());
395 UniqueArray<Integer> option_in_param;
396 pco.indexesInParam(full_xpath, option_in_param,
true);
398 Integer size = elem_list.size();
400 bool is_optional = configList()->
isOptional();
402 if (size == 0 && option_in_param.empty() && is_optional) {
406 Integer min_occurs = configList()->minOccurs();
407 Integer max_occurs = configList()->maxOccurs();
412 if (!option_in_param.empty()) {
413 max_in_param = option_in_param[0];
414 for (
Integer index : option_in_param) {
415 if (index > max_in_param)
416 max_in_param = index;
418 if (max_occurs >= 0) {
419 if (max_in_param > max_occurs) {
420 StringBuilder msg =
"Bad number of occurences in command line (greater than max)";
421 msg +=
" index_max_in_param=";
423 msg +=
" max_occur=";
427 throw CaseOptionException(A_FUNCINFO, msg.toString(),
true);
432 if (max_occurs >= 0) {
433 if (size > max_occurs) {
434 StringBuilder msg =
"Bad number of occurences (greater than max)";
437 msg +=
" max_occur=";
441 throw CaseOptionException(A_FUNCINFO, msg.toString(),
true);
448 Integer final_size = std::max(size, std::max(min_occurs, max_in_param));
450 ITraceMng* tm = traceMng();
452 IApplication* app = caseMng()->application();
453 ICaseDocumentFragment* doc = caseDocumentFragment();
455 m_container->allocate(final_size);
467 for (
Integer index = 0; index < final_size; ++index) {
474 if (option_in_param.contains(index + 1)) {
475 mesh_name = pco.getParameterOrNull(full_xpath,
"@mesh-name", index + 1);
476 str_val = pco.getParameterOrNull(full_xpath,
"@name", index + 1);
479 if (index < size && (mesh_name.null() || str_val.null())) {
480 element = elem_list[index];
481 if (!element.null()) {
482 if (mesh_name.null())
483 mesh_name = element.attrValue(
"mesh-name");
485 str_val = element.attrValue(
"name");
490 if (mesh_name.null()) {
491 mesh_name = meshName();
495 mesh_name = StringVariableReplace::replaceWithCmdLineArgs(params, mesh_name,
true);
499 if (str_val.null()) {
500 str_val = _defaultValue();
504 str_val = StringVariableReplace::replaceWithCmdLineArgs(params, str_val,
true);
508 if (element.null()) {
509 element = parent_element.createElement(
name());
511 element.setAttrValue(
"mesh-name", mesh_name);
512 element.setAttrValue(
"name", str_val);
515 tm->info(5) <<
"CaseOptionMultiServiceImpl name=" <<
name()
516 <<
" index=" << index
518 <<
" default_value='" << _defaultValue() <<
"'"
519 <<
" mesh=" << meshHandle().meshName();
524 throw CaseOptionException(
"get_value",
"@name");
527 auto* coptions =
new CaseOptions(configList(),
name(), parent_element,
false,
true);
528 if (coptions->_setMeshHandleAndCheckDisabled(mesh_name)) {
532 coptions->configList()->_internalApi()->setRootElement(element);
533 bool is_found = _tryCreateService(m_container, app, str_val, index, coptions);
536 tm->info(5) <<
"CaseOptionMultiServiceImpl name=" <<
name()
537 <<
" index=" << index
538 <<
" service not found";
545 String::format(
"Unable to find a service named '{0}' (valid values:{1})",
546 str_val, valid_names),
553 if (m_notify_functor)
554 m_notify_functor->executeFunctor();
563 _getAvailableServiceNames(m_container,caseMng()->application(),names);
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
const CommandLineArguments & commandLineArguments() const
Arguments de la ligne de commande.
static void addError(ICaseDocumentFragment *document, const TraceInfo &where, const String &node_name, const String &message, bool is_collective=false)
Erreur générique.
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.
UniqueArray< String > m_services_name
Noms du service pour chaque occurence.
void setContainer(ICaseOptionServiceContainer *container)
Positionne le conteneur d'instances.
UniqueArray< ReferenceCounter< ICaseOptions > > m_allocated_options
Liste des options allouées qu'il faudra supprimer.
void visit(ICaseDocumentVisitor *visitor) const override
Applique le visiteur sur cette option.
void getAvailableNames(StringArray &names) const
Retourne dans names les noms d'implémentations valides pour ce service.
String meshName() const
Nom du maillage auquel le service est associé.
void setMeshName(const String &mesh_name)
Positionne le nom du maillage auquel le service sera associé.
void setContainer(ICaseOptionServiceContainer *container)
Positionne le conteneur d'instances.
void read(eCaseOptionReadPhase phase) override
Effectue la lecture de la phase read_phase des options.
void visit(ICaseDocumentVisitor *visitor) const override
Applique le visiteur sur cette option.
virtual void getAvailableNames(StringArray &names) const
Retourne dans names les noms d'implémentations valides pour ce service.
void setMeshName(const String &mesh_name)
Positionne le nom du maillage auquel le service sera associé.
String meshName() const
Nom du maillage auquel le service est associé.
bool _setMeshHandleAndCheckDisabled(const String &mesh_name)
Positionne le maillage associé à cette option.
void visit(ICaseDocumentVisitor *visitor) const override
Applique le visiteur sur cette option.
String rootTagName() const override
Retourne le nom de l'élément dans le langage du jeu de données.
virtual String name() const
Retourne le nom de l'élément dans le langage du jeu de données.
CaseOptions(ICaseMng *cm, const String &name)
Construit un jeu d'options.
EnumeratorT< Internal::IServiceFactory2 * > Enumerator
const ParameterList & parameters() const
Liste des paramètres.
Interface de l'application.
virtual const ApplicationInfo & applicationInfo() const =0
Informations sur l'exécutable.
Interface du visiteur pour une option du jeu de données.
virtual IApplication * application()=0
Application associée.
virtual XmlNode rootElement() const =0
Retourne l'élément lié à cette liste d'option.
virtual bool isOptional() const =0
Indique si l'option est optionnelle.
virtual XmlNode parentElement() const =0
Retourne l'élément parent.
virtual bool isPresent() const =0
Indique si l'option est présente dans le jeu de données.
virtual ICaseOptionListInternal * _internalApi()=0
API interne à Arcane.
Interface d'un conteneur d'instances de service.
Interface des informations d'un service ou d'un module.
Interface du gestionnaire de traces.
virtual TraceMessage info()=0
Flot pour un message d'information.
Classe représentant l'ensemble des paramètres pouvant modifier les options du jeu de données.
ParameterCaseOption getParameterCaseOption(const String &language) const
Méthode permettant de récupérer un objet de type ParameterCaseOption.
Informations pour créer un service.
Chaîne de caractères unicode.
bool null() const
Retourne true si la chaîne est nulle.
Liste de noeuds d'un arbre DOM.
String xpathFullName() const
Nom XPath du noeud avec ces ancêtres.
XmlNode child(const String &name) const
Noeud fils de celui-ci de nom name.
bool null() const
Vrai si le noeud est nul.
String name() const
Nom du noeud.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
Array< String > StringArray
Tableau dynamique à une dimension de chaînes de caractères.
eCaseOptionReadPhase
Phases de la lecture.
Int32 Integer
Type représentant un entier.
@ ST_CaseOption
Le service s'utilise au niveau du jeu de données.
UniqueArray< String > StringUniqueArray
Tableau dynamique à une dimension de chaînes de caractères.