From 1a6111e3f02b0a9cff0f81fb524b4dfb7d69854b Mon Sep 17 00:00:00 2001 From: Yuqian Yang Date: Tue, 4 Nov 2025 21:59:42 +0800 Subject: Move xml to base. --- src/xml/XmlNode.cpp | 76 ----------------------------------------------------- 1 file changed, 76 deletions(-) delete mode 100644 src/xml/XmlNode.cpp (limited to 'src/xml/XmlNode.cpp') diff --git a/src/xml/XmlNode.cpp b/src/xml/XmlNode.cpp deleted file mode 100644 index c9b73c50..00000000 --- a/src/xml/XmlNode.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include "cru/xml/XmlNode.h" -#include - -namespace cru::xml { - -XmlElementNode* XmlNode::AsElement() { - return static_cast(this); -} - -XmlTextNode* XmlNode::AsText() { return static_cast(this); } - -XmlCommentNode* XmlNode::AsComment() { - return static_cast(this); -} - -const XmlElementNode* XmlNode::AsElement() const { - return static_cast(this); -} - -const XmlTextNode* XmlNode::AsText() const { - return static_cast(this); -} - -const XmlCommentNode* XmlNode::AsComment() const { - return static_cast(this); -} - -XmlElementNode::~XmlElementNode() { - for (auto child : children_) { - delete child; - } -} - -void XmlElementNode::AddAttribute(std::string key, std::string value) { - attributes_[std::move(key)] = std::move(value); -} - -void XmlElementNode::AddChild(XmlNode* child) { - Expects(child->GetParent() == nullptr); - children_.push_back(child); - child->parent_ = this; -} - -Index XmlElementNode::GetChildElementCount() const { - return std::count_if( - children_.cbegin(), children_.cend(), - [](xml::XmlNode* node) { return node->IsElementNode(); }); -} - -XmlElementNode* XmlElementNode::GetFirstChildElement() const { - for (auto child : children_) { - if (child->GetType() == XmlNode::Type::Element) { - return child->AsElement(); - } - } - return nullptr; -} - -XmlNode* XmlElementNode::Clone() const { - XmlElementNode* node = new XmlElementNode(tag_, attributes_); - - for (auto child : children_) { - node->AddChild(child->Clone()); - } - - return node; -} - -XmlCommentNode::~XmlCommentNode() {} - -XmlNode* XmlCommentNode::Clone() const { - XmlCommentNode* node = new XmlCommentNode(text_); - - return node; -} -} // namespace cru::xml -- cgit v1.2.3