diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-12-21 15:38:29 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-12-30 11:41:41 +0100 |
commit | 9bdc1118c7b7fe10529b3320daa278f108e8f2c3 (patch) | |
tree | 39b305ec636fed88fa67c7e7f86015b20e1e7135 /starmath/source | |
parent | 931b1931ec46928e62cced4e81c30d8fb3c619d0 (diff) |
use unique_ptr in SmStructureNode::SetSubNodes
Change-Id: I1dafb03f72a3a662eeae3bb23fb0a8b7ba4e6d95
Reviewed-on: https://gerrit.libreoffice.org/65734
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'starmath/source')
-rw-r--r-- | starmath/source/cursor.cxx | 130 | ||||
-rw-r--r-- | starmath/source/mathmlimport.cxx | 54 | ||||
-rw-r--r-- | starmath/source/node.cxx | 8 | ||||
-rw-r--r-- | starmath/source/parse.cxx | 32 |
4 files changed, 112 insertions, 112 deletions
diff --git a/starmath/source/cursor.cxx b/starmath/source/cursor.cxx index a883b679ce2a..6b27956cb83f 100644 --- a/starmath/source/cursor.cxx +++ b/starmath/source/cursor.cxx @@ -617,13 +617,13 @@ void SmCursor::InsertBrackets(SmBracketType eBracketType) { it = FindPositionInLineList(pLineList.get(), mpPosition->CaretPos); //If there's no selected nodes, create a place node - SmNode *pBodyNode; + std::unique_ptr<SmNode> pBodyNode; SmCaretPos PosAfterInsert; if(pSelectedNodesList->empty()) { - pBodyNode = new SmPlaceNode(); - PosAfterInsert = SmCaretPos(pBodyNode, 1); + pBodyNode.reset(new SmPlaceNode()); + PosAfterInsert = SmCaretPos(pBodyNode.get(), 1); } else - pBodyNode = SmNodeListParser().Parse(pSelectedNodesList.get()); + pBodyNode.reset(SmNodeListParser().Parse(pSelectedNodesList.get())); pSelectedNodesList.reset(); @@ -631,11 +631,11 @@ void SmCursor::InsertBrackets(SmBracketType eBracketType) { SmToken aTok(TLEFT, '\0', "left", TG::NONE, 5); SmBraceNode *pBrace = new SmBraceNode(aTok); pBrace->SetScaleMode(SmScaleMode::Height); - SmNode *pLeft = CreateBracket(eBracketType, true), - *pRight = CreateBracket(eBracketType, false); - SmBracebodyNode *pBody = new SmBracebodyNode(SmToken()); - pBody->SetSubNodes(pBodyNode, nullptr); - pBrace->SetSubNodes(pLeft, pBody, pRight); + std::unique_ptr<SmNode> pLeft( CreateBracket(eBracketType, true) ), + pRight( CreateBracket(eBracketType, false) ); + std::unique_ptr<SmBracebodyNode> pBody(new SmBracebodyNode(SmToken())); + pBody->SetSubNodes(std::move(pBodyNode), nullptr); + pBrace->SetSubNodes(std::move(pLeft), std::move(pBody), std::move(pRight)); pBrace->Prepare(mpDocShell->GetFormat(), *mpDocShell, 0); //Insert into line @@ -750,22 +750,22 @@ bool SmCursor::InsertRow() { if(pNewLineList->empty()) pNewLineList->push_front(new SmPlaceNode()); //Parse new line - SmNode *pNewLine = SmNodeListParser().Parse(pNewLineList); + std::unique_ptr<SmNode> pNewLine(SmNodeListParser().Parse(pNewLineList)); delete pNewLineList; //Wrap pNewLine in SmLineNode if needed if(pLineParent->GetType() == SmNodeType::Line) { - SmLineNode *pNewLineNode = new SmLineNode(SmToken(TNEWLINE, '\0', "newline")); - pNewLineNode->SetSubNodes(pNewLine, nullptr); - pNewLine = pNewLineNode; + std::unique_ptr<SmLineNode> pNewLineNode(new SmLineNode(SmToken(TNEWLINE, '\0', "newline"))); + pNewLineNode->SetSubNodes(std::move(pNewLine), nullptr); + pNewLine = std::move(pNewLineNode); } //Get position - PosAfterInsert = SmCaretPos(pNewLine, 0); + PosAfterInsert = SmCaretPos(pNewLine.get(), 0); //Move other nodes if needed for( int i = pTable->GetNumSubNodes(); i > nTableIndex + 1; i--) pTable->SetSubNode(i, pTable->GetSubNode(i-1)); //Insert new line - pTable->SetSubNode(nTableIndex + 1, pNewLine); + pTable->SetSubNode(nTableIndex + 1, pNewLine.get()); //Check if we need to change token type: if(pTable->GetNumSubNodes() > 2 && pTable->GetToken().eType == TBINOM) { @@ -835,16 +835,16 @@ void SmCursor::InsertFraction() { //Create pNum, and pDenom bool bEmptyFraction = pSelectedNodesList->empty(); - SmNode *pNum = bEmptyFraction + std::unique_ptr<SmNode> pNum( bEmptyFraction ? new SmPlaceNode() - : SmNodeListParser().Parse(pSelectedNodesList.get()); - SmNode *pDenom = new SmPlaceNode(); + : SmNodeListParser().Parse(pSelectedNodesList.get()) ); + std::unique_ptr<SmNode> pDenom(new SmPlaceNode()); pSelectedNodesList.reset(); //Create new fraction SmBinVerNode *pFrac = new SmBinVerNode(SmToken(TOVER, '\0', "over", TG::Product, 0)); - SmNode *pRect = new SmRectangleNode(SmToken()); - pFrac->SetSubNodes(pNum, pRect, pDenom); + std::unique_ptr<SmNode> pRect(new SmRectangleNode(SmToken())); + pFrac->SetSubNodes(std::move(pNum), std::move(pRect), std::move(pDenom)); //Insert in pLineList SmNodeList::iterator patchIt = pLineList->insert(it, pFrac); @@ -852,7 +852,7 @@ void SmCursor::InsertFraction() { PatchLineList(pLineList.get(), it); //Finish editing - SmNode *pSelectedNode = bEmptyFraction ? pNum : pDenom; + SmNode *pSelectedNode = bEmptyFraction ? pFrac->GetSubNode(0) : pFrac->GetSubNode(2); FinishEdit(std::move(pLineList), pLineParent, nParentIndex, SmCaretPos(pSelectedNode, 1)); } @@ -1223,7 +1223,7 @@ void SmCursor::FinishEdit(std::unique_ptr<SmNodeList> pLineList, //Parse list of nodes to a tree SmNodeListParser parser; - SmNode* pLine = parser.Parse(pLineList.get()); + std::unique_ptr<SmNode> pLine(parser.Parse(pLineList.get())); pLineList.reset(); //Check if we're making the body of a subsup node bigger than one @@ -1232,15 +1232,15 @@ void SmCursor::FinishEdit(std::unique_ptr<SmNodeList> pLineList, entries > 1) { //Wrap pLine in scalable round brackets SmToken aTok(TLEFT, '\0', "left", TG::NONE, 5); - SmBraceNode *pBrace = new SmBraceNode(aTok); + std::unique_ptr<SmBraceNode> pBrace(new SmBraceNode(aTok)); pBrace->SetScaleMode(SmScaleMode::Height); - SmNode *pLeft = CreateBracket(SmBracketType::Round, true), - *pRight = CreateBracket(SmBracketType::Round, false); - SmBracebodyNode *pBody = new SmBracebodyNode(SmToken()); - pBody->SetSubNodes(pLine, nullptr); - pBrace->SetSubNodes(pLeft, pBody, pRight); + std::unique_ptr<SmNode> pLeft( CreateBracket(SmBracketType::Round, true) ), + pRight( CreateBracket(SmBracketType::Round, false) ); + std::unique_ptr<SmBracebodyNode> pBody(new SmBracebodyNode(SmToken())); + pBody->SetSubNodes(std::move(pLine), nullptr); + pBrace->SetSubNodes(std::move(pLeft), std::move(pBody), std::move(pRight)); pBrace->Prepare(mpDocShell->GetFormat(), *mpDocShell, 0); - pLine = pBrace; + pLine = std::move(pBrace); //TODO: Consider the following alternative behavior: //Consider the line: A + {B + C}^D lsub E //Here pLineList is B, + and C and pParent is a subsup node with @@ -1257,10 +1257,10 @@ void SmCursor::FinishEdit(std::unique_ptr<SmNodeList> pLineList, //Set pStartLine if NULL if(!pStartLine) - pStartLine = pLine; + pStartLine = pLine.get(); //Insert it back into the parent - pParent->SetSubNode(nParentIndex, pLine); + pParent->SetSubNode(nParentIndex, pLine.release()); //Rebuild graph of caret position mpAnchor = nullptr; @@ -1441,53 +1441,53 @@ SmNode* SmNodeListParser::Expression(){ SmNode* SmNodeListParser::Relation(){ //Read a sum - SmNode* pLeft = Sum(); + std::unique_ptr<SmNode> pLeft(Sum()); //While we have tokens and the next is a relation while(Terminal() && IsRelationOperator(Terminal()->GetToken())){ //Take the operator - SmNode* pOper = Take(); + std::unique_ptr<SmNode> pOper(Take()); //Find the right side of the relation - SmNode* pRight = Sum(); + std::unique_ptr<SmNode> pRight(Sum()); //Create new SmBinHorNode - SmStructureNode* pNewNode = new SmBinHorNode(SmToken()); - pNewNode->SetSubNodes(pLeft, pOper, pRight); - pLeft = pNewNode; + std::unique_ptr<SmStructureNode> pNewNode(new SmBinHorNode(SmToken())); + pNewNode->SetSubNodes(std::move(pLeft), std::move(pOper), std::move(pRight)); + pLeft = std::move(pNewNode); } - return pLeft; + return pLeft.release(); } SmNode* SmNodeListParser::Sum(){ //Read a product - SmNode* pLeft = Product(); + std::unique_ptr<SmNode> pLeft(Product()); //While we have tokens and the next is a sum while(Terminal() && IsSumOperator(Terminal()->GetToken())){ //Take the operator - SmNode* pOper = Take(); + std::unique_ptr<SmNode> pOper(Take()); //Find the right side of the sum - SmNode* pRight = Product(); + std::unique_ptr<SmNode> pRight(Product()); //Create new SmBinHorNode - SmStructureNode* pNewNode = new SmBinHorNode(SmToken()); - pNewNode->SetSubNodes(pLeft, pOper, pRight); - pLeft = pNewNode; + std::unique_ptr<SmStructureNode> pNewNode(new SmBinHorNode(SmToken())); + pNewNode->SetSubNodes(std::move(pLeft), std::move(pOper), std::move(pRight)); + pLeft = std::move(pNewNode); } - return pLeft; + return pLeft.release(); } SmNode* SmNodeListParser::Product(){ //Read a Factor - SmNode* pLeft = Factor(); + std::unique_ptr<SmNode> pLeft(Factor()); //While we have tokens and the next is a product while(Terminal() && IsProductOperator(Terminal()->GetToken())){ //Take the operator - SmNode* pOper = Take(); + std::unique_ptr<SmNode> pOper(Take()); //Find the right side of the operation - SmNode* pRight = Factor(); + std::unique_ptr<SmNode> pRight(Factor()); //Create new SmBinHorNode - SmStructureNode* pNewNode = new SmBinHorNode(SmToken()); - pNewNode->SetSubNodes(pLeft, pOper, pRight); - pLeft = pNewNode; + std::unique_ptr<SmStructureNode> pNewNode(new SmBinHorNode(SmToken())); + pNewNode->SetSubNodes(std::move(pLeft), std::move(pOper), std::move(pRight)); + pLeft = std::move(pNewNode); } - return pLeft; + return pLeft.release(); } SmNode* SmNodeListParser::Factor(){ @@ -1498,15 +1498,15 @@ SmNode* SmNodeListParser::Factor(){ else if(IsUnaryOperator(Terminal()->GetToken())) { SmStructureNode *pUnary = new SmUnHorNode(SmToken()); - SmNode *pOper = Terminal(), - *pArg; + std::unique_ptr<SmNode> pOper(Terminal()), + pArg; if(Next()) - pArg = Factor(); + pArg.reset(Factor()); else - pArg = Error(); + pArg.reset(Error()); - pUnary->SetSubNodes(pOper, pArg); + pUnary->SetSubNodes(std::move(pOper), std::move(pArg)); return pUnary; } return Postfix(); @@ -1515,20 +1515,20 @@ SmNode* SmNodeListParser::Factor(){ SmNode* SmNodeListParser::Postfix(){ if(!Terminal()) return Error(); - SmNode *pArg = nullptr; + std::unique_ptr<SmNode> pArg; if(IsPostfixOperator(Terminal()->GetToken())) - pArg = Error(); + pArg.reset(Error()); else if(IsOperator(Terminal()->GetToken())) return Error(); else - pArg = Take(); + pArg.reset(Take()); while(Terminal() && IsPostfixOperator(Terminal()->GetToken())) { - SmStructureNode *pUnary = new SmUnHorNode(SmToken()); - SmNode *pOper = Take(); - pUnary->SetSubNodes(pArg, pOper); - pArg = pUnary; + std::unique_ptr<SmStructureNode> pUnary(new SmUnHorNode(SmToken()) ); + std::unique_ptr<SmNode> pOper(Take()); + pUnary->SetSubNodes(std::move(pArg), std::move(pOper)); + pArg = std::move(pUnary); } - return pArg; + return pArg.release(); } SmNode* SmNodeListParser::Error(){ diff --git a/starmath/source/mathmlimport.cxx b/starmath/source/mathmlimport.cxx index fd4f3b0d5d1b..1802d95474ca 100644 --- a/starmath/source/mathmlimport.cxx +++ b/starmath/source/mathmlimport.cxx @@ -682,7 +682,7 @@ void SmXMLContext_Helper::ApplyAttrs() else aToken.eType = TNBOLD; std::unique_ptr<SmFontNode> pFontNode(new SmFontNode(aToken)); - pFontNode->SetSubNodes(nullptr,popOrZero(rNodeStack).release()); + pFontNode->SetSubNodes(nullptr, popOrZero(rNodeStack)); rNodeStack.push_front(std::move(pFontNode)); } if (nIsItalic != -1) @@ -692,7 +692,7 @@ void SmXMLContext_Helper::ApplyAttrs() else aToken.eType = TNITALIC; std::unique_ptr<SmFontNode> pFontNode(new SmFontNode(aToken)); - pFontNode->SetSubNodes(nullptr,popOrZero(rNodeStack).release()); + pFontNode->SetSubNodes(nullptr,popOrZero(rNodeStack)); rNodeStack.push_front(std::move(pFontNode)); } if (nFontSize != 0.0) @@ -713,7 +713,7 @@ void SmXMLContext_Helper::ApplyAttrs() else pFontNode->SetSizeParameter(Fraction(nFontSize),FontSizeType::ABSOLUT); - pFontNode->SetSubNodes(nullptr,popOrZero(rNodeStack).release()); + pFontNode->SetSubNodes(nullptr, popOrZero(rNodeStack)); rNodeStack.push_front(std::move(pFontNode)); } if (!sFontFamily.isEmpty()) @@ -730,7 +730,7 @@ void SmXMLContext_Helper::ApplyAttrs() aToken.aText = sFontFamily; std::unique_ptr<SmFontNode> pFontNode(new SmFontNode(aToken)); - pFontNode->SetSubNodes(nullptr,popOrZero(rNodeStack).release()); + pFontNode->SetSubNodes(nullptr, popOrZero(rNodeStack)); rNodeStack.push_front(std::move(pFontNode)); } if (!sColor.isEmpty()) @@ -744,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).release()); + pFontNode->SetSubNodes(nullptr, popOrZero(rNodeStack)); rNodeStack.push_front(std::move(pFontNode)); } } @@ -872,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).release()); + pFontNode->SetSubNodes(nullptr, popOrZero(rNodeStack)); rNodeStack.push_front(std::move(pFontNode)); } } @@ -1058,7 +1058,7 @@ void SmXMLPhantomContext_Impl::EndElement() std::unique_ptr<SmFontNode> pPhantom(new SmFontNode(aToken)); SmNodeStack &rNodeStack = GetSmImport().GetNodeStack(); - pPhantom->SetSubNodes(nullptr,popOrZero(rNodeStack).release()); + pPhantom->SetSubNodes(nullptr, popOrZero(rNodeStack)); rNodeStack.push_front(std::move(pPhantom)); } @@ -1120,11 +1120,11 @@ void SmXMLFencedContext_Impl::EndElement() aToken.eType = TLPARENT; aToken.cMathChar = cBegin; std::unique_ptr<SmStructureNode> pSNode(new SmBraceNode(aToken)); - SmNode *pLeft = new SmMathSymbolNode(aToken); + std::unique_ptr<SmNode> pLeft(new SmMathSymbolNode(aToken)); aToken.cMathChar = cEnd; aToken.eType = TRPARENT; - SmNode *pRight = new SmMathSymbolNode(aToken); + std::unique_ptr<SmNode> pRight(new SmMathSymbolNode(aToken)); SmNodeArray aRelationArray; SmNodeStack &rNodeStack = GetSmImport().GetNodeStack(); @@ -1146,11 +1146,11 @@ void SmXMLFencedContext_Impl::EndElement() } SmToken aDummy; - SmStructureNode *pBody = new SmExpressionNode(aDummy); + std::unique_ptr<SmStructureNode> pBody(new SmExpressionNode(aDummy)); pBody->SetSubNodes(std::move(aRelationArray)); - pSNode->SetSubNodes(pLeft,pBody,pRight); + pSNode->SetSubNodes(std::move(pLeft), std::move(pBody), std::move(pRight)); pSNode->SetScaleMode(SmScaleMode::Height); GetSmImport().GetNodeStack().push_front(std::move(pSNode)); } @@ -1693,17 +1693,17 @@ void SmXMLUnderContext_Impl::HandleAccent() aToken.cMathChar = '\0'; aToken.eType = TUNDERLINE; - SmNode *pFirst; + std::unique_ptr<SmNode> pFirst; std::unique_ptr<SmStructureNode> pNode(new SmAttributNode(aToken)); if ((pTest->GetToken().cMathChar & 0x0FFF) == 0x0332) { - pFirst = new SmRectangleNode(aToken); + pFirst.reset(new SmRectangleNode(aToken)); } else - pFirst = pTest.release(); + pFirst = std::move(pTest); std::unique_ptr<SmNode> pSecond = popOrZero(rNodeStack); - pNode->SetSubNodes(pFirst, pSecond.release()); + pNode->SetSubNodes(std::move(pFirst), std::move(pSecond)); pNode->SetScaleMode(SmScaleMode::Width); rNodeStack.push_front(std::move(pNode)); } @@ -1766,7 +1766,7 @@ void SmXMLOverContext_Impl::HandleAccent() std::unique_ptr<SmNode> pFirst = popOrZero(rNodeStack); std::unique_ptr<SmNode> pSecond = popOrZero(rNodeStack); - pNode->SetSubNodes(pFirst.release(), pSecond.release()); + pNode->SetSubNodes(std::move(pFirst), std::move(pSecond)); pNode->SetScaleMode(SmScaleMode::Width); rNodeStack.push_front(std::move(pNode)); @@ -2316,7 +2316,7 @@ void SmXMLDocContext_Impl::EndElement() SmToken aDummy; std::unique_ptr<SmStructureNode> pSNode(new SmLineNode(aDummy)); - pSNode->SetSubNodes(pContextNode.release(), nullptr); + pSNode->SetSubNodes(std::move(pContextNode), nullptr); rNodeStack.push_front(std::move(pSNode)); SmNodeArray LineArray; @@ -2345,10 +2345,10 @@ void SmXMLFracContext_Impl::EndElement() aToken.cMathChar = '\0'; aToken.eType = TOVER; std::unique_ptr<SmStructureNode> pSNode(new SmBinVerNode(aToken)); - SmNode *pOper = new SmRectangleNode(aToken); + std::unique_ptr<SmNode> pOper(new SmRectangleNode(aToken)); std::unique_ptr<SmNode> pSecond = popOrZero(rNodeStack); std::unique_ptr<SmNode> pFirst = popOrZero(rNodeStack); - pSNode->SetSubNodes(pFirst.release(), pOper, pSecond.release()); + pSNode->SetSubNodes(std::move(pFirst), std::move(pOper), std::move(pSecond)); rNodeStack.push_front(std::move(pSNode)); } @@ -2364,11 +2364,11 @@ void SmXMLRootContext_Impl::EndElement() aToken.cMathChar = MS_SQRT; //Temporary: alert, based on StarSymbol font aToken.eType = TNROOT; std::unique_ptr<SmStructureNode> pSNode(new SmRootNode(aToken)); - SmNode *pOper = new SmRootSymbolNode(aToken); + std::unique_ptr<SmNode> pOper(new SmRootSymbolNode(aToken)); SmNodeStack &rNodeStack = GetSmImport().GetNodeStack(); std::unique_ptr<SmNode> pIndex = popOrZero(rNodeStack); std::unique_ptr<SmNode> pBase = popOrZero(rNodeStack); - pSNode->SetSubNodes(pIndex.release(), pOper, pBase.release()); + pSNode->SetSubNodes(std::move(pIndex), std::move(pOper), std::move(pBase)); rNodeStack.push_front(std::move(pSNode)); } @@ -2386,9 +2386,9 @@ void SmXMLSqrtContext_Impl::EndElement() aToken.cMathChar = MS_SQRT; //Temporary: alert, based on StarSymbol font aToken.eType = TSQRT; std::unique_ptr<SmStructureNode> pSNode(new SmRootNode(aToken)); - SmNode *pOper = new SmRootSymbolNode(aToken); + std::unique_ptr<SmNode> pOper(new SmRootSymbolNode(aToken)); SmNodeStack &rNodeStack = GetSmImport().GetNodeStack(); - pSNode->SetSubNodes(nullptr,pOper,popOrZero(rNodeStack).release()); + pSNode->SetSubNodes(nullptr, std::move(pOper), popOrZero(rNodeStack)); rNodeStack.push_front(std::move(pSNode)); } @@ -2434,7 +2434,7 @@ void SmXMLRowContext_Impl::EndElement() aToken.cMathChar = '\0'; aToken.eType = TLPARENT; - SmNode *pLeft = new SmMathSymbolNode(aToken); + std::unique_ptr<SmNode> pLeft(new SmMathSymbolNode(aToken)); if ((aRelationArray[nSize-1]->GetScaleMode() == SmScaleMode::Height) && (aRelationArray[nSize-1]->GetType() == SmNodeType::Math)) @@ -2446,7 +2446,7 @@ void SmXMLRowContext_Impl::EndElement() aToken.cMathChar = '\0'; aToken.eType = TRPARENT; - SmNode *pRight = new SmMathSymbolNode(aToken); + std::unique_ptr<SmNode> pRight(new SmMathSymbolNode(aToken)); SmNodeArray aRelationArray2; @@ -2464,10 +2464,10 @@ void SmXMLRowContext_Impl::EndElement() SmToken aDummy; std::unique_ptr<SmStructureNode> pSNode(new SmBraceNode(aToken)); - SmStructureNode *pBody = new SmExpressionNode(aDummy); + std::unique_ptr<SmStructureNode> pBody(new SmExpressionNode(aDummy)); pBody->SetSubNodes(std::move(aRelationArray2)); - pSNode->SetSubNodes(pLeft,pBody,pRight); + pSNode->SetSubNodes(std::move(pLeft), std::move(pBody), std::move(pRight)); pSNode->SetScaleMode(SmScaleMode::Height); rNodeStack.push_front(std::move(pSNode)); diff --git a/starmath/source/node.cxx b/starmath/source/node.cxx index 9e1ef9279997..d78e847350e1 100644 --- a/starmath/source/node.cxx +++ b/starmath/source/node.cxx @@ -384,16 +384,16 @@ void SmStructureNode::ClearSubNodes() maSubNodes.clear(); } -void SmStructureNode::SetSubNodes(SmNode *pFirst, SmNode *pSecond, SmNode *pThird) +void SmStructureNode::SetSubNodes(std::unique_ptr<SmNode> pFirst, std::unique_ptr<SmNode> pSecond, std::unique_ptr<SmNode> pThird) { size_t nSize = pThird ? 3 : (pSecond ? 2 : (pFirst ? 1 : 0)); maSubNodes.resize( nSize ); if (pFirst) - maSubNodes[0] = pFirst; + maSubNodes[0] = pFirst.release(); if (pSecond) - maSubNodes[1] = pSecond; + maSubNodes[1] = pSecond.release(); if (pThird) - maSubNodes[2] = pThird; + maSubNodes[2] = pThird.release(); ClaimPaternity(); } diff --git a/starmath/source/parse.cxx b/starmath/source/parse.cxx index b033a1dbb47c..6080e5711736 100644 --- a/starmath/source/parse.cxx +++ b/starmath/source/parse.cxx @@ -1090,7 +1090,7 @@ std::unique_ptr<SmNode> SmParser::DoRelation() std::unique_ptr<SmStructureNode> xSNode(new SmBinHorNode(m_aCurToken)); auto xSecond = DoOpSubSup(); auto xThird = DoSum(); - xSNode->SetSubNodes(xFirst.release(), xSecond.release(), xThird.release()); + xSNode->SetSubNodes(std::move(xFirst), std::move(xSecond), std::move(xThird)); xFirst = std::move(xSNode); } return xFirst; @@ -1108,7 +1108,7 @@ std::unique_ptr<SmNode> SmParser::DoSum() std::unique_ptr<SmStructureNode> xSNode(new SmBinHorNode(m_aCurToken)); auto xSecond = DoOpSubSup(); auto xThird = DoProduct(); - xSNode->SetSubNodes(xFirst.release(), xSecond.release(), xThird.release()); + xSNode->SetSubNodes(std::move(xFirst), std::move(xSecond), std::move(xThird)); xFirst = std::move(xSNode); } return xFirst; @@ -1189,11 +1189,11 @@ std::unique_ptr<SmNode> SmParser::DoProduct() if (bSwitchArgs) { //! vgl siehe SmBinDiagonalNode::Arrange - xSNode->SetSubNodes(xFirst.release(), xArg.release(), xOper.release()); + xSNode->SetSubNodes(std::move(xFirst), std::move(xArg), std::move(xOper)); } else { - xSNode->SetSubNodes(xFirst.release(), xOper.release(), xArg.release()); + xSNode->SetSubNodes(std::move(xFirst), std::move(xOper), std::move(xArg)); } xFirst = std::move(xSNode); ++nDepthLimit; @@ -1371,7 +1371,7 @@ std::unique_ptr<SmNode> SmParser::DoTerm(bool bGroupNumberIdent) } auto xSNode = o3tl::make_unique<SmExpressionNode>(m_aCurToken); std::unique_ptr<SmNode> xError(DoError(SmParseError::RgroupExpected)); - xSNode->SetSubNodes(pNode.release(), xError.release()); + xSNode->SetSubNodes(std::move(pNode), std::move(xError)); return std::unique_ptr<SmNode>(xSNode.release()); } @@ -1535,7 +1535,7 @@ std::unique_ptr<SmNode> SmParser::DoTerm(bool bGroupNumberIdent) { std::unique_ptr<SmStructureNode> xNode = std::move(aStack.top()); aStack.pop(); - xNode->SetSubNodes(nullptr, xFirstNode.release()); + xNode->SetSubNodes(nullptr, std::move(xFirstNode)); xFirstNode = std::move(xNode); } return xFirstNode; @@ -1605,7 +1605,7 @@ std::unique_ptr<SmOperNode> SmParser::DoOperator() // get argument auto xArg = DoPower(); - xSNode->SetSubNodes(xOperator.release(), xArg.release()); + xSNode->SetSubNodes(std::move(xOperator), std::move(xArg)); return xSNode; } @@ -1734,23 +1734,23 @@ std::unique_ptr<SmStructureNode> SmParser::DoUnOper() std::unique_ptr<SmNode> xLeft(new SmMathSymbolNode(aNodeToken)); std::unique_ptr<SmNode> xRight(new SmMathSymbolNode(aNodeToken)); - xSNode->SetSubNodes(xLeft.release(), xArg.release(), xRight.release()); + xSNode->SetSubNodes(std::move(xLeft), std::move(xArg), std::move(xRight)); } else if (eType == TSQRT || eType == TNROOT) { xSNode.reset(new SmRootNode(aNodeToken)); xOper.reset(new SmRootSymbolNode(aNodeToken)); - xSNode->SetSubNodes(xExtra.release(), xOper.release(), xArg.release()); + xSNode->SetSubNodes(std::move(xExtra), std::move(xOper), std::move(xArg)); } else { xSNode.reset(new SmUnHorNode(aNodeToken)); if (bIsPostfix) - xSNode->SetSubNodes(xArg.release(), xOper.release()); + xSNode->SetSubNodes(std::move(xArg), std::move(xOper)); else { // prefix operator - xSNode->SetSubNodes(xOper.release(), xArg.release()); + xSNode->SetSubNodes(std::move(xOper), std::move(xArg)); } } return xSNode; @@ -1790,7 +1790,7 @@ std::unique_ptr<SmStructureNode> SmParser::DoAttribut() NextToken(); - xSNode->SetSubNodes(xAttr.release(), nullptr); // the body will be filled later + xSNode->SetSubNodes(std::move(xAttr), nullptr); // the body will be filled later xSNode->SetScaleMode(eScaleMode); return xSNode; } @@ -2057,7 +2057,7 @@ std::unique_ptr<SmStructureNode> SmParser::DoBrace() { assert(pLeft); assert(pRight); - xSNode->SetSubNodes(pLeft.release(), pBody.release(), pRight.release()); + xSNode->SetSubNodes(std::move(pLeft), std::move(pBody), std::move(pRight)); xSNode->SetScaleMode(eScaleMode); return xSNode; } @@ -2169,7 +2169,7 @@ std::unique_ptr<SmTableNode> SmParser::DoBinom() auto xFirst = DoSum(); auto xSecond = DoSum(); - xSNode->SetSubNodes(xFirst.release(), xSecond.release()); + xSNode->SetSubNodes(std::move(xFirst), std::move(xSecond)); return xSNode; } @@ -2321,8 +2321,8 @@ std::unique_ptr<SmExpressionNode> SmParser::DoError(SmParseError eError) throw std::range_error("parser depth limit"); auto xSNode = o3tl::make_unique<SmExpressionNode>(m_aCurToken); - SmErrorNode *pErr = new SmErrorNode(m_aCurToken); - xSNode->SetSubNodes(pErr, nullptr); + std::unique_ptr<SmErrorNode> pErr(new SmErrorNode(m_aCurToken)); + xSNode->SetSubNodes(std::move(pErr), nullptr); AddError(eError, xSNode.get()); |