diff options
| author | Yuqian Yang <crupest@crupest.life> | 2025-11-04 21:59:42 +0800 |
|---|---|---|
| committer | Yuqian Yang <crupest@crupest.life> | 2025-11-04 21:59:42 +0800 |
| commit | 1a6111e3f02b0a9cff0f81fb524b4dfb7d69854b (patch) | |
| tree | 3a92e1bf61fc165c2148f38ca6602f5066011f06 /src/xml/XmlNode.cpp | |
| parent | f48505c96a70e2f1d1982fea30f3015e42fcd49d (diff) | |
| download | cru-1a6111e3f02b0a9cff0f81fb524b4dfb7d69854b.tar.gz cru-1a6111e3f02b0a9cff0f81fb524b4dfb7d69854b.tar.bz2 cru-1a6111e3f02b0a9cff0f81fb524b4dfb7d69854b.zip | |
Move xml to base.
Diffstat (limited to 'src/xml/XmlNode.cpp')
| -rw-r--r-- | src/xml/XmlNode.cpp | 76 |
1 files changed, 0 insertions, 76 deletions
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 <algorithm> - -namespace cru::xml { - -XmlElementNode* XmlNode::AsElement() { - return static_cast<XmlElementNode*>(this); -} - -XmlTextNode* XmlNode::AsText() { return static_cast<XmlTextNode*>(this); } - -XmlCommentNode* XmlNode::AsComment() { - return static_cast<XmlCommentNode*>(this); -} - -const XmlElementNode* XmlNode::AsElement() const { - return static_cast<const XmlElementNode*>(this); -} - -const XmlTextNode* XmlNode::AsText() const { - return static_cast<const XmlTextNode*>(this); -} - -const XmlCommentNode* XmlNode::AsComment() const { - return static_cast<const XmlCommentNode*>(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 |
