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

Noel Grandin noel.grandin at collabora.co.uk
Thu Jul 12 06:31:35 UTC 2018


 sw/source/core/inc/SwGrammarMarkUp.hxx      |    2 +-
 sw/source/core/inc/wrong.hxx                |    2 +-
 sw/source/core/text/SwGrammarMarkUp.cxx     |    4 ++--
 sw/source/core/text/wrong.cxx               |    6 +++---
 sw/source/core/txtnode/SwGrammarContact.cxx |   20 +++++++++-----------
 5 files changed, 16 insertions(+), 18 deletions(-)

New commits:
commit 478d967eeb7ef8247033918da09d022427593f68
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Wed Jul 11 14:05:42 2018 +0200

    loplugin:useuniqueptr in SwGrammarContact
    
    Change-Id: I13b346751a001871fe2db04c0b40a0201d55352b
    Reviewed-on: https://gerrit.libreoffice.org/57304
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sw/source/core/inc/SwGrammarMarkUp.hxx b/sw/source/core/inc/SwGrammarMarkUp.hxx
index f37605556353..535776981ac3 100644
--- a/sw/source/core/inc/SwGrammarMarkUp.hxx
+++ b/sw/source/core/inc/SwGrammarMarkUp.hxx
@@ -41,7 +41,7 @@ public:
     SwGrammarMarkUp() : SwWrongList( WRONGLIST_GRAMMAR ) {}
 
     virtual ~SwGrammarMarkUp() override;
-    virtual SwWrongList* Clone() override;
+    virtual std::unique_ptr<SwWrongList> Clone() override;
     virtual void CopyFrom( const SwWrongList& rCopy ) override;
 
     /* SwWrongList::Move() + handling of maSentence */
diff --git a/sw/source/core/inc/wrong.hxx b/sw/source/core/inc/wrong.hxx
index 0003d54266ba..1f3fe2c8e082 100644
--- a/sw/source/core/inc/wrong.hxx
+++ b/sw/source/core/inc/wrong.hxx
@@ -259,7 +259,7 @@ public:
     SwWrongList( WrongListType eType );
 
     virtual ~SwWrongList();
-    virtual SwWrongList* Clone();
+    virtual std::unique_ptr<SwWrongList> Clone();
     virtual void CopyFrom( const SwWrongList& rCopy );
 
     WrongListType GetWrongListType() const { return meType; }
diff --git a/sw/source/core/text/SwGrammarMarkUp.cxx b/sw/source/core/text/SwGrammarMarkUp.cxx
index a752619d8f81..bf49a899c917 100644
--- a/sw/source/core/text/SwGrammarMarkUp.cxx
+++ b/sw/source/core/text/SwGrammarMarkUp.cxx
@@ -23,9 +23,9 @@ SwGrammarMarkUp::~SwGrammarMarkUp()
 {
 }
 
-SwWrongList* SwGrammarMarkUp::Clone()
+std::unique_ptr<SwWrongList> SwGrammarMarkUp::Clone()
 {
-    SwWrongList* pClone = new SwGrammarMarkUp();
+    std::unique_ptr<SwWrongList> pClone(new SwGrammarMarkUp());
     pClone->CopyFrom( *this );
     return pClone;
 }
diff --git a/sw/source/core/text/wrong.cxx b/sw/source/core/text/wrong.cxx
index d85cf9a99bdf..2ade53ca0036 100644
--- a/sw/source/core/text/wrong.cxx
+++ b/sw/source/core/text/wrong.cxx
@@ -62,9 +62,9 @@ SwWrongList::~SwWrongList()
     ClearList();
 }
 
-SwWrongList* SwWrongList::Clone()
+std::unique_ptr<SwWrongList> SwWrongList::Clone()
 {
-    SwWrongList* pClone = new SwWrongList( meType );
+    std::unique_ptr<SwWrongList> pClone(new SwWrongList( meType ));
     pClone->CopyFrom( *this );
     return pClone;
 }
