aboutsummaryrefslogtreecommitdiff
path: root/src/xml/XmlNode.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-01-01 01:28:21 +0800
committercrupest <crupest@outlook.com>2022-01-01 01:28:21 +0800
commit96a93e17baaff2c2050eba2afada639e93001232 (patch)
tree4e1625c0004b711c0bcf5c774ad37b54e3975de1 /src/xml/XmlNode.cpp
parent4e92e8709b30c385e1a88d7d4f76c50ee4a3d736 (diff)
downloadcru-96a93e17baaff2c2050eba2afada639e93001232.tar.gz
cru-96a93e17baaff2c2050eba2afada639e93001232.tar.bz2
cru-96a93e17baaff2c2050eba2afada639e93001232.zip
...
Diffstat (limited to 'src/xml/XmlNode.cpp')
-rw-r--r--src/xml/XmlNode.cpp23
1 files changed, 16 insertions, 7 deletions
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