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

Takeshi Abe tabe at fixedpoint.jp
Mon Jan 22 05:26:27 UTC 2018


 starmath/inc/document.hxx                       |    6 ++---
 starmath/inc/parse.hxx                          |    4 +--
 starmath/qa/cppunit/test_cursor.cxx             |    8 +++----
 starmath/qa/cppunit/test_node.cxx               |    8 +++----
 starmath/qa/cppunit/test_nodetotextvisitors.cxx |   26 +++++++-----------------
 starmath/qa/cppunit/test_parse.cxx              |    4 +--
 starmath/source/document.cxx                    |   19 +++++++----------
 starmath/source/mathmlexport.cxx                |    4 +--
 starmath/source/mathmlimport.cxx                |    4 +--
 starmath/source/node.cxx                        |    2 -
 starmath/source/parse.cxx                       |    6 ++---
 11 files changed, 39 insertions(+), 52 deletions(-)

New commits:
commit f3d1b2e58c39618d99bf017702ef19f373464b34
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date:   Thu Jan 18 18:20:12 2018 +0900

    starmath: Make SmParser::Parse() return std::unique_ptr
    
    Change-Id: I6c8811f71ab40398043cdcfa3334eee4381b4c7e
    Reviewed-on: https://gerrit.libreoffice.org/48098
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Takeshi Abe <tabe at fixedpoint.jp>

diff --git a/starmath/inc/document.hxx b/starmath/inc/document.hxx
index 2d6e63da5f2f..af2ce9475fc3 100644
--- a/starmath/inc/document.hxx
+++ b/starmath/inc/document.hxx
@@ -89,7 +89,7 @@ class SM_DLLPUBLIC SmDocShell : public SfxObjectShell, public SfxListener
     SmParser            maParser;
     OUString            maAccText;
     SvtLinguOptions     maLinguOptions;
-    SmTableNode        *mpTree;
+    std::unique_ptr<SmTableNode> mpTree;
     SfxItemPool        *mpEditEngineItemPool;
     EditEngine         *mpEditEngine;
     VclPtr<SfxPrinter>  mpPrinter;       //q.v. comment to SmPrinter Access!
@@ -177,8 +177,8 @@ public:
 
     void            Parse();
     SmParser &      GetParser() { return maParser; }
-    const SmTableNode *GetFormulaTree() const  { return mpTree; }
-    void            SetFormulaTree(SmTableNode *pTree) { mpTree = pTree; }
+    const SmTableNode *GetFormulaTree() const  { return mpTree.get(); }
+    void            SetFormulaTree(SmTableNode *pTree) { mpTree.reset(pTree); }
 
     const std::set< OUString > &    GetUsedSymbols() const  { return maUsedSymbols; }
 
diff --git a/starmath/inc/parse.hxx b/starmath/inc/parse.hxx
index 5c4646e28eb8..a2faa73a3b40 100644
--- a/starmath/inc/parse.hxx
+++ b/starmath/inc/parse.hxx
@@ -78,7 +78,7 @@ class SmParser
     inline bool     TokenInGroup( TG nGroup );
 
     // grammar
-    SmTableNode *DoTable();
+    std::unique_ptr<SmTableNode> DoTable();
     SmLineNode *DoLine();
     std::unique_ptr<SmNode> DoExpression(bool bUseExtraSpaces = true);
     SmNode *DoRelation();
@@ -114,7 +114,7 @@ public:
                  SmParser();
 
     /** Parse rBuffer to formula tree */
-    SmTableNode *Parse(const OUString &rBuffer);
+    std::unique_ptr<SmTableNode> Parse(const OUString &rBuffer);
     /** Parse rBuffer to formula subtree that constitutes an expression */
     std::unique_ptr<SmNode> ParseExpression(const OUString &rBuffer);
 
