13#include <unordered_map>
16#include "util/stringutil.h"
20T XValue(
const std::string &value) {
23 std::istringstream temp(v);
30bool XValue(
const std::string &value) {
39std::string XValue(
const std::string &value) {
63 explicit IXmlNode(
const std::string &tag_name);
89 [[nodiscard]]
bool IsTagName(
const std::string &tag)
const;
99 const std::string &value)
const;
110 [[nodiscard]] T
Attribute(
const std::string &key,
const T &def = {})
const {
113 return XValue<T>(p.second);
126 void SetAttribute(
const std::string &key,
const T &value);
146 void Value(
const T &value);
158 [[nodiscard]] T
Property(
const std::string &key,
const T &def = {})
const {
160 return node !=
nullptr ? node->
Value<T>() : def;
184 const std::string &tag)
const;
186 const std::string &key,
187 const std::string &attr)
198 return GetNode(tag) !=
nullptr;
203 const std::string &name);
205 const std::string &name,
const std::string &key,
206 const std::string &attr);
208 virtual void AddNode(std::unique_ptr<IXmlNode> p);
213 virtual void Write(std::ostream &dest,
237 using NodeList = std::vector<std::unique_ptr<IXmlNode> >;
241 const std::string &name)
const;
247 std::ostringstream temp;
268 std::ostringstream temp;
Interface class against a XML tag (node) in a XML file.
Definition ixmlnode.h:61
T Attribute(const std::string &key, const T &def={}) const
Returns an attribute.
Definition ixmlnode.h:110
virtual const IXmlNode * GetNode(const std::string &tag) const
Returns a node if it exist.
virtual void Write(std::ostream &dest, size_t level)
Write the node to the stream.
T Property(const std::string &key, const T &def={}) const
Returns a specific tag value.
Definition ixmlnode.h:158
void SetProperty(const std::string &key, const T &value)
Sets a property.
Definition ixmlnode.h:171
IXmlNode(const std::string &tag_name)
Creates a XML tag.
std::string TagName() const
Returns the nodes tag name.
Definition ixmlnode.h:73
bool ExistProperty(const std::string &tag) const
Returns true if the named property exist.
Definition ixmlnode.h:197
virtual IXmlNode & AddUniqueNode(const std::string &name, const std::string &key, const std::string &attr)
Adds a unique tag with an attribute.
bool HasChildren() const
Returns true if the XML node has children.
Definition ixmlnode.h:220
virtual IXmlNode & AddUniqueNode(const std::string &name)
Adds a unique tag.
NodeList node_list_
List of nodes.
Definition ixmlnode.h:238
virtual ~IXmlNode()=default
Destructor.
void SetAttribute(const std::string &key, const T &value)
Sets an attribute.
Definition ixmlnode.h:267
std::vector< const IXmlNode * > ChildList
List of pointer to child nodes.
Definition ixmlnode.h:179
T Value() const
Returns a value.
Definition ixmlnode.h:135
virtual void AddNode(std::unique_ptr< IXmlNode > p)
Adds a node.
void DeleteNode(const std::string &name)
Deletes all nodes with name.
void DeleteNode(const IXmlNode *node)
Deletes a specific node.
bool IsAttribute(const std::string &key, const std::string &value) const
Checks if an attribute exist.
virtual const IXmlNode * GetNode(const std::string &tag, const std::string &key, const std::string &attr) const
Returns a node with a specific attribute.
std::string tag_name_
Name of this tag.
Definition ixmlnode.h:225
bool IsTagName(const std::string &tag) const
Returns true if the tag name match. Check if this is a specific tag name. The check ignore case and n...
virtual void GetChildList(ChildList &child_list) const
Returns the child nodes.
void TagName(const std::string &name)
Sets the tag name.
Definition ixmlnode.h:80
AttributeList attribute_list_
Indexed list of attribute.
Definition ixmlnode.h:232
std::vector< std::unique_ptr< IXmlNode > > NodeList
List of nodes.
Definition ixmlnode.h:237
std::unordered_map< std::string, std::string > AttributeList
Indexed list of to key, attribute value pair.
Definition ixmlnode.h:231
virtual IXmlNode & AddNode(const std::string &name)
Adds a new tag.
virtual std::unique_ptr< IXmlNode > CreateNode(const std::string &name) const
Create a node.
std::string value_
String value of this tag.
Definition ixmlnode.h:226
void Trim(std::string &text)
Remove white space from string.
bool IEquals(const std::string &s1, const std::string &s2, size_t nChar=0)
Compare strings by ignoring case.
The xml namespace is used for XML related classes and functions.
Definition isuperviseapplication.h:22