![]() |
ATLAS Offline Software
|
Simple DOM-like node structure to hold the result of XML parsing. More...
#include <XMLCoreNode.h>
Public Types | |
| enum | NodeType { DOCUMENT_NODE , ELEMENT_NODE , COMMENT_NODE , TEXT_NODE , ENTITY_NODE , ENTITY_REFERENCE_NODE } |
| Classify node types. More... | |
Public Member Functions | |
| XMLCoreNode (NodeType type, const std::string &name="", const std::string &value="") | |
| Constructor. | |
| void | set_attrib (const std::string &name, const std::string &value) |
| Set the value of an attribute for this node. | |
| XMLCoreNode * | add_child (std::unique_ptr< XMLCoreNode > child) |
| Add a new child to this node. | |
| XMLCoreNode * | get_parent () |
| Get the parent of this node, or nullptr for a top-level node. | |
| const XMLCoreNode * | get_parent () const |
| Get the parent of this node, or nullptr for a top-level node. | |
| NodeType | get_type () const |
| Return the type of this node. | |
| const std::string & | get_name () const |
| Return the name of this node, or an empty string if no name. | |
| const std::string & | get_value () const |
| Return the value of this node, or an empty string if no value. | |
| size_t | n_attribs () const |
| Return the number of attributes for this node. | |
| std::string | get_attrib_name (size_t i) const |
| Return the name of the i'th attribute. | |
| bool | has_attrib (const std::string &name) const |
| Test for presence of an attribute with a given name. | |
| std::optional< int > | try_int_attrib (const std::string &name) const |
| Try to retrieve an integer attribute. | |
| std::optional< double > | try_double_attrib (const std::string &name) const |
| Try to retrieve an double attribute. | |
| const std::string & | get_attrib (const std::string &name) const |
| Retrieve the value of an attribute. | |
| int | get_int_attrib (const std::string &name) const |
| Retrieve the value of an attribute as an integer. | |
| double | get_double_attrib (const std::string &name) const |
| Retrieve the value of an attribute as a double. | |
| const XMLCoreNode * | get_child (const std::string &path) const |
| Return the first child matching a pattern, or nullptr. | |
| std::vector< const XMLCoreNode * > | get_children (const std::string &path="*") const |
| Return all children matching a pattern. | |
| void | print (const std::string &header, int depth=0) const |
| void | print (std::ostream &os, const std::string &header, int depth=0) const |
Private Member Functions | |
| void | set_parent (XMLCoreNode *parent) |
| Set the parent for this node. | |
| template<class T> | |
| std::optional< T > | try_attrib (const std::string &name) const |
Try to retrieve an attribute of type T. | |
| void | collect_children (const std::string &path, std::vector< const XMLCoreNode * > &children, bool only_one) const |
| Collect children of this node matching a path. | |
Private Attributes | |
| XMLCoreNode * | m_parent = nullptr |
| The parent of this node, or null for a top-level node. | |
| NodeType | m_type |
| The type of this node. | |
| std::string | m_name |
| The name of this node. | |
| std::string | m_value |
| The value fo this node. | |
| std::map< std::string, std::string > | m_attribs |
| Attributes of this node. | |
| std::vector< std::unique_ptr< XMLCoreNode > > | m_children |
| Children of this node. | |
Simple DOM-like node structure to hold the result of XML parsing.
Definition at line 44 of file XMLCoreNode.h.
Classify node types.
| Enumerator | |
|---|---|
| DOCUMENT_NODE | |
| ELEMENT_NODE | |
| COMMENT_NODE | |
| TEXT_NODE | |
| ENTITY_NODE | |
| ENTITY_REFERENCE_NODE | |
Definition at line 50 of file XMLCoreNode.h.
| XMLCoreNode::XMLCoreNode | ( | NodeType | type, |
| const std::string & | name = "", | ||
| const std::string & | value = "" ) |
| XMLCoreNode * XMLCoreNode::add_child | ( | std::unique_ptr< XMLCoreNode > | child | ) |
Add a new child to this node.
| child | The child to add. |
Children are ordered according to the order of add_child calls.
Definition at line 63 of file XMLCoreNode.cxx.
|
private |
Collect children of this node matching a path.
| path | Pattern of the child path for which to search. |
| children[out] | Vector in which to collect matching children. |
| only_one | If true, stop after finding the first child. |
See get_child above for a description of path.
Definition at line 371 of file XMLCoreNode.cxx.
Retrieve the value of an attribute.
| name | Name of the attribute. |
Throws an exception if the attribute does not exist.
Definition at line 213 of file XMLCoreNode.cxx.
| std::string XMLCoreNode::get_attrib_name | ( | size_t | i | ) | const |
Return the name of the i'th attribute.
| i | The index of the attribute. |
Indexes count attributes in order sorted by name. Throws an exception if the index is out of range.
Definition at line 132 of file XMLCoreNode.cxx.
| const XMLCoreNode * XMLCoreNode::get_child | ( | const std::string & | path | ) | const |
Return the first child matching a pattern, or nullptr.
| path | Pattern of the child path for which to search. |
The @path argument is a set of nested child node names, separated by dots. For example, path node1.node2 means to look for a child of the current node named node1, and then look for a child of that one named node2. A node name may also be * to match any child.
| path | Pattern of the child path for which to search. |
The @path argument is a set of nested child node names, separated by slashes. For example, path node1/node2 means to look for a child of the current node named node1, and then look for a child of that one named node2. A node name may also be * to match any child.
Definition at line 266 of file XMLCoreNode.cxx.
| std::vector< const XMLCoreNode * > XMLCoreNode::get_children | ( | const std::string & | path = "*" | ) | const |
Return all children matching a pattern.
| path | Pattern of the child path for which to search. |
The @path argument is a set of nested child node names, separated by dots. For example, path node1.node2 means to look for a child of the current node named node1, and then look for a child of that one named node2. A node name may also be * to match any child.
| path | Pattern of the child path for which to search. |
For example, path node1/node2 means to look for a child of the current node named node1, and then look for a child of that one named node2. node named node1, and then look for a child of that one named node2. A node name may also be * to match any child.
Definition at line 287 of file XMLCoreNode.cxx.
| double XMLCoreNode::get_double_attrib | ( | const std::string & | name | ) | const |
Retrieve the value of an attribute as a double.
| name | Name of the attribute. |
Throws an exception if the attribute does not exist or cannot be converted to a double.
Definition at line 247 of file XMLCoreNode.cxx.
| int XMLCoreNode::get_int_attrib | ( | const std::string & | name | ) | const |
Retrieve the value of an attribute as an integer.
| name | Name of the attribute. |
Throws an exception if the attribute does not exist or cannot be converted to an int.
Definition at line 230 of file XMLCoreNode.cxx.
| const std::string & XMLCoreNode::get_name | ( | ) | const |
Return the name of this node, or an empty string if no name.
Definition at line 101 of file XMLCoreNode.cxx.
| XMLCoreNode * XMLCoreNode::get_parent | ( | ) |
Get the parent of this node, or nullptr for a top-level node.
Definition at line 74 of file XMLCoreNode.cxx.
| const XMLCoreNode * XMLCoreNode::get_parent | ( | ) | const |
Get the parent of this node, or nullptr for a top-level node.
Definition at line 83 of file XMLCoreNode.cxx.
| XMLCoreNode::NodeType XMLCoreNode::get_type | ( | ) | const |
Return the type of this node.
Definition at line 92 of file XMLCoreNode.cxx.
| const std::string & XMLCoreNode::get_value | ( | ) | const |
Return the value of this node, or an empty string if no value.
Definition at line 110 of file XMLCoreNode.cxx.
| bool XMLCoreNode::has_attrib | ( | const std::string & | name | ) | const |
Test for presence of an attribute with a given name.
| name | Attribute name to test. |
Definition at line 148 of file XMLCoreNode.cxx.
| size_t XMLCoreNode::n_attribs | ( | ) | const |
Return the number of attributes for this node.
Definition at line 119 of file XMLCoreNode.cxx.
| void XMLCoreNode::print | ( | const std::string & | header, |
| int | depth = 0 ) const |
Definition at line 300 of file XMLCoreNode.cxx.
| void XMLCoreNode::print | ( | std::ostream & | os, |
| const std::string & | header, | ||
| int | depth = 0 ) const |
Definition at line 313 of file XMLCoreNode.cxx.
Set the value of an attribute for this node.
| name | Attribute name. |
| value | Attribute value (as a string). |
Definition at line 51 of file XMLCoreNode.cxx.
|
private |
Set the parent for this node.
| Pointer | to the parent node. |
Definition at line 357 of file XMLCoreNode.cxx.
|
private |
Try to retrieve an attribute of type T.
param name Name of the attribute to retrieve.
Returns an invalid optional if the attribute does not exist or cannot be converted to T.
Definition at line 162 of file XMLCoreNode.cxx.
| std::optional< double > XMLCoreNode::try_double_attrib | ( | const std::string & | name | ) | const |
Try to retrieve an double attribute.
| name | Name of the attribute. |
Returns an invalid optional if the attribute does not exist or cannot be converted to a double.
Definition at line 201 of file XMLCoreNode.cxx.
| std::optional< int > XMLCoreNode::try_int_attrib | ( | const std::string & | name | ) | const |
Try to retrieve an integer attribute.
| name | Name of the attribute. |
Returns an invalid optional if the attribute does not exist or cannot be converted to an integer.
Definition at line 188 of file XMLCoreNode.cxx.
|
private |
Attributes of this node.
Definition at line 277 of file XMLCoreNode.h.
|
private |
Children of this node.
Definition at line 280 of file XMLCoreNode.h.
|
private |
The name of this node.
Definition at line 271 of file XMLCoreNode.h.
|
private |
The parent of this node, or null for a top-level node.
Definition at line 265 of file XMLCoreNode.h.
|
private |
The type of this node.
Definition at line 268 of file XMLCoreNode.h.
|
private |
The value fo this node.
Definition at line 274 of file XMLCoreNode.h.