Kaydet (Commit) 9ed9f30f authored tarafından Michael Stahl's avatar Michael Stahl

starmath: replace boost::ptr_deque with std::deque<std::unique_ptr>

Change-Id: I1d2671a0b355bd4dbb195d69af2c432c50df904e
üst e126cf6c
...@@ -20,16 +20,16 @@ ...@@ -20,16 +20,16 @@
#ifndef INCLUDED_STARMATH_INC_NODE_HXX #ifndef INCLUDED_STARMATH_INC_NODE_HXX
#define INCLUDED_STARMATH_INC_NODE_HXX #define INCLUDED_STARMATH_INC_NODE_HXX
#include <vector>
#include <ostream>
#include "types.hxx" #include "types.hxx"
#include "token.hxx" #include "token.hxx"
#include "error.hxx" #include "error.hxx"
#include "rect.hxx" #include "rect.hxx"
#include "format.hxx" #include "format.hxx"
#include <boost/ptr_container/ptr_deque.hpp>
#include <memory> #include <memory>
#include <vector>
#include <deque>
#include <ostream>
#define ATTR_BOLD 0x0001 #define ATTR_BOLD 0x0001
#define ATTR_ITALIC 0x0002 #define ATTR_ITALIC 0x0002
...@@ -61,15 +61,16 @@ class SmNode; ...@@ -61,15 +61,16 @@ class SmNode;
class SmStructureNode; class SmStructureNode;
typedef std::shared_ptr<SmNode> SmNodePointer; typedef std::shared_ptr<SmNode> SmNodePointer;
typedef boost::ptr_deque<SmNode> SmNodeStack; typedef std::deque<std::unique_ptr<SmNode>> SmNodeStack;
typedef std::vector< SmNode * > SmNodeArray; typedef std::vector< SmNode * > SmNodeArray;
template < typename T > template < typename T >
T* popOrZero( boost::ptr_deque<T> & rStack ) T* popOrZero(std::deque<std::unique_ptr<T>> & rStack)
{ {
if (rStack.empty()) if (rStack.empty())
return 0; return nullptr;
auto pTmp = rStack.pop_front(); std::unique_ptr<T> pTmp(std::move(rStack.front()));
rStack.pop_front();
return pTmp.release(); return pTmp.release();
} }
......
...@@ -42,6 +42,7 @@ one go*/ ...@@ -42,6 +42,7 @@ one go*/
#include <comphelper/processfactory.hxx> #include <comphelper/processfactory.hxx>
#include <comphelper/servicehelper.hxx> #include <comphelper/servicehelper.hxx>
#include <comphelper/string.hxx> #include <comphelper/string.hxx>
#include <o3tl/make_unique.hxx>
#include <rtl/math.hxx> #include <rtl/math.hxx>
#include <sfx2/frame.hxx> #include <sfx2/frame.hxx>
#include <sfx2/docfile.hxx> #include <sfx2/docfile.hxx>
...@@ -670,9 +671,9 @@ void SmXMLContext_Helper::ApplyAttrs() ...@@ -670,9 +671,9 @@ void SmXMLContext_Helper::ApplyAttrs()
aToken.eType = TBOLD; aToken.eType = TBOLD;
else else
aToken.eType = TNBOLD; aToken.eType = TNBOLD;
SmFontNode *pFontNode = new SmFontNode(aToken); std::unique_ptr<SmFontNode> pFontNode(new SmFontNode(aToken));
pFontNode->SetSubNodes(0,popOrZero(rNodeStack)); pFontNode->SetSubNodes(0,popOrZero(rNodeStack));
rNodeStack.push_front(pFontNode); rNodeStack.push_front(std::move(pFontNode));
} }
if (nIsItalic != -1) if (nIsItalic != -1)
{ {
...@@ -680,14 +681,14 @@ void SmXMLContext_Helper::ApplyAttrs() ...@@ -680,14 +681,14 @@ void SmXMLContext_Helper::ApplyAttrs()
aToken.eType = TITALIC; aToken.eType = TITALIC;
else else
aToken.eType = TNITALIC; aToken.eType = TNITALIC;
SmFontNode *pFontNode = new SmFontNode(aToken); std::unique_ptr<SmFontNode> pFontNode(new SmFontNode(aToken));
pFontNode->SetSubNodes(0,popOrZero(rNodeStack)); pFontNode->SetSubNodes(0,popOrZero(rNodeStack));
rNodeStack.push_front(pFontNode); rNodeStack.push_front(std::move(pFontNode));
} }
if (nFontSize != 0.0) if (nFontSize != 0.0)
{ {
aToken.eType = TSIZE; aToken.eType = TSIZE;
SmFontNode *pFontNode = new SmFontNode(aToken); std::unique_ptr<SmFontNode> pFontNode(new SmFontNode(aToken));
if (util::MeasureUnit::PERCENT == rContext.GetSmImport() if (util::MeasureUnit::PERCENT == rContext.GetSmImport()
.GetMM100UnitConverter().GetXMLMeasureUnit()) .GetMM100UnitConverter().GetXMLMeasureUnit())
...@@ -703,7 +704,7 @@ void SmXMLContext_Helper::ApplyAttrs() ...@@ -703,7 +704,7 @@ void SmXMLContext_Helper::ApplyAttrs()
pFontNode->SetSizeParameter(Fraction(nFontSize),FontSizeType::ABSOLUT); pFontNode->SetSizeParameter(Fraction(nFontSize),FontSizeType::ABSOLUT);
pFontNode->SetSubNodes(0,popOrZero(rNodeStack)); pFontNode->SetSubNodes(0,popOrZero(rNodeStack));
rNodeStack.push_front(pFontNode); rNodeStack.push_front(std::move(pFontNode));
} }
if (!sFontFamily.isEmpty()) if (!sFontFamily.isEmpty())
{ {
...@@ -718,9 +719,9 @@ void SmXMLContext_Helper::ApplyAttrs() ...@@ -718,9 +719,9 @@ void SmXMLContext_Helper::ApplyAttrs()
return; return;
aToken.aText = sFontFamily; aToken.aText = sFontFamily;
SmFontNode *pFontNode = new SmFontNode(aToken); std::unique_ptr<SmFontNode> pFontNode(new SmFontNode(aToken));
pFontNode->SetSubNodes(0,popOrZero(rNodeStack)); pFontNode->SetSubNodes(0,popOrZero(rNodeStack));
rNodeStack.push_front(pFontNode); rNodeStack.push_front(std::move(pFontNode));
} }
if (!sColor.isEmpty()) if (!sColor.isEmpty())
{ {
...@@ -732,9 +733,9 @@ void SmXMLContext_Helper::ApplyAttrs() ...@@ -732,9 +733,9 @@ void SmXMLContext_Helper::ApplyAttrs()
if (tok != XML_TOK_UNKNOWN) if (tok != XML_TOK_UNKNOWN)
{ {
aToken.eType = static_cast<SmTokenType>(tok); aToken.eType = static_cast<SmTokenType>(tok);
SmFontNode *pFontNode = new SmFontNode(aToken); std::unique_ptr<SmFontNode> pFontNode(new SmFontNode(aToken));
pFontNode->SetSubNodes(0,popOrZero(rNodeStack)); pFontNode->SetSubNodes(0,popOrZero(rNodeStack));
rNodeStack.push_front(pFontNode); rNodeStack.push_front(std::move(pFontNode));
} }
} }
...@@ -929,10 +930,10 @@ void SmXMLPhantomContext_Impl::EndElement() ...@@ -929,10 +930,10 @@ void SmXMLPhantomContext_Impl::EndElement()
aToken.nLevel = 5; aToken.nLevel = 5;
aToken.eType = TPHANTOM; aToken.eType = TPHANTOM;
SmFontNode *pPhantom = new SmFontNode(aToken); std::unique_ptr<SmFontNode> pPhantom(new SmFontNode(aToken));
SmNodeStack &rNodeStack = GetSmImport().GetNodeStack(); SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
pPhantom->SetSubNodes(0,popOrZero(rNodeStack)); pPhantom->SetSubNodes(0,popOrZero(rNodeStack));
rNodeStack.push_front(pPhantom); rNodeStack.push_front(std::move(pPhantom));
} }
...@@ -994,7 +995,7 @@ void SmXMLFencedContext_Impl::EndElement() ...@@ -994,7 +995,7 @@ void SmXMLFencedContext_Impl::EndElement()
aToken.eType = TLPARENT; aToken.eType = TLPARENT;
aToken.cMathChar = cBegin; aToken.cMathChar = cBegin;
SmStructureNode *pSNode = new SmBraceNode(aToken); std::unique_ptr<SmStructureNode> pSNode(new SmBraceNode(aToken));
SmNode *pLeft = new SmMathSymbolNode(aToken); SmNode *pLeft = new SmMathSymbolNode(aToken);
aToken.cMathChar = cEnd; aToken.cMathChar = cEnd;
...@@ -1014,7 +1015,8 @@ void SmXMLFencedContext_Impl::EndElement() ...@@ -1014,7 +1015,8 @@ void SmXMLFencedContext_Impl::EndElement()
aRelationArray.resize(i); aRelationArray.resize(i);
while (rNodeStack.size() > nElementCount) while (rNodeStack.size() > nElementCount)
{ {
auto pNode = rNodeStack.pop_front(); auto pNode = std::move(rNodeStack.front());
rNodeStack.pop_front();
aRelationArray[--i] = pNode.release(); aRelationArray[--i] = pNode.release();
if (i > 1 && rNodeStack.size() > 1) if (i > 1 && rNodeStack.size() > 1)
aRelationArray[--i] = new SmGlyphSpecialNode(aToken); aRelationArray[--i] = new SmGlyphSpecialNode(aToken);
...@@ -1027,7 +1029,7 @@ void SmXMLFencedContext_Impl::EndElement() ...@@ -1027,7 +1029,7 @@ void SmXMLFencedContext_Impl::EndElement()
pSNode->SetSubNodes(pLeft,pBody,pRight); pSNode->SetSubNodes(pLeft,pBody,pRight);
pSNode->SetScaleMode(SCALE_HEIGHT); pSNode->SetScaleMode(SCALE_HEIGHT);
GetSmImport().GetNodeStack().push_front(pSNode); GetSmImport().GetNodeStack().push_front(std::move(pSNode));
} }
...@@ -1088,7 +1090,7 @@ void SmXMLNumberContext_Impl::TCharacters(const OUString &rChars) ...@@ -1088,7 +1090,7 @@ void SmXMLNumberContext_Impl::TCharacters(const OUString &rChars)
void SmXMLNumberContext_Impl::EndElement() void SmXMLNumberContext_Impl::EndElement()
{ {
GetSmImport().GetNodeStack().push_front(new SmTextNode(aToken,FNT_NUMBER)); GetSmImport().GetNodeStack().push_front(o3tl::make_unique<SmTextNode>(aToken,FNT_NUMBER));
} }
...@@ -1167,7 +1169,7 @@ void SmXMLTextContext_Impl::TCharacters(const OUString &rChars) ...@@ -1167,7 +1169,7 @@ void SmXMLTextContext_Impl::TCharacters(const OUString &rChars)
void SmXMLTextContext_Impl::EndElement() void SmXMLTextContext_Impl::EndElement()
{ {
GetSmImport().GetNodeStack().push_front(new SmTextNode(aToken,FNT_TEXT)); GetSmImport().GetNodeStack().push_front(o3tl::make_unique<SmTextNode>(aToken,FNT_TEXT));
} }
...@@ -1209,7 +1211,7 @@ void SmXMLStringContext_Impl::TCharacters(const OUString &rChars) ...@@ -1209,7 +1211,7 @@ void SmXMLStringContext_Impl::TCharacters(const OUString &rChars)
void SmXMLStringContext_Impl::EndElement() void SmXMLStringContext_Impl::EndElement()
{ {
GetSmImport().GetNodeStack().push_front(new SmTextNode(aToken,FNT_FIXED)); GetSmImport().GetNodeStack().push_front(o3tl::make_unique<SmTextNode>(aToken,FNT_FIXED));
} }
...@@ -1240,18 +1242,18 @@ public: ...@@ -1240,18 +1242,18 @@ public:
void SmXMLIdentifierContext_Impl::EndElement() void SmXMLIdentifierContext_Impl::EndElement()
{ {
SmTextNode *pNode = 0; std::unique_ptr<SmTextNode> pNode;
//we will handle identifier italic/normal here instead of with a standalone //we will handle identifier italic/normal here instead of with a standalone
//font node //font node
if (((aStyleHelper.nIsItalic == -1) && (aToken.aText.getLength() > 1)) if (((aStyleHelper.nIsItalic == -1) && (aToken.aText.getLength() > 1))
|| ((aStyleHelper.nIsItalic == 0) && (aToken.aText.getLength() == 1))) || ((aStyleHelper.nIsItalic == 0) && (aToken.aText.getLength() == 1)))
{ {
pNode = new SmTextNode(aToken,FNT_FUNCTION); pNode.reset(new SmTextNode(aToken,FNT_FUNCTION));
pNode->GetFont().SetItalic(ITALIC_NONE); pNode->GetFont().SetItalic(ITALIC_NONE);
aStyleHelper.nIsItalic = -1; aStyleHelper.nIsItalic = -1;
} }
else else
pNode = new SmTextNode(aToken,FNT_VARIABLE); pNode.reset(new SmTextNode(aToken,FNT_VARIABLE));
if (aStyleHelper.bFontNodeNeeded && aStyleHelper.nIsItalic != -1) if (aStyleHelper.bFontNodeNeeded && aStyleHelper.nIsItalic != -1)
{ {
if (aStyleHelper.nIsItalic) if (aStyleHelper.nIsItalic)
...@@ -1268,7 +1270,7 @@ void SmXMLIdentifierContext_Impl::EndElement() ...@@ -1268,7 +1270,7 @@ void SmXMLIdentifierContext_Impl::EndElement()
aStyleHelper.bFontNodeNeeded=false; aStyleHelper.bFontNodeNeeded=false;
if (aStyleHelper.bFontNodeNeeded) if (aStyleHelper.bFontNodeNeeded)
aStyleHelper.ApplyAttrs(); aStyleHelper.ApplyAttrs();
GetSmImport().GetNodeStack().push_front(pNode); GetSmImport().GetNodeStack().push_front(std::move(pNode));
} }
void SmXMLIdentifierContext_Impl::TCharacters(const OUString &rChars) void SmXMLIdentifierContext_Impl::TCharacters(const OUString &rChars)
...@@ -1306,13 +1308,13 @@ void SmXMLOperatorContext_Impl::TCharacters(const OUString &rChars) ...@@ -1306,13 +1308,13 @@ void SmXMLOperatorContext_Impl::TCharacters(const OUString &rChars)
void SmXMLOperatorContext_Impl::EndElement() void SmXMLOperatorContext_Impl::EndElement()
{ {
SmMathSymbolNode *pNode = new SmMathSymbolNode(aToken); std::unique_ptr<SmMathSymbolNode> pNode(new SmMathSymbolNode(aToken));
//For stretchy scaling the scaling must be retrieved from this node //For stretchy scaling the scaling must be retrieved from this node
//and applied to the expression itself so as to get the expression //and applied to the expression itself so as to get the expression
//to scale the operator to the height of the expression itself //to scale the operator to the height of the expression itself
if (bIsStretchy) if (bIsStretchy)
pNode->SetScaleMode(SCALE_HEIGHT); pNode->SetScaleMode(SCALE_HEIGHT);
GetSmImport().GetNodeStack().push_front(pNode); GetSmImport().GetNodeStack().push_front(std::move(pNode));
} }
...@@ -1365,9 +1367,9 @@ void SmXMLSpaceContext_Impl::StartElement( ...@@ -1365,9 +1367,9 @@ void SmXMLSpaceContext_Impl::StartElement(
aToken.cMathChar = '\0'; aToken.cMathChar = '\0';
aToken.eType = TBLANK; aToken.eType = TBLANK;
aToken.nLevel = 5; aToken.nLevel = 5;
SmBlankNode *pBlank = new SmBlankNode(aToken); std::unique_ptr<SmBlankNode> pBlank(new SmBlankNode(aToken));
pBlank->IncreaseBy(aToken); pBlank->IncreaseBy(aToken);
GetSmImport().GetNodeStack().push_front(pBlank); GetSmImport().GetNodeStack().push_front(std::move(pBlank));
} }
...@@ -1400,7 +1402,7 @@ void SmXMLSubContext_Impl::GenericEndElement(SmTokenType eType, SmSubSup eSubSup ...@@ -1400,7 +1402,7 @@ void SmXMLSubContext_Impl::GenericEndElement(SmTokenType eType, SmSubSup eSubSup
SmToken aToken; SmToken aToken;
aToken.cMathChar = '\0'; aToken.cMathChar = '\0';
aToken.eType = eType; aToken.eType = eType;
SmSubSupNode *pNode = new SmSubSupNode(aToken); std::unique_ptr<SmSubSupNode> pNode(new SmSubSupNode(aToken));
SmNodeStack &rNodeStack = GetSmImport().GetNodeStack(); SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
// initialize subnodes array // initialize subnodes array
...@@ -1412,7 +1414,7 @@ void SmXMLSubContext_Impl::GenericEndElement(SmTokenType eType, SmSubSup eSubSup ...@@ -1412,7 +1414,7 @@ void SmXMLSubContext_Impl::GenericEndElement(SmTokenType eType, SmSubSup eSubSup
aSubNodes[eSubSup+1] = popOrZero(rNodeStack); aSubNodes[eSubSup+1] = popOrZero(rNodeStack);
aSubNodes[0] = popOrZero(rNodeStack); aSubNodes[0] = popOrZero(rNodeStack);
pNode->SetSubNodes(aSubNodes); pNode->SetSubNodes(aSubNodes);
rNodeStack.push_front(pNode); rNodeStack.push_front(std::move(pNode));
} }
...@@ -1460,7 +1462,7 @@ void SmXMLSubSupContext_Impl::GenericEndElement(SmTokenType eType, ...@@ -1460,7 +1462,7 @@ void SmXMLSubSupContext_Impl::GenericEndElement(SmTokenType eType,
SmToken aToken; SmToken aToken;
aToken.cMathChar = '\0'; aToken.cMathChar = '\0';
aToken.eType = eType; aToken.eType = eType;
SmSubSupNode *pNode = new SmSubSupNode(aToken); std::unique_ptr<SmSubSupNode> pNode(new SmSubSupNode(aToken));
SmNodeStack &rNodeStack = GetSmImport().GetNodeStack(); SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
// initialize subnodes array // initialize subnodes array
...@@ -1473,7 +1475,7 @@ void SmXMLSubSupContext_Impl::GenericEndElement(SmTokenType eType, ...@@ -1473,7 +1475,7 @@ void SmXMLSubSupContext_Impl::GenericEndElement(SmTokenType eType,
aSubNodes[aSub+1] = popOrZero(rNodeStack); aSubNodes[aSub+1] = popOrZero(rNodeStack);
aSubNodes[0] = popOrZero(rNodeStack); aSubNodes[0] = popOrZero(rNodeStack);
pNode->SetSubNodes(aSubNodes); pNode->SetSubNodes(aSubNodes);
rNodeStack.push_front(pNode); rNodeStack.push_front(std::move(pNode));
} }
...@@ -1519,7 +1521,7 @@ void SmXMLUnderContext_Impl::HandleAccent() ...@@ -1519,7 +1521,7 @@ void SmXMLUnderContext_Impl::HandleAccent()
SmNodeArray aSubNodes; SmNodeArray aSubNodes;
aSubNodes.resize(2); aSubNodes.resize(2);
SmStructureNode *pNode = new SmAttributNode(aToken); std::unique_ptr<SmStructureNode> pNode(new SmAttributNode(aToken));
if ((pTest->GetToken().cMathChar & 0x0FFF) == 0x0332) if ((pTest->GetToken().cMathChar & 0x0FFF) == 0x0332)
{ {
aSubNodes[0] = new SmRectangleNode(aToken); aSubNodes[0] = new SmRectangleNode(aToken);
...@@ -1531,7 +1533,7 @@ void SmXMLUnderContext_Impl::HandleAccent() ...@@ -1531,7 +1533,7 @@ void SmXMLUnderContext_Impl::HandleAccent()
aSubNodes[1] = popOrZero(rNodeStack); aSubNodes[1] = popOrZero(rNodeStack);
pNode->SetSubNodes(aSubNodes); pNode->SetSubNodes(aSubNodes);
pNode->SetScaleMode(SCALE_WIDTH); pNode->SetScaleMode(SCALE_WIDTH);
rNodeStack.push_front(pNode); rNodeStack.push_front(std::move(pNode));
} }
...@@ -1588,7 +1590,7 @@ void SmXMLOverContext_Impl::HandleAccent() ...@@ -1588,7 +1590,7 @@ void SmXMLOverContext_Impl::HandleAccent()
aToken.cMathChar = '\0'; aToken.cMathChar = '\0';
aToken.eType = TACUTE; aToken.eType = TACUTE;
SmAttributNode *pNode = new SmAttributNode(aToken); std::unique_ptr<SmAttributNode> pNode(new SmAttributNode(aToken));
SmNodeStack &rNodeStack = GetSmImport().GetNodeStack(); SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
SmNodeArray aSubNodes; SmNodeArray aSubNodes;
...@@ -1597,7 +1599,7 @@ void SmXMLOverContext_Impl::HandleAccent() ...@@ -1597,7 +1599,7 @@ void SmXMLOverContext_Impl::HandleAccent()
aSubNodes[1] = popOrZero(rNodeStack); aSubNodes[1] = popOrZero(rNodeStack);
pNode->SetSubNodes(aSubNodes); pNode->SetSubNodes(aSubNodes);
pNode->SetScaleMode(SCALE_WIDTH); pNode->SetScaleMode(SCALE_WIDTH);
rNodeStack.push_front(pNode); rNodeStack.push_front(std::move(pNode));
} }
...@@ -1657,7 +1659,7 @@ void SmXMLNoneContext_Impl::EndElement() ...@@ -1657,7 +1659,7 @@ void SmXMLNoneContext_Impl::EndElement()
aToken.nLevel = 5; aToken.nLevel = 5;
aToken.eType = TIDENT; aToken.eType = TIDENT;
GetSmImport().GetNodeStack().push_front( GetSmImport().GetNodeStack().push_front(
new SmTextNode(aToken,FNT_VARIABLE)); o3tl::make_unique<SmTextNode>(aToken,FNT_VARIABLE));
} }
...@@ -2136,21 +2138,22 @@ void SmXMLDocContext_Impl::EndElement() ...@@ -2136,21 +2138,22 @@ void SmXMLDocContext_Impl::EndElement()
ContextArray[0] = popOrZero(rNodeStack); ContextArray[0] = popOrZero(rNodeStack);
SmToken aDummy; SmToken aDummy;
SmStructureNode *pSNode = new SmLineNode(aDummy); std::unique_ptr<SmStructureNode> pSNode(new SmLineNode(aDummy));
pSNode->SetSubNodes(ContextArray); pSNode->SetSubNodes(ContextArray);
rNodeStack.push_front(pSNode); rNodeStack.push_front(std::move(pSNode));
SmNodeArray LineArray; SmNodeArray LineArray;
auto n = rNodeStack.size(); auto n = rNodeStack.size();
LineArray.resize(n); LineArray.resize(n);
for (size_t j = 0; j < n; j++) for (size_t j = 0; j < n; j++)
{ {
auto pNode = rNodeStack.pop_front(); auto pNode = std::move(rNodeStack.front());
rNodeStack.pop_front();
LineArray[n - (j + 1)] = pNode.release(); LineArray[n - (j + 1)] = pNode.release();
} }
SmStructureNode *pSNode2 = new SmTableNode(aDummy); std::unique_ptr<SmStructureNode> pSNode2(new SmTableNode(aDummy));
pSNode2->SetSubNodes(LineArray); pSNode2->SetSubNodes(LineArray);
rNodeStack.push_front(pSNode2); rNodeStack.push_front(std::move(pSNode2));
} }
void SmXMLFracContext_Impl::EndElement() void SmXMLFracContext_Impl::EndElement()
...@@ -2164,12 +2167,12 @@ void SmXMLFracContext_Impl::EndElement() ...@@ -2164,12 +2167,12 @@ void SmXMLFracContext_Impl::EndElement()
SmToken aToken; SmToken aToken;
aToken.cMathChar = '\0'; aToken.cMathChar = '\0';
aToken.eType = TOVER; aToken.eType = TOVER;
SmStructureNode *pSNode = new SmBinVerNode(aToken); std::unique_ptr<SmStructureNode> pSNode(new SmBinVerNode(aToken));
SmNode *pOper = new SmRectangleNode(aToken); SmNode *pOper = new SmRectangleNode(aToken);
SmNode *pSecond = popOrZero(rNodeStack); SmNode *pSecond = popOrZero(rNodeStack);
SmNode *pFirst = popOrZero(rNodeStack); SmNode *pFirst = popOrZero(rNodeStack);
pSNode->SetSubNodes(pFirst,pOper,pSecond); pSNode->SetSubNodes(pFirst,pOper,pSecond);
rNodeStack.push_front(pSNode); rNodeStack.push_front(std::move(pSNode));
} }
void SmXMLRootContext_Impl::EndElement() void SmXMLRootContext_Impl::EndElement()
...@@ -2183,13 +2186,13 @@ void SmXMLRootContext_Impl::EndElement() ...@@ -2183,13 +2186,13 @@ void SmXMLRootContext_Impl::EndElement()
SmToken aToken; SmToken aToken;
aToken.cMathChar = MS_SQRT; //Temporary: alert, based on StarSymbol font aToken.cMathChar = MS_SQRT; //Temporary: alert, based on StarSymbol font
aToken.eType = TNROOT; aToken.eType = TNROOT;
SmStructureNode *pSNode = new SmRootNode(aToken); std::unique_ptr<SmStructureNode> pSNode(new SmRootNode(aToken));
SmNode *pOper = new SmRootSymbolNode(aToken); SmNode *pOper = new SmRootSymbolNode(aToken);
SmNodeStack &rNodeStack = GetSmImport().GetNodeStack(); SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
SmNode *pIndex = popOrZero(rNodeStack); SmNode *pIndex = popOrZero(rNodeStack);
SmNode *pBase = popOrZero(rNodeStack); SmNode *pBase = popOrZero(rNodeStack);
pSNode->SetSubNodes(pIndex,pOper,pBase); pSNode->SetSubNodes(pIndex,pOper,pBase);
rNodeStack.push_front(pSNode); rNodeStack.push_front(std::move(pSNode));
} }
void SmXMLSqrtContext_Impl::EndElement() void SmXMLSqrtContext_Impl::EndElement()
...@@ -2205,11 +2208,11 @@ void SmXMLSqrtContext_Impl::EndElement() ...@@ -2205,11 +2208,11 @@ void SmXMLSqrtContext_Impl::EndElement()
SmToken aToken; SmToken aToken;
aToken.cMathChar = MS_SQRT; //Temporary: alert, based on StarSymbol font aToken.cMathChar = MS_SQRT; //Temporary: alert, based on StarSymbol font
aToken.eType = TSQRT; aToken.eType = TSQRT;
SmStructureNode *pSNode = new SmRootNode(aToken); std::unique_ptr<SmStructureNode> pSNode(new SmRootNode(aToken));
SmNode *pOper = new SmRootSymbolNode(aToken); SmNode *pOper = new SmRootSymbolNode(aToken);
SmNodeStack &rNodeStack = GetSmImport().GetNodeStack(); SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
pSNode->SetSubNodes(0,pOper,popOrZero(rNodeStack)); pSNode->SetSubNodes(0,pOper,popOrZero(rNodeStack));
rNodeStack.push_front(pSNode); rNodeStack.push_front(std::move(pSNode));
} }
void SmXMLRowContext_Impl::EndElement() void SmXMLRowContext_Impl::EndElement()
...@@ -2224,7 +2227,8 @@ void SmXMLRowContext_Impl::EndElement() ...@@ -2224,7 +2227,8 @@ void SmXMLRowContext_Impl::EndElement()
aRelationArray.resize(nSize); aRelationArray.resize(nSize);
for (auto j=nSize;j > 0;j--) for (auto j=nSize;j > 0;j--)
{ {
auto pNode = rNodeStack.pop_front(); auto pNode = std::move(rNodeStack.front());
rNodeStack.pop_front();
aRelationArray[j-1] = pNode.release(); aRelationArray[j-1] = pNode.release();
} }
...@@ -2279,13 +2283,13 @@ void SmXMLRowContext_Impl::EndElement() ...@@ -2279,13 +2283,13 @@ void SmXMLRowContext_Impl::EndElement()
} }
SmToken aDummy; SmToken aDummy;
SmStructureNode *pSNode = new SmBraceNode(aToken); std::unique_ptr<SmStructureNode> pSNode(new SmBraceNode(aToken));
SmStructureNode *pBody = new SmExpressionNode(aDummy); SmStructureNode *pBody = new SmExpressionNode(aDummy);
pBody->SetSubNodes(aRelationArray2); pBody->SetSubNodes(aRelationArray2);
pSNode->SetSubNodes(pLeft,pBody,pRight); pSNode->SetSubNodes(pLeft,pBody,pRight);
pSNode->SetScaleMode(SCALE_HEIGHT); pSNode->SetScaleMode(SCALE_HEIGHT);
rNodeStack.push_front(pSNode); rNodeStack.push_front(std::move(pSNode));
return; return;
} }
} }
...@@ -2300,9 +2304,9 @@ void SmXMLRowContext_Impl::EndElement() ...@@ -2300,9 +2304,9 @@ void SmXMLRowContext_Impl::EndElement()
} }
SmToken aDummy; SmToken aDummy;
SmStructureNode *pSNode = new SmExpressionNode(aDummy); std::unique_ptr<SmStructureNode> pSNode(new SmExpressionNode(aDummy));
pSNode->SetSubNodes(aRelationArray); pSNode->SetSubNodes(aRelationArray);
rNodeStack.push_front(pSNode); rNodeStack.push_front(std::move(pSNode));
} }
...@@ -2429,8 +2433,9 @@ void SmXMLMultiScriptsContext_Impl::ProcessSubSupPairs(bool bIsPrescript) ...@@ -2429,8 +2433,9 @@ void SmXMLMultiScriptsContext_Impl::ProcessSubSupPairs(bool bIsPrescript)
SmNodeStack aReverseStack; SmNodeStack aReverseStack;
for (size_t i = 0; i < nCount + 1; i++) for (size_t i = 0; i < nCount + 1; i++)
{ {
auto pNode = rNodeStack.pop_front(); auto pNode = std::move(rNodeStack.front());
aReverseStack.push_front(pNode.release()); rNodeStack.pop_front();
aReverseStack.push_front(std::move(pNode));
} }
SmSubSup eSub = bIsPrescript ? LSUB : RSUB; SmSubSup eSub = bIsPrescript ? LSUB : RSUB;
...@@ -2438,7 +2443,7 @@ void SmXMLMultiScriptsContext_Impl::ProcessSubSupPairs(bool bIsPrescript) ...@@ -2438,7 +2443,7 @@ void SmXMLMultiScriptsContext_Impl::ProcessSubSupPairs(bool bIsPrescript)
for (size_t i = 0; i < nCount; i += 2) for (size_t i = 0; i < nCount; i += 2)
{ {
SmSubSupNode *pNode = new SmSubSupNode(aToken); std::unique_ptr<SmSubSupNode> pNode(new SmSubSupNode(aToken));
// initialize subnodes array // initialize subnodes array
SmNodeArray aSubNodes(1 + SUBSUP_NUM_ENTRIES); SmNodeArray aSubNodes(1 + SUBSUP_NUM_ENTRIES);
...@@ -2459,11 +2464,12 @@ void SmXMLMultiScriptsContext_Impl::ProcessSubSupPairs(bool bIsPrescript) ...@@ -2459,11 +2464,12 @@ void SmXMLMultiScriptsContext_Impl::ProcessSubSupPairs(bool bIsPrescript)
aSubNodes[eSup+1] = pScriptNode; aSubNodes[eSup+1] = pScriptNode;
pNode->SetSubNodes(aSubNodes); pNode->SetSubNodes(aSubNodes);
aReverseStack.push_front(pNode); aReverseStack.push_front(std::move(pNode));
} }
assert(!aReverseStack.empty()); assert(!aReverseStack.empty());
auto pNode = aReverseStack.pop_front(); auto pNode = std::move(aReverseStack.front());
rNodeStack.push_front(pNode.release()); aReverseStack.pop_front();
rNodeStack.push_front(std::move(pNode));
} }
else else
{ {
...@@ -2489,8 +2495,8 @@ void SmXMLTableContext_Impl::EndElement() ...@@ -2489,8 +2495,8 @@ void SmXMLTableContext_Impl::EndElement()
SmStructureNode *pArray; SmStructureNode *pArray;
for (auto i=nRows;i > 0;i--) for (auto i=nRows;i > 0;i--)
{ {
auto pNode = rNodeStack.pop_front(); pArray = static_cast<SmStructureNode *>(rNodeStack.front().release());
pArray = static_cast<SmStructureNode *>(pNode.release()); rNodeStack.pop_front();
if (pArray->GetNumSubNodes() == 0) if (pArray->GetNumSubNodes() == 0)
{ {
//This is a little tricky, it is possible that there was //This is a little tricky, it is possible that there was
...@@ -2511,14 +2517,14 @@ void SmXMLTableContext_Impl::EndElement() ...@@ -2511,14 +2517,14 @@ void SmXMLTableContext_Impl::EndElement()
if (pArray->GetNumSubNodes() > nCols) if (pArray->GetNumSubNodes() > nCols)
nCols = pArray->GetNumSubNodes(); nCols = pArray->GetNumSubNodes();
aReverseStack.push_front(pArray); aReverseStack.push_front(std::unique_ptr<SmStructureNode>(pArray));
} }
aExpressionArray.resize(nCols*nRows); aExpressionArray.resize(nCols*nRows);
size_t j=0; size_t j=0;
while ( !aReverseStack.empty() ) while ( !aReverseStack.empty() )
{ {
auto pNode = aReverseStack.pop_front(); pArray = static_cast<SmStructureNode *>(aReverseStack.front().release());
pArray = static_cast<SmStructureNode *>(pNode.release()); aReverseStack.pop_front();
for (sal_uInt16 i=0;i<pArray->GetNumSubNodes();i++) for (sal_uInt16 i=0;i<pArray->GetNumSubNodes();i++)
aExpressionArray[j++] = pArray->GetSubNode(i); aExpressionArray[j++] = pArray->GetSubNode(i);
} }
...@@ -2527,10 +2533,10 @@ void SmXMLTableContext_Impl::EndElement() ...@@ -2527,10 +2533,10 @@ void SmXMLTableContext_Impl::EndElement()
aToken.cMathChar = '\0'; aToken.cMathChar = '\0';
aToken.nGroup = TRGROUP; aToken.nGroup = TRGROUP;
aToken.eType = TMATRIX; aToken.eType = TMATRIX;
SmMatrixNode *pSNode = new SmMatrixNode(aToken); std::unique_ptr<SmMatrixNode> pSNode(new SmMatrixNode(aToken));
pSNode->SetSubNodes(aExpressionArray); pSNode->SetSubNodes(aExpressionArray);
pSNode->SetRowCol(static_cast<sal_uInt16>(nRows),nCols); pSNode->SetRowCol(static_cast<sal_uInt16>(nRows),nCols);
rNodeStack.push_front(pSNode); rNodeStack.push_front(std::move(pSNode));
} }
SvXMLImportContext *SmXMLTableRowContext_Impl::CreateChildContext( SvXMLImportContext *SmXMLTableRowContext_Impl::CreateChildContext(
...@@ -2630,12 +2636,13 @@ void SmXMLActionContext_Impl::EndElement() ...@@ -2630,12 +2636,13 @@ void SmXMLActionContext_Impl::EndElement()
{ {
rNodeStack.pop_front(); rNodeStack.pop_front();
} }
auto pSelected = rNodeStack.pop_front(); auto pSelected = std::move(rNodeStack.front());
rNodeStack.pop_front();
for (auto i=rNodeStack.size()-nElementCount; i > 0; i--) for (auto i=rNodeStack.size()-nElementCount; i > 0; i--)
{ {
rNodeStack.pop_front(); rNodeStack.pop_front();
} }
rNodeStack.push_front(pSelected.release()); rNodeStack.push_front(std::move(pSelected));
} }
SvXMLImportContext *SmXMLImport::CreateContext(sal_uInt16 nPrefix, SvXMLImportContext *SmXMLImport::CreateContext(sal_uInt16 nPrefix,
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <editeng/unolingu.hxx> #include <editeng/unolingu.hxx>
#include <unotools/syslocale.hxx> #include <unotools/syslocale.hxx>
#include <sal/macros.h> #include <sal/macros.h>
#include <o3tl/make_unique.hxx>
#include <vcl/settings.hxx> #include <vcl/settings.hxx>
#include "parse.hxx" #include "parse.hxx"
#include "starmath.hrc" #include "starmath.hrc"
...@@ -978,13 +979,14 @@ void SmParser::DoTable() ...@@ -978,13 +979,14 @@ void SmParser::DoTable()
for (size_t i = 0; i < n; i++) for (size_t i = 0; i < n; i++)
{ {
auto pNode = m_aNodeStack.pop_front(); auto pNode = std::move(m_aNodeStack.front());
m_aNodeStack.pop_front();
LineArray[n - (i + 1)] = pNode.release(); LineArray[n - (i + 1)] = pNode.release();
} }
SmStructureNode *pSNode = new SmTableNode(m_aCurToken); std::unique_ptr<SmStructureNode> pSNode(new SmTableNode(m_aCurToken));
pSNode->SetSubNodes(LineArray); pSNode->SetSubNodes(LineArray);
m_aNodeStack.push_front(pSNode); m_aNodeStack.push_front(std::move(pSNode));
} }
void SmParser::DoAlign() void SmParser::DoAlign()
...@@ -1012,7 +1014,7 @@ void SmParser::DoAlign() ...@@ -1012,7 +1014,7 @@ void SmParser::DoAlign()
if (pSNode) if (pSNode)
{ {
pSNode->SetSubNode(0, popOrZero(m_aNodeStack)); pSNode->SetSubNode(0, popOrZero(m_aNodeStack));
m_aNodeStack.push_front(pSNode); m_aNodeStack.push_front(std::unique_ptr<SmStructureNode>(pSNode));
} }
} }
...@@ -1045,9 +1047,9 @@ void SmParser::DoLine() ...@@ -1045,9 +1047,9 @@ void SmParser::DoLine()
ExpressionArray.push_back(new SmExpressionNode(aTok)); ExpressionArray.push_back(new SmExpressionNode(aTok));
} }
SmStructureNode *pSNode = new SmLineNode(m_aCurToken); std::unique_ptr<SmStructureNode> pSNode(new SmLineNode(m_aCurToken));
pSNode->SetSubNodes(ExpressionArray); pSNode->SetSubNodes(ExpressionArray);
m_aNodeStack.push_front(pSNode); m_aNodeStack.push_front(std::move(pSNode));
} }
void SmParser::DoExpression() void SmParser::DoExpression()
...@@ -1055,11 +1057,16 @@ void SmParser::DoExpression() ...@@ -1055,11 +1057,16 @@ void SmParser::DoExpression()
bool bUseExtraSpaces = true; bool bUseExtraSpaces = true;
if (!m_aNodeStack.empty()) if (!m_aNodeStack.empty())
{ {
auto pNode = m_aNodeStack.pop_front(); auto pNode = std::move(m_aNodeStack.front());
m_aNodeStack.pop_front();
if (pNode->GetToken().eType == TNOSPACE) if (pNode->GetToken().eType == TNOSPACE)
bUseExtraSpaces = false; bUseExtraSpaces = false;
else else
m_aNodeStack.push_front(pNode.release()); // push the node from above again (now to be used as argument to this current 'nospace' node) {
// push the node from above again (now to be used as argument
// to this current 'nospace' node)
m_aNodeStack.push_front(std::move(pNode));
}
} }
SmNodeArray RelationArray; SmNodeArray RelationArray;
...@@ -1075,15 +1082,15 @@ void SmParser::DoExpression() ...@@ -1075,15 +1082,15 @@ void SmParser::DoExpression()
if (RelationArray.size() > 1) if (RelationArray.size() > 1)
{ {
SmExpressionNode *pSNode = new SmExpressionNode(m_aCurToken); std::unique_ptr<SmExpressionNode> pSNode(new SmExpressionNode(m_aCurToken));
pSNode->SetSubNodes(RelationArray); pSNode->SetSubNodes(RelationArray);
pSNode->SetUseExtraSpaces(bUseExtraSpaces); pSNode->SetUseExtraSpaces(bUseExtraSpaces);
m_aNodeStack.push_front(pSNode); m_aNodeStack.push_front(std::move(pSNode));
} }
else else
{ {
// This expression has only one node so just push this node. // This expression has only one node so just push this node.
m_aNodeStack.push_front(RelationArray[0]); m_aNodeStack.push_front(std::unique_ptr<SmNode>(RelationArray[0]));
} }
} }
...@@ -1092,7 +1099,7 @@ void SmParser::DoRelation() ...@@ -1092,7 +1099,7 @@ void SmParser::DoRelation()
DoSum(); DoSum();
while (TokenInGroup(TGRELATION)) while (TokenInGroup(TGRELATION))
{ {
SmStructureNode *pSNode = new SmBinHorNode(m_aCurToken); std::unique_ptr<SmStructureNode> pSNode(new SmBinHorNode(m_aCurToken));
SmNode *pFirst = popOrZero(m_aNodeStack); SmNode *pFirst = popOrZero(m_aNodeStack);
DoOpSubSup(); DoOpSubSup();
...@@ -1101,7 +1108,7 @@ void SmParser::DoRelation() ...@@ -1101,7 +1108,7 @@ void SmParser::DoRelation()
DoSum(); DoSum();
pSNode->SetSubNodes(pFirst, pSecond, popOrZero(m_aNodeStack)); pSNode->SetSubNodes(pFirst, pSecond, popOrZero(m_aNodeStack));
m_aNodeStack.push_front(pSNode); m_aNodeStack.push_front(std::move(pSNode));
} }
} }
...@@ -1110,7 +1117,7 @@ void SmParser::DoSum() ...@@ -1110,7 +1117,7 @@ void SmParser::DoSum()
DoProduct(); DoProduct();
while (TokenInGroup(TGSUM)) while (TokenInGroup(TGSUM))
{ {
SmStructureNode *pSNode = new SmBinHorNode(m_aCurToken); std::unique_ptr<SmStructureNode> pSNode(new SmBinHorNode(m_aCurToken));
SmNode *pFirst = popOrZero(m_aNodeStack); SmNode *pFirst = popOrZero(m_aNodeStack);
DoOpSubSup(); DoOpSubSup();
...@@ -1119,7 +1126,7 @@ void SmParser::DoSum() ...@@ -1119,7 +1126,7 @@ void SmParser::DoSum()
DoProduct(); DoProduct();
pSNode->SetSubNodes(pFirst, pSecond, popOrZero(m_aNodeStack)); pSNode->SetSubNodes(pFirst, pSecond, popOrZero(m_aNodeStack));
m_aNodeStack.push_front(pSNode); m_aNodeStack.push_front(std::move(pSNode));
} }
} }
...@@ -1195,7 +1202,7 @@ void SmParser::DoProduct() ...@@ -1195,7 +1202,7 @@ void SmParser::DoProduct()
{ {
pSNode->SetSubNodes(pFirst, pOper, popOrZero(m_aNodeStack)); pSNode->SetSubNodes(pFirst, pOper, popOrZero(m_aNodeStack));
} }
m_aNodeStack.push_front(pSNode); m_aNodeStack.push_front(std::unique_ptr<SmStructureNode>(pSNode));
} }
} }
...@@ -1208,7 +1215,7 @@ void SmParser::DoSubSup(sal_uLong nActiveGroup) ...@@ -1208,7 +1215,7 @@ void SmParser::DoSubSup(sal_uLong nActiveGroup)
// already finish // already finish
return; return;
SmSubSupNode *pNode = new SmSubSupNode(m_aCurToken); std::unique_ptr<SmSubSupNode> pNode(new SmSubSupNode(m_aCurToken));
//! Of course 'm_aCurToken' is just the first sub-/supscript token. //! Of course 'm_aCurToken' is just the first sub-/supscript token.
//! It should be of no further interest. The positions of the //! It should be of no further interest. The positions of the
//! sub-/supscripts will be identified by the corresponding subnodes //! sub-/supscripts will be identified by the corresponding subnodes
...@@ -1264,13 +1271,13 @@ void SmParser::DoSubSup(sal_uLong nActiveGroup) ...@@ -1264,13 +1271,13 @@ void SmParser::DoSubSup(sal_uLong nActiveGroup)
} }
pNode->SetSubNodes(aSubNodes); pNode->SetSubNodes(aSubNodes);
m_aNodeStack.push_front(pNode); m_aNodeStack.push_front(std::move(pNode));
} }
void SmParser::DoOpSubSup() void SmParser::DoOpSubSup()
{ {
// push operator symbol // push operator symbol
m_aNodeStack.push_front(new SmMathSymbolNode(m_aCurToken)); m_aNodeStack.push_front(o3tl::make_unique<SmMathSymbolNode>(m_aCurToken));
// skip operator token // skip operator token
NextToken(); NextToken();
// get sub- supscripts if any // get sub- supscripts if any
...@@ -1289,7 +1296,7 @@ void SmParser::DoPower() ...@@ -1289,7 +1296,7 @@ void SmParser::DoPower()
void SmParser::DoBlank() void SmParser::DoBlank()
{ {
OSL_ENSURE(TokenInGroup(TGBLANK), "Sm : wrong token"); OSL_ENSURE(TokenInGroup(TGBLANK), "Sm : wrong token");
SmBlankNode *pBlankNode = new SmBlankNode(m_aCurToken); std::unique_ptr<SmBlankNode> pBlankNode(new SmBlankNode(m_aCurToken));
while (TokenInGroup(TGBLANK)) while (TokenInGroup(TGBLANK))
{ {
...@@ -1304,7 +1311,7 @@ void SmParser::DoBlank() ...@@ -1304,7 +1311,7 @@ void SmParser::DoBlank()
pBlankNode->Clear(); pBlankNode->Clear();
} }
m_aNodeStack.push_front(pBlankNode); m_aNodeStack.push_front(std::move(pBlankNode));
} }
void SmParser::DoTerm(bool bGroupNumberIdent) void SmParser::DoTerm(bool bGroupNumberIdent)
...@@ -1321,7 +1328,7 @@ void SmParser::DoTerm(bool bGroupNumberIdent) ...@@ -1321,7 +1328,7 @@ void SmParser::DoTerm(bool bGroupNumberIdent)
bool bNoSpace = m_aCurToken.eType == TNOSPACE; bool bNoSpace = m_aCurToken.eType == TNOSPACE;
if (bNoSpace) // push 'no space' node and continue to parse expression if (bNoSpace) // push 'no space' node and continue to parse expression
{ {
m_aNodeStack.push_front(new SmExpressionNode(m_aCurToken)); m_aNodeStack.push_front(o3tl::make_unique<SmExpressionNode>(m_aCurToken));
NextToken(); NextToken();
} }
if (m_aCurToken.eType != TLGROUP) if (m_aCurToken.eType != TLGROUP)
...@@ -1338,9 +1345,9 @@ void SmParser::DoTerm(bool bGroupNumberIdent) ...@@ -1338,9 +1345,9 @@ void SmParser::DoTerm(bool bGroupNumberIdent)
{ {
if (bNoSpace) // get rid of the 'no space' node pushed above if (bNoSpace) // get rid of the 'no space' node pushed above
m_aNodeStack.pop_front(); m_aNodeStack.pop_front();
SmStructureNode *pSNode = new SmExpressionNode(m_aCurToken); std::unique_ptr<SmStructureNode> pSNode(new SmExpressionNode(m_aCurToken));
pSNode->SetSubNodes(NULL, NULL); pSNode->SetSubNodes(NULL, NULL);
m_aNodeStack.push_front(pSNode); m_aNodeStack.push_front(std::move(pSNode));
NextToken(); NextToken();
} }
...@@ -1366,17 +1373,17 @@ void SmParser::DoTerm(bool bGroupNumberIdent) ...@@ -1366,17 +1373,17 @@ void SmParser::DoTerm(bool bGroupNumberIdent)
break; break;
case TTEXT : case TTEXT :
m_aNodeStack.push_front(new SmTextNode(m_aCurToken, FNT_TEXT)); m_aNodeStack.push_front(o3tl::make_unique<SmTextNode>(m_aCurToken, FNT_TEXT));
NextToken(); NextToken();
break; break;
case TCHARACTER : case TCHARACTER :
m_aNodeStack.push_front(new SmTextNode(m_aCurToken, FNT_VARIABLE)); m_aNodeStack.push_front(o3tl::make_unique<SmTextNode>(m_aCurToken, FNT_VARIABLE));
NextToken(); NextToken();
break; break;
case TIDENT : case TIDENT :
case TNUMBER : case TNUMBER :
{ {
m_aNodeStack.push_front(new SmTextNode(m_aCurToken, m_aNodeStack.push_front(o3tl::make_unique<SmTextNode>(m_aCurToken,
m_aCurToken.eType == TNUMBER ? m_aCurToken.eType == TNUMBER ?
FNT_NUMBER : FNT_NUMBER :
FNT_VARIABLE)); FNT_VARIABLE));
...@@ -1413,7 +1420,7 @@ void SmParser::DoTerm(bool bGroupNumberIdent) ...@@ -1413,7 +1420,7 @@ void SmParser::DoTerm(bool bGroupNumberIdent)
moveToNextToken = false; moveToNextToken = false;
break; break;
} }
m_aNodeStack.push_front(new SmTextNode(m_aCurToken, m_aNodeStack.push_front(o3tl::make_unique<SmTextNode>(m_aCurToken,
m_aCurToken.eType == m_aCurToken.eType ==
TNUMBER ? TNUMBER ?
FNT_NUMBER : FNT_NUMBER :
...@@ -1432,9 +1439,9 @@ void SmParser::DoTerm(bool bGroupNumberIdent) ...@@ -1432,9 +1439,9 @@ void SmParser::DoTerm(bool bGroupNumberIdent)
nodeArray[nTokens-1] = popOrZero(m_aNodeStack); nodeArray[nTokens-1] = popOrZero(m_aNodeStack);
nTokens--; nTokens--;
} }
SmExpressionNode* pNode = new SmExpressionNode(SmToken()); std::unique_ptr<SmExpressionNode> pNode(new SmExpressionNode(SmToken()));
pNode->SetSubNodes(nodeArray); pNode->SetSubNodes(nodeArray);
m_aNodeStack.push_front(pNode); m_aNodeStack.push_front(std::move(pNode));
} }
} }
break; break;
...@@ -1459,7 +1466,7 @@ void SmParser::DoTerm(bool bGroupNumberIdent) ...@@ -1459,7 +1466,7 @@ void SmParser::DoTerm(bool bGroupNumberIdent)
case TDOTSLOW : case TDOTSLOW :
case TDOTSUP : case TDOTSUP :
case TDOTSVERT : case TDOTSVERT :
m_aNodeStack.push_front(new SmMathSymbolNode(m_aCurToken)); m_aNodeStack.push_front(o3tl::make_unique<SmMathSymbolNode>(m_aCurToken));
NextToken(); NextToken();
break; break;
...@@ -1477,12 +1484,12 @@ void SmParser::DoTerm(bool bGroupNumberIdent) ...@@ -1477,12 +1484,12 @@ void SmParser::DoTerm(bool bGroupNumberIdent)
case TWP : case TWP :
case TEMPTYSET : case TEMPTYSET :
case TINFINITY : case TINFINITY :
m_aNodeStack.push_front(new SmMathIdentifierNode(m_aCurToken)); m_aNodeStack.push_front(o3tl::make_unique<SmMathIdentifierNode>(m_aCurToken));
NextToken(); NextToken();
break; break;
case TPLACE: case TPLACE:
m_aNodeStack.push_front(new SmPlaceNode(m_aCurToken)); m_aNodeStack.push_front(o3tl::make_unique<SmPlaceNode>(m_aCurToken));
NextToken(); NextToken();
break; break;
...@@ -1546,7 +1553,7 @@ void SmParser::DoTerm(bool bGroupNumberIdent) ...@@ -1546,7 +1553,7 @@ void SmParser::DoTerm(bool bGroupNumberIdent)
pNode->SetSubNodes(0, pFirstNode); pNode->SetSubNodes(0, pFirstNode);
pFirstNode = pNode; pFirstNode = pNode;
} }
m_aNodeStack.push_front(pFirstNode); m_aNodeStack.push_front(std::unique_ptr<SmNode>(pFirstNode));
} }
else if (TokenInGroup(TGFUNCTION)) else if (TokenInGroup(TGFUNCTION))
{ {
...@@ -1588,8 +1595,8 @@ void SmParser::DoEscape() ...@@ -1588,8 +1595,8 @@ void SmParser::DoEscape()
Error(PE_UNEXPECTED_TOKEN); Error(PE_UNEXPECTED_TOKEN);
} }
SmNode *pNode = new SmMathSymbolNode(m_aCurToken); std::unique_ptr<SmNode> pNode(new SmMathSymbolNode(m_aCurToken));
m_aNodeStack.push_front(pNode); m_aNodeStack.push_front(std::move(pNode));
NextToken(); NextToken();
} }
...@@ -1597,7 +1604,8 @@ void SmParser::DoEscape() ...@@ -1597,7 +1604,8 @@ void SmParser::DoEscape()
void SmParser::DoOperator() void SmParser::DoOperator()
{ {
if (TokenInGroup(TGOPER)) if (TokenInGroup(TGOPER))
{ SmStructureNode *pSNode = new SmOperNode(m_aCurToken); {
std::unique_ptr<SmStructureNode> pSNode(new SmOperNode(m_aCurToken));
// put operator on top of stack // put operator on top of stack
DoOper(); DoOper();
...@@ -1610,14 +1618,14 @@ void SmParser::DoOperator() ...@@ -1610,14 +1618,14 @@ void SmParser::DoOperator()
DoPower(); DoPower();
pSNode->SetSubNodes(pOperator, popOrZero(m_aNodeStack)); pSNode->SetSubNodes(pOperator, popOrZero(m_aNodeStack));
m_aNodeStack.push_front(pSNode); m_aNodeStack.push_front(std::move(pSNode));
} }
} }
void SmParser::DoOper() void SmParser::DoOper()
{ {
SmTokenType eType (m_aCurToken.eType); SmTokenType eType (m_aCurToken.eType);
SmNode *pNode = NULL; std::unique_ptr<SmNode> pNode;
switch (eType) switch (eType)
{ {
...@@ -1630,7 +1638,7 @@ void SmParser::DoOper() ...@@ -1630,7 +1638,7 @@ void SmParser::DoOper()
case TLINT : case TLINT :
case TLLINT : case TLLINT :
case TLLLINT : case TLLLINT :
pNode = new SmMathSymbolNode(m_aCurToken); pNode.reset(new SmMathSymbolNode(m_aCurToken));
break; break;
case TLIM : case TLIM :
...@@ -1648,7 +1656,7 @@ void SmParser::DoOper() ...@@ -1648,7 +1656,7 @@ void SmParser::DoOper()
} }
if( pLim ) if( pLim )
m_aCurToken.aText = OUString::createFromAscii(pLim); m_aCurToken.aText = OUString::createFromAscii(pLim);
pNode = new SmTextNode(m_aCurToken, FNT_TEXT); pNode.reset(new SmTextNode(m_aCurToken, FNT_TEXT));
} }
break; break;
...@@ -1656,13 +1664,13 @@ void SmParser::DoOper() ...@@ -1656,13 +1664,13 @@ void SmParser::DoOper()
NextToken(); NextToken();
OSL_ENSURE(m_aCurToken.eType == TSPECIAL, "Sm: wrong token"); OSL_ENSURE(m_aCurToken.eType == TSPECIAL, "Sm: wrong token");
pNode = new SmGlyphSpecialNode(m_aCurToken); pNode.reset(new SmGlyphSpecialNode(m_aCurToken));
break; break;
default : default :
assert(false && "unknown case"); assert(false && "unknown case");
} }
m_aNodeStack.push_front(pNode); m_aNodeStack.push_front(std::move(pNode));
NextToken(); NextToken();
} }
...@@ -1675,7 +1683,7 @@ void SmParser::DoUnOper() ...@@ -1675,7 +1683,7 @@ void SmParser::DoUnOper()
SmTokenType eType = m_aCurToken.eType; SmTokenType eType = m_aCurToken.eType;
bool bIsPostfix = eType == TFACT; bool bIsPostfix = eType == TFACT;
SmStructureNode *pSNode; std::unique_ptr<SmStructureNode> pSNode;
SmNode *pOper = 0, SmNode *pOper = 0,
*pExtra = 0, *pExtra = 0,
*pArg; *pArg;
...@@ -1725,7 +1733,8 @@ void SmParser::DoUnOper() ...@@ -1725,7 +1733,8 @@ void SmParser::DoUnOper()
pArg = popOrZero(m_aNodeStack); pArg = popOrZero(m_aNodeStack);
if (eType == TABS) if (eType == TABS)
{ pSNode = new SmBraceNode(aNodeToken); {
pSNode.reset(new SmBraceNode(aNodeToken));
pSNode->SetScaleMode(SCALE_HEIGHT); pSNode->SetScaleMode(SCALE_HEIGHT);
// build nodes for left & right lines // build nodes for left & right lines
...@@ -1742,18 +1751,20 @@ void SmParser::DoUnOper() ...@@ -1742,18 +1751,20 @@ void SmParser::DoUnOper()
pSNode->SetSubNodes(pLeft, pArg, pRight); pSNode->SetSubNodes(pLeft, pArg, pRight);
} }
else if (eType == TSQRT || eType == TNROOT) else if (eType == TSQRT || eType == TNROOT)
{ pSNode = new SmRootNode(aNodeToken); {
pSNode.reset(new SmRootNode(aNodeToken));
pOper = new SmRootSymbolNode(aNodeToken); pOper = new SmRootSymbolNode(aNodeToken);
pSNode->SetSubNodes(pExtra, pOper, pArg); pSNode->SetSubNodes(pExtra, pOper, pArg);
} }
else if(eType == TINTD) else if(eType == TINTD)
{ pSNode = new SmDynIntegralNode(aNodeToken); {
pSNode.reset(new SmDynIntegralNode(aNodeToken));
pOper = new SmDynIntegralSymbolNode(aNodeToken); pOper = new SmDynIntegralSymbolNode(aNodeToken);
pSNode->SetSubNodes(pOper, pArg); pSNode->SetSubNodes(pOper, pArg);
} }
else else
{ pSNode = new SmUnHorNode(aNodeToken); {
pSNode.reset(new SmUnHorNode(aNodeToken));
if (bIsPostfix) if (bIsPostfix)
pSNode->SetSubNodes(pArg, pOper); pSNode->SetSubNodes(pArg, pOper);
else else
...@@ -1761,14 +1772,14 @@ void SmParser::DoUnOper() ...@@ -1761,14 +1772,14 @@ void SmParser::DoUnOper()
pSNode->SetSubNodes(pOper, pArg); pSNode->SetSubNodes(pOper, pArg);
} }
m_aNodeStack.push_front(pSNode); m_aNodeStack.push_front(std::move(pSNode));
} }
void SmParser::DoAttribut() void SmParser::DoAttribut()
{ {
OSL_ENSURE(TokenInGroup(TGATTRIBUT), "Sm: wrong token group"); OSL_ENSURE(TokenInGroup(TGATTRIBUT), "Sm: wrong token group");
SmStructureNode *pSNode = new SmAttributNode(m_aCurToken); std::unique_ptr<SmStructureNode> pSNode(new SmAttributNode(m_aCurToken));
SmNode *pAttr; SmNode *pAttr;
SmScaleMode eScaleMode = SCALE_NONE; SmScaleMode eScaleMode = SCALE_NONE;
...@@ -1796,7 +1807,7 @@ void SmParser::DoAttribut() ...@@ -1796,7 +1807,7 @@ void SmParser::DoAttribut()
pSNode->SetSubNodes(pAttr, 0); pSNode->SetSubNodes(pAttr, 0);
pSNode->SetScaleMode(eScaleMode); pSNode->SetScaleMode(eScaleMode);
m_aNodeStack.push_front(pSNode); m_aNodeStack.push_front(std::move(pSNode));
} }
...@@ -1811,7 +1822,7 @@ void SmParser::DoFontAttribut() ...@@ -1811,7 +1822,7 @@ void SmParser::DoFontAttribut()
case TBOLD : case TBOLD :
case TNBOLD : case TNBOLD :
case TPHANTOM : case TPHANTOM :
m_aNodeStack.push_front(new SmFontNode(m_aCurToken)); m_aNodeStack.push_front(o3tl::make_unique<SmFontNode>(m_aCurToken));
NextToken(); NextToken();
break; break;
...@@ -1849,7 +1860,7 @@ void SmParser::DoColor() ...@@ -1849,7 +1860,7 @@ void SmParser::DoColor()
Error(PE_COLOR_EXPECTED); Error(PE_COLOR_EXPECTED);
} while (m_aCurToken.eType == TCOLOR); } while (m_aCurToken.eType == TCOLOR);
m_aNodeStack.push_front(new SmFontNode(aToken)); m_aNodeStack.push_front(o3tl::make_unique<SmFontNode>(aToken));
} }
void SmParser::DoFont() void SmParser::DoFont()
...@@ -1869,7 +1880,7 @@ void SmParser::DoFont() ...@@ -1869,7 +1880,7 @@ void SmParser::DoFont()
Error(PE_FONT_EXPECTED); Error(PE_FONT_EXPECTED);
} while (m_aCurToken.eType == TFONT); } while (m_aCurToken.eType == TFONT);
m_aNodeStack.push_front(new SmFontNode(aToken)); m_aNodeStack.push_front(o3tl::make_unique<SmFontNode>(aToken));
} }
...@@ -1900,7 +1911,7 @@ void SmParser::DoFontSize() ...@@ -1900,7 +1911,7 @@ void SmParser::DoFontSize()
OSL_ENSURE(m_aCurToken.eType == TSIZE, "Sm : Ooops..."); OSL_ENSURE(m_aCurToken.eType == TSIZE, "Sm : Ooops...");
FontSizeType Type; FontSizeType Type;
SmFontNode *pFontNode = new SmFontNode(m_aCurToken); std::unique_ptr<SmFontNode> pFontNode(new SmFontNode(m_aCurToken));
NextToken(); NextToken();
...@@ -1913,7 +1924,6 @@ void SmParser::DoFontSize() ...@@ -1913,7 +1924,6 @@ void SmParser::DoFontSize()
case TDIVIDEBY: Type = FontSizeType::DIVIDE; break; case TDIVIDEBY: Type = FontSizeType::DIVIDE; break;
default: default:
delete pFontNode;
Error(PE_SIZE_EXPECTED); Error(PE_SIZE_EXPECTED);
return; return;
} }
...@@ -1923,7 +1933,6 @@ void SmParser::DoFontSize() ...@@ -1923,7 +1933,6 @@ void SmParser::DoFontSize()
NextToken(); NextToken();
if (m_aCurToken.eType != TNUMBER) if (m_aCurToken.eType != TNUMBER)
{ {
delete pFontNode;
Error(PE_SIZE_EXPECTED); Error(PE_SIZE_EXPECTED);
return; return;
} }
...@@ -1960,7 +1969,7 @@ void SmParser::DoFontSize() ...@@ -1960,7 +1969,7 @@ void SmParser::DoFontSize()
NextToken(); NextToken();
pFontNode->SetSizeParameter(aValue, Type); pFontNode->SetSizeParameter(aValue, Type);
m_aNodeStack.push_front(pFontNode); m_aNodeStack.push_front(std::move(pFontNode));
} }
void SmParser::DoBrace() void SmParser::DoBrace()
...@@ -1968,7 +1977,7 @@ void SmParser::DoBrace() ...@@ -1968,7 +1977,7 @@ void SmParser::DoBrace()
OSL_ENSURE(m_aCurToken.eType == TLEFT || TokenInGroup(TGLBRACES), OSL_ENSURE(m_aCurToken.eType == TLEFT || TokenInGroup(TGLBRACES),
"Sm: kein Klammer Ausdruck"); "Sm: kein Klammer Ausdruck");
SmStructureNode *pSNode = new SmBraceNode(m_aCurToken); std::unique_ptr<SmStructureNode> pSNode(new SmBraceNode(m_aCurToken));
SmNode *pBody = 0, SmNode *pBody = 0,
*pLeft = 0, *pLeft = 0,
*pRight = 0; *pRight = 0;
...@@ -2049,10 +2058,11 @@ void SmParser::DoBrace() ...@@ -2049,10 +2058,11 @@ void SmParser::DoBrace()
OSL_ENSURE(pRight, "Sm: NULL pointer"); OSL_ENSURE(pRight, "Sm: NULL pointer");
pSNode->SetSubNodes(pLeft, pBody, pRight); pSNode->SetSubNodes(pLeft, pBody, pRight);
pSNode->SetScaleMode(eScaleMode); pSNode->SetScaleMode(eScaleMode);
m_aNodeStack.push_front(pSNode); m_aNodeStack.push_front(std::move(pSNode));
} }
else else
{ delete pSNode; {
pSNode.reset();
delete pBody; delete pBody;
delete pLeft; delete pLeft;
delete pRight; delete pRight;
...@@ -2063,7 +2073,7 @@ void SmParser::DoBrace() ...@@ -2063,7 +2073,7 @@ void SmParser::DoBrace()
void SmParser::DoBracebody(bool bIsLeftRight) void SmParser::DoBracebody(bool bIsLeftRight)
{ {
SmStructureNode *pBody = new SmBracebodyNode(m_aCurToken); std::unique_ptr<SmStructureNode> pBody(new SmBracebodyNode(m_aCurToken));
SmNodeArray aNodes; SmNodeArray aNodes;
sal_uInt16 nNum = 0; sal_uInt16 nNum = 0;
...@@ -2074,7 +2084,7 @@ void SmParser::DoBracebody(bool bIsLeftRight) ...@@ -2074,7 +2084,7 @@ void SmParser::DoBracebody(bool bIsLeftRight)
{ {
if (m_aCurToken.eType == TMLINE) if (m_aCurToken.eType == TMLINE)
{ {
m_aNodeStack.push_front(new SmMathSymbolNode(m_aCurToken)); m_aNodeStack.push_front(o3tl::make_unique<SmMathSymbolNode>(m_aCurToken));
NextToken(); NextToken();
nNum++; nNum++;
} }
...@@ -2094,7 +2104,7 @@ void SmParser::DoBracebody(bool bIsLeftRight) ...@@ -2094,7 +2104,7 @@ void SmParser::DoBracebody(bool bIsLeftRight)
{ {
if (m_aCurToken.eType == TMLINE) if (m_aCurToken.eType == TMLINE)
{ {
m_aNodeStack.push_front(new SmMathSymbolNode(m_aCurToken)); m_aNodeStack.push_front(o3tl::make_unique<SmMathSymbolNode>(m_aCurToken));
NextToken(); NextToken();
nNum++; nNum++;
} }
...@@ -2118,7 +2128,7 @@ void SmParser::DoBracebody(bool bIsLeftRight) ...@@ -2118,7 +2128,7 @@ void SmParser::DoBracebody(bool bIsLeftRight)
pBody->SetSubNodes(aNodes); pBody->SetSubNodes(aNodes);
pBody->SetScaleMode(bIsLeftRight ? SCALE_HEIGHT : SCALE_NONE); pBody->SetScaleMode(bIsLeftRight ? SCALE_HEIGHT : SCALE_NONE);
m_aNodeStack.push_front(pBody); m_aNodeStack.push_front(std::move(pBody));
} }
void SmParser::DoFunction() void SmParser::DoFunction()
...@@ -2148,7 +2158,7 @@ void SmParser::DoFunction() ...@@ -2148,7 +2158,7 @@ void SmParser::DoFunction()
case TLN : case TLN :
case TLOG : case TLOG :
case TEXP : case TEXP :
m_aNodeStack.push_front(new SmTextNode(m_aCurToken, FNT_FUNCTION)); m_aNodeStack.push_front(o3tl::make_unique<SmTextNode>(m_aCurToken, FNT_FUNCTION));
NextToken(); NextToken();
break; break;
...@@ -2160,7 +2170,7 @@ void SmParser::DoFunction() ...@@ -2160,7 +2170,7 @@ void SmParser::DoFunction()
void SmParser::DoBinom() void SmParser::DoBinom()
{ {
SmNodeArray ExpressionArray; SmNodeArray ExpressionArray;
SmStructureNode *pSNode = new SmTableNode(m_aCurToken); std::unique_ptr<SmStructureNode> pSNode(new SmTableNode(m_aCurToken));
NextToken(); NextToken();
...@@ -2175,7 +2185,7 @@ void SmParser::DoBinom() ...@@ -2175,7 +2185,7 @@ void SmParser::DoBinom()
} }
pSNode->SetSubNodes(ExpressionArray); pSNode->SetSubNodes(ExpressionArray);
m_aNodeStack.push_front(pSNode); m_aNodeStack.push_front(std::move(pSNode));
} }
void SmParser::DoStack() void SmParser::DoStack()
...@@ -2210,9 +2220,9 @@ void SmParser::DoStack() ...@@ -2210,9 +2220,9 @@ void SmParser::DoStack()
//it's used in SmNodeToTextVisitor //it's used in SmNodeToTextVisitor
SmToken aTok = m_aCurToken; SmToken aTok = m_aCurToken;
aTok.eType = TSTACK; aTok.eType = TSTACK;
SmStructureNode *pSNode = new SmTableNode(aTok); std::unique_ptr<SmStructureNode> pSNode(new SmTableNode(aTok));
pSNode->SetSubNodes(ExpressionArray); pSNode->SetSubNodes(ExpressionArray);
m_aNodeStack.push_front(pSNode); m_aNodeStack.push_front(std::move(pSNode));
} }
else else
Error(PE_LGROUP_EXPECTED); Error(PE_LGROUP_EXPECTED);
...@@ -2271,10 +2281,10 @@ void SmParser::DoMatrix() ...@@ -2271,10 +2281,10 @@ void SmParser::DoMatrix()
NextToken(); NextToken();
SmMatrixNode *pMNode = new SmMatrixNode(m_aCurToken); std::unique_ptr<SmMatrixNode> pMNode(new SmMatrixNode(m_aCurToken));
pMNode->SetSubNodes(ExpressionArray); pMNode->SetSubNodes(ExpressionArray);
pMNode->SetRowCol(r, c); pMNode->SetRowCol(r, c);
m_aNodeStack.push_front(pMNode); m_aNodeStack.push_front(std::move(pMNode));
} }
else else
Error(PE_LGROUP_EXPECTED); Error(PE_LGROUP_EXPECTED);
...@@ -2317,13 +2327,13 @@ void SmParser::DoSpecial() ...@@ -2317,13 +2327,13 @@ void SmParser::DoSpecial()
if (!aSymbolName.isEmpty()) if (!aSymbolName.isEmpty())
AddToUsedSymbols( aSymbolName ); AddToUsedSymbols( aSymbolName );
m_aNodeStack.push_front(new SmSpecialNode(m_aCurToken)); m_aNodeStack.push_front(o3tl::make_unique<SmSpecialNode>(m_aCurToken));
NextToken(); NextToken();
} }
void SmParser::DoGlyphSpecial() void SmParser::DoGlyphSpecial()
{ {
m_aNodeStack.push_front(new SmGlyphSpecialNode(m_aCurToken)); m_aNodeStack.push_front(o3tl::make_unique<SmGlyphSpecialNode>(m_aCurToken));
NextToken(); NextToken();
} }
...@@ -2336,7 +2346,7 @@ void SmParser::Error(SmParseError eError) ...@@ -2336,7 +2346,7 @@ void SmParser::Error(SmParseError eError)
//! put a structure node on the stack (instead of the error node itself) //! put a structure node on the stack (instead of the error node itself)
//! because sometimes such a node is expected in order to attach some //! because sometimes such a node is expected in order to attach some
//! subnodes //! subnodes
m_aNodeStack.push_front(pSNode); m_aNodeStack.push_front(std::unique_ptr<SmStructureNode>(pSNode));
AddError(eError, pSNode); AddError(eError, pSNode);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment