[Libreoffice-commits] core.git: 2 commits - sc/inc sc/source sw/source
Noel Grandin
noel.grandin at collabora.co.uk
Tue Jul 3 06:17:50 UTC 2018
sc/inc/textuno.hxx | 6 +-
sc/source/ui/unoobj/textuno.cxx | 16 ++---
sw/source/core/inc/SwGrammarMarkUp.hxx | 4 -
sw/source/core/inc/wrong.hxx | 15 +++--
sw/source/core/text/SwGrammarMarkUp.cxx | 13 ++--
sw/source/core/text/wrong.cxx | 77 ++++++++++------------------
sw/source/core/txtnode/SwGrammarContact.cxx | 20 +++----
7 files changed, 66 insertions(+), 85 deletions(-)
New commits:
commit 3769a6271120e0e856b53f906654bc2c593804fe
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date: Mon Jul 2 16:56:17 2018 +0200
loplugin:useuniqueptr in ScHeaderFooterTextData
Change-Id: Ia359ee8e9e4876f6bbf86702c476c9f9602295a0
Reviewed-on: https://gerrit.libreoffice.org/56832
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/sc/inc/textuno.hxx b/sc/inc/textuno.hxx
index 0d3919727436..bb90c82f85f4 100644
--- a/sc/inc/textuno.hxx
+++ b/sc/inc/textuno.hxx
@@ -105,8 +105,8 @@ private:
std::unique_ptr<EditTextObject> mpTextObj;
css::uno::WeakReference<css::sheet::XHeaderFooterContent> xContentObj;
ScHeaderFooterPart nPart;
- ScEditEngineDefaulter* pEditEngine;
- SvxEditEngineForwarder* pForwarder;
+ std::unique_ptr<ScEditEngineDefaulter> pEditEngine;
+ std::unique_ptr<SvxEditEngineForwarder> pForwarder;
bool bDataValid;
public:
@@ -120,7 +120,7 @@ public:
SvxTextForwarder* GetTextForwarder();
void UpdateData();
void UpdateData(EditEngine& rEditEngine);
- ScEditEngineDefaulter* GetEditEngine() { GetTextForwarder(); return pEditEngine; }
+ ScEditEngineDefaulter* GetEditEngine() { GetTextForwarder(); return pEditEngine.get(); }
ScHeaderFooterPart GetPart() const { return nPart; }
const css::uno::Reference<css::sheet::XHeaderFooterContent> GetContentObj() const { return xContentObj; }
diff --git a/sc/source/ui/unoobj/textuno.cxx b/sc/source/ui/unoobj/textuno.cxx
index 49fc91b2037a..7d92fd868a67 100644
--- a/sc/source/ui/unoobj/textuno.cxx
+++ b/sc/source/ui/unoobj/textuno.cxx
@@ -187,8 +187,6 @@ ScHeaderFooterTextData::ScHeaderFooterTextData(
mpTextObj(pTextObj ? pTextObj->Clone() : nullptr),
xContentObj( xContent ),
nPart( nP ),
- pEditEngine( nullptr ),
- pForwarder( nullptr ),
bDataValid(false)
{
}
@@ -197,8 +195,8 @@ ScHeaderFooterTextData::~ScHeaderFooterTextData()
{
SolarMutexGuard aGuard; // needed for EditEngine dtor
- delete pForwarder;
- delete pEditEngine;
+ pForwarder.reset();
+ pEditEngine.reset();
}
SvxTextForwarder* ScHeaderFooterTextData::GetTextForwarder()
@@ -207,7 +205,7 @@ SvxTextForwarder* ScHeaderFooterTextData::GetTextForwarder()
{
SfxItemPool* pEnginePool = EditEngine::CreatePool();
pEnginePool->FreezeIdRanges();
- ScHeaderEditEngine* pHdrEngine = new ScHeaderEditEngine( pEnginePool );
+ std::unique_ptr<ScHeaderEditEngine> pHdrEngine(new ScHeaderEditEngine( pEnginePool ));
pHdrEngine->EnableUndo( false );
pHdrEngine->SetRefMapMode(MapMode(MapUnit::MapTwip));
@@ -232,18 +230,18 @@ SvxTextForwarder* ScHeaderFooterTextData::GetTextForwarder()
ScHeaderFooterTextObj::FillDummyFieldData( aData );
pHdrEngine->SetData( aData );
- pEditEngine = pHdrEngine;
- pForwarder = new SvxEditEngineForwarder(*pEditEngine);
+ pEditEngine = std::move(pHdrEngine);
+ pForwarder.reset( new SvxEditEngineForwarder(*pEditEngine) );
}
if (bDataValid)
- return pForwarder;
+ return pForwarder.get();
if (mpTextObj)
pEditEngine->SetText(*mpTextObj);
bDataValid = true;
- return pForwarder;
+ return pForwarder.get();
}
void ScHeaderFooterTextData::UpdateData()
commit 09d9419bf2072fdab2d7c1d1c6a8dee70b9f0f8a
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date: Mon Jul 2 15:20:42 2018 +0200
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 at collabora.co.uk>
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();
}
}
More information about the Libreoffice-commits
mailing list