diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-05-09 13:56:07 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-05-15 15:56:14 +0200 |
commit | 863d2485e60251ac45b019b2c58ced7cfc9d978e (patch) | |
tree | 5b7222b6957289a68c4359097d3f672fc20bd152 /editeng/source | |
parent | 941193639939c759616595c08241a817f7aed501 (diff) |
loplugin:useuniqueptr in ParagraphList
Change-Id: I042fb945b0585a0409d76a509c7f9287aa220b68
Reviewed-on: https://gerrit.libreoffice.org/54180
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'editeng/source')
-rw-r--r-- | editeng/source/outliner/outliner.cxx | 25 | ||||
-rw-r--r-- | editeng/source/outliner/paralist.cxx | 33 | ||||
-rw-r--r-- | editeng/source/outliner/paralist.hxx | 9 |
3 files changed, 34 insertions, 33 deletions
diff --git a/editeng/source/outliner/outliner.cxx b/editeng/source/outliner/outliner.cxx index cc19399e1812..344ece6b82ff 100644 --- a/editeng/source/outliner/outliner.cxx +++ b/editeng/source/outliner/outliner.cxx @@ -101,7 +101,7 @@ Paragraph* Outliner::Insert(const OUString& rText, sal_Int32 nAbsPos, sal_Int16 pEditEngine->SetUpdateMode( false ); ImplBlockInsertionCallbacks( true ); pPara = new Paragraph( nDepth ); - pParaList->Insert( pPara, nAbsPos ); + pParaList->Insert( std::unique_ptr<Paragraph>(pPara), nAbsPos ); pEditEngine->InsertParagraph( nAbsPos, OUString() ); DBG_ASSERT(pPara==pParaList->GetParagraph(nAbsPos),"Insert:Failed"); ImplInitDepth( nAbsPos, nDepth, false ); @@ -126,7 +126,7 @@ void Outliner::ParagraphInserted( sal_Int32 nPara ) if( bPasting || pEditEngine->IsInUndo() ) { Paragraph* pPara = new Paragraph( -1 ); - pParaList->Insert( pPara, nPara ); + pParaList->Insert( std::unique_ptr<Paragraph>(pPara), nPara ); if( pEditEngine->IsInUndo() ) { pPara->nFlags = ParaFlag::SETBULLETTEXT; @@ -143,7 +143,7 @@ void Outliner::ParagraphInserted( sal_Int32 nPara ) nDepth = pParaBefore->GetDepth(); Paragraph* pPara = new Paragraph( nDepth ); - pParaList->Insert( pPara, nPara ); + pParaList->Insert( std::unique_ptr<Paragraph>(pPara), nPara ); if( !pEditEngine->IsInUndo() ) { @@ -171,7 +171,6 @@ void Outliner::ParagraphDeleted( sal_Int32 nPara ) } pParaList->Remove( nPara ); - delete pPara; if( !pEditEngine->IsInUndo() && !bPasting ) { @@ -468,7 +467,7 @@ void Outliner::SetText( const OUString& rText, Paragraph* pPara ) } if( nPos ) // not with the first paragraph { - pParaList->Insert( pPara, nInsPos ); + pParaList->Insert( std::unique_ptr<Paragraph>(pPara), nInsPos ); pEditEngine->InsertParagraph( nInsPos, aStr ); ParagraphInsertedHdl(pPara); } @@ -581,10 +580,10 @@ void Outliner::SetText( const OutlinerParaObject& rPObj ) pParaList->Clear(); for( sal_Int32 nCurPara = 0; nCurPara < rPObj.Count(); nCurPara++ ) { - Paragraph* pPara = new Paragraph( rPObj.GetParagraphData(nCurPara)); + std::unique_ptr<Paragraph> pPara(new Paragraph( rPObj.GetParagraphData(nCurPara))); ImplCheckDepth( pPara->nDepth ); - pParaList->Append(pPara); + pParaList->Append(std::move(pPara)); ImplCheckNumBulletItem( nCurPara ); } @@ -622,7 +621,7 @@ void Outliner::AddText( const OutlinerParaObject& rPObj ) for( sal_Int32 n = 0; n < rPObj.Count(); n++ ) { Paragraph* pPara = new Paragraph( rPObj.GetParagraphData(n) ); - pParaList->Append(pPara); + pParaList->Append(std::unique_ptr<Paragraph>(pPara)); sal_Int32 nP = nPara+n; DBG_ASSERT(pParaList->GetAbsPos(pPara)==nP,"AddText:Out of sync"); ImplInitDepth( nP, pPara->GetDepth(), false ); @@ -1110,8 +1109,8 @@ ErrCode Outliner::Read( SvStream& rInput, const OUString& rBaseURL, EETextFormat pParaList->Clear(); for ( sal_Int32 n = 0; n < nParas; n++ ) { - Paragraph* pPara = new Paragraph( 0 ); - pParaList->Append(pPara); + std::unique_ptr<Paragraph> pPara(new Paragraph( 0 )); + pParaList->Append(std::move(pPara)); } ImpFilterIndents( 0, nParas-1 ); @@ -1257,8 +1256,8 @@ Outliner::Outliner(SfxItemPool* pPool, OutlinerMode nMode) pParaList.reset( new ParagraphList ); pParaList->SetVisibleStateChangedHdl( LINK( this, Outliner, ParaVisibleStateChangedHdl ) ); - Paragraph* pPara = new Paragraph( 0 ); - pParaList->Append(pPara); + std::unique_ptr<Paragraph> pPara(new Paragraph( 0 )); + pParaList->Append(std::move(pPara)); pEditEngine.reset( new OutlinerEditEng( this, pPool ) ); pEditEngine->SetBeginMovingParagraphsHdl( LINK( this, Outliner, BeginMovingParagraphsHdl ) ); @@ -1887,7 +1886,7 @@ void Outliner::Clear() ImplBlockInsertionCallbacks( true ); pEditEngine->Clear(); pParaList->Clear(); - pParaList->Append( new Paragraph( nMinDepth )); + pParaList->Append( std::unique_ptr<Paragraph>(new Paragraph( nMinDepth ))); bFirstParaIsEmpty = true; ImplBlockInsertionCallbacks( false ); } diff --git a/editeng/source/outliner/paralist.cxx b/editeng/source/outliner/paralist.cxx index af4c8f53da09..f4c178ac0ec2 100644 --- a/editeng/source/outliner/paralist.cxx +++ b/editeng/source/outliner/paralist.cxx @@ -93,27 +93,25 @@ void Paragraph::dumpAsXml(struct _xmlTextWriter* pWriter) const void ParagraphList::Clear() { - for (auto const& entry : maEntries) - delete entry; maEntries.clear(); } -void ParagraphList::Append( Paragraph* pPara) +void ParagraphList::Append( std::unique_ptr<Paragraph> pPara) { SAL_WARN_IF( maEntries.size() >= EE_PARA_MAX_COUNT, "editeng", "ParagraphList::Append - overflow"); - maEntries.push_back(pPara); + maEntries.push_back(std::move(pPara)); } -void ParagraphList::Insert( Paragraph* pPara, sal_Int32 nAbsPos) +void ParagraphList::Insert( std::unique_ptr<Paragraph> pPara, sal_Int32 nAbsPos) { SAL_WARN_IF( nAbsPos < 0 || (maEntries.size() < static_cast<size_t>(nAbsPos) && nAbsPos != EE_PARA_APPEND), "editeng", "ParagraphList::Insert - bad insert position " << nAbsPos); SAL_WARN_IF( maEntries.size() >= EE_PARA_MAX_COUNT, "editeng", "ParagraphList::Insert - overflow"); if (nAbsPos < 0 || maEntries.size() <= static_cast<size_t>(nAbsPos)) - Append( pPara); + Append( std::move(pPara) ); else - maEntries.insert(maEntries.begin()+nAbsPos,pPara); + maEntries.insert(maEntries.begin()+nAbsPos, std::move(pPara)); } void ParagraphList::Remove( sal_Int32 nPara ) @@ -133,20 +131,23 @@ void ParagraphList::MoveParagraphs( sal_Int32 nStart, sal_Int32 nDest, sal_Int32 if ( (( nDest < nStart ) || ( nDest >= ( nStart + _nCount ) )) && nStart >= 0 && nDest >= 0 && _nCount >= 0 ) { - std::vector<Paragraph*> aParas; - std::vector<Paragraph*>::iterator iterBeg = maEntries.begin() + nStart; - std::vector<Paragraph*>::iterator iterEnd = iterBeg + _nCount; + std::vector<std::unique_ptr<Paragraph>> aParas; + auto iterBeg = maEntries.begin() + nStart; + auto iterEnd = iterBeg + _nCount; - std::copy(iterBeg,iterEnd,std::back_inserter(aParas)); + for (auto it = iterBeg; it != iterEnd; ++it) + aParas.push_back(std::move(*it)); maEntries.erase(iterBeg,iterEnd); if ( nDest > nStart ) nDest -= _nCount; - std::vector<Paragraph*>::iterator iterIns = maEntries.begin() + nDest; - - std::copy(aParas.begin(),aParas.end(),std::inserter(maEntries,iterIns)); + for (auto & i : aParas) + { + maEntries.insert(maEntries.begin() + nDest, std::move(i)); + ++nDest; + } } else { @@ -237,7 +238,7 @@ sal_Int32 ParagraphList::GetAbsPos( Paragraph const * pParent ) const sal_Int32 pos = 0; for (auto const& entry : maEntries) { - if (entry == pParent) + if (entry.get() == pParent) return pos; ++pos; } @@ -248,7 +249,7 @@ sal_Int32 ParagraphList::GetAbsPos( Paragraph const * pParent ) const void ParagraphList::dumpAsXml(struct _xmlTextWriter* pWriter) const { xmlTextWriterStartElement(pWriter, BAD_CAST("ParagraphList")); - for (const Paragraph* pParagraph : maEntries) + for (auto const & pParagraph : maEntries) pParagraph->dumpAsXml(pWriter); xmlTextWriterEndElement(pWriter); } diff --git a/editeng/source/outliner/paralist.hxx b/editeng/source/outliner/paralist.hxx index b557629dee18..a3a1b5158c28 100644 --- a/editeng/source/outliner/paralist.hxx +++ b/editeng/source/outliner/paralist.hxx @@ -23,6 +23,7 @@ #include <sal/config.h> #include <sal/log.hxx> +#include <memory> #include <vector> #include <tools/link.hxx> @@ -47,13 +48,13 @@ public: Paragraph* GetParagraph( sal_Int32 nPos ) const { - return 0 <= nPos && static_cast<size_t>(nPos) < maEntries.size() ? maEntries[nPos] : nullptr; + return 0 <= nPos && static_cast<size_t>(nPos) < maEntries.size() ? maEntries[nPos].get() : nullptr; } sal_Int32 GetAbsPos( Paragraph const * pParent ) const; - void Append( Paragraph *pPara); - void Insert( Paragraph* pPara, sal_Int32 nAbsPos); + void Append( std::unique_ptr<Paragraph> pPara); + void Insert( std::unique_ptr<Paragraph> pPara, sal_Int32 nAbsPos); void Remove( sal_Int32 nPara ); void MoveParagraphs( sal_Int32 nStart, sal_Int32 nDest, sal_Int32 nCount ); @@ -73,7 +74,7 @@ public: private: Link<Paragraph&,void> aVisibleStateChangedHdl; - std::vector<Paragraph*> maEntries; + std::vector<std::unique_ptr<Paragraph>> maEntries; }; #endif |