Kaydet (Commit) 09d9419b authored tarafından Noel Grandin's avatar Noel Grandin

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: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 1c588317
......@@ -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 );
......
......@@ -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 );
......
......@@ -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 )
......
......@@ -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 ) {
......
......@@ -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();
}
}
......
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