diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-12-21 15:12:31 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-12-30 11:41:30 +0100 |
commit | 931b1931ec46928e62cced4e81c30d8fb3c619d0 (patch) | |
tree | c8c85b403afa93ae343f841ff3946e5a3645baea /starmath | |
parent | 4db55ce4c677f0193d7833042ab7529a0e82db2f (diff) |
return by unique_ptr in popOrZero in starmath
Change-Id: I41ac1ccf2b8d9896dbb325154150becada6683df
Reviewed-on: https://gerrit.libreoffice.org/65733
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'starmath')
-rw-r--r-- | starmath/source/mathmlimport.cxx | 76 |
1 files changed, 38 insertions, 38 deletions
diff --git a/starmath/source/mathmlimport.cxx b/starmath/source/mathmlimport.cxx index 4db3dfef7fdf..fd4f3b0d5d1b 100644 --- a/starmath/source/mathmlimport.cxx +++ b/starmath/source/mathmlimport.cxx @@ -81,13 +81,13 @@ using namespace ::xmloff::token; namespace { -SmNode* popOrZero(SmNodeStack& rStack) +std::unique_ptr<SmNode> popOrZero(SmNodeStack& rStack) { if (rStack.empty()) return nullptr; auto pTmp = std::move(rStack.front()); rStack.pop_front(); - return pTmp.release(); + return pTmp; } } @@ -469,7 +469,7 @@ sal_Int64 SAL_CALL SmXMLImport::getSomething( void SmXMLImport::endDocument() { //Set the resulted tree into the SmDocShell where it belongs - SmNode *pTree = popOrZero(aNodeStack); + std::unique_ptr<SmNode> pTree = popOrZero(aNodeStack); if (pTree && pTree->GetType() == SmNodeType::Table) { uno::Reference <frame::XModel> xModel = GetModel(); @@ -481,12 +481,13 @@ void SmXMLImport::endDocument() { SmDocShell *pDocShell = static_cast<SmDocShell*>(pModel->GetObjectShell()); - pDocShell->SetFormulaTree(static_cast<SmTableNode *>(pTree)); + auto pTreeTmp = pTree.get(); + pDocShell->SetFormulaTree(static_cast<SmTableNode *>(pTree.release())); if (aText.isEmpty()) //If we picked up no annotation text { OUStringBuffer aStrBuf; // Get text from imported formula - pTree->CreateTextFromNode(aStrBuf); + pTreeTmp->CreateTextFromNode(aStrBuf); aStrBuf.stripEnd(' '); aText = aStrBuf.makeStringAndClear(); } @@ -681,7 +682,7 @@ void SmXMLContext_Helper::ApplyAttrs() else aToken.eType = TNBOLD; std::unique_ptr<SmFontNode> pFontNode(new SmFontNode(aToken)); - pFontNode->SetSubNodes(nullptr,popOrZero(rNodeStack)); + pFontNode->SetSubNodes(nullptr,popOrZero(rNodeStack).release()); rNodeStack.push_front(std::move(pFontNode)); } if (nIsItalic != -1) @@ -691,7 +692,7 @@ void SmXMLContext_Helper::ApplyAttrs() else aToken.eType = TNITALIC; std::unique_ptr<SmFontNode> pFontNode(new SmFontNode(aToken)); - pFontNode->SetSubNodes(nullptr,popOrZero(rNodeStack)); + pFontNode->SetSubNodes(nullptr,popOrZero(rNodeStack).release()); rNodeStack.push_front(std::move(pFontNode)); } if (nFontSize != 0.0) @@ -712,7 +713,7 @@ void SmXMLContext_Helper::ApplyAttrs() else pFontNode->SetSizeParameter(Fraction(nFontSize),FontSizeType::ABSOLUT); - pFontNode->SetSubNodes(nullptr,popOrZero(rNodeStack)); + pFontNode->SetSubNodes(nullptr,popOrZero(rNodeStack).release()); rNodeStack.push_front(std::move(pFontNode)); } if (!sFontFamily.isEmpty()) @@ -729,7 +730,7 @@ void SmXMLContext_Helper::ApplyAttrs() aToken.aText = sFontFamily; std::unique_ptr<SmFontNode> pFontNode(new SmFontNode(aToken)); - pFontNode->SetSubNodes(nullptr,popOrZero(rNodeStack)); + pFontNode->SetSubNodes(nullptr,popOrZero(rNodeStack).release()); rNodeStack.push_front(std::move(pFontNode)); } if (!sColor.isEmpty()) @@ -743,7 +744,7 @@ void SmXMLContext_Helper::ApplyAttrs() { aToken.eType = static_cast<SmTokenType>(tok); std::unique_ptr<SmFontNode> pFontNode(new SmFontNode(aToken)); - pFontNode->SetSubNodes(nullptr,popOrZero(rNodeStack)); + pFontNode->SetSubNodes(nullptr,popOrZero(rNodeStack).release()); rNodeStack.push_front(std::move(pFontNode)); } } @@ -871,7 +872,7 @@ void SmXMLTokenAttrHelper::ApplyAttrs(MathMLMathvariantValue eDefaultMv) aToken.cMathChar = '\0'; aToken.nLevel = 5; std::unique_ptr<SmFontNode> pFontNode(new SmFontNode(aToken)); - pFontNode->SetSubNodes(nullptr, popOrZero(rNodeStack)); + pFontNode->SetSubNodes(nullptr, popOrZero(rNodeStack).release()); rNodeStack.push_front(std::move(pFontNode)); } } @@ -1057,7 +1058,7 @@ void SmXMLPhantomContext_Impl::EndElement() std::unique_ptr<SmFontNode> pPhantom(new SmFontNode(aToken)); SmNodeStack &rNodeStack = GetSmImport().GetNodeStack(); - pPhantom->SetSubNodes(nullptr,popOrZero(rNodeStack)); + pPhantom->SetSubNodes(nullptr,popOrZero(rNodeStack).release()); rNodeStack.push_front(std::move(pPhantom)); } @@ -1589,8 +1590,8 @@ void SmXMLSubContext_Impl::GenericEndElement(SmTokenType eType, SmSubSup eSubSup for (size_t i = 1; i < aSubNodes.size(); i++) aSubNodes[i] = nullptr; - aSubNodes[eSubSup+1] = popOrZero(rNodeStack); - aSubNodes[0] = popOrZero(rNodeStack); + aSubNodes[eSubSup+1] = popOrZero(rNodeStack).release(); + aSubNodes[0] = popOrZero(rNodeStack).release(); pNode->SetSubNodes(std::move(aSubNodes)); rNodeStack.push_front(std::move(pNode)); } @@ -1647,9 +1648,9 @@ void SmXMLSubSupContext_Impl::GenericEndElement(SmTokenType eType, for (size_t i = 1; i < aSubNodes.size(); i++) aSubNodes[i] = nullptr; - aSubNodes[aSup+1] = popOrZero(rNodeStack); - aSubNodes[aSub+1] = popOrZero(rNodeStack); - aSubNodes[0] = popOrZero(rNodeStack); + aSubNodes[aSup+1] = popOrZero(rNodeStack).release(); + aSubNodes[aSub+1] = popOrZero(rNodeStack).release(); + aSubNodes[0] = popOrZero(rNodeStack).release(); pNode->SetSubNodes(std::move(aSubNodes)); rNodeStack.push_front(std::move(pNode)); } @@ -1687,7 +1688,7 @@ void SmXMLUnderContext_Impl::HandleAccent() /*Just one special case for the underline thing*/ SmNodeStack &rNodeStack = GetSmImport().GetNodeStack(); - SmNode *pTest = popOrZero(rNodeStack); + std::unique_ptr<SmNode> pTest = popOrZero(rNodeStack); SmToken aToken; aToken.cMathChar = '\0'; aToken.eType = TUNDERLINE; @@ -1697,13 +1698,12 @@ void SmXMLUnderContext_Impl::HandleAccent() if ((pTest->GetToken().cMathChar & 0x0FFF) == 0x0332) { pFirst = new SmRectangleNode(aToken); - delete pTest; } else - pFirst = pTest; + pFirst = pTest.release(); - SmNode *pSecond = popOrZero(rNodeStack); - pNode->SetSubNodes(pFirst, pSecond); + std::unique_ptr<SmNode> pSecond = popOrZero(rNodeStack); + pNode->SetSubNodes(pFirst, pSecond.release()); pNode->SetScaleMode(SmScaleMode::Width); rNodeStack.push_front(std::move(pNode)); } @@ -1764,9 +1764,9 @@ void SmXMLOverContext_Impl::HandleAccent() std::unique_ptr<SmAttributNode> pNode(new SmAttributNode(aToken)); SmNodeStack &rNodeStack = GetSmImport().GetNodeStack(); - SmNode *pFirst = popOrZero(rNodeStack); - SmNode *pSecond = popOrZero(rNodeStack); - pNode->SetSubNodes(pFirst, pSecond); + std::unique_ptr<SmNode> pFirst = popOrZero(rNodeStack); + std::unique_ptr<SmNode> pSecond = popOrZero(rNodeStack); + pNode->SetSubNodes(pFirst.release(), pSecond.release()); pNode->SetScaleMode(SmScaleMode::Width); rNodeStack.push_front(std::move(pNode)); @@ -2312,11 +2312,11 @@ void SmXMLDocContext_Impl::EndElement() { SmNodeStack &rNodeStack = GetSmImport().GetNodeStack(); - SmNode *pContextNode = popOrZero(rNodeStack); + std::unique_ptr<SmNode> pContextNode = popOrZero(rNodeStack); SmToken aDummy; std::unique_ptr<SmStructureNode> pSNode(new SmLineNode(aDummy)); - pSNode->SetSubNodes(pContextNode, nullptr); + pSNode->SetSubNodes(pContextNode.release(), nullptr); rNodeStack.push_front(std::move(pSNode)); SmNodeArray LineArray; @@ -2346,9 +2346,9 @@ void SmXMLFracContext_Impl::EndElement() aToken.eType = TOVER; std::unique_ptr<SmStructureNode> pSNode(new SmBinVerNode(aToken)); SmNode *pOper = new SmRectangleNode(aToken); - SmNode *pSecond = popOrZero(rNodeStack); - SmNode *pFirst = popOrZero(rNodeStack); - pSNode->SetSubNodes(pFirst,pOper,pSecond); + std::unique_ptr<SmNode> pSecond = popOrZero(rNodeStack); + std::unique_ptr<SmNode> pFirst = popOrZero(rNodeStack); + pSNode->SetSubNodes(pFirst.release(), pOper, pSecond.release()); rNodeStack.push_front(std::move(pSNode)); } @@ -2366,9 +2366,9 @@ void SmXMLRootContext_Impl::EndElement() std::unique_ptr<SmStructureNode> pSNode(new SmRootNode(aToken)); SmNode *pOper = new SmRootSymbolNode(aToken); SmNodeStack &rNodeStack = GetSmImport().GetNodeStack(); - SmNode *pIndex = popOrZero(rNodeStack); - SmNode *pBase = popOrZero(rNodeStack); - pSNode->SetSubNodes(pIndex,pOper,pBase); + std::unique_ptr<SmNode> pIndex = popOrZero(rNodeStack); + std::unique_ptr<SmNode> pBase = popOrZero(rNodeStack); + pSNode->SetSubNodes(pIndex.release(), pOper, pBase.release()); rNodeStack.push_front(std::move(pSNode)); } @@ -2388,7 +2388,7 @@ void SmXMLSqrtContext_Impl::EndElement() std::unique_ptr<SmStructureNode> pSNode(new SmRootNode(aToken)); SmNode *pOper = new SmRootSymbolNode(aToken); SmNodeStack &rNodeStack = GetSmImport().GetNodeStack(); - pSNode->SetSubNodes(nullptr,pOper,popOrZero(rNodeStack)); + pSNode->SetSubNodes(nullptr,pOper,popOrZero(rNodeStack).release()); rNodeStack.push_front(std::move(pSNode)); } @@ -2634,17 +2634,17 @@ void SmXMLMultiScriptsContext_Impl::ProcessSubSupPairs(bool bIsPrescript) /*On each loop the base and its sub sup pair becomes the base for the next loop to which the next sub sup pair is attached, i.e. wheels within wheels*/ - aSubNodes[0] = popOrZero(aReverseStack); + aSubNodes[0] = popOrZero(aReverseStack).release(); - SmNode *pScriptNode = popOrZero(aReverseStack); + std::unique_ptr<SmNode> pScriptNode = popOrZero(aReverseStack); if (pScriptNode && ((pScriptNode->GetToken().eType != TIDENT) || (!pScriptNode->GetToken().aText.isEmpty()))) - aSubNodes[eSub+1] = pScriptNode; + aSubNodes[eSub+1] = pScriptNode.release(); pScriptNode = popOrZero(aReverseStack); if (pScriptNode && ((pScriptNode->GetToken().eType != TIDENT) || (!pScriptNode->GetToken().aText.isEmpty()))) - aSubNodes[eSup+1] = pScriptNode; + aSubNodes[eSup+1] = pScriptNode.release(); pNode->SetSubNodes(std::move(aSubNodes)); aReverseStack.push_front(std::move(pNode)); |