Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
XmlNode.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2023 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/* XmlNode.h (C) 2000-2023 */
9/* */
10/* Noeud quelconque d'un arbre DOM. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_XMLNODE_H
13#define ARCANE_CORE_XMLNODE_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/String.h"
18#include "arcane/core/Dom.h"
19
20#include <iterator>
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
31class IRessourceMng;
32
33/*---------------------------------------------------------------------------*/
34/*---------------------------------------------------------------------------*/
35
36class XmlNodeIterator;
37class XmlNodeConstIterator;
38class XmlNodeList;
39
50class ARCANE_CORE_EXPORT XmlNode
51{
52 public:
53
63 typedef const value_type* const_pointer;
69 typedef Integer size_type;
71 typedef int difference_type;
72
77
78 public:
79
84 enum eType
85 {
87 ELEMENT = 1,
89 ATTRIBUTE = 2,
91 TEXT = 3,
93 CDATA_SECTION = 4,
95 ENTITY_REFERENCE = 5,
97 ENTITY = 6,
99 PROCESSING_INSTRUCTION = 7,
101 COMMENT = 8,
103 DOCUMENT = 9,
105 DOCUMENT_TYPE = 10,
107 DOCUMENT_FRAGMENT = 11,
109 NOTATION = 12
110 };
111
112 public:
113
114 XmlNode(IRessourceMng* m,const dom::Node& node) : m_rm(m), m_node(node) {}
115 //TODO: à supprimer
116 explicit XmlNode(IRessourceMng* m) : m_rm(m), m_node() {}
117 XmlNode() : m_rm(nullptr), m_node() {}
118
119 public:
120
122 inline iterator begin();
124 inline iterator end();
126 inline const_iterator begin() const;
128 inline const_iterator end() const;
129
130 public:
131
133 eType type() const;
134
136 String name() const;
137
141 String xpathFullName() const;
142
144 bool isNamed(const String& name) const;
145
153 String value() const;
154
160 Integer valueAsInteger(bool throw_exception=false) const;
161
167 Int64 valueAsInt64(bool throw_exception=false) const;
168
176 bool valueAsBoolean(bool throw_exception=false) const;
177
182 Real valueAsReal(bool throw_exception=false) const;
183
190 void setValue(const String& value);
191
197 String attrValue(const String& name,bool throw_exception=false) const;
198
200 void setAttrValue(const String& name,const String& value);
201
208 XmlNode attr(const String& name,bool throw_exception=false) const;
209
215 XmlNode forceAttr(const String& name);
216
221 void removeAttr(const String& name) const;
222
227 XmlNode documentElement() const;
228
233 XmlNode ownerElement() const;
234
236 void clear();
237
244 XmlNode child(const String& name) const;
245
252 XmlNode expectedChild(const String& name) const;
253
255 XmlNodeList children(const String& name) const;
256
258 XmlNodeList children() const;
259
261 XmlNode parent() const { return XmlNode(m_rm,m_node.parentNode()); }
262
267 void append(const XmlNode& child_node) { m_node.appendChild(child_node.domNode()); }
269 void remove(const XmlNode& child_node);
271 void replace(const XmlNode& new_node,XmlNode& ref_node);
273 void remove();
275 XmlNode front() const { return XmlNode(m_rm,m_node.firstChild()); }
277 XmlNode last() const { return XmlNode(m_rm,m_node.lastChild()); }
279 XmlNode next() const { return XmlNode(m_rm,m_node.nextSibling()); }
281 XmlNode prev() const { return XmlNode(m_rm,m_node.previousSibling()); }
283 XmlNode nextWithName(const String& name) const;
285 XmlNode prevWithName(const String& name) const;
287 XmlNode nextSameType() const;
289 XmlNode prevSameType() const;
290 void operator++() { m_node = m_node.nextSibling(); }
291 void operator--() { m_node = m_node.previousSibling(); }
292
294 bool null() const { return m_node._null(); }
295 bool operator!() const { return null(); }
296
298 dom::Node domNode() const { return m_node; }
300 void assignDomNode(const dom::Node& node);
301
311 XmlNode insertAfter(const XmlNode& new_child,const XmlNode& ref_node);
312
317 XmlNode childWithAttr(const String& elem_name,const String& attr_name,
318 const String& attr_value) const;
323 XmlNode childWithNameAttr(const String& elem_name,
324 const String& attr_value) const;
325
330 XmlNode xpathNode(const String& xpath_expr) const;
331
344 XmlNode createNode(eType type,const String& name,const String& value);
345
356 XmlNode createNode(eType type,const String& name_or_value);
357
363 XmlNode createText(const String& value);
364
365 XmlNode createElement(const String& name);
366
367 XmlNode createAndAppendElement(const String& name);
368
369 XmlNode createAndAppendElement(const String& name,const String& value);
370
371 XmlNode ownerDocument() const { return XmlNode(m_rm,m_node.ownerDocument()); }
372
373 IRessourceMng* rm() const { return m_rm; }
374
375 private:
376
377 IRessourceMng* m_rm;
378 dom::Node m_node;
379
380 protected:
381
382 String _value() const;
383 XmlNode _build(const dom::Node& node) const;
384 XmlNode _nullNode() const;
385 void _setNode(const dom::Node& n) { m_node = n; }
386 inline void _throwBadConvert(const char* type_name,const String& value) const;
387};
388
389/*---------------------------------------------------------------------------*/
390/*---------------------------------------------------------------------------*/
394class ARCANE_CORE_EXPORT XmlElement
395: public XmlNode
396{
397 public:
402 XmlElement(XmlNode& parent,const String& name,const String& value);
407 XmlElement(XmlNode& parent,const String& name);
408};
409
410/*---------------------------------------------------------------------------*/
411/*---------------------------------------------------------------------------*/
412
413inline bool
414operator==(const XmlNode& n1,const XmlNode& n2)
415{
416 return n1.domNode()==n2.domNode();
417}
418
419inline bool
420operator!=(const XmlNode& n1,const XmlNode& n2)
421{
422 return n1.domNode()!=n2.domNode();
423}
424
425/*---------------------------------------------------------------------------*/
426/*---------------------------------------------------------------------------*/
427
428}
429
430/*---------------------------------------------------------------------------*/
431/*---------------------------------------------------------------------------*/
432
433#endif
434
Interface d'un gestionnaire de ressource.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
Elément d'un arbre DOM.
Definition XmlNode.h:396
Noeud d'un arbre DOM.
Definition XmlNode.h:51
int difference_type
Type d'une distance entre itérateur éléments du tableau.
Definition XmlNode.h:71
Integer size_type
Type indexant le tableau.
Definition XmlNode.h:69
XmlNode value_type
Type des éléments du tableau.
Definition XmlNode.h:55
value_type & reference
Type référence d'un élément du tableau.
Definition XmlNode.h:65
const value_type & const_reference
Type référence constante d'un élément du tableau.
Definition XmlNode.h:67
value_type * pointer
Type pointeur d'un élément du tableau.
Definition XmlNode.h:61
const value_type * const_pointer
Type pointeur constant d'un élément du tableau.
Definition XmlNode.h:63
XmlNodeIterator iterator
Type de l'itérateur sur un élément du tableau.
Definition XmlNode.h:57
XmlNode prev() const
Noeud précédent (previousSibling())
Definition XmlNode.h:281
XmlNodeConstIterator const_iterator
Type de l'itérateur constant sur un élément du tableau.
Definition XmlNode.h:59
void append(const XmlNode &child_node)
Ajoute child_node comme fils de ce noeud.
Definition XmlNode.h:267
IterT< XmlNode > iter
Type d'un itérateur sur tout le tableau.
Definition XmlNode.h:74
XmlNode front() const
Premier fils.
Definition XmlNode.h:275
bool null() const
Vrai si le noeud est nul.
Definition XmlNode.h:294
XmlNode next() const
Noeud suivant (nextSibling())
Definition XmlNode.h:279
eType
NodeType An integer indicating which type of node this is.
Definition XmlNode.h:85
ConstIterT< XmlNode > const_iter
Type d'un itérateur constant sur tout le tableau.
Definition XmlNode.h:76
XmlNode parent() const
Parent de ce noeud (null si aucun)
Definition XmlNode.h:261
XmlNode last() const
Dernier fils.
Definition XmlNode.h:277
dom::Node domNode() const
Definition XmlNode.h:298
Chaîne de caractères unicode.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
Int32 Integer
Type représentant un entier.