• 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 <vector>
10 
11 #include "third_party/base/stl_util.h"
12 
CXFA_ArrayNodeList(CXFA_Document * pDocument)13 CXFA_ArrayNodeList::CXFA_ArrayNodeList(CXFA_Document* pDocument)
14     : CXFA_TreeList(pDocument) {}
15 
~CXFA_ArrayNodeList()16 CXFA_ArrayNodeList::~CXFA_ArrayNodeList() {}
17 
SetArrayNodeList(const std::vector<CXFA_Node * > & srcArray)18 void CXFA_ArrayNodeList::SetArrayNodeList(
19     const std::vector<CXFA_Node*>& srcArray) {
20   if (!srcArray.empty())
21     m_array = srcArray;
22 }
23 
GetLength()24 size_t CXFA_ArrayNodeList::GetLength() {
25   return m_array.size();
26 }
27 
Append(CXFA_Node * pNode)28 bool CXFA_ArrayNodeList::Append(CXFA_Node* pNode) {
29   m_array.push_back(pNode);
30   return true;
31 }
32 
Insert(CXFA_Node * pNewNode,CXFA_Node * pBeforeNode)33 bool CXFA_ArrayNodeList::Insert(CXFA_Node* pNewNode, CXFA_Node* pBeforeNode) {
34   if (!pBeforeNode) {
35     m_array.push_back(pNewNode);
36   } else {
37     auto it = std::find(m_array.begin(), m_array.end(), pBeforeNode);
38     if (it != m_array.end())
39       m_array.insert(it, pNewNode);
40   }
41   return true;
42 }
43 
Remove(CXFA_Node * pNode)44 bool 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   return true;
49 }
50 
Item(size_t index)51 CXFA_Node* CXFA_ArrayNodeList::Item(size_t index) {
52   return index < m_array.size() ? m_array[index] : nullptr;
53 }
54