14#include "arcane/utils/TraceAccessor.h"
15#include "arcane/utils/FatalErrorException.h"
16#include "arcane/utils/Iterator.h"
17#include "arcane/utils/StringBuilder.h"
19#include "arcane/core/CaseOptions.h"
20#include "arcane/core/ICaseMng.h"
21#include "arcane/core/XmlNodeList.h"
22#include "arcane/core/XmlNodeIterator.h"
23#include "arcane/core/CaseOptionError.h"
24#include "arcane/core/ICaseDocumentVisitor.h"
25#include "arcane/core/CaseOptionException.h"
26#include "arcane/core/ICaseDocument.h"
27#include "arcane/core/MeshHandle.h"
28#include "arcane/core/internal/ICaseOptionListInternal.h"
31#include "arcane/core/IServiceInfo.h"
32#include "arcane/core/ICaseFunction.h"
58class XmlElementContentChecker
86 if (ns != m_space_string)
88 String::format(
"Invalid text node between elements (value='{0}')",
118 :
public ICaseOptionListInternal
122 InternalApi(CaseOptionList* opt_list)
123 : m_opt_list(opt_list)
131 m_opt_list->addConfig(o, parent);
133 void setRootElementWithParent(
const XmlNode& parent_element)
override
135 m_opt_list->setRootElementWithParent(parent_element);
137 void setRootElement(
const XmlNode& root_element)
override
139 m_opt_list->setRootElement(root_element);
141 void addInvalidChildren(
XmlNodeList& nlist)
override
143 m_opt_list->addInvalidChildren(nlist);
148 CaseOptionList* m_opt_list;
153 typedef std::pair<CaseOptionBase*, XmlNode> CaseOptionBasePair;
154 typedef std::vector<CaseOptionBasePair> CaseOptionBasePairList;
163 , m_is_present(false)
165 , m_is_optional(false)
166 , m_internal_api(this)
170 , m_case_mng(parent->
caseMng())
175 , m_is_present(false)
177 , m_is_optional(false)
178 , m_internal_api(this)
186 std::vector<ICaseOptions*> copy_list(m_case_options);
187 for (ICaseOptions* co : copy_list)
204 <<
" this=" <<
this <<
" n=" << m_case_options.size();
205 m_case_options.push_back(c);
209 info(5) <<
" REMOVE_CHILD " << c->
rootTagName() <<
" instance=" << c <<
" this=" <<
this;
210 auto i = std::find(m_case_options.begin(), m_case_options.end(), c);
211 if (i == m_case_options.end())
213 m_case_options.erase(i);
228 co->deepGetChildren(col);
234 void setOptional(
bool v) { m_is_optional = v; }
241 _setRootElement(
false, parent_element);
247 throw CaseOptionException(
"CaseOptionsList::setRootElement()",
"root_element already set",
true);
249 _setRootElement(
true,
XmlNode());
278 return m_ref_opt->caseDocumentFragment();
285 info(5) <<
"INTERNAL REMOVE CHILDREN root=" <<
m_root_element.xpathFullName() <<
" this=" <<
this;
287 m_case_options.clear();
288 m_is_disabled =
true;
293 virtual ICaseOptionListInternal*
_internalApi()
override {
return &m_internal_api; }
298 void _searchChildren(
bool is_phase1);
299 void _setRootElement(
bool force_init,
XmlNode parent_element);
300 void _strIndent(
char* buf,
int indent,
int max_indent);
302 bool _isValidChildTagName(
const String& name);
311 std::vector<ICaseOptions*> m_case_options;
316 bool m_is_disabled =
false;
331 <<
" id=" <<
typeid(*this).name()
332 <<
" phase1?=" << is_phase1
338 if (all_children.size() > 1) {
341 String::format(
"Only one token of the element is allowed (nb_occur={0})",
342 all_children.size()),
346 _setRootElement(
false,
XmlNode());
349 _searchChildren(is_phase1);
361 char str_indent[128];
362 _strIndent(str_indent, indent, 127);
368 service_name =
" name=\"" + service->
localName() +
"\"";
369 String mesh_handle_name = m_ref_opt->meshHandle().meshName();
370 if (mesh_handle_name !=
"Mesh0")
371 mesh_name =
" mesh=\"" + m_ref_opt->meshHandle().meshName() +
"\"";
373 info() << str_indent <<
"<" <<
rootTagName() << service_name << mesh_name <<
">";
375 _printOption(lang, indent, i->first,
info().file());
378 co->printChildren(lang, indent + 1);
392 visitor->beginVisit(m_ref_opt);
394 i->first->visit(visitor);
399 visitor->endVisit(m_ref_opt);
419 co->addInvalidChildren(nlist);
426_searchChildren(
bool is_phase1)
432 i->first->search(is_phase1);
435 co->read(read_phase);
442_setRootElement(
bool force_init, XmlNode parent_element)
449 throw CaseOptionException(
"CaseOptionsList::_setRootElement()",
"root_element not set",
true);
453 if (!parent_element.null())
468 m_is_present =
false;
486_strIndent(
char* buf,
int indent,
int max_indent)
490 if (indent > max_indent)
493 for (
int i = 0; i < indent; ++i)
504 std::ios_base::fmtflags f = o.flags(std::ios::left);
506 for (
int i = 0; i < indent; ++i)
508 o.width(40 - indent);
511 ICaseFunction* func = co->function();
513 o <<
" (fonction: " << func->name() <<
")";
522_isValidChildTagName(
const String& name)
524 for (ConstIterT<CaseOptionBasePairList> i(
m_config_list); i(); ++i) {
525 CaseOptionBase* co = i->first;
526 if (co->name() == name)
529 for (ICaseOptions* co : m_case_options) {
530 info(5) <<
" CHECK CHILDREN this=" <<
this <<
" instance=" << co <<
" tag=" << co->rootTagName();
531 if (co->rootTagName() == name)
543 for (
auto i = parent.begin(), end = parent.end(); i != end; ++i) {
546 const String& name = i->name();
547 bool is_valid = _isValidChildTagName(name);
548 info(5) <<
" CHECK Valid tag_name=" << name <<
" is_valid=" << is_valid;
566class CaseOptionListMulti
567:
public CaseOptionList
571 typedef std::pair<CaseOptionBase*, XmlNode> CaseOptionBasePair;
572 typedef std::vector<CaseOptionBasePair> CaseOptionBasePairList;
578 : CaseOptionList(m, co, element)
579 , m_case_option_multi(com)
580 , m_min_occurs(min_occurs)
581 , m_max_occurs(max_occurs)
586 : CaseOptionList(parent, co, element)
587 , m_case_option_multi(com)
588 , m_min_occurs(min_occurs)
589 , m_max_occurs(max_occurs)
602 void _checkMinMaxOccurs(
Integer nb_occur);
608 return m_root_element_list[position];
613 ICaseOptionsMulti* m_case_option_multi;
614 UniqueArray<ICaseOptionList*> m_case_config_list;
615 XmlNodeList m_root_element_list;
629 _setRootElement(
false,
XmlNode());
633 <<
" id=" <<
typeid(*this).name()
634 <<
" phase1?=" << is_phase1
640 m_case_config_list.clear();
645 m_case_option_multi->multiAllocate(m_root_element_list);
648 Integer nb_children = m_case_option_multi->nbChildren();
649 for (
Integer i = 0; i < nb_children; ++i) {
651 co_value->
_internalApi()->setRootElement(m_root_element_list[i]);
652 m_case_config_list.add(co_value);
656 opt->readChildren(is_phase1);
658 _searchChildren(is_phase1);
671 co->addInvalidChildren(nlist);
673 opt->_internalApi()->addInvalidChildren(nlist);
684 co->printChildren(lang, indent);
686 opt->printChildren(lang, indent);
696 co->deepGetChildren(col);
698 opt->deepGetChildren(col);
710 opt_list->visit(visitor);
716void CaseOptionListMulti::
717_checkMinMaxOccurs(
Integer nb_occur)
719 if (nb_occur < m_min_occurs) {
722 String::format(
"Bad number of occurences (less than min)"
725 nb_occur, m_min_occurs),
728 if (m_max_occurs >= 0)
729 if (nb_occur > m_max_occurs) {
732 String::format(
"Bad number of occurences (greater than max)"
735 nb_occur, m_max_occurs),
760 bool is_optional,
bool is_multi)
764 x->setOptional(
true);
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
#define ARCCORE_DEFINE_REFERENCE_COUNTED_CLASS(class_name)
Macro to define methods and types for a class that uses a reference counter.
#define ARCCORE_DEFINE_REFERENCE_COUNTED_INCLASS_METHODS()
Macro to define methods managing counters of references.
Base class for 1D data vectors.
void add(ConstReferenceType val)
Adds element val to the end of the array.
Base class for a data set option.
static void addWarning(ICaseDocumentFragment *document, const TraceInfo &where, const String &node_name, const String &message, bool is_collective=false)
Generic error.
static void addError(ICaseDocumentFragment *document, const TraceInfo &where, const String &node_name, const String &message, bool is_collective=false)
Generic error.
Exception related to the dataset.
void readChildren(bool is_phase1) override
Reads the option values from the DOM elements.
Integer minOccurs() const override
Minimum number of occurrences.
void visit(ICaseDocumentVisitor *visitor) override
Applies the visitor visitor.
Integer maxOccurs() const override
Maximum number of occurrences.
void deepGetChildren(Array< CaseOptionBase * > &col) override
Adds all child options to the list col.
void addInvalidChildren(XmlNodeList &nlist) override
Adds child elements that do not correspond to options in nlist.
void printChildren(const String &lang, int indent) override
Displays the list of child options in language lang and their value.
bool isOptional() const override
Indicates if the option is optional.
XmlNode parentElement() const override
Returns the parent element.
String xpathFullName() const override
Full name in XPath format corresponding to rootElement().
MeshHandle meshHandle() const override
Handle of the associated mesh.
XmlNode m_root_element
Root element for this option list.
void removeChild(ICaseOptions *c) override
Removes co from the list of children.
void visit(ICaseDocumentVisitor *visitor) override
Applies the visitor visitor.
XmlNode m_parent_element
Parent element.
void setRootElement(XmlNode root_element) override
Positions the root element of the list. If already positioned, throws an exception.
bool isOptional() const override
Indicates if the option is optional.
void readChildren(bool is_phase1) override
Reads the option values from the DOM elements.
Integer minOccurs() const override
Minimum number of occurrences.
Integer maxOccurs() const override
Maximum number of occurrences.
void addInvalidChildren(XmlNodeList &nlist) override
Adds child elements that do not correspond to options in nlist.
void deepGetChildren(Array< CaseOptionBase * > &col) override
Adds all child options to the list col.
CaseOptionBasePairList m_config_list
List of configuration values.
void addChild(ICaseOptions *c) override
Adds the list co to the list of children.
bool isPresent() const override
Indicates if the option is present in the data set.
XmlNode rootElement() const override
Returns the element associated with this options list.
ICaseDocumentFragment * caseDocumentFragment() const override
Associated document.
virtual ICaseOptionListInternal * _internalApi() override
Internal Arcane API.
void printChildren(const String &lang, int indent) override
Displays the list of child options in language lang and their value.
void setRootElementWithParent(XmlNode parent_element) override
Positions the root element of the list, with parent_element as parent. If already positioned,...
ICaseMng * caseMng() const override
Returns the case manager.
void setIsMulti(bool v)
Indicates if the option can be present multiple times.
void addConfig(CaseOptionBase *cbi, XmlNode parent) override
Adds option o with parent parent.
void disable() override
Disables the option as if it were absent.
String rootTagName() const override
Returns the name of the element of this list.
virtual XmlNode rootElement()=0
Returns the root element.
Visitor interface for a dataset option.
virtual ICaseOptionListInternal * _internalApi()=0
Internal Arcane API.
virtual String rootTagName() const =0
Name of the element in the data set language.
Interface for service or module information.
virtual String localName() const =0
Local part of the service name.
Thread-safe implementation of a reference counter.
Unicode character string constructor.
StringBuilder & collapseWhiteSpace()
Performs whitespace character normalization. The behavior is identical to replaceWhiteSpace() plus:
String toString() const
Returns the constructed character string.
Unicode character string.
TraceAccessor(ITraceMng *m)
Constructs an accessor via the trace manager m.
TraceMessage info() const
Flow for an information message.
ITraceMng * traceMng() const
Trace manager.
void check(XmlNode element)
Checks the validity of child elements of element.
List of nodes of a DOM tree.
String xpathFullName() const
XPath name of the node with its ancestors.
eType type() const
Node type.
iterator end()
Returns an iterator over the first element after the end of the array.
XmlNodeConstIterator const_iterator
Type of the constant iterator over an element in the array.
String value() const
Node value.
bool null() const
True if the node is null.
@ TEXT
The node is a Text node.
@ ELEMENT
The node is an Element.
XmlNode parent() const
Parent of this node (null if none).
iterator begin()
Returns an iterator over the first element of the array.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
eCaseOptionReadPhase
Reading phases.
Int32 Integer
Type representing an integer.