starmath: Simplify code with std::unique_ptr

Change-Id: I2f6f993b92ae7f2f89b2d9d6c89b51d827226a3d
Reviewed-on: https://gerrit.libreoffice.org/29554
Reviewed-by: Takeshi Abe <tabe@fixedpoint.jp>
Tested-by: Takeshi Abe <tabe@fixedpoint.jp>
This commit is contained in:
Takeshi Abe 2016-10-06 18:17:15 +09:00
parent 8daf6707ef
commit 33c57f1550

View File

@ -1935,9 +1935,7 @@ void SmParser::DoBrace()
assert(m_aCurToken.eType == TLEFT || TokenInGroup(TG::LBrace)); assert(m_aCurToken.eType == TLEFT || TokenInGroup(TG::LBrace));
std::unique_ptr<SmStructureNode> pSNode(new SmBraceNode(m_aCurToken)); std::unique_ptr<SmStructureNode> pSNode(new SmBraceNode(m_aCurToken));
SmNode *pBody = nullptr, std::unique_ptr<SmNode> pBody, pLeft, pRight;
*pLeft = nullptr,
*pRight = nullptr;
SmScaleMode eScaleMode = SCALE_NONE; SmScaleMode eScaleMode = SCALE_NONE;
SmParseError eError = PE_NONE; SmParseError eError = PE_NONE;
@ -1949,11 +1947,11 @@ void SmParser::DoBrace()
// check for left bracket // check for left bracket
if (TokenInGroup(TG::LBrace) || TokenInGroup(TG::RBrace)) if (TokenInGroup(TG::LBrace) || TokenInGroup(TG::RBrace))
{ {
pLeft = new SmMathSymbolNode(m_aCurToken); pLeft.reset(new SmMathSymbolNode(m_aCurToken));
NextToken(); NextToken();
DoBracebody(true); DoBracebody(true);
pBody = popOrZero(m_aNodeStack); pBody.reset(popOrZero(m_aNodeStack));
if (m_aCurToken.eType == TRIGHT) if (m_aCurToken.eType == TRIGHT)
{ NextToken(); { NextToken();
@ -1961,7 +1959,7 @@ void SmParser::DoBrace()
// check for right bracket // check for right bracket
if (TokenInGroup(TG::LBrace) || TokenInGroup(TG::RBrace)) if (TokenInGroup(TG::LBrace) || TokenInGroup(TG::RBrace))
{ {
pRight = new SmMathSymbolNode(m_aCurToken); pRight.reset(new SmMathSymbolNode(m_aCurToken));
NextToken(); NextToken();
} }
else else
@ -1977,11 +1975,11 @@ void SmParser::DoBrace()
{ {
assert(TokenInGroup(TG::LBrace)); assert(TokenInGroup(TG::LBrace));
pLeft = new SmMathSymbolNode(m_aCurToken); pLeft.reset(new SmMathSymbolNode(m_aCurToken));
NextToken(); NextToken();
DoBracebody(false); DoBracebody(false);
pBody = popOrZero(m_aNodeStack); pBody.reset(popOrZero(m_aNodeStack));
SmTokenType eExpectedType = TUNKNOWN; SmTokenType eExpectedType = TUNKNOWN;
switch (pLeft->GetToken().eType) switch (pLeft->GetToken().eType)
@ -2000,29 +1998,23 @@ void SmParser::DoBrace()
if (m_aCurToken.eType == eExpectedType) if (m_aCurToken.eType == eExpectedType)
{ {
pRight = new SmMathSymbolNode(m_aCurToken); pRight.reset(new SmMathSymbolNode(m_aCurToken));
NextToken(); NextToken();
} }
else else
eError = PE_PARENT_MISMATCH; eError = PE_PARENT_MISMATCH;
} }
if (eError == PE_NONE) if (eError == PE_NONE)
{ OSL_ENSURE(pLeft, "Sm: NULL pointer"); {
OSL_ENSURE(pRight, "Sm: NULL pointer"); assert(pLeft);
pSNode->SetSubNodes(pLeft, pBody, pRight); assert(pRight);
pSNode->SetSubNodes(pLeft.release(), pBody.release(), pRight.release());
pSNode->SetScaleMode(eScaleMode); pSNode->SetScaleMode(eScaleMode);
m_aNodeStack.push_front(std::move(pSNode)); m_aNodeStack.push_front(std::move(pSNode));
} }
else else
{
pSNode.reset();
delete pBody;
delete pLeft;
delete pRight;
Error(eError); Error(eError);
}
} }
void SmParser::DoBracebody(bool bIsLeftRight) void SmParser::DoBracebody(bool bIsLeftRight)