[Libreoffice-commits] core.git: starmath/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Thu Sep 13 06:31:02 UTC 2018


 starmath/source/cursor.cxx       |   24 ++++++-------
 starmath/source/mathmlexport.cxx |   68 ++++++++++++++++-----------------------
 2 files changed, 39 insertions(+), 53 deletions(-)

New commits:
commit 4b4a6d43a8cff2bc335f813d5c300bad14a9ba6e
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Wed Sep 12 10:25:55 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu Sep 13 08:30:34 2018 +0200

    loplugin:useuniqeptr in starmath
    
    Change-Id: I2a62b63f17b7a9daf4d42f2e9d7272d3b78bdf7f
    Reviewed-on: https://gerrit.libreoffice.org/60408
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/starmath/source/cursor.cxx b/starmath/source/cursor.cxx
index cc0037f2ef85..a1ada63bede4 100644
--- a/starmath/source/cursor.cxx
+++ b/starmath/source/cursor.cxx
@@ -513,10 +513,10 @@ void SmCursor::InsertSubSup(SmSubSup eSubSup) {
     NodeToList(pLine, *pLineList);
 
     //Take the selection, and/or find iterator for current position
-    SmNodeList* pSelectedNodesList = new SmNodeList;
+    std::unique_ptr<SmNodeList> pSelectedNodesList(new SmNodeList);
     SmNodeList::iterator it;
     if(HasSelection())
-        it = TakeSelectedNodesFromList(pLineList.get(), pSelectedNodesList);
+        it = TakeSelectedNodesFromList(pLineList.get(), pSelectedNodesList.get());
     else
         it = FindPositionInLineList(pLineList.get(), mpPosition->CaretPos);
 
@@ -563,8 +563,7 @@ void SmCursor::InsertSubSup(SmSubSup eSubSup) {
     //Add selection to pScriptLineList
     unsigned int nOldSize = pScriptLineList->size();
     pScriptLineList->insert(pScriptLineList->end(), pSelectedNodesList->begin(), pSelectedNodesList->end());
-    delete pSelectedNodesList;
-    pSelectedNodesList = nullptr;
+    pSelectedNodesList.reset();
 
     //Patch pScriptLineList if needed
     if(0 < nOldSize && nOldSize < pScriptLineList->size()) {
@@ -613,10 +612,10 @@ void SmCursor::InsertBrackets(SmBracketType eBracketType) {
     NodeToList(pLine, *pLineList);
 
     //Take the selection, and/or find iterator for current position
-    SmNodeList *pSelectedNodesList = new SmNodeList;
+    std::unique_ptr<SmNodeList> pSelectedNodesList(new SmNodeList);
     SmNodeList::iterator it;
     if(HasSelection())
-        it = TakeSelectedNodesFromList(pLineList.get(), pSelectedNodesList);
+        it = TakeSelectedNodesFromList(pLineList.get(), pSelectedNodesList.get());
     else
         it = FindPositionInLineList(pLineList.get(), mpPosition->CaretPos);
 
@@ -627,9 +626,9 @@ void SmCursor::InsertBrackets(SmBracketType eBracketType) {
         pBodyNode = new SmPlaceNode();
         PosAfterInsert = SmCaretPos(pBodyNode, 1);
     } else
-        pBodyNode = SmNodeListParser().Parse(pSelectedNodesList);
+        pBodyNode = SmNodeListParser().Parse(pSelectedNodesList.get());
 
-    delete pSelectedNodesList;
+    pSelectedNodesList.reset();
 
     //Create SmBraceNode
     SmToken aTok(TLEFT, '\0', "left", TG::NONE, 5);
@@ -830,10 +829,10 @@ void SmCursor::InsertFraction() {
     NodeToList(pLine, *pLineList);
 
     //Take the selection, and/or find iterator for current position
-    SmNodeList* pSelectedNodesList = new SmNodeList;
+    std::unique_ptr<SmNodeList> pSelectedNodesList(new SmNodeList);
     SmNodeList::iterator it;
     if(HasSelection())
-        it = TakeSelectedNodesFromList(pLineList.get(), pSelectedNodesList);
+        it = TakeSelectedNodesFromList(pLineList.get(), pSelectedNodesList.get());
     else
         it = FindPositionInLineList(pLineList.get(), mpPosition->CaretPos);
 
@@ -841,10 +840,9 @@ void SmCursor::InsertFraction() {
     bool bEmptyFraction = pSelectedNodesList->empty();
     SmNode *pNum = bEmptyFraction
         ? new SmPlaceNode()
-        : SmNodeListParser().Parse(pSelectedNodesList);
+        : SmNodeListParser().Parse(pSelectedNodesList.get());
     SmNode *pDenom = new SmPlaceNode();
-    delete pSelectedNodesList;
-    pSelectedNodesList = nullptr;
+    pSelectedNodesList.reset();
 
     //Create new fraction
     SmBinVerNode *pFrac = new SmBinVerNode(SmToken(TOVER, '\0', "over", TG::Product, 0));
diff --git a/starmath/source/mathmlexport.cxx b/starmath/source/mathmlexport.cxx
index 1ba6adce7c30..52b417622eaf 100644
--- a/starmath/source/mathmlexport.cxx
+++ b/starmath/source/mathmlexport.cxx
@@ -466,12 +466,12 @@ void SmXMLExport::ExportContent_()
         AddAttribute(XML_NAMESPACE_MATH, XML_DISPLAY, XML_BLOCK);
     }
     SvXMLElementExport aEquation(*this, XML_NAMESPACE_MATH, XML_MATH, true, true);
-    SvXMLElementExport *pSemantics=nullptr;
+    std::unique_ptr<SvXMLElementExport> pSemantics;
 
     if (!aText.isEmpty())
     {
-        pSemantics = new SvXMLElementExport(*this, XML_NAMESPACE_MATH,
-            XML_SEMANTICS, true, true);
+        pSemantics.reset( new SvXMLElementExport(*this, XML_NAMESPACE_MATH,
+            XML_SEMANTICS, true, true) );
     }
 
     ExportNodes(pTree, 0);
@@ -496,7 +496,6 @@ void SmXMLExport::ExportContent_()
             XML_ANNOTATION, true, false);
         GetDocHandler()->characters( aText );
     }
-    delete pSemantics;
 }
 
 void SmXMLExport::GetViewSettings( Sequence < PropertyValue >& aProps)
@@ -630,21 +629,19 @@ void SmXMLExport::ExportUnaryHorizontal(const SmNode *pNode, int nLevel)
 void SmXMLExport::ExportExpression(const SmNode *pNode, int nLevel,
                                    bool bNoMrowContainer /*=false*/)
 {
-    SvXMLElementExport *pRow=nullptr;
+    std::unique_ptr<SvXMLElementExport> pRow;
     size_t nSize = pNode->GetNumSubNodes();
 
     // #i115443: nodes of type expression always need to be grouped with mrow statement
     if (!bNoMrowContainer &&
         (nSize > 1 || pNode->GetType() == SmNodeType::Expression))
-        pRow = new SvXMLElementExport(*this, XML_NAMESPACE_MATH, XML_MROW, true, true);
+        pRow.reset(new SvXMLElementExport(*this, XML_NAMESPACE_MATH, XML_MROW, true, true));
 
     for (size_t i = 0; i < nSize; ++i)
     {
         if (const SmNode *pTemp = pNode->GetSubNode(i))
             ExportNodes(pTemp, nLevel+1);
     }
-
-    delete pRow;
 }
 
 void SmXMLExport::ExportBinaryVertical(const SmNode *pNode, int nLevel)
@@ -707,7 +704,7 @@ void SmXMLExport::ExportBinaryDiagonal(const SmNode *pNode, int nLevel)
 
 void SmXMLExport::ExportTable(const SmNode *pNode, int nLevel)
 {
-    SvXMLElementExport *pTable=nullptr;
+    std::unique_ptr<SvXMLElementExport> pTable;
 
     size_t nSize = pNode->GetNumSubNodes();
 
@@ -727,7 +724,7 @@ void SmXMLExport::ExportTable(const SmNode *pNode, int nLevel)
     // try to avoid creating a mtable element when the formula consists only
     // of a single output line
     if (nLevel || (nSize >1))
-        pTable = new SvXMLElementExport(*this, XML_NAMESPACE_MATH, XML_MTABLE, true, true);
+        pTable.reset(new SvXMLElementExport(*this, XML_NAMESPACE_MATH, XML_MTABLE, true, true));
 
     for (size_t i = 0; i < nSize; ++i)
     {
@@ -771,26 +768,24 @@ void SmXMLExport::ExportTable(const SmNode *pNode, int nLevel)
             delete pRow;
         }
     }
-
-    delete pTable;
 }
 
 void SmXMLExport::ExportMath(const SmNode *pNode)
 {
     const SmTextNode *pTemp = static_cast<const SmTextNode *>(pNode);
-    SvXMLElementExport *pMath = nullptr;
+    std::unique_ptr<SvXMLElementExport> pMath;
 
     if (pNode->GetType() == SmNodeType::Math || pNode->GetType() == SmNodeType::GlyphSpecial)
     {
         // Export SmNodeType::Math and SmNodeType::GlyphSpecial symbols as <mo> elements
-        pMath = new SvXMLElementExport(*this, XML_NAMESPACE_MATH, XML_MO, true, false);
+        pMath.reset(new SvXMLElementExport(*this, XML_NAMESPACE_MATH, XML_MO, true, false));
     }
     else if (pNode->GetType() == SmNodeType::Special)
     {
         bool bIsItalic = IsItalic(pNode->GetFont());
         if (!bIsItalic)
             AddAttribute(XML_NAMESPACE_MATH, XML_MATHVARIANT, XML_NORMAL);
-        pMath = new SvXMLElementExport(*this, XML_NAMESPACE_MATH, XML_MI, true, false);
+        pMath.reset(new SvXMLElementExport(*this, XML_NAMESPACE_MATH, XML_MI, true, false));
     }
     else
     {
@@ -803,7 +798,7 @@ void SmXMLExport::ExportMath(const SmNode *pNode)
         // placeholders but they won't be visible in most MathML rendering
         // engines so let's use an empty square for SmNodeType::Place instead.
         AddAttribute(XML_NAMESPACE_MATH, XML_MATHVARIANT, XML_NORMAL);
-        pMath = new SvXMLElementExport(*this, XML_NAMESPACE_MATH, XML_MI, true, false);
+        pMath.reset(new SvXMLElementExport(*this, XML_NAMESPACE_MATH, XML_MI, true, false));
     }
     sal_Unicode nArse[2];
     nArse[0] = pTemp->GetText()[0];
@@ -813,13 +808,11 @@ void SmXMLExport::ExportMath(const SmNode *pNode)
     OSL_ENSURE(nArse[0] != 0xffff,"Non existent symbol");
     nArse[1] = 0;
     GetDocHandler()->characters(nArse);
-
-    delete pMath;
 }
 
 void SmXMLExport::ExportText(const SmNode *pNode)
 {
-    SvXMLElementExport *pText;
+    std::unique_ptr<SvXMLElementExport> pText;
     const SmTextNode *pTemp = static_cast<const SmTextNode *>(pNode);
     switch (pNode->GetToken().eType)
     {
@@ -833,18 +826,17 @@ void SmXMLExport::ExportText(const SmNode *pNode)
                 AddAttribute(XML_NAMESPACE_MATH, XML_MATHVARIANT, XML_ITALIC);
             else if ((pTemp->GetText().getLength() == 1) && !bIsItalic)
                 AddAttribute(XML_NAMESPACE_MATH, XML_MATHVARIANT, XML_NORMAL);
-            pText = new SvXMLElementExport(*this, XML_NAMESPACE_MATH, XML_MI, true, false);
+            pText.reset(new SvXMLElementExport(*this, XML_NAMESPACE_MATH, XML_MI, true, false));
             break;
         }
         case TNUMBER:
-            pText = new SvXMLElementExport(*this, XML_NAMESPACE_MATH, XML_MN, true, false);
+            pText.reset(new SvXMLElementExport(*this, XML_NAMESPACE_MATH, XML_MN, true, false));
             break;
         case TTEXT:
-            pText = new SvXMLElementExport(*this, XML_NAMESPACE_MATH, XML_MTEXT, true, false);
+            pText.reset(new SvXMLElementExport(*this, XML_NAMESPACE_MATH, XML_MTEXT, true, false));
             break;
         }
     GetDocHandler()->characters(pTemp->GetText());
-    delete pText;
 }
 
 void SmXMLExport::ExportBlank(const SmNode *pNode)
