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/StringBuilder.h"
21#include "arcane/utils/internal/ParameterCaseOption.h"
23#include "arcane/core/IApplication.h"
24#include "arcane/core/IServiceFactory.h"
25#include "arcane/core/CaseOptionBuildInfo.h"
26#include "arcane/core/CaseOptionException.h"
27#include "arcane/core/CaseOptionError.h"
28#include "arcane/core/XmlNodeList.h"
29#include "arcane/core/ICaseDocumentVisitor.h"
30#include "arcane/core/ICaseDocument.h"
31#include "arcane/core/ICaseMng.h"
32#include "arcane/core/internal/ICaseOptionListInternal.h"
33#include "arcane/core/internal/StringVariableReplace.h"
34#include "arcane/core/internal/ICaseMngInternal.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();
195 const ParameterListWithCaseOption& params = caseMng()->_internalImpl()->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
230 String reference_input = pco.getParameterOrNull(element.xpathFullName(),
"@name", 1);
231 if (!reference_input.null())
232 str_val = reference_input;
234 str_val = element.attrValue(
"name");
239 if (str_val.null()) {
244 if (!m_is_override_default) {
245 String category = doc->defaultCategory();
246 if (!category.null()) {
253 str_val = m_default_value;
257 str_val = StringVariableReplace::replaceWithCmdLineArgs(params, str_val,
true);
259 if (str_val.null() && !isOptional()) {
263 m_service_name = str_val;
267 bool need_create = col->
isPresent() || !isOptional();
270 m_container->allocate(1);
271 bool is_found = _tryCreateService(m_container, caseMng()->application(), str_val, 0,
this);
273 if (!is_found && !m_allow_null) {
279 String::format(
"Unable to find a service named '{0}' (valid values:{1})",
280 str_val, valid_names),
292 if (read_phase == eCaseOptionReadPhase::Phase1)
294 CaseOptions::read(read_phase);
300void CaseOptionServiceImpl::
301setDefaultValue(
const String& def_value)
303 if (!m_service_name.
null()) {
305 ARCANE_FATAL(
"Can not set default service name because service is already allocated (option='{0}')",
308 m_default_value = def_value;
309 m_is_override_default =
true;
315void CaseOptionServiceImpl::
316addDefaultValue(
const String& category,
const String& value)
327 _getAvailableServiceNames(m_container, caseMng()->application(), names);
336CaseOptionMultiServiceImpl::
338:
CaseOptionsMulti(cob.caseOptionList(), cob.name(), cob.element(), cob.minOccurs(), cob.maxOccurs())
339, m_allow_null(allow_null)
340, m_default_value(cob.defaultValue())
341, m_notify_functor(nullptr)
342, m_container(nullptr)
349CaseOptionMultiServiceImpl::
350~CaseOptionMultiServiceImpl()
360 m_container = container;
371 visitor->beginVisit(
this, index);
373 visitor->endVisit(
this, index);
381void CaseOptionMultiServiceImpl::
385 ARCANE_FATAL(
"null 'm_container'. did you called setContainer() method ?");
392 String full_xpath = String::format(
"{0}/{1}", parent_element.xpathFullName(),
name());
394 UniqueArray<Integer> option_in_param;
397 Integer size = elem_list.size();
399 bool is_optional = configList()->
isOptional();
401 if (size == 0 && option_in_param.empty() && is_optional) {
405 Integer min_occurs = configList()->minOccurs();
406 Integer max_occurs = configList()->maxOccurs();
411 if (!option_in_param.empty()) {
412 max_in_param = option_in_param[0];
413 for (
Integer index : option_in_param) {
414 if (index > max_in_param)
415 max_in_param = index;
417 if (max_occurs >= 0) {
418 if (max_in_param > max_occurs) {
419 StringBuilder msg =
"Bad number of occurences in command line (greater than max)";
420 msg +=
" index_max_in_param=";
422 msg +=
" max_occur=";
426 throw CaseOptionException(A_FUNCINFO, msg.toString(),
true);
431 if (max_occurs >= 0) {
432 if (size > max_occurs) {
433 StringBuilder msg =
"Bad number of occurences (greater than max)";
436 msg +=
" max_occur=";
440 throw CaseOptionException(A_FUNCINFO, msg.toString(),
true);
447 Integer final_size = std::max(size, std::max(min_occurs, max_in_param));
449 ITraceMng* tm = traceMng();
451 IApplication* app = caseMng()->application();
452 ICaseDocumentFragment* doc = caseDocumentFragment();
454 m_container->allocate(final_size);
466 for (
Integer index = 0; index < final_size; ++index) {
473 if (option_in_param.contains(index + 1)) {
478 if (index < size && (mesh_name.null() || str_val.null())) {
479 element = elem_list[index];
480 if (!element.null()) {
481 if (mesh_name.null())
482 mesh_name = element.attrValue(
"mesh-name");
484 str_val = element.attrValue(
"name");
489 if (mesh_name.null()) {
490 mesh_name = meshName();
494 mesh_name = StringVariableReplace::replaceWithCmdLineArgs(params, mesh_name,
true);
498 if (str_val.null()) {
499 str_val = _defaultValue();
503 str_val = StringVariableReplace::replaceWithCmdLineArgs(params, str_val,
true);
507 if (element.null()) {
508 element = parent_element.createElement(
name());
510 element.setAttrValue(
"mesh-name", mesh_name);
511 element.setAttrValue(
"name", str_val);
514 tm->info(5) <<
"CaseOptionMultiServiceImpl name=" <<
name()
515 <<
" index=" << index
517 <<
" default_value='" << _defaultValue() <<
"'"
518 <<
" mesh=" << meshHandle().meshName();
522 throw CaseOptionException(
"get_value",
"@name");
525 auto* coptions =
new CaseOptions(configList(),
name(), parent_element,
false,
true);
526 if (coptions->_setMeshHandleAndCheckDisabled(mesh_name)) {
530 coptions->configList()->_internalApi()->setRootElement(element);
531 bool is_found = _tryCreateService(m_container, app, str_val, index, coptions);
534 tm->info(5) <<
"CaseOptionMultiServiceImpl name=" <<
name()
535 <<
" index=" << index
536 <<
" service not found";
543 String::format(
"Unable to find a service named '{0}' (valid values:{1})",
544 str_val, valid_names),
551 if (m_notify_functor)
552 m_notify_functor->executeFunctor();
561 _getAvailableServiceNames(m_container, caseMng()->application(), names);
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Information for building a dataset option.
static void addError(ICaseDocumentFragment *document, const TraceInfo &where, const String &node_name, const String &message, bool is_collective=false)
Generic error.
static void addOptionNotFoundError(ICaseDocumentFragment *document, const TraceInfo &where, const String &node_name, const XmlNode &parent)
Error when a dataset option is not found. This error is collective.
UniqueArray< String > m_services_name
Service names for each occurrence.
void setContainer(ICaseOptionServiceContainer *container)
Positions the instance container.
UniqueArray< ReferenceCounter< ICaseOptions > > m_allocated_options
List of allocated options that must be deleted.
void visit(ICaseDocumentVisitor *visitor) const override
Applies the visitor to this option.
void getAvailableNames(StringArray &names) const
Returns the valid implementation names for this service in names.
String meshName() const
Mesh name to which the service is associated.
void setMeshName(const String &mesh_name)
Sets the mesh name to which the service will be associated.
void setContainer(ICaseOptionServiceContainer *container)
Positions the instance container.
void read(eCaseOptionReadPhase phase) override
Performs the reading of the read_phase phase of the options.
void visit(ICaseDocumentVisitor *visitor) const override
Applies the visitor to this option.
virtual void getAvailableNames(StringArray &names) const
Returns the valid implementation names for this service in names.
XmlNode m_element
Option element.
StringDictionary m_default_values
List of default values by category.
void setMeshName(const String &mesh_name)
Sets the mesh name to which the service will be associated.
String meshName() const
Mesh name to which the service is associated.
Base class for an array of complex data set options.
Base class for a data set options list.
bool _setMeshHandleAndCheckDisabled(const String &mesh_name)
Positions the mesh associated with this option.
void visit(ICaseDocumentVisitor *visitor) const override
Applies the visitor to this option.
String rootTagName() const override
Returns the name of the element in the data set language.
virtual String name() const
Returns the name of the element in the data set language.
CaseOptions(ICaseMng *cm, const String &name)
Constructs an options set.
EnumeratorT< Internal::IServiceFactory2 * > Enumerator
Visitor interface for a dataset option.
virtual const ParameterListWithCaseOption & parameters() const =0
List of parameters that can override the dataset.
virtual ICaseMngInternal * _internalImpl()=0
Internal implementation.
virtual void setRootElementWithParent(const XmlNode &parent_element)=0
Positions the root element of the list, with parent_element as parent. If already positioned,...
virtual void setRootElement(const XmlNode &root_element)=0
Positions the root element of the list. If already positioned, throws an exception.
Interface for a data set options list.
virtual XmlNode rootElement() const =0
Returns the element associated with this options list.
virtual bool isOptional() const =0
Indicates if the option is optional.
virtual XmlNode parentElement() const =0
Returns the parent element.
virtual bool isPresent() const =0
Indicates if the option is present in the data set.
virtual ICaseOptionListInternal * _internalApi()=0
Internal Arcane API.
Interface of a service instance container.
Interface for a list of data set options.
Interface for service or module information.
virtual TraceMessage info()=0
Stream for an information message.
Class representing the set of parameters that can modify the dataset options.
void indexesInParam(const String &xpath_before_index, const String &xpath_after_index, UniqueArray< Integer > &indexes) const
Method allowing retrieval of the index or indices of the option.
String getParameterOrNull(const String &xpath_before_index, const String &xpath_after_index, Integer index) const
Method allowing retrieval of an option's value.
Parameter list with information to override dataset options.
ParameterCaseOption getParameterCaseOption(const String &language) const
Method to retrieve an object of type ParameterCaseOption.
Information for creating a service.
Unicode character string.
bool null() const
Returns true if the string is null.
List of nodes of a DOM tree.
String xpathFullName() const
XPath name of the node with its ancestors.
XmlNode child(const String &name) const
Child node of this node with name name.
bool null() const
True if the node is null.
String name() const
Node name.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Array< String > StringArray
Dynamic one-dimensional array of strings.
eCaseOptionReadPhase
Reading phases.
Int32 Integer
Type representing an integer.
@ ST_CaseOption
The service is used at the dataset level.
UniqueArray< String > StringUniqueArray
Dynamic 1D array of strings.