@@ -78,7 +78,7 @@ void SwWrongList::CopyFrom( const SwWrongList& rCopy )
     for(SwWrongArea & i : maList)
     {
         if( i.mpSubList )
-            i.mpSubList = i.mpSubList->Clone();
+            i.mpSubList = i.mpSubList->Clone().release();
     }
 }
 
diff --git a/sw/source/core/txtnode/SwGrammarContact.cxx b/sw/source/core/txtnode/SwGrammarContact.cxx
index d1ae37a7571d..09402d1950c2 100644
--- a/sw/source/core/txtnode/SwGrammarContact.cxx
+++ b/sw/source/core/txtnode/SwGrammarContact.cxx
@@ -41,14 +41,14 @@
 class SwGrammarContact : public IGrammarContact, public SwClient
 {
     Timer aTimer;
-    SwGrammarMarkUp *mpProxyList;
+    std::unique_ptr<SwGrammarMarkUp> mpProxyList;
     bool mbFinished;
     SwTextNode* getMyTextNode() { return static_cast<SwTextNode*>(GetRegisteredIn()); }
       DECL_LINK( TimerRepaint, Timer *, void );
 
 public:
     SwGrammarContact();
-    virtual ~SwGrammarContact() override { aTimer.Stop(); delete mpProxyList; }
+    virtual ~SwGrammarContact() override { aTimer.Stop(); }
 
     // (pure) virtual functions of IGrammarContact
     virtual void updateCursorPosition( const SwPosition& rNewPos ) override;
@@ -73,7 +73,7 @@ IMPL_LINK( SwGrammarContact, TimerRepaint, Timer *, pTimer, void )
         pTimer->Stop();
         if( GetRegisteredIn() )
         {   //Replace the old wrong list by the proxy list and repaint all frames
-            getMyTextNode()->SetGrammarCheck( mpProxyList );
+            getMyTextNode()->SetGrammarCheck( mpProxyList.get() );
             mpProxyList = nullptr;
             SwTextFrame::repaintTextFrames( *getMyTextNode() );
         }
@@ -91,7 +91,7 @@ void SwGrammarContact::updateCursorPosition( const SwPosition& rNewPos )
         {
             if( mpProxyList )
             {   // replace old list by the proxy list and repaint
-                getMyTextNode()->SetGrammarCheck( mpProxyList );
+                getMyTextNode()->SetGrammarCheck( mpProxyList.get() );
                 SwTextFrame::repaintTextFrames( *getMyTextNode() );
             }
             EndListeningAll();
@@ -112,22 +112,21 @@ SwGrammarMarkUp* SwGrammarContact::getGrammarCheck( SwTextNode& rTextNode, bool
         {
             if( mbFinished )
             {
-                delete mpProxyList;
-                mpProxyList = nullptr;
+                mpProxyList.reset();
             }
             if( !mpProxyList )
             {
                 if( rTextNode.GetGrammarCheck() )
-                    mpProxyList = static_cast<SwGrammarMarkUp*>(rTextNode.GetGrammarCheck()->Clone());
+                    mpProxyList.reset( static_cast<SwGrammarMarkUp*>(rTextNode.GetGrammarCheck()->Clone().release()) );
                 else
                 {
-                    mpProxyList = new SwGrammarMarkUp();
+                    mpProxyList.reset( new SwGrammarMarkUp() );
                     mpProxyList->SetInvalid( 0, COMPLETE_STRING );
                 }
             }
            mbFinished = false;
         }
-        pRet = mpProxyList;
+        pRet = mpProxyList.get();
     }
     else
     {
@@ -153,8 +152,7 @@ void SwGrammarContact::Modify( const SfxPoolItem* pOld, const SfxPoolItem * )
     {    // if my current paragraph dies, I throw the proxy list away
         aTimer.Stop();
         EndListeningAll();
-        delete mpProxyList;
-        mpProxyList = nullptr;
+        mpProxyList.reset();
     }
 }
 


More information about the Libreoffice-commits mailing list