From 39055a06a3af142fa362d137e472cb8efe8cd9cb Mon Sep 17 00:00:00 2001 From: Jihun Ahn Date: Sat, 14 Mar 2020 23:04:35 +0900 Subject: [PATCH] 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 --- src/pugixml.cpp | 5 +++++ src/pugixml.hpp | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/pugixml.cpp b/src/pugixml.cpp index c3df93b..45b0c13 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -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; diff --git a/src/pugixml.hpp b/src/pugixml.hpp index f658109..52b0499 100644 --- a/src/pugixml.hpp +++ b/src/pugixml.hpp @@ -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;