1 // Copyright 2016 The PDFium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #include "xfa/fxfa/parser/cxfa_arraynodelist.h" 8 9 #include <utility> 10 #include <vector> 11 12 #include "fxjs/gc/container_trace.h" 13 #include "xfa/fxfa/parser/cxfa_node.h" 14 CXFA_ArrayNodeList(CXFA_Document * pDocument)15CXFA_ArrayNodeList::CXFA_ArrayNodeList(CXFA_Document* pDocument) 16 : CXFA_TreeList(pDocument) {} 17 18 CXFA_ArrayNodeList::~CXFA_ArrayNodeList() = default; 19 Trace(cppgc::Visitor * visitor) const20void CXFA_ArrayNodeList::Trace(cppgc::Visitor* visitor) const { 21 CXFA_TreeList::Trace(visitor); 22 ContainerTrace(visitor, m_array); 23 } 24 SetArrayNodeList(const std::vector<CXFA_Node * > & srcArray)25void CXFA_ArrayNodeList::SetArrayNodeList( 26 const std::vector<CXFA_Node*>& srcArray) { 27 if (!srcArray.empty()) { 28 m_array = 29 std::vector<cppgc::Member<CXFA_Node>>(srcArray.begin(), srcArray.end()); 30 } 31 } 32 GetLength()33size_t CXFA_ArrayNodeList::GetLength() { 34 return m_array.size(); 35 } 36 Append(CXFA_Node * pNode)37bool CXFA_ArrayNodeList::Append(CXFA_Node* pNode) { 38 m_array.push_back(pNode); 39 return true; 40 } 41 Insert(CXFA_Node * pNewNode,CXFA_Node * pBeforeNode)42bool CXFA_ArrayNodeList::Insert(CXFA_Node* pNewNode, CXFA_Node* pBeforeNode) { 43 if (!pBeforeNode) { 44 m_array.push_back(pNewNode); 45 return true; 46 } 47 48 auto it = std::find(m_array.begin(), m_array.end(), pBeforeNode); 49 if (it == m_array.end()) 50 return false; 51 52 m_array.insert(it, pNewNode); 53 return true; 54 } 55 Remove(CXFA_Node * pNode)56void CXFA_ArrayNodeList::Remove(CXFA_Node* pNode) { 57 auto it = std::find(m_array.begin(), m_array.end(), pNode); 58 if (it != m_array.end()) 59 m_array.erase(it); 60 } 61 Item(size_t index)62CXFA_Node* CXFA_ArrayNodeList::Item(size_t index) { 63 return index < m_array.size() ? m_array[index] : nullptr; 64 } 65