diff --git a/starmath/qa/cppunit/test_cursor.cxx b/starmath/qa/cppunit/test_cursor.cxx
index 702777a614f8..403994707d27 100644
--- a/starmath/qa/cppunit/test_cursor.cxx
+++ b/starmath/qa/cppunit/test_cursor.cxx
@@ -68,7 +68,7 @@ void Test::tearDown()
 void Test::testCopyPaste()
 {
     OUString const sInput("a * b + c");
-    std::unique_ptr<SmNode> xTree(SmParser().Parse(sInput));
+    auto xTree = SmParser().Parse(sInput);
     xTree->Prepare(xDocShRef->GetFormat(), *xDocShRef, 0);
 
     SmCursor aCursor(xTree.get(), xDocShRef.get());
@@ -91,7 +91,7 @@ void Test::testCopyPaste()
 void Test::testCopySelectPaste()
 {
     OUString const sInput("a * b + c");
-    std::unique_ptr<SmNode> xTree(SmParser().Parse(sInput));
+    auto xTree = SmParser().Parse(sInput);
     xTree->Prepare(xDocShRef->GetFormat(), *xDocShRef, 0);
 
     SmCursor aCursor(xTree.get(), xDocShRef.get());
@@ -118,7 +118,7 @@ void Test::testCopySelectPaste()
 void Test::testCutPaste()
 {
     OUString const sInput("a * b + c");
-    std::unique_ptr<SmNode> xTree(SmParser().Parse(sInput));
+    auto xTree = SmParser().Parse(sInput);
     xTree->Prepare(xDocShRef->GetFormat(), *xDocShRef, 0);
 
     SmCursor aCursor(xTree.get(), xDocShRef.get());
@@ -141,7 +141,7 @@ void Test::testCutPaste()
 void Test::testCutSelectPaste()
 {
     OUString const sInput("a * b + c");
-    std::unique_ptr<SmNode> xTree(SmParser().Parse(sInput));
+    auto xTree = SmParser().Parse(sInput);
     xTree->Prepare(xDocShRef->GetFormat(), *xDocShRef, 0);
 
     SmCursor aCursor(xTree.get(), xDocShRef.get());
diff --git a/starmath/qa/cppunit/test_node.cxx b/starmath/qa/cppunit/test_node.cxx
index 2a35bdffbe4c..ebf0682f531e 100644
--- a/starmath/qa/cppunit/test_node.cxx
+++ b/starmath/qa/cppunit/test_node.cxx
@@ -64,10 +64,10 @@ void NodeTest::testTdf47813()
 {
     SmParser aParser;
 #define MATRIX "matrix {-2#33##4#-5##6,0#7}"
-    std::unique_ptr<SmTableNode> pNodeA(aParser.Parse(MATRIX));
-    std::unique_ptr<SmTableNode> pNodeC(aParser.Parse("alignc " MATRIX));
-    std::unique_ptr<SmTableNode> pNodeL(aParser.Parse("alignl " MATRIX));
-    std::unique_ptr<SmTableNode> pNodeR(aParser.Parse("alignr " MATRIX));
+    auto pNodeA = aParser.Parse(MATRIX);
+    auto pNodeC = aParser.Parse("alignc " MATRIX);
+    auto pNodeL = aParser.Parse("alignl " MATRIX);
+    auto pNodeR = aParser.Parse("alignr " MATRIX);
 #undef MATRIX
     ScopedVclPtrInstance<VirtualDevice> pOutputDevice;
     SmFormat aFmt;
diff --git a/starmath/qa/cppunit/test_nodetotextvisitors.cxx b/starmath/qa/cppunit/test_nodetotextvisitors.cxx
index 5399e68ec338..5c92b712334b 100644
--- a/starmath/qa/cppunit/test_nodetotextvisitors.cxx
+++ b/starmath/qa/cppunit/test_nodetotextvisitors.cxx
@@ -503,14 +503,13 @@ void Test::ParseAndCompare(const char *formula1, const char *formula2, const cha
 void Test::testBinomInBinHor()
 {
     OUString sInput, sExpected;
-    SmNode* pTree;
 
     // set up a binom (table) node
     sInput += "binom a b + c";
-    pTree = SmParser().Parse(sInput);
+    auto pTree = SmParser().Parse(sInput);
     pTree->Prepare(xDocShRef->GetFormat(), *xDocShRef, 0);
 
-    SmCursor aCursor(pTree, xDocShRef.get());
+    SmCursor aCursor(pTree.get(), xDocShRef.get());
     ScopedVclPtrInstance< VirtualDevice > pOutputDevice;
 
     // move forward (more than) enough places to be at the end
@@ -524,21 +523,18 @@ void Test::testBinomInBinHor()
 
     sExpected += " { { binom a b + c } + d } ";
     CPPUNIT_ASSERT_EQUAL_MESSAGE("Binom Node in BinHor Node", sExpected, xDocShRef->GetText());
-
-    delete pTree;
 }
 
 void Test::testBinVerInUnary()
 {
     OUString sInput, sExpected;
-    SmNode* pTree;
 
     // set up a unary operator with operand
     sInput += "- 1";
-    pTree = SmParser().Parse(sInput);
+    auto pTree = SmParser().Parse(sInput);
     pTree->Prepare(xDocShRef->GetFormat(), *xDocShRef, 0);
 
-    SmCursor aCursor(pTree, xDocShRef.get());
+    SmCursor aCursor(pTree.get(), xDocShRef.get());
     ScopedVclPtrInstance< VirtualDevice > pOutputDevice;
 
     // move forward (more than) enough places to be at the end
@@ -555,17 +551,15 @@ void Test::testBinVerInUnary()
 
     sExpected += " - { 1 over 2 } ";
     CPPUNIT_ASSERT_EQUAL_MESSAGE("Binary Vertical in Unary Operator", sExpected, xDocShRef->GetText());
-
-    delete pTree;
 }
 
 void Test::testBinHorInSubSup()
 {
     // set up a blank formula
-    SmNode* pTree = SmParser().Parse(OUString());
+    auto pTree = SmParser().Parse(OUString());
     pTree->Prepare(xDocShRef->GetFormat(), *xDocShRef, 0);
 
-    SmCursor aCursor(pTree, xDocShRef.get());
+    SmCursor aCursor(pTree.get(), xDocShRef.get());
     ScopedVclPtrInstance< VirtualDevice > pOutputDevice;
 
     // Insert an RSup expression with a BinHor for the exponent
@@ -582,18 +576,16 @@ void Test::testBinHorInSubSup()
 
     OUString sExpected = " { a ^ { b + c } + d } ";
     CPPUNIT_ASSERT_EQUAL_MESSAGE("BinHor in SubSup", sExpected, xDocShRef->GetText());
-
-    delete pTree;
 }
 
 void Test::testUnaryInMixedNumberAsNumerator()
 {
     // set up a unary operator
     OUString sInput = "- 1";
-    SmNode* pTree = SmParser().Parse(sInput);
+    auto pTree = SmParser().Parse(sInput);
     pTree->Prepare(xDocShRef->GetFormat(), *xDocShRef, 0);
 
-    SmCursor aCursor(pTree, xDocShRef.get());
+    SmCursor aCursor(pTree.get(), xDocShRef.get());
     ScopedVclPtrInstance< VirtualDevice > pOutputDevice;
 
     // move forward (more than) enough places to be at the end
@@ -625,8 +617,6 @@ void Test::testUnaryInMixedNumberAsNumerator()
 
     OUString sExpected = " { 2 { - 1 over 2 } + 4 } ";
     CPPUNIT_ASSERT_EQUAL_MESSAGE("Unary in mixed number as Numerator", sExpected, xDocShRef->GetText());
-
-    delete pTree;
 }
 
 void Test::testMiscEquivalent()
diff --git a/starmath/qa/cppunit/test_parse.cxx b/starmath/qa/cppunit/test_parse.cxx
index c99a80568839..ff5a12e72425 100644
--- a/starmath/qa/cppunit/test_parse.cxx
+++ b/starmath/qa/cppunit/test_parse.cxx
@@ -65,7 +65,7 @@ void ParseTest::tearDown()
  */
 void ParseTest::testMinus()
 {
-    std::unique_ptr<SmTableNode> pNode(SmParser().Parse("-1.2"));
+    auto pNode = SmParser().Parse("-1.2");
     CPPUNIT_ASSERT_EQUAL(size_t(1), pNode->GetNumSubNodes());
     const SmNode *pNode0 = pNode->GetSubNode(0);
     CPPUNIT_ASSERT(pNode0);
@@ -98,7 +98,7 @@ void ParseTest::testMinus()
  */
 void ParseTest::testNospace()
 {
-    std::unique_ptr<SmTableNode> pNode(SmParser().Parse("nospace{ nitalic d {F(x) G(x)} }"));
+    auto pNode = SmParser().Parse("nospace{ nitalic d {F(x) G(x)} }");
     CPPUNIT_ASSERT_EQUAL(size_t(1), pNode->GetNumSubNodes());
     const SmNode *pNode0 = pNode->GetSubNode(0);
     CPPUNIT_ASSERT(pNode0);
diff --git a/starmath/source/document.cxx b/starmath/source/document.cxx
index 2d5a29e2f6ba..d1ab6b0d02fe 100644
--- a/starmath/source/document.cxx
+++ b/starmath/source/document.cxx
@@ -213,7 +213,7 @@ OUString const & SmDocShell::GetAccessibleText()
 
 void SmDocShell::Parse()
 {
-    delete mpTree;
+    mpTree.reset();
     ReplaceBadChars();
     mpTree = maParser.Parse(maText);
     mnModifyCount++;     //! see comment for SID_GAPHIC_SM in SmDocShell::GetState
@@ -412,11 +412,11 @@ void SmDocShell::DrawFormula(OutputDevice &rDev, Point &rPosition, bool bDrawSel
     //Set selection if any
     if(mpCursor && bDrawSelection){
         mpCursor->AnnotateSelection();
-        SmSelectionDrawingVisitor(rDev, mpTree, rPosition);
+        SmSelectionDrawingVisitor(rDev, mpTree.get(), rPosition);
     }
 
     //Drawing using visitor
-    SmDrawingVisitor(rDev, rPosition, mpTree);
+    SmDrawingVisitor(rDev, rPosition, mpTree.get());
 
 
     rDev.SetLayoutMode( nLayoutMode );
@@ -459,7 +459,7 @@ void SmDocShell::InvalidateCursor(){
 
 SmCursor& SmDocShell::GetCursor(){
     if(!mpCursor)
-        mpCursor.reset(new SmCursor(mpTree, this));
+        mpCursor.reset(new SmCursor(mpTree.get(), this));
     return *mpCursor;
 }
 
@@ -611,7 +611,6 @@ void SmDocShell::Repaint()
 
 SmDocShell::SmDocShell( SfxModelFlags i_nSfxCreationFlags )
     : SfxObjectShell(i_nSfxCreationFlags)
-    , mpTree(nullptr)
     , mpEditEngineItemPool(nullptr)
     , mpEditEngine(nullptr)
     , mpPrinter(nullptr)
@@ -642,7 +641,6 @@ SmDocShell::~SmDocShell()
     mpCursor.reset();
     delete mpEditEngine;
     SfxItemPool::Free(mpEditEngineItemPool);
-    delete mpTree;
     mpPrinter.disposeAndClear();
 }
 
@@ -657,8 +655,7 @@ bool SmDocShell::ConvertFrom(SfxMedium &rMedium)
     {
         if (mpTree)
         {
-            delete mpTree;
-            mpTree = nullptr;
+            mpTree.reset();
             InvalidateCursor();
         }
         Reference<css::frame::XModel> xModel(GetModel());
@@ -867,7 +864,7 @@ void SmDocShell::writeFormulaOoxml(
         Parse();
     if( mpTree )
         ArrangeFormula();
-    SmOoxmlExport aEquation(mpTree, version, documentType);
+    SmOoxmlExport aEquation(mpTree.get(), version, documentType);
     aEquation.ConvertFromStarMath( pSerializer );
 }
 
@@ -877,7 +874,7 @@ void SmDocShell::writeFormulaRtf(OStringBuffer& rBuffer, rtl_TextEncoding nEncod
         Parse();
     if (mpTree)
         ArrangeFormula();
-    SmRtfExport aEquation(mpTree);
+    SmRtfExport aEquation(mpTree.get());
     aEquation.ConvertFromStarMath(rBuffer, nEncoding);
 }
 
@@ -1287,7 +1284,7 @@ void SmDocShell::SetModified(bool bModified)
 
 bool SmDocShell::WriteAsMathType3( SfxMedium& rMedium )
 {
-    MathType aEquation( maText, mpTree );
+    MathType aEquation( maText, mpTree.get() );
     return aEquation.ConvertFromStarMath( rMedium );
 }
 
diff --git a/starmath/source/mathmlexport.cxx b/starmath/source/mathmlexport.cxx
index 780bf226c6ef..61827cefa36d 100644
--- a/starmath/source/mathmlexport.cxx
+++ b/starmath/source/mathmlexport.cxx
@@ -482,9 +482,9 @@ void SmXMLExport::ExportContent_()
             SmParser &rParser = pDocShell->GetParser();
             bool bVal = rParser.IsExportSymbolNames();
             rParser.SetExportSymbolNames( true );
-            SmNode *pTmpTree = rParser.Parse( aText );
+            auto pTmpTree = rParser.Parse( aText );
             aText = rParser.GetText();
-            delete pTmpTree;
+            pTmpTree.reset();
             rParser.SetExportSymbolNames( bVal );
         }
 
diff --git a/starmath/source/mathmlimport.cxx b/starmath/source/mathmlimport.cxx
index 62a705cae930..b22cb0c5387b 100644
--- a/starmath/source/mathmlimport.cxx
+++ b/starmath/source/mathmlimport.cxx
@@ -516,9 +516,9 @@ void SmXMLImport::endDocument()
             SmParser &rParser = pDocShell->GetParser();
             bool bVal = rParser.IsImportSymbolNames();
             rParser.SetImportSymbolNames( true );
-            SmNode *pTmpTree = rParser.Parse( aText );
+            auto pTmpTree = rParser.Parse( aText );
             aText = rParser.GetText();
-            delete pTmpTree;
+            pTmpTree.reset();
             rParser.SetImportSymbolNames( bVal );
 
             pDocShell->SetText( aText );
diff --git a/starmath/source/node.cxx b/starmath/source/node.cxx
index b7a138e2da9b..d44845411267 100644
--- a/starmath/source/node.cxx
+++ b/starmath/source/node.cxx
@@ -2097,7 +2097,7 @@ void SmTextNode::CreateTextFromNode(OUString &rText)
     else
     {
         SmParser aParseTest;
-        std::unique_ptr<SmTableNode> pTable(aParseTest.Parse(GetToken().aText));
+        auto pTable = aParseTest.Parse(GetToken().aText);
         assert(pTable->GetType() == SmNodeType::Table);
         bQuoted=true;
         if (pTable->GetNumSubNodes() == 1)
diff --git a/starmath/source/parse.cxx b/starmath/source/parse.cxx
index 6d299ce1fee5..7e026673a69a 100644
--- a/starmath/source/parse.cxx
+++ b/starmath/source/parse.cxx
@@ -950,7 +950,7 @@ namespace
 
 // grammar
 
-SmTableNode *SmParser::DoTable()
+std::unique_ptr<SmTableNode> SmParser::DoTable()
 {
     DepthProtect aDepthGuard(m_nParseDepth);
     if (aDepthGuard.TooDeep())
@@ -966,7 +966,7 @@ SmTableNode *SmParser::DoTable()
     assert(m_aCurToken.eType == TEND);
     std::unique_ptr<SmTableNode> xSNode(new SmTableNode(m_aCurToken));
     xSNode->SetSubNodes(buildNodeArray(aLineArray));
-    return xSNode.release();
+    return xSNode;
 }
 
 SmNode *SmParser::DoAlign(bool bUseExtraSpaces)
@@ -2314,7 +2314,7 @@ SmParser::SmParser()
 {
 }
 
-SmTableNode *SmParser::Parse(const OUString &rBuffer)
+std::unique_ptr<SmTableNode> SmParser::Parse(const OUString &rBuffer)
 {
     m_aUsedSymbols.clear();
 


More information about the Libreoffice-commits mailing list