summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-07-02 15:20:42 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-07-03 08:17:26 +0200
commit09d9419bf2072fdab2d7c1d1c6a8dee70b9f0f8a (patch)
tree605387a086777705ffa8f573b3507c2e732d080b
parent1c588317c6e55ede11c577ea16e1af85eee4810a (diff)
loplugin:useuniqueptr in SwWrongList
and simplify, just use copy constructors and operator=, instead of special-case CopyFrom methods Change-Id: I3e14fa08e820cf7ae2c5424ae22ae95516933773 Reviewed-on: https://gerrit.libreoffice.org/56831 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--sw/source/core/inc/SwGrammarMarkUp.hxx4
-rw-r--r--sw/source/core/inc/wrong.hxx15
-rw-r--r--sw/source/core/text/SwGrammarMarkUp.cxx13
-rw-r--r--sw/source/core/text/wrong.cxx77
-rw-r--r--sw/source/core/txtnode/SwGrammarContact.cxx20
5 files changed, 56 insertions, 73 deletions
diff --git a/sw/source/core/inc/SwGrammarMarkUp.hxx b/sw/source/core/inc/SwGrammarMarkUp.hxx
index f37605556353..94cf6c93a6aa 100644
--- a/sw/source/core/inc/SwGrammarMarkUp.hxx
+++ b/sw/source/core/inc/SwGrammarMarkUp.hxx
@@ -39,10 +39,10 @@ class SwGrammarMarkUp : public SwWrongList
public:
SwGrammarMarkUp() : SwWrongList( WRONGLIST_GRAMMAR ) {}
+ SwGrammarMarkUp(SwGrammarMarkUp const &);
virtual ~SwGrammarMarkUp() override;
- virtual SwWrongList* Clone() override;
- virtual void CopyFrom( const SwWrongList& rCopy ) override;
+ virtual std::unique_ptr<SwWrongList> Clone() override;
/* SwWrongList::Move() + handling of maSentence */
void MoveGrammar( sal_Int32 nPos, sal_Int32 nDiff );
diff --git a/sw/source/core/inc/wrong.hxx b/sw/source/core/inc/wrong.hxx
index 0003d54266ba..695a33b6219d 100644
--- a/sw/source/core/inc/wrong.hxx
+++ b/sw/source/core/inc/wrong.hxx
@@ -59,7 +59,7 @@ public:
css::uno::Reference< css::container::XStringKeyMap > mxPropertyBag;
sal_Int32 mnPos;
sal_Int32 mnLen;
- SwWrongList* mpSubList;
+ std::unique_ptr<SwWrongList> mpSubList;
Color mColor;
WrongAreaLineType mLineType;
@@ -75,6 +75,10 @@ public:
sal_Int32 nPos,
sal_Int32 nLen,
SwWrongList* pSubList);
+
+ SwWrongArea( const SwWrongArea& );
+ SwWrongArea& operator=( const SwWrongArea& );
+
private:
static Color getGrammarColor ( css::uno::Reference< css::container::XStringKeyMap > const & xPropertyBag)
@@ -253,14 +257,13 @@ class SwWrongList
void Remove( sal_uInt16 nIdx, sal_uInt16 nLen );
SwWrongList& operator= (const SwWrongList &) = delete;
- SwWrongList( const SwWrongList& rCpy ) = delete;
public:
SwWrongList( WrongListType eType );
+ SwWrongList( SwWrongList const & );
virtual ~SwWrongList();
- virtual SwWrongList* Clone();
- virtual void CopyFrom( const SwWrongList& rCopy );
+ virtual std::unique_ptr<SwWrongList> Clone();
WrongListType GetWrongListType() const { return meType; }
sal_Int32 GetBeginInv() const { return mnBeginInvalid; }
@@ -319,14 +322,14 @@ public:
SwWrongList* SubList( sal_uInt16 nIdx ) const
{
- return nIdx < maList.size() ? maList[nIdx].mpSubList : nullptr;
+ return maList[nIdx].mpSubList.get();
}
void InsertSubList( sal_Int32 nNewPos, sal_Int32 nNewLen, sal_uInt16 nWhere, SwWrongList* pSubList );
const SwWrongArea* GetElement( sal_uInt16 nIdx ) const
{
- return nIdx < maList.size() ? &maList[nIdx] : nullptr;
+ return &maList[nIdx];
}
void RemoveEntry( sal_Int32 nBegin, sal_Int32 nEnd );
bool LookForEntry( sal_Int32 nBegin, sal_Int32 nEnd );
diff --git a/sw/source/core/text/SwGrammarMarkUp.cxx b/sw/source/core/text/SwGrammarMarkUp.cxx
index a752619d8f81..806ba46ad937 100644
--- a/sw/source/core/text/SwGrammarMarkUp.cxx
+++ b/sw/source/core/text/SwGrammarMarkUp.cxx
@@ -18,22 +18,21 @@
*/
#include <SwGrammarMarkUp.hxx>
+#include <o3tl/make_unique.hxx>
SwGrammarMarkUp::~SwGrammarMarkUp()
{
}
-SwWrongList* SwGrammarMarkUp::Clone()
+SwGrammarMarkUp::SwGrammarMarkUp(SwGrammarMarkUp const & other)
+ : SwWrongList(other),
+ maSentence(other.maSentence)
{
- SwWrongList* pClone = new SwGrammarMarkUp();
- pClone->CopyFrom( *this );
- return pClone;
}
-void SwGrammarMarkUp::CopyFrom( const SwWrongList& rCopy )
+std::unique_ptr<SwWrongList> SwGrammarMarkUp::Clone()
{
- maSentence = static_cast<const SwGrammarMarkUp&>(rCopy).maSentence;
- SwWrongList::CopyFrom( rCopy );
+ return o3tl::make_unique<SwGrammarMarkUp>();
}
void SwGrammarMarkUp::MoveGrammar( sal_Int32 nPos, sal_Int32 nDiff )
diff --git a/sw/source/core/text/wrong.cxx b/sw/source/core/text/wrong.cxx
index d85cf9a99bdf..7a6893bafc46 100644
--- a/sw/source/core/text/wrong.cxx
+++ b/sw/source/core/text/wrong.cxx
@@ -24,6 +24,7 @@
#include <txtfrm.hxx>
#include <osl/diagnose.h>
+#include <o3tl/make_unique.hxx>
SwWrongArea::SwWrongArea( const OUString& rType, WrongListType listType,
css::uno::Reference< css::container::XStringKeyMap > const & xPropertyBag,
@@ -49,6 +50,26 @@ SwWrongArea::SwWrongArea( const OUString& rType,
}
}
+SwWrongArea::SwWrongArea( SwWrongArea const & other )
+{
+ this->operator=(other);
+}
+
+SwWrongArea & SwWrongArea::operator=( SwWrongArea const & other )
+{
+ maType = other.maType;
+ mxPropertyBag = other.mxPropertyBag;
+ mnPos = other.mnPos;
+ mnLen= other.mnLen;
+ if (other.mpSubList)
+ mpSubList = other.mpSubList->Clone();
+ else
+ mpSubList.reset();
+ mColor = other.mColor;
+ mLineType = other.mLineType;
+ return *this;
+}
+
SwWrongList::SwWrongList( WrongListType eType ) :
meType (eType),
mnBeginInvalid(COMPLETE_STRING), // everything correct... (the invalid area starts beyond the string)
@@ -57,38 +78,25 @@ SwWrongList::SwWrongList( WrongListType eType ) :
maList.reserve( 5 );
}
-SwWrongList::~SwWrongList()
+SwWrongList::SwWrongList( SwWrongList const & other ) :
+ maList(other.maList),
+ meType(other.meType),
+ mnBeginInvalid(other.mnBeginInvalid),
+ mnEndInvalid (other.mnEndInvalid)
{
- ClearList();
}
-SwWrongList* SwWrongList::Clone()
+SwWrongList::~SwWrongList()
{
- SwWrongList* pClone = new SwWrongList( meType );
- pClone->CopyFrom( *this );
- return pClone;
}
-void SwWrongList::CopyFrom( const SwWrongList& rCopy )
+std::unique_ptr<SwWrongList> SwWrongList::Clone()
{
- maList = rCopy.maList;
- meType = rCopy.meType;
- mnBeginInvalid = rCopy.mnBeginInvalid;
- mnEndInvalid = rCopy.mnEndInvalid;
- for(SwWrongArea & i : maList)
- {
- if( i.mpSubList )
- i.mpSubList = i.mpSubList->Clone();
- }
+ return o3tl::make_unique<SwWrongList>( *this );
}
void SwWrongList::ClearList()
{
- for (SwWrongArea & i : maList)
- {
- delete i.mpSubList;
- i.mpSubList = nullptr;
- }
maList.clear();
}
@@ -562,32 +570,7 @@ void SwWrongList::Insert(sal_uInt16 nWhere, std::vector<SwWrongArea>::iterator s
void SwWrongList::Remove(sal_uInt16 nIdx, sal_uInt16 nLen )
{
- if ( nIdx >= maList.size() ) return;
- std::vector<SwWrongArea>::iterator i1 = maList.begin();
- i1 += nIdx;
-
- std::vector<SwWrongArea>::iterator i2 = i1;
- if ( nIdx + nLen >= static_cast<sal_uInt16>(maList.size()) )
- i2 = maList.end(); // robust
- else
- i2 += nLen;
-
- std::vector<SwWrongArea>::iterator iLoop = i1;
- while ( iLoop != i2 )
- {
- delete (*iLoop).mpSubList;
- ++iLoop;
- }
-
-#if OSL_DEBUG_LEVEL > 0
- const int nOldSize = Count();
-#endif
-
- maList.erase(i1, i2);
-
-#if OSL_DEBUG_LEVEL > 0
- OSL_ENSURE( Count() + nLen == nOldSize, "SwWrongList::Remove() trouble" );
-#endif
+ maList.erase(maList.begin() + nIdx, maList.begin() + nIdx + nLen);
}
void SwWrongList::RemoveEntry( sal_Int32 nBegin, sal_Int32 nEnd ) {
diff --git a/sw/source/core/txtnode/SwGrammarContact.cxx b/sw/source/core/txtnode/SwGrammarContact.cxx
index d1ae37a7571d..e57afb9620a5 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(); mpProxyList.reset(); }
// (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();
}
}