diff options
author | Tom Sepez <tsepez@chromium.org> | 2017-03-14 12:13:22 -0700 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-03-14 19:59:49 +0000 |
commit | f8a943908a414836271a1b7d7e4a97635d941b7f (patch) | |
tree | 7f900d57e21c72a67a0347e4f25d0784bdad7c83 /xfa/fxfa/parser/xfa_document_datamerger_imp.cpp | |
parent | 05df075154a832fcb476e1dfcfb865722d0ea898 (diff) | |
download | pdfium-f8a943908a414836271a1b7d7e4a97635d941b7f.tar.xz |
Replace CXFA_{Object,Node}Array with std::vector
These two ought to happen at the same time as they are
intertwined in spots. Remove blatant casts between the
two along the way.
Change-Id: I9ce5d2faadf1e38aba7cade316560d24a66d8669
Reviewed-on: https://pdfium-review.googlesource.com/2933
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fxfa/parser/xfa_document_datamerger_imp.cpp')
-rw-r--r-- | xfa/fxfa/parser/xfa_document_datamerger_imp.cpp | 77 |
1 files changed, 37 insertions, 40 deletions
diff --git a/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp b/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp index 03ab81e39f..227064a73b 100644 --- a/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp +++ b/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp @@ -297,20 +297,19 @@ void CreateDataBinding(CXFA_Node* pFormNode, } case XFA_Element::ChoiceList: if (pWidgetData->GetChoiceListOpen() == XFA_ATTRIBUTEENUM_MultiSelect) { - CXFA_NodeArray items; - pDataNode->GetNodeList(items); - int32_t iCounts = items.GetSize(); - if (iCounts > 0) { + std::vector<CXFA_Node*> items = pDataNode->GetNodeList(); + if (!items.empty()) { + bool single = items.size() == 1; wsNormalizeValue.clear(); CFX_WideString wsItem; - for (int32_t i = 0; i < iCounts; i++) { - items[i]->TryContent(wsItem); - wsItem = (iCounts == 1) ? wsItem : wsItem + L"\n"; + for (CXFA_Node* pNode : items) { + pNode->TryContent(wsItem); + wsItem = single ? wsItem : wsItem + L"\n"; wsNormalizeValue += wsItem; } CXFA_ExData exData = defValue.GetExData(); ASSERT(exData); - exData.SetContentType(iCounts == 1 ? L"text/plain" : L"text/xml"); + exData.SetContentType(single ? L"text/plain" : L"text/xml"); } FormValueNode_SetChildContent(defValue.GetNode(), wsNormalizeValue, XFA_Element::ExData); @@ -464,12 +463,12 @@ CXFA_Node* FindDataRefDataNode(CXFA_Document* pDocument, pTemplateNode); if (rs.dwFlags == XFA_RESOLVENODE_RSTYPE_CreateNodeAll || rs.dwFlags == XFA_RESOLVENODE_RSTYPE_CreateNodeMidAll || - rs.nodes.GetSize() > 1) { - return pDocument->GetNotBindNode(rs.nodes); + rs.objects.size() > 1) { + return pDocument->GetNotBindNode(rs.objects); } if (rs.dwFlags == XFA_RESOLVENODE_RSTYPE_CreateNodeOne) { - CXFA_Object* pObject = (rs.nodes.GetSize() > 0) ? rs.nodes[0] : nullptr; + CXFA_Object* pObject = !rs.objects.empty() ? rs.objects[0] : nullptr; CXFA_Node* pNode = ToNode(pObject); return (bForceBind || !pNode || !pNode->HasBindItem()) ? pNode : nullptr; } @@ -492,7 +491,7 @@ bool NeedGenerateForm(CXFA_Node* pTemplateChild, bool bUseInstanceManager) { CXFA_Node* CloneOrMergeInstanceManager(CXFA_Document* pDocument, CXFA_Node* pFormParent, CXFA_Node* pTemplateNode, - CXFA_NodeArray& subforms) { + std::vector<CXFA_Node*>* subforms) { CFX_WideStringC wsSubformName = pTemplateNode->GetCData(XFA_ATTRIBUTE_Name); CFX_WideString wsInstMgrNodeName = L"_" + wsSubformName; uint32_t dwInstNameHash = @@ -518,7 +517,7 @@ CXFA_Node* CloneOrMergeInstanceManager(CXFA_Document* pDocument, CXFA_Node* pNextNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling); pFormParent->RemoveChild(pNode); - subforms.Add(pNode); + subforms->push_back(pNode); pNode = pNextNode; } pFormParent->RemoveChild(pExistingNode); @@ -700,13 +699,13 @@ CXFA_Node* CopyContainer_SubformSet(CXFA_Document* pDocument, bool bUseInstanceManager = pFormParentNode->GetElementType() != XFA_Element::Area; CXFA_Node* pInstMgrNode = nullptr; - CXFA_NodeArray subformArray; - CXFA_NodeArray* pSearchArray = nullptr; + std::vector<CXFA_Node*> subformArray; + std::vector<CXFA_Node*>* pSearchArray = nullptr; if (!bOneInstance && (eType == XFA_Element::SubformSet || eType == XFA_Element::Subform)) { pInstMgrNode = bUseInstanceManager ? CloneOrMergeInstanceManager( pDocument, pFormParentNode, - pTemplateNode, subformArray) + pTemplateNode, &subformArray) : nullptr; if (CXFA_Node* pOccurTemplateNode = pTemplateNode->GetFirstChildByClass(XFA_Element::Occur)) { @@ -724,10 +723,9 @@ CXFA_Node* CopyContainer_SubformSet(CXFA_Document* pDocument, pSearchArray = &subformArray; if (pFormParentNode->GetElementType() == XFA_Element::PageArea) { bOneInstance = true; - if (subformArray.GetSize() < 1) + if (subformArray.empty()) pSearchArray = nullptr; - } else if ((pTemplateNode->GetNameHash() == 0) && - (subformArray.GetSize() < 1)) { + } else if (pTemplateNode->GetNameHash() == 0 && subformArray.empty()) { pSearchArray = nullptr; } } @@ -753,7 +751,7 @@ CXFA_Node* CopyContainer_SubformSet(CXFA_Document* pDocument, sNodeIterator.MoveToNext(); } else { std::map<CXFA_Node*, CXFA_Node*> subformMapArray; - CXFA_NodeArray nodeArray; + std::vector<CXFA_Node*> nodeArray; for (; iMax < 0 || iCurRepeatIndex < iMax; iCurRepeatIndex++) { bool bSelfMatch = false; XFA_ATTRIBUTEENUM eBindMatch = XFA_ATTRIBUTEENUM_None; @@ -772,11 +770,10 @@ CXFA_Node* CopyContainer_SubformSet(CXFA_Document* pDocument, CreateDataBinding(pSubformNode, pDataNode, true); ASSERT(pSubformNode); subformMapArray[pSubformNode] = pDataNode; - nodeArray.Add(pSubformNode); + nodeArray.push_back(pSubformNode); } - for (int32_t iIndex = 0; iIndex < nodeArray.GetSize(); iIndex++) { - CXFA_Node* pSubform = nodeArray[iIndex]; + for (CXFA_Node* pSubform : nodeArray) { CXFA_Node* pDataNode = nullptr; auto it = subformMapArray.find(pSubform); if (it != subformMapArray.end()) @@ -904,14 +901,14 @@ CXFA_Node* CopyContainer_SubformSet(CXFA_Document* pDocument, if (iCurRepeatIndex == 0 && bAccessedDataDOM == false) { int32_t iLimit = iMax; if (pInstMgrNode && pTemplateNode->GetNameHash() == 0) { - iLimit = subformArray.GetSize(); + iLimit = pdfium::CollectionSize<int32_t>(subformArray); if (iLimit < iMin) iLimit = iInit; } for (; (iLimit < 0 || iCurRepeatIndex < iLimit); iCurRepeatIndex++) { if (pInstMgrNode) { - if (pSearchArray && pSearchArray->GetSize() < 1) { + if (pSearchArray && pSearchArray->empty()) { if (pTemplateNode->GetNameHash() != 0) break; pSearchArray = nullptr; @@ -1157,8 +1154,7 @@ void UpdateBindingRelations(CXFA_Document* pDocument, XFA_RESOLVENODE_RS rs; pDocument->GetScriptContext()->ResolveObjects(pDataScope, wsRef, rs, dFlags, pTemplateNode); - CXFA_Object* pObject = - (rs.nodes.GetSize() > 0) ? rs.nodes[0] : nullptr; + CXFA_Object* pObject = !rs.objects.empty() ? rs.objects[0] : nullptr; pDataNode = ToNode(pObject); if (pDataNode) { CreateDataBinding(pFormNode, pDataNode, @@ -1247,21 +1243,21 @@ CXFA_Node* XFA_DataMerge_FindFormDOMInstance(CXFA_Document* pDocument, return nullptr; } -CXFA_Node* XFA_NodeMerge_CloneOrMergeContainer(CXFA_Document* pDocument, - CXFA_Node* pFormParent, - CXFA_Node* pTemplateNode, - bool bRecursive, - CXFA_NodeArray* pSubformArray) { +CXFA_Node* XFA_NodeMerge_CloneOrMergeContainer( + CXFA_Document* pDocument, + CXFA_Node* pFormParent, + CXFA_Node* pTemplateNode, + bool bRecursive, + std::vector<CXFA_Node*>* pSubformArray) { CXFA_Node* pExistingNode = nullptr; if (!pSubformArray) { pExistingNode = XFA_DataMerge_FindFormDOMInstance( pDocument, pTemplateNode->GetElementType(), pTemplateNode->GetNameHash(), pFormParent); - } else if (pSubformArray->GetSize() > 0) { - pExistingNode = pSubformArray->GetAt(0); - pSubformArray->RemoveAt(0); + } else if (!pSubformArray->empty()) { + pExistingNode = pSubformArray->front(); + pSubformArray->erase(pSubformArray->begin()); } - if (pExistingNode) { if (pSubformArray) { pFormParent->InsertChild(pExistingNode); @@ -1354,9 +1350,10 @@ void CXFA_Document::DataMerge_UpdateBindingRelations( UpdateBindingRelations(this, pFormUpdateRoot, pDataScope, true, false); } -CXFA_Node* CXFA_Document::GetNotBindNode(CXFA_ObjArray& arrayNodes) { - for (int32_t i = 0; i < arrayNodes.GetSize(); i++) { - CXFA_Node* pNode = arrayNodes[i]->AsNode(); +CXFA_Node* CXFA_Document::GetNotBindNode( + const std::vector<CXFA_Object*>& arrayObjects) { + for (CXFA_Object* pObject : arrayObjects) { + CXFA_Node* pNode = pObject->AsNode(); if (pNode && !pNode->HasBindItem()) return pNode; } @@ -1482,7 +1479,7 @@ void CXFA_Document::DoDataMerge() { CXFA_Node* pPageSetNode = pSubformSetNode->GetFirstChildByClass(XFA_Element::PageSet); while (pPageSetNode) { - m_pPendingPageSet.Add(pPageSetNode); + m_pPendingPageSet.push_back(pPageSetNode); CXFA_Node* pNextPageSetNode = pPageSetNode->GetNextSameClassSibling(XFA_Element::PageSet); pSubformSetNode->RemoveChild(pPageSetNode); |