diff options
Diffstat (limited to 'core/fxcrt')
-rw-r--r-- | core/fxcrt/xml/cfx_xmlelement.cpp | 10 | ||||
-rw-r--r-- | core/fxcrt/xml/cfx_xmlnode.cpp | 104 | ||||
-rw-r--r-- | core/fxcrt/xml/cfx_xmlnode.h | 23 |
3 files changed, 60 insertions, 77 deletions
diff --git a/core/fxcrt/xml/cfx_xmlelement.cpp b/core/fxcrt/xml/cfx_xmlelement.cpp index bba6fe6187..39233190b1 100644 --- a/core/fxcrt/xml/cfx_xmlelement.cpp +++ b/core/fxcrt/xml/cfx_xmlelement.cpp @@ -29,7 +29,7 @@ std::unique_ptr<CFX_XMLNode> CFX_XMLElement::Clone() { pClone->SetAttributes(GetAttributes()); WideString wsText; - CFX_XMLNode* pChild = m_pChild; + CFX_XMLNode* pChild = GetFirstChild(); while (pChild) { switch (pChild->GetType()) { case FX_XMLNODE_Text: @@ -38,7 +38,7 @@ std::unique_ptr<CFX_XMLNode> CFX_XMLElement::Clone() { default: break; } - pChild = pChild->m_pNext; + pChild = pChild->GetNextSibling(); } pClone->SetTextData(wsText); return std::move(pClone); @@ -71,7 +71,7 @@ WideString CFX_XMLElement::GetNamespaceURI() const { auto* pElement = static_cast<const CFX_XMLElement*>(pNode); if (!pElement->HasAttribute(wsAttri)) { - pNode = pNode->GetNodeItem(CFX_XMLNode::Parent); + pNode = pNode->GetParent(); continue; } return pElement->GetString(wsAttri); @@ -81,7 +81,7 @@ WideString CFX_XMLElement::GetNamespaceURI() const { WideString CFX_XMLElement::GetTextData() const { CFX_WideTextBuf buffer; - CFX_XMLNode* pChild = m_pChild; + CFX_XMLNode* pChild = GetFirstChild(); while (pChild) { switch (pChild->GetType()) { case FX_XMLNODE_Text: @@ -91,7 +91,7 @@ WideString CFX_XMLElement::GetTextData() const { default: break; } - pChild = pChild->m_pNext; + pChild = pChild->GetNextSibling(); } return buffer.MakeString(); } diff --git a/core/fxcrt/xml/cfx_xmlnode.cpp b/core/fxcrt/xml/cfx_xmlnode.cpp index 19f397deb2..7cc506af9f 100644 --- a/core/fxcrt/xml/cfx_xmlnode.cpp +++ b/core/fxcrt/xml/cfx_xmlnode.cpp @@ -15,28 +15,25 @@ #include "core/fxcrt/xml/cfx_xmltext.h" #include "third_party/base/stl_util.h" -CFX_XMLNode::CFX_XMLNode() - : m_pParent(nullptr), - m_pChild(nullptr), - m_pPrior(nullptr), - m_pNext(nullptr) {} - -FX_XMLNODETYPE CFX_XMLNode::GetType() const { - return FX_XMLNODE_Unknown; -} +CFX_XMLNode::CFX_XMLNode() = default; CFX_XMLNode::~CFX_XMLNode() { DeleteChildren(); } +FX_XMLNODETYPE CFX_XMLNode::GetType() const { + return FX_XMLNODE_Unknown; +} + void CFX_XMLNode::DeleteChildren() { - CFX_XMLNode* pChild = m_pChild; + CFX_XMLNode* pChild = first_child_; + first_child_ = nullptr; + while (pChild) { - CFX_XMLNode* pNext = pChild->m_pNext; + CFX_XMLNode* pNext = pChild->next_sibling_; delete pChild; pChild = pNext; } - m_pChild = nullptr; } void CFX_XMLNode::AppendChild(CFX_XMLNode* pNode) { @@ -44,68 +41,57 @@ void CFX_XMLNode::AppendChild(CFX_XMLNode* pNode) { } void CFX_XMLNode::InsertChildNode(CFX_XMLNode* pNode, int32_t index) { - ASSERT(!pNode->m_pParent); + ASSERT(!pNode->parent_); - pNode->m_pParent = this; - if (!m_pChild) { - m_pChild = pNode; - pNode->m_pPrior = nullptr; - pNode->m_pNext = nullptr; + pNode->parent_ = this; + if (!first_child_) { + first_child_ = pNode; + pNode->prev_sibling_ = nullptr; + pNode->next_sibling_ = nullptr; return; } if (index == 0) { - pNode->m_pNext = m_pChild; - pNode->m_pPrior = nullptr; - m_pChild->m_pPrior = pNode; - m_pChild = pNode; + pNode->next_sibling_ = first_child_; + pNode->prev_sibling_ = nullptr; + first_child_->prev_sibling_ = pNode; + first_child_ = pNode; return; } int32_t iCount = 0; - CFX_XMLNode* pFind = m_pChild; - while (++iCount != index && pFind->m_pNext) - pFind = pFind->m_pNext; - - pNode->m_pPrior = pFind; - pNode->m_pNext = pFind->m_pNext; - if (pFind->m_pNext) - pFind->m_pNext->m_pPrior = pNode; - pFind->m_pNext = pNode; + CFX_XMLNode* pFind = first_child_; + while (++iCount != index && pFind->next_sibling_) + pFind = pFind->next_sibling_; + + pNode->prev_sibling_ = pFind; + pNode->next_sibling_ = pFind->next_sibling_; + if (pFind->next_sibling_) + pFind->next_sibling_->prev_sibling_ = pNode; + pFind->next_sibling_ = pNode; } void CFX_XMLNode::RemoveChildNode(CFX_XMLNode* pNode) { - ASSERT(m_pChild && pNode); + ASSERT(first_child_ && pNode); - if (m_pChild == pNode) - m_pChild = pNode->m_pNext; + if (first_child_ == pNode) + first_child_ = pNode->next_sibling_; else - pNode->m_pPrior->m_pNext = pNode->m_pNext; + pNode->prev_sibling_->next_sibling_ = pNode->next_sibling_; - if (pNode->m_pNext) - pNode->m_pNext->m_pPrior = pNode->m_pPrior; + if (pNode->next_sibling_) + pNode->next_sibling_->prev_sibling_ = pNode->prev_sibling_; - pNode->m_pParent = nullptr; - pNode->m_pNext = nullptr; - pNode->m_pPrior = nullptr; + pNode->parent_ = nullptr; + pNode->next_sibling_ = nullptr; + pNode->prev_sibling_ = nullptr; } -CFX_XMLNode* CFX_XMLNode::GetNodeItem(CFX_XMLNode::NodeItem eItem) const { - switch (eItem) { - case CFX_XMLNode::Root: { - CFX_XMLNode* pParent = (CFX_XMLNode*)this; - while (pParent->m_pParent) - pParent = pParent->m_pParent; +CFX_XMLNode* CFX_XMLNode::GetRoot() { + CFX_XMLNode* pParent = this; + while (pParent->parent_) + pParent = pParent->parent_; - return pParent; - } - case CFX_XMLNode::Parent: - return m_pParent; - case CFX_XMLNode::NextSibling: - return m_pNext; - case CFX_XMLNode::FirstChild: - return m_pChild; - } - return nullptr; + return pParent; } std::unique_ptr<CFX_XMLNode> CFX_XMLNode::Clone() { @@ -183,13 +169,13 @@ void CFX_XMLNode::SaveXMLNode( ws += L"\""; pXMLStream->WriteString(ws.AsStringView()); } - if (pNode->m_pChild) { + if (pNode->first_child_) { ws = L"\n>"; pXMLStream->WriteString(ws.AsStringView()); - CFX_XMLNode* pChild = pNode->m_pChild; + CFX_XMLNode* pChild = pNode->first_child_; while (pChild) { pChild->SaveXMLNode(pXMLStream); - pChild = pChild->m_pNext; + pChild = pChild->next_sibling_; } ws = L"</"; ws += static_cast<CFX_XMLElement*>(pNode)->GetName(); diff --git a/core/fxcrt/xml/cfx_xmlnode.h b/core/fxcrt/xml/cfx_xmlnode.h index dc3152f19a..55c79dcfe0 100644 --- a/core/fxcrt/xml/cfx_xmlnode.h +++ b/core/fxcrt/xml/cfx_xmlnode.h @@ -27,32 +27,29 @@ struct FX_XMLNODE { class CFX_XMLNode { public: - enum NodeItem { - Root = 0, - Parent, - NextSibling, - FirstChild, - }; - CFX_XMLNode(); virtual ~CFX_XMLNode(); virtual FX_XMLNODETYPE GetType() const; virtual std::unique_ptr<CFX_XMLNode> Clone(); + CFX_XMLNode* GetRoot(); + CFX_XMLNode* GetParent() const { return parent_; } + CFX_XMLNode* GetFirstChild() const { return first_child_; } + CFX_XMLNode* GetNextSibling() const { return next_sibling_; } + void AppendChild(CFX_XMLNode* pNode); void InsertChildNode(CFX_XMLNode* pNode, int32_t index); void RemoveChildNode(CFX_XMLNode* pNode); void DeleteChildren(); - CFX_XMLNode* GetNodeItem(CFX_XMLNode::NodeItem eItem) const; - void SaveXMLNode(const RetainPtr<CFX_SeekableStreamProxy>& pXMLStream); - CFX_XMLNode* m_pParent; - CFX_XMLNode* m_pChild; - CFX_XMLNode* m_pPrior; - CFX_XMLNode* m_pNext; + private: + CFX_XMLNode* parent_ = nullptr; + CFX_XMLNode* first_child_ = nullptr; + CFX_XMLNode* prev_sibling_ = nullptr; + CFX_XMLNode* next_sibling_ = nullptr; }; #endif // CORE_FXCRT_XML_CFX_XMLNODE_H_ |