Modify to override operator[] into xml_node

Currently, users can add xml_node by calling append_child(). If
repeatedly insert xml_nodes, operator[] may be more useful than using
this function.
This commit modifies to override operator[] to make appending xml_node
more useful. In additional, this operator inserts a new element with
that key and returns a reference to its mapped value. Notice that this
always increases the xml size by one, even if no mapped value is
assigned to the element.

Signed-off-by: Jihun Ahn <jhun.ahnn@gmail.com>
This commit is contained in:
Jihun Ahn 2020-03-14 23:04:35 +09:00
parent 5e64076af9
commit 39055a06a3
2 changed files with 7 additions and 0 deletions

View File

@ -5496,6 +5496,11 @@ namespace pugi
return (_root >= r._root);
}
PUGI__FN xml_node xml_node::operator[](const char_t* name_)
{
return append_child(name_);
}
PUGI__FN bool xml_node::empty() const
{
return !_root;

View File

@ -488,6 +488,8 @@ namespace pugi
bool operator<=(const xml_node& r) const;
bool operator>=(const xml_node& r) const;
xml_node operator[](const char_t* name_);
// Check if node is empty.
bool empty() const;