13#ifndef XMLCOREPARSER_XMLCORENODE_H
14#define XMLCOREPARSER_XMLCORENODE_H
30 :
public std::runtime_error
68 const std::string& name=
"",
69 const std::string& value=
"");
77 void set_attrib (
const std::string& name,
const std::string& value);
110 const std::string&
get_name ()
const;
139 bool has_attrib (
const std::string& name)
const;
149 std::optional<int>
try_int_attrib (
const std::string& name)
const;
168 const std::string&
get_attrib (
const std::string& name)
const;
212 std::vector<const XMLCoreNode*>
get_children (
const std::string& path =
"*")
const;
229 void print (std::ostream& os,
const std::string&
header,
int depth = 0)
const;
248 std::optional<T>
try_attrib (
const std::string& name)
const;
260 std::vector<const XMLCoreNode*>& children,
261 bool only_one)
const;
ExcXMLCore(const std::string &what)
Constructor.
Simple DOM-like node structure to hold the result of XML parsing.
std::string m_value
The value fo this node.
NodeType
Classify node types.
double get_double_attrib(const std::string &name) const
Retrieve the value of an attribute as a double.
std::string m_name
The name of this node.
const std::string & get_attrib(const std::string &name) const
Retrieve the value of an attribute.
XMLCoreNode * m_parent
The parent of this node, or null for a top-level node.
NodeType m_type
The type of this node.
XMLCoreNode(NodeType type, const std::string &name="", const std::string &value="")
Constructor.
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::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
XMLCoreNode * add_child(std::unique_ptr< XMLCoreNode > child)
Add a new child to this node.
void set_parent(XMLCoreNode *parent)
Set the parent for this node.
NodeType get_type() const
Return the type of this node.
std::optional< int > try_int_attrib(const std::string &name) const
Try to retrieve an integer attribute.
size_t n_attribs() const
Return the number of attributes for this node.
const std::string & get_value() const
Return the value of this node, or an empty string if no value.
XMLCoreNode * get_parent()
Get the parent of this node, or nullptr for a top-level node.
void set_attrib(const std::string &name, const std::string &value)
Set the value of an attribute for this node.
std::optional< double > try_double_attrib(const std::string &name) const
Try to retrieve an double attribute.
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.
const std::string & get_name() const
Return the name of this node, or an empty string if no name.
int get_int_attrib(const std::string &name) const
Retrieve the value of an attribute as an integer.
std::map< std::string, std::string > m_attribs
Attributes of this node.
std::vector< std::unique_ptr< XMLCoreNode > > m_children
Children of this node.
const XMLCoreNode * get_child(const std::string &path) const
Return the first child matching a pattern, or nullptr.
std::string depth
tag string for intendation