@@ -865,13 +857,11 @@ void SmXMLExport::ExportBlank(const SmNode *pNode)
         AddAttribute(XML_NAMESPACE_MATH, XML_WIDTH, sStrBuf.getStr());
     }
 
-    SvXMLElementExport *pText;
-
-    pText = new SvXMLElementExport(*this, XML_NAMESPACE_MATH, XML_MSPACE,
-        true, false);
+    std::unique_ptr<SvXMLElementExport> pText(
+        new SvXMLElementExport(*this, XML_NAMESPACE_MATH, XML_MSPACE,
+                                true, false));
 
     GetDocHandler()->characters( OUString() );
-    delete pText;
 }
 
 void SmXMLExport::ExportSubSupScript(const SmNode *pNode, int nLevel)
@@ -1020,7 +1010,6 @@ void SmXMLExport::ExportBrace(const SmNode *pNode, int nLevel)
     const SmNode *pTemp;
     const SmNode *pLeft=pNode->GetSubNode(0);
     const SmNode *pRight=pNode->GetSubNode(2);
-    SvXMLElementExport *pRow=nullptr;
 
     // This used to generate <mfenced> or <mrow>+<mo> elements according to
     // the stretchiness of fences. The MathML recommendation defines an
@@ -1031,8 +1020,9 @@ void SmXMLExport::ExportBrace(const SmNode *pNode, int nLevel)
     // See #fdo 66282.
 
     // <mrow>
