From 57e594f047f86bfa4d26864e993ce330ad66bfcd Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Tue, 3 Jul 2018 20:49:46 +0000 Subject: Use UnownedPtr<> in cxfa_nodeiteratortemplate.h Change-Id: I48c20a56ca25a6821bc9b51aa59c037fe2341194 Reviewed-on: https://pdfium-review.googlesource.com/36972 Reviewed-by: dsinclair Commit-Queue: Tom Sepez --- xfa/fxfa/parser/cxfa_nodeiteratortemplate.h | 32 +++++++++++++++-------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'xfa/fxfa/parser') diff --git a/xfa/fxfa/parser/cxfa_nodeiteratortemplate.h b/xfa/fxfa/parser/cxfa_nodeiteratortemplate.h index 214f38e501..10543fdbcf 100644 --- a/xfa/fxfa/parser/cxfa_nodeiteratortemplate.h +++ b/xfa/fxfa/parser/cxfa_nodeiteratortemplate.h @@ -7,14 +7,16 @@ #ifndef XFA_FXFA_PARSER_CXFA_NODEITERATORTEMPLATE_H_ #define XFA_FXFA_PARSER_CXFA_NODEITERATORTEMPLATE_H_ +#include "core/fxcrt/unowned_ptr.h" + template class CXFA_NodeIteratorTemplate { public: explicit CXFA_NodeIteratorTemplate(NodeType* pRoot) : m_pRoot(pRoot), m_pCurrent(pRoot) {} - NodeType* GetRoot() const { return m_pRoot; } - NodeType* GetCurrent() const { return m_pCurrent; } + NodeType* GetRoot() const { return m_pRoot.Get(); } + NodeType* GetCurrent() const { return m_pCurrent.Get(); } void Reset() { m_pCurrent = m_pRoot; } bool SetCurrent(NodeType* pNode) { @@ -30,18 +32,18 @@ class CXFA_NodeIteratorTemplate { if (!m_pRoot) return nullptr; if (!m_pCurrent) { - m_pCurrent = LastDescendant(m_pRoot); - return m_pCurrent; + m_pCurrent = LastDescendant(m_pRoot.Get()); + return m_pCurrent.Get(); } - NodeType* pSibling = PreviousSiblingWithinSubtree(m_pCurrent); + NodeType* pSibling = PreviousSiblingWithinSubtree(m_pCurrent.Get()); if (pSibling) { m_pCurrent = LastDescendant(pSibling); - return m_pCurrent; + return m_pCurrent.Get(); } - NodeType* pParent = ParentWithinSubtree(m_pCurrent); + NodeType* pParent = ParentWithinSubtree(m_pCurrent.Get()); if (pParent) { m_pCurrent = pParent; - return m_pCurrent; + return pParent; } return nullptr; } @@ -49,10 +51,10 @@ class CXFA_NodeIteratorTemplate { NodeType* MoveToNext() { if (!m_pRoot || !m_pCurrent) return nullptr; - NodeType* pChild = TraverseStrategy::GetFirstChild(m_pCurrent); + NodeType* pChild = TraverseStrategy::GetFirstChild(m_pCurrent.Get()); if (pChild) { m_pCurrent = pChild; - return m_pCurrent; + return pChild; } return SkipChildrenAndMoveToNext(); } @@ -60,17 +62,17 @@ class CXFA_NodeIteratorTemplate { NodeType* SkipChildrenAndMoveToNext() { if (!m_pRoot) return nullptr; - NodeType* pNode = m_pCurrent; + NodeType* pNode = m_pCurrent.Get(); while (pNode) { NodeType* pSibling = NextSiblingWithinSubtree(pNode); if (pSibling) { m_pCurrent = pSibling; - return m_pCurrent; + return pSibling; } pNode = ParentWithinSubtree(pNode); } m_pCurrent = nullptr; - return m_pCurrent; + return nullptr; } private: @@ -122,8 +124,8 @@ class CXFA_NodeIteratorTemplate { return pChild ? LastDescendant(pChild) : pNode; } - NodeType* m_pRoot; - NodeType* m_pCurrent; + UnownedPtr m_pRoot; + UnownedPtr m_pCurrent; }; #endif // XFA_FXFA_PARSER_CXFA_NODEITERATORTEMPLATE_H_ -- cgit v1.2.3