• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 PDFium Authors. All rights reserved.
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 
CXFA_ArrayNodeList(CXFA_Document * pDocument)12 CXFA_ArrayNodeList::CXFA_ArrayNodeList(CXFA_Document* pDocument)
13     : CXFA_TreeList(pDocument) {}
14 
~CXFA_ArrayNodeList()15 CXFA_ArrayNodeList::~CXFA_ArrayNodeList() {}
16 
SetArrayNodeList(std::vector<CXFA_Node * > srcArray)17 void CXFA_ArrayNodeList::SetArrayNodeList(std::vector<CXFA_Node*> srcArray) {
18   if (!srcArray.empty())
19     m_array = std::move(srcArray);
20 }
21 
GetLength()22 size_t CXFA_ArrayNodeList::GetLength() {
23   return m_array.size();
24 }
25 
Append(CXFA_Node * pNode)26 void CXFA_ArrayNodeList::Append(CXFA_Node* pNode) {
27   m_array.push_back(pNode);
28 }
29 
Insert(CXFA_Node * pNewNode,CXFA_Node * pBeforeNode)30 bool CXFA_ArrayNodeList::Insert(CXFA_Node* pNewNode, CXFA_Node* pBeforeNode) {
31   if (!pBeforeNode) {
32     m_array.push_back(pNewNode);
33     return true;
34   }
35 
36   auto it = std::find(m_array.begin(), m_array.end(), pBeforeNode);
37   if (it == m_array.end())
38     return false;
39 
40   m_array.insert(it, pNewNode);
41   return true;
42 }
43 
Remove(CXFA_Node * pNode)44 void CXFA_ArrayNodeList::Remove(CXFA_Node* pNode) {
45   auto it = std::find(m_array.begin(), m_array.end(), pNode);
46   if (it != m_array.end())
47     m_array.erase(it);
48 }
49 
Item(size_t index)50 CXFA_Node* CXFA_ArrayNodeList::Item(size_t index) {
51   return index < m_array.size() ? m_array[index] : nullptr;
52 }
53