-    pRow = new SvXMLElementExport(*this, XML_NAMESPACE_MATH, XML_MROW,
-        true, true);
+    std::unique_ptr<SvXMLElementExport> pRow(
+            new SvXMLElementExport(*this, XML_NAMESPACE_MATH, XML_MROW,
+                                    true, true));
 
     //   <mo fence="true"> opening-fence </mo>
     if (pLeft && (pLeft->GetToken().eType != TNONE))
@@ -1065,7 +1055,6 @@ void SmXMLExport::ExportBrace(const SmNode *pNode, int nLevel)
         ExportNodes(pRight, nLevel+1);
     }
 
-    delete pRow;
     // </mrow>
 }
 
@@ -1098,28 +1087,28 @@ void SmXMLExport::ExportOperator(const SmNode *pNode, int nLevel)
 
 void SmXMLExport::ExportAttributes(const SmNode *pNode, int nLevel)
 {
-    SvXMLElementExport *pElement=nullptr;
+    std::unique_ptr<SvXMLElementExport> pElement;
 
     if (pNode->GetToken().eType == TUNDERLINE)
     {
         AddAttribute(XML_NAMESPACE_MATH, XML_ACCENTUNDER,
             XML_TRUE);
-        pElement = new SvXMLElementExport(*this, XML_NAMESPACE_MATH, XML_MUNDER,
-            true, true);
+        pElement.reset(new SvXMLElementExport(*this, XML_NAMESPACE_MATH, XML_MUNDER,
+            true, true));
     }
     else if (pNode->GetToken().eType == TOVERSTRIKE)
     {
         // export as <menclose notation="horizontalstrike">
         AddAttribute(XML_NAMESPACE_MATH, XML_NOTATION, XML_HORIZONTALSTRIKE);
-        pElement = new SvXMLElementExport(*this, XML_NAMESPACE_MATH,
-            XML_MENCLOSE, true, true);
+        pElement.reset(new SvXMLElementExport(*this, XML_NAMESPACE_MATH,
+            XML_MENCLOSE, true, true));
     }
     else
     {
         AddAttribute(XML_NAMESPACE_MATH, XML_ACCENT,
             XML_TRUE);
-        pElement = new SvXMLElementExport(*this, XML_NAMESPACE_MATH, XML_MOVER,
-            true, true);
+        pElement.reset(new SvXMLElementExport(*this, XML_NAMESPACE_MATH, XML_MOVER,
+            true, true));
     }
 
     ExportNodes(pNode->GetSubNode(1), nLevel+1);
@@ -1158,7 +1147,6 @@ void SmXMLExport::ExportAttributes(const SmNode *pNode, int nLevel)
             ExportNodes(pNode->GetSubNode(0), nLevel+1);
             break;
     }
-    delete pElement;
 }
 
 static bool lcl_HasEffectOnMathvariant( const SmTokenType eType )


More information about the Libreoffice-commits mailing list