diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-11-21 21:57:35 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-11-21 21:57:35 +0000 |
commit | b06d3f8d7658eeab6624f66aef690a7f4b44936e (patch) | |
tree | 7780958ea43c869938dfd538ecb3e53ffbf2c723 | |
parent | 36261b631e1847bcfdda6d381ae414c954d73e88 (diff) | |
download | pdfium-b06d3f8d7658eeab6624f66aef690a7f4b44936e.tar.xz |
Cleanup CXFA_OccurData
Make methods const, use return instead of out params.
Change-Id: Idfdae8df5cd74ba0bce08c05a6fc34b168d25f79
Reviewed-on: https://pdfium-review.googlesource.com/19050
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
-rw-r--r-- | xfa/fxfa/parser/cxfa_occurdata.cpp | 21 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_occurdata.h | 10 | ||||
-rw-r--r-- | xfa/fxfa/parser/xfa_document_datamerger_imp.cpp | 28 |
3 files changed, 29 insertions, 30 deletions
diff --git a/xfa/fxfa/parser/cxfa_occurdata.cpp b/xfa/fxfa/parser/cxfa_occurdata.cpp index 4538919d10..ffad9fdf00 100644 --- a/xfa/fxfa/parser/cxfa_occurdata.cpp +++ b/xfa/fxfa/parser/cxfa_occurdata.cpp @@ -10,7 +10,7 @@ CXFA_OccurData::CXFA_OccurData(CXFA_Node* pNode) : CXFA_DataData(pNode) {} -int32_t CXFA_OccurData::GetMax() { +int32_t CXFA_OccurData::GetMax() const { if (!m_pNode) return 1; @@ -19,7 +19,7 @@ int32_t CXFA_OccurData::GetMax() { return max ? *max : GetMin(); } -int32_t CXFA_OccurData::GetMin() { +int32_t CXFA_OccurData::GetMin() const { if (!m_pNode) return 1; @@ -28,25 +28,21 @@ int32_t CXFA_OccurData::GetMin() { return min && *min >= 0 ? *min : 1; } -bool CXFA_OccurData::GetOccurInfo(int32_t& iMin, - int32_t& iMax, - int32_t& iInit) { - if (!m_pNode) - return false; +std::tuple<int32_t, int32_t, int32_t> CXFA_OccurData::GetOccurInfo() const { + ASSERT(m_pNode); - iMin = GetMin(); - iMax = GetMax(); + int32_t iMin = GetMin(); + int32_t iMax = GetMax(); pdfium::Optional<int32_t> init = m_pNode->JSNode()->TryInteger(XFA_Attribute::Initial, false); - iInit = init && *init >= iMin ? *init : iMin; - - return true; + return {iMin, iMax, init && *init >= iMin ? *init : iMin}; } void CXFA_OccurData::SetMax(int32_t iMax) { iMax = (iMax != -1 && iMax < 1) ? 1 : iMax; m_pNode->JSNode()->SetInteger(XFA_Attribute::Max, iMax, false); + int32_t iMin = GetMin(); if (iMax != -1 && iMax < iMin) { iMin = iMax; @@ -57,6 +53,7 @@ void CXFA_OccurData::SetMax(int32_t iMax) { void CXFA_OccurData::SetMin(int32_t iMin) { iMin = (iMin < 0) ? 1 : iMin; m_pNode->JSNode()->SetInteger(XFA_Attribute::Min, iMin, false); + int32_t iMax = GetMax(); if (iMax > 0 && iMax < iMin) { iMax = iMin; diff --git a/xfa/fxfa/parser/cxfa_occurdata.h b/xfa/fxfa/parser/cxfa_occurdata.h index 4ce7bda319..7c90a1993b 100644 --- a/xfa/fxfa/parser/cxfa_occurdata.h +++ b/xfa/fxfa/parser/cxfa_occurdata.h @@ -7,6 +7,8 @@ #ifndef XFA_FXFA_PARSER_CXFA_OCCURDATA_H_ #define XFA_FXFA_PARSER_CXFA_OCCURDATA_H_ +#include <tuple> + #include "core/fxcrt/fx_system.h" #include "xfa/fxfa/parser/cxfa_datadata.h" @@ -16,11 +18,13 @@ class CXFA_OccurData : public CXFA_DataData { public: explicit CXFA_OccurData(CXFA_Node* pNode); - int32_t GetMax(); - int32_t GetMin(); - bool GetOccurInfo(int32_t& iMin, int32_t& iMax, int32_t& iInit); + int32_t GetMax() const; void SetMax(int32_t iMax); + + int32_t GetMin() const; void SetMin(int32_t iMin); + + std::tuple<int32_t, int32_t, int32_t> GetOccurInfo() const; }; #endif // XFA_FXFA_PARSER_CXFA_OCCURDATA_H_ diff --git a/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp b/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp index b7b3c0c12e..381e176927 100644 --- a/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp +++ b/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp @@ -46,14 +46,6 @@ struct RecurseRecord { CXFA_Node* pDataChild; }; -bool GetOccurInfo(CXFA_Node* pOccurNode, - int32_t& iMin, - int32_t& iMax, - int32_t& iInit) { - return pOccurNode ? CXFA_OccurData(pOccurNode).GetOccurInfo(iMin, iMax, iInit) - : false; -} - CXFA_Node* FormValueNode_CreateChild(CXFA_Node* pValueNode, XFA_Element iType) { CXFA_Node* pChildNode = pValueNode->GetNodeItem(XFA_NODEITEM_FirstChild); if (!pChildNode) { @@ -597,13 +589,19 @@ CXFA_Node* FindMatchingDataNode( pCurTemplateNode = pIterator->MoveToNext(); continue; } + CXFA_Node* pTemplateNodeOccur = pCurTemplateNode->GetFirstChildByClass(XFA_Element::Occur); - int32_t iMin, iMax, iInit; - if (pTemplateNodeOccur && - GetOccurInfo(pTemplateNodeOccur, iMin, iMax, iInit) && iMax == 0) { - pCurTemplateNode = pIterator->MoveToNext(); - continue; + if (pTemplateNodeOccur) { + int32_t iMin; + int32_t iMax; + int32_t iInit; + std::tie(iMin, iMax, iInit) = + CXFA_OccurData(pTemplateNodeOccur).GetOccurInfo(); + if (iMax == 0) { + pCurTemplateNode = pIterator->MoveToNext(); + continue; + } } CXFA_Node* pTemplateNodeBind = @@ -750,8 +748,8 @@ CXFA_Node* CopyContainer_SubformSet(CXFA_Document* pDocument, int32_t iMax = 1; int32_t iInit = 1; int32_t iMin = 1; - if (!bOneInstance) - GetOccurInfo(pOccurNode, iMin, iMax, iInit); + if (!bOneInstance && pOccurNode) + std::tie(iMin, iMax, iInit) = CXFA_OccurData(pOccurNode).GetOccurInfo(); XFA_ATTRIBUTEENUM eRelation = eType == XFA_Element::SubformSet |