47 #ifndef _MIRA_XMLDOM_H_ 48 #define _MIRA_XMLDOM_H_ 53 #include <boost/noncopyable.hpp> 87 typedef std::pair<std::string, std::string>
Attribute;
93 NameSpace(
const std::string& p,
const std::string& h=
"") :
111 static constexpr
size_t npos = std::numeric_limits<size_t>::max();
176 std::string
name()
const;
181 std::string
value()
const;
192 _xmlAttr* mAttribute;
263 std::string
name()
const;
268 std::string
value()
const;
281 _xmlAttr* mAttribute;
339 [[nodiscard]] std::string
prefix()
const;
344 [[nodiscard]] std::string
href()
const;
348 _xmlNs* mNamespace =
nullptr;
551 void setName(
const std::string& name);
558 std::string
uri()
const;
718 template <
typename T>
723 MIRA_THROW(XInvalidConfig,
"The attribute '" << name
724 <<
"' could not be found in node '" << *(*
this) <<
"'");
725 return fromString<T>((*a).second);
736 template <
typename T>
742 return fromString<T>((*a).second);
1019 const std::string& value);
1026 template <
typename T>
1040 template <
typename T>
1215 XMLDom(
const std::string& rootNodeName =
"root");
1265 bool resolve =
true);
1277 const std::string&
encoding =
"UTF-8",
1278 bool resolve =
true)
const;
1289 bool resolve)
const;
1313 sibling_iterator
root();
1321 std::string
uri()
const;
1335 void loadFromPath(
const Path& filename);
1338 void saveToPath(
const Path& filename,
1339 const std::string&
encoding)
const;
1341 _xmlDoc* mXMLDocument;
bool operator==(const attribute_iterator &other) const
Compare two attribute iterators.
std::string value_type
STL-conform typedefs.
Definition: XMLDom.h:857
T get_attribute(const std::string &name) const
Return an attribute value cast to a given type.
Definition: XMLDom.h:719
std::string value_type
STL-conform typedefs.
Definition: XMLDom.h:124
const_attribute_iterator & operator--()
Predecrement.
XMLDom & operator=(XMLDom &&other) noexcept
Move assignment operator.
_xmlNode * mNode
The node pointer.
Definition: XMLDom.h:753
const_attribute_iterator attribute_begin() const
Get the const iterator to the first attribute.
Definition: XMLDom.h:685
std::string value_type
STL-conform typedefs.
Definition: XMLDom.h:440
Iterator for iterating over data nodes.
Definition: XMLDom.h:433
const_sibling_iterator root() const
Return a const sibling_iterator to the root node of the XML document.
Definition: XMLDom.h:1310
A STL conform wrapper for libxml2 to read XML files as DOM.
Definition: XMLDom.h:74
XMLDom::sibling_iterator & insert_content_after(const XMLDom::const_content_iterator &content)
Insert content after this node.
bool has_attribute(const std::string &name) const
Returns true if node contains the attribute with name name.
Definition: XMLDom.h:708
sibling_iterator & operator--()
Predecrement.
namespace_iterator()=default
Constructor.
const_sibling_iterator cparent() const
Get the const parent node sibling_iterator for this node.
void saveToFile(const Path &filename, const std::string &encoding="UTF-8", bool resolve=true) const
Save the XML document to a file.
const std::string & reference
The reference type.
Definition: XMLDom.h:367
ptrdiff_t difference_type
The difference type.
Definition: XMLDom.h:130
std::string * pointer
The pointer type.
Definition: XMLDom.h:442
const_sibling_iterator end() const
Get the const end node sibling_iterator.
Definition: XMLDom.h:628
std::string & reference
The reference type.
Definition: XMLDom.h:861
Attribute operator*() const
Dereference operator to Attribute.
attribute_iterator find_attribute(const std::string &name)
Find an attribute with the name name.
data_iterator< COMMENT_NODE > comment_iterator
The iterator for comments.
Definition: XMLDom.h:522
std::string encoding() const
Get the initial encoding of the document.
Const iterator for iterating over data nodes.
Definition: XMLDom.h:356
bool operator==(const data_iterator &other) const
Compare two iterators.
std::string uri() const
Return the uri of the node.
attribute_iterator attribute_begin()
Get the iterator to the first attribute.
std::string & reference
The reference type.
Definition: XMLDom.h:444
const_sibling_iterator operator+(std::size_t increment) const
Increment by given value.
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
boost::filesystem::path Path
Typedef of a Path (shorter version for boost::filesystem::path)
Definition: Path.h:69
std::string value_type
The value type.
Definition: XMLDom.h:771
const std::string & reference
The reference type.
Definition: XMLDom.h:775
std::bidirectional_iterator_tag iterator_category
The iterator category.
Definition: XMLDom.h:779
const_content_iterator content_end() const
Get the const end content iterator.
Definition: XMLDom.h:648
std::string * pointer
The pointer type.
Definition: XMLDom.h:208
ptrdiff_t difference_type
The difference type.
Definition: XMLDom.h:301
content_iterator content_begin()
Get the iterator to the first content.
sibling_iterator operator+(std::size_t increment) const
Increment by given value.
XMLDom::sibling_iterator insert_before(const XMLDom::const_sibling_iterator &node)
Inserts a given node before this node.
void setUri(const std::string &uri)
Set the uri of the node.
attribute_iterator attribute_end()
Get the end attribute iterator.
const std::string * pointer
The pointer type.
Definition: XMLDom.h:773
data_iterator & operator++()
Preincrement.
const_comment_iterator comment_end() const
Get the const end comment iterator.
Definition: XMLDom.h:669
NameSpace nameSpace() const
Return the namespace information of the node.
Iterator for iterating over attributes.
Definition: XMLDom.h:199
Contains toString and fromString functions for converting data types to strings and the other way rou...
NameSpace(const std::string &p, const std::string &h="")
Definition: XMLDom.h:93
bool operator==(const const_sibling_iterator &other) const
Compare two iterators.
Definition: XMLDom.h:805
const_content_iterator content_begin() const
Get the const iterator to the first content.
Definition: XMLDom.h:643
namespace_iterator & operator++()
Preincrement.
void loadFromFile(const Path &filename, bool resolve=true)
Load and parse an XML document from a file.
const_data_iterator< TEXT_NODE > const_content_iterator
The const iterator for content.
Definition: XMLDom.h:517
ptrdiff_t difference_type
The difference type.
Definition: XMLDom.h:446
attribute_iterator & operator--()
Predecrement.
sibling_iterator end()
Get the end node sibling_iterator.
const_sibling_iterator & operator--()
Predecrement.
static constexpr size_t npos
Definition: XMLDom.h:111
sibling_iterator find(const std::string &name, std::size_t nth=0)
Find the nth subnode with a given name.
const_sibling_iterator & operator+=(std::size_t increment)
Increment self by given value.
const_sibling_iterator & operator++()
Preincrement.
std::string name() const
Get the name of the attribute.
Base iterator for iterating over xml nodes with the same parent (siblings)
Definition: XMLDom.h:533
#define MIRA_THROW(ex, msg)
Macro for throwing an exception.
Definition: Exception.h:78
Attribute operator*() const
Dereference operator Attribute.
const_sibling_iterator begin(const std::string &name) const
Get the const sibling_same_name_iterator to the first sub node with the given name.
Definition: XMLDom.h:616
bool operator!=(const namespace_iterator &other) const
Compare two iterators.
std::string toString(const T &value, int precision=-1)
Converts any data type to string (the data type must support the stream << operator).
Definition: ToString.h:252
void clear()
Clears the whole content of this XMLDom document, i.e.
std::string uri() const
Get the URL of the document (i.e.
Const sibling_iterator for iterating over xml nodes that have the same parent (siblings) ...
Definition: XMLDom.h:763
sibling_iterator iterator
typedefs for backward compatibility
Definition: XMLDom.h:1204
const_attribute_iterator & operator++()
Preincrement.
std::string value() const
Get the value of the attribute.
sibling_iterator begin()
Get the sibling_iterator to the first sub node.
namespace_iterator(_xmlNs *ns)
Constructor.
Definition: XMLDom.h:315
NameSpace nameSpace() const
Return the namespace information of the attribute.
Const iterator for iterating over attributes.
Definition: XMLDom.h:117
XMLDom::sibling_iterator & add_content(const std::string &content)
Add content to this node.
Namespace information of a node.
Definition: XMLDom.h:90
const std::string * pointer
The pointer type.
Definition: XMLDom.h:365
Iterator for iterating over xmlns declarations.
Definition: XMLDom.h:288
bool operator==(const const_data_iterator &other) const
Compare two iterators.
const std::string & reference
The reference type.
Definition: XMLDom.h:128
bool operator!=(const data_iterator &other) const
Compare two iterators.
Commonly used exception classes.
std::pair< std::string, std::string > Attribute
An XML attribute.
Definition: XMLDom.h:87
const_attribute_iterator()
Constructor.
bool operator!=(const sibling_iterator &other) const
Compare two iterators.
Definition: XMLDom.h:899
std::string operator*() const
Dereference operator to std::string.
XMLDom::sibling_iterator & add_cdata_content(const std::string &cdata_content)
Add a cdata content block to this node.
std::bidirectional_iterator_tag iterator_category
The iterator category.
Definition: XMLDom.h:303
const_data_iterator & operator++()
Preincrement.
XMLDom::sibling_iterator & add_attribute(const Attribute &attribute)
Add an attribute to this node.
const_sibling_iterator(const const_sibling_iterator &other)
Copy-constructor.
Definition: XMLDom.h:795
std::string value_type
STL-conform typedefs.
Definition: XMLDom.h:206
std::bidirectional_iterator_tag iterator_category
The iterator category.
Definition: XMLDom.h:371
XMLDom::sibling_iterator & insert_content_before(const XMLDom::const_content_iterator &content)
Insert content before this node.
std::string href() const
Get the href of the ns.
NameSpace nameSpace() const
Return the namespace information of the node.
const attribute_iterator & operator=(const std::string &value)
Set the value of the attribute.
const_attribute_iterator attribute_cend() const
Get the const end attribute iterator.
std::bidirectional_iterator_tag iterator_category
The iterator category.
Definition: XMLDom.h:448
const_data_iterator & operator--()
Predecrement.
const_sibling_iterator begin() const
Get the const sibling_iterator to the first sub node.
Definition: XMLDom.h:602
sibling_iterator()
Default-constructor.
const_sibling_iterator cend() const
Get the const end node sibling_iterator.
const std::string * pointer
The pointer type.
Definition: XMLDom.h:126
XMLDom::sibling_iterator & add_comment(const std::string &comment)
Add a comment to this node.
uint32 line() const
Gets the underlying line number of the loaded document for this node.
namespace_iterator ns_end() const
XMLDom::sibling_iterator & insert_comment_before(const XMLDom::const_comment_iterator &comment)
Insert a comment before this node.
Iterator for iterating over xml nodes that have the same parent (sibligs)
Definition: XMLDom.h:850
std::string mName
the node name (optional)
Definition: XMLDom.h:755
const_sibling_iterator()
Constructor.
bool operator==(const const_attribute_iterator &other) const
Compare two attribute iterators.
NameSpace()
Definition: XMLDom.h:92
XMLDom::sibling_iterator & add_attribute(const std::string &name, const T &value)
Add an attribute to this node.
Definition: XMLDom.h:1027
bool operator!=(const attribute_iterator &other) const
Compare two attribute iterators.
std::string value() const
Get the value of the attribute.
const_comment_iterator comment_cend() const
Get the const end comment iterator.
ptrdiff_t difference_type
The difference type.
Definition: XMLDom.h:863
XMLDom(const std::string &rootNodeName="root")
Constructor for creating a new empty document.
const_comment_iterator comment_cbegin() const
Get the const iterator to the first comment.
content_iterator content_end()
Get the end content iterator.
data_iterator< TEXT_NODE > content_iterator
The iterator for content.
Definition: XMLDom.h:527
comment_iterator comment_begin()
Get the iterator to the first comment.
void setUri(const std::string &uri)
Set the URL of the document (i.e.
std::string prefix() const
Get the prefix of the ns.
bool operator!=(const const_data_iterator &other) const
Compare two iterators.
attribute_iterator()
Constructor.
const_sibling_iterator cbegin() const
Get the const sibling_iterator to the first sub node.
const_attribute_iterator attribute_cbegin() const
Get the const iterator to the first attribute.
const data_iterator & operator=(const std::string &value)
Set the data value of the node.
const_sibling_iterator const_iterator
Definition: XMLDom.h:1205
const_sibling_iterator parent() const
Get the const parent node sibling_iterator for this node.
Definition: XMLDom.h:592
std::string & reference
The reference type.
Definition: XMLDom.h:210
sibling_iterator & operator+=(std::size_t increment)
Increment self by given value.
uint32 line() const
Gets the underlying line number of the loaded document for this node.
std::bidirectional_iterator_tag iterator_category
The iterator category.
Definition: XMLDom.h:214
T get_attribute(const std::string &name, const T &defaultValue) const
Return an attribute value casted to a given type If the attribute could not be found the given defaul...
Definition: XMLDom.h:737
ptrdiff_t difference_type
The difference type.
Definition: XMLDom.h:777
std::string prefix
Definition: XMLDom.h:97
sibling_iterator(const sibling_iterator &other)
Copy-constructor.
Definition: XMLDom.h:881
sibling_iterator parent()
Get the parent node sibling_iterator for this node.
Functions for modifying file system paths.
const_content_iterator content_cend() const
Get the const end content iterator.
std::string * pointer
The pointer type.
Definition: XMLDom.h:297
void remove_attribute(attribute_iterator it)
Removes the attribute the given iterator points on from this node, if it exists.
PropertyHint precision(int p)
Sets the attribute "precision".
Definition: PropertyHint.h:285
const_attribute_iterator find_attribute(const std::string &name) const
Find an attribute with the name name.
std::string name() const
Get the name of the attribute.
std::string operator*() const
Dereference operator to get the name of the node.
comment_iterator comment_end()
Get the end comment sibling_iterator.
std::string & reference
The reference type.
Definition: XMLDom.h:299
XMLDom::sibling_iterator add_child(const std::string &name, const NameSpace &ns=NameSpace())
Add a sub node to this node.
XMLDom::sibling_iterator replace_by_content(const XMLDom::const_content_iterator &node)
Replaces this node by content node.
const_content_iterator content_cbegin() const
Get the const iterator to the first content.
XMLDom::sibling_iterator insert_after(const XMLDom::const_sibling_iterator &node)
Inserts a given node after this node.
namespace_iterator ns_begin() const
iterator_base(_xmlNode *node, const std::string &name)
Constructor.
std::string value_type
STL-conform typedefs.
Definition: XMLDom.h:295
XMLDom clone()
Create and return a copy of the document.
bool operator==(const namespace_iterator &other) const
Compare two iterators.
void loadFromString(const std::string &buffer)
Load and parse an XML document from memory.
std::string * pointer
The pointer type.
Definition: XMLDom.h:859
const_data_iterator()
Constructor.
attribute_iterator & operator++()
Preincrement.
void setName(const std::string &name)
Change the node's name.
const_data_iterator< COMMENT_NODE > const_comment_iterator
STL-conform typedefs.
Definition: XMLDom.h:512
bool operator!=(const const_sibling_iterator &other) const
Compare two iterators.
Definition: XMLDom.h:813
bool operator!=(const const_attribute_iterator &other) const
Compare two attribute iterators.
std::string value_type
STL-conform typedefs.
Definition: XMLDom.h:363
std::string href
Definition: XMLDom.h:98
sibling_iterator & operator++()
Preincrement.
const_attribute_iterator attribute_end() const
Get the const end attribute iterator.
Definition: XMLDom.h:693
ptrdiff_t difference_type
The difference type.
Definition: XMLDom.h:369
XMLDom::sibling_iterator & add_attribute(const std::string &name, const T &value, int precision)
Add an attribute to this node.
Definition: XMLDom.h:1041
ptrdiff_t difference_type
The difference type.
Definition: XMLDom.h:212
data_iterator()
Constructor.
XMLDom::sibling_iterator replace_by_comment(const XMLDom::const_comment_iterator &node)
Replaces this node by comment node.
const_sibling_iterator croot() const
Return a const sibling_iterator to the root node of the XML document.
bool operator==(const sibling_iterator &other) const
Compare two iterators.
Definition: XMLDom.h:891
XMLDom::sibling_iterator replace(const XMLDom::const_sibling_iterator &node)
Replaces this node by a recursive copy of iNode.
const_comment_iterator comment_begin() const
Get the const iterator to the first comment.
Definition: XMLDom.h:664
std::string saveToString(const std::string &encoding="UTF-8") const
Save the XML document to a string.
XMLDom::sibling_iterator & insert_comment_after(const XMLDom::const_comment_iterator &comment)
Insert a comment after this node.
const sibling_iterator & operator=(const std::string &name)
Change the name of this node.
data_iterator & operator--()
Predecrement.
std::bidirectional_iterator_tag iterator_category
The iterator category.
Definition: XMLDom.h:132
std::bidirectional_iterator_tag iterator_category
The iterator category.
Definition: XMLDom.h:865
std::string operator*() const
Dereference operator to std::string.
const_sibling_iterator find(const std::string &name, std::size_t nth=0) const
Find the nth subnode with a given name.