From 96a93e17baaff2c2050eba2afada639e93001232 Mon Sep 17 00:00:00 2001 From: crupest Date: Sat, 1 Jan 2022 01:28:21 +0800 Subject: ... --- src/xml/XmlNode.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'src/xml/XmlNode.cpp') diff --git a/src/xml/XmlNode.cpp b/src/xml/XmlNode.cpp index cfeb5cf9..f4b43ea6 100644 --- a/src/xml/XmlNode.cpp +++ b/src/xml/XmlNode.cpp @@ -1,14 +1,23 @@ #include "cru/xml/XmlNode.hpp" namespace cru::xml { -bool operator==(const XmlNode& lhs, const XmlNode& rhs) { - return lhs.GetType() == rhs.GetType() && lhs.GetText() == rhs.GetText() && - lhs.GetTag() == rhs.GetTag() && - lhs.GetAttributes() == rhs.GetAttributes() && - lhs.GetChildren() == rhs.GetChildren(); +void XmlElementNode::AddAttribute(String key, String value) { + attributes_[std::move(key)] = std::move(value); } -bool operator!=(const XmlNode& lhs, const XmlNode& rhs) { - return !(lhs == rhs); +void XmlElementNode::AddChild(XmlNode* child) { + assert(child->GetParent() == nullptr); + children_.push_back(child); + child->parent_ = this; +} + +XmlNode* XmlElementNode::Clone() const { + XmlElementNode* node = new XmlElementNode(tag_, attributes_); + + for (auto child : children_) { + node->AddChild(child->Clone()); + } + + return node; } } // namespace cru::xml -- cgit v1.2.3