summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-07-13 11:53:26 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-07-16 08:38:58 +0200
commit9df9e5b0a92caeda305c53214632a3ba42f02b2d (patch)
treeb8086f23a21c8214d844cc8f271fbec4399cd0d5
parent8bcea1698c6ec45923a7675ab1250204e952527d (diff)
loplugin:useuniqueptr in SwHistory
Change-Id: Ie36cdf1e7b3d09ae27cb2a5b51f8a644693fe2b3 Reviewed-on: https://gerrit.libreoffice.org/57424 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--sw/source/core/inc/rolbck.hxx11
-rw-r--r--sw/source/core/undo/rolbck.cxx102
2 files changed, 52 insertions, 61 deletions
diff --git a/sw/source/core/inc/rolbck.hxx b/sw/source/core/inc/rolbck.hxx
index 60edcb313033..5163fd59ca0e 100644
--- a/sw/source/core/inc/rolbck.hxx
+++ b/sw/source/core/inc/rolbck.hxx
@@ -311,7 +311,7 @@ class SwHistory
friend class SwDoc; // actually only SwDoc::DelUndoObj may access
friend class SwRegHistory; // for inserting History attributes
- std::vector<SwHistoryHint*> m_SwpHstry;
+ std::vector<std::unique_ptr<SwHistoryHint>> m_SwpHstry;
sal_uInt16 m_nEndDiff;
public:
@@ -338,9 +338,9 @@ public:
sal_uInt16 Count() const { return m_SwpHstry.size(); }
sal_uInt16 GetTmpEnd() const { return m_SwpHstry.size() - m_nEndDiff; }
sal_uInt16 SetTmpEnd( sal_uInt16 nTmpEnd ); // return previous value
- SwHistoryHint * operator[]( sal_uInt16 nPos ) { return m_SwpHstry[nPos]; }
+ SwHistoryHint * operator[]( sal_uInt16 nPos ) { return m_SwpHstry[nPos].get(); }
SwHistoryHint const* operator[]( sal_uInt16 nPos ) const
- { return m_SwpHstry[nPos]; }
+ { return m_SwpHstry[nPos].get(); }
// for SwUndoDelete::Undo/Redo
void Move( sal_uInt16 nPos, SwHistory *pIns,
@@ -348,8 +348,9 @@ public:
{
auto itSourceBegin = pIns->m_SwpHstry.begin() + nStart;
auto itSourceEnd = pIns->m_SwpHstry.end();
- if (itSourceBegin == itSourceEnd) return;
- m_SwpHstry.insert(m_SwpHstry.begin() + nPos, itSourceBegin, itSourceEnd);
+ if (itSourceBegin == itSourceEnd)
+ return;
+ m_SwpHstry.insert(m_SwpHstry.begin() + nPos, std::make_move_iterator(itSourceBegin), std::make_move_iterator(itSourceEnd));
pIns->m_SwpHstry.erase( itSourceBegin, itSourceEnd );
}
diff --git a/sw/source/core/undo/rolbck.cxx b/sw/source/core/undo/rolbck.cxx
index 4d1b3889c21e..9de53a698523 100644
--- a/sw/source/core/undo/rolbck.cxx
+++ b/sw/source/core/undo/rolbck.cxx
@@ -879,10 +879,6 @@ SwHistory::SwHistory()
SwHistory::~SwHistory()
{
- Delete();
- std::vector<SwHistoryHint*>::const_iterator it;
- for(it = m_SwpHstry.begin(); it != m_SwpHstry.end(); ++it)
- delete *it;
}
void SwHistory::Add(
@@ -900,7 +896,7 @@ void SwHistory::Add(
}
// no default Attribute?
- SwHistoryHint* pHt = nullptr;
+ std::unique_ptr<SwHistoryHint> pHt;
// To be able to include the DrawingLayer FillItems something more
// general has to be done to check if an Item is default than to check
@@ -911,14 +907,14 @@ void SwHistory::Add(
// global tooling aka IsDefaultItem(const SfxPoolItem*) for now
if(pOldValue && !IsDefaultItem(pOldValue))
{
- pHt = new SwHistorySetFormat( pOldValue, nNodeIdx );
+ pHt.reset( new SwHistorySetFormat( pOldValue, nNodeIdx ) );
}
else
{
- pHt = new SwHistoryResetFormat( pNewValue, nNodeIdx );
+ pHt.reset( new SwHistoryResetFormat( pNewValue, nNodeIdx ) );
}
- m_SwpHstry.push_back( pHt );
+ m_SwpHstry.push_back( std::move(pHt) );
}
// FIXME: refactor the following "Add" methods (DRY)?
@@ -926,65 +922,65 @@ void SwHistory::Add( SwTextAttr* pHint, sal_uLong nNodeIdx, bool bNewAttr )
{
OSL_ENSURE( !m_nEndDiff, "History was not deleted after REDO" );
- SwHistoryHint * pHt = nullptr;
+ std::unique_ptr<SwHistoryHint> pHt;
if( !bNewAttr )
{
switch ( pHint->Which() )
{
case RES_TXTATR_FTN:
- pHt = new SwHistorySetFootnote(
- static_cast<SwTextFootnote*>(pHint), nNodeIdx );
+ pHt.reset( new SwHistorySetFootnote(
+ static_cast<SwTextFootnote*>(pHint), nNodeIdx ) );
break;
case RES_TXTATR_FLYCNT:
- pHt = new SwHistoryTextFlyCnt( static_cast<SwTextFlyCnt*>(pHint)
- ->GetFlyCnt().GetFrameFormat() );
+ pHt.reset( new SwHistoryTextFlyCnt( static_cast<SwTextFlyCnt*>(pHint)
+ ->GetFlyCnt().GetFrameFormat() ) );
break;
case RES_TXTATR_FIELD:
case RES_TXTATR_ANNOTATION:
- pHt = new SwHistorySetTextField(
- static_txtattr_cast<SwTextField*>(pHint), nNodeIdx);
+ pHt.reset( new SwHistorySetTextField(
+ static_txtattr_cast<SwTextField*>(pHint), nNodeIdx) );
break;
case RES_TXTATR_TOXMARK:
- pHt = new SwHistorySetTOXMark(
- static_txtattr_cast<SwTextTOXMark*>(pHint), nNodeIdx);
+ pHt.reset( new SwHistorySetTOXMark(
+ static_txtattr_cast<SwTextTOXMark*>(pHint), nNodeIdx) );
break;
case RES_TXTATR_REFMARK:
- pHt = new SwHistorySetRefMark(
- static_txtattr_cast<SwTextRefMark*>(pHint), nNodeIdx);
+ pHt.reset( new SwHistorySetRefMark(
+ static_txtattr_cast<SwTextRefMark*>(pHint), nNodeIdx) );
break;
default:
- pHt = new SwHistorySetText( pHint, nNodeIdx );
+ pHt.reset( new SwHistorySetText( pHint, nNodeIdx ) );
}
}
else
{
- pHt = new SwHistoryResetText( pHint->Which(), pHint->GetStart(),
- *pHint->GetAnyEnd(), nNodeIdx );
+ pHt.reset( new SwHistoryResetText( pHint->Which(), pHint->GetStart(),
+ *pHint->GetAnyEnd(), nNodeIdx ) );
}
- m_SwpHstry.push_back( pHt );
+ m_SwpHstry.push_back( std::move(pHt) );
}
void SwHistory::Add( SwFormatColl* pColl, sal_uLong nNodeIdx, SwNodeType nWhichNd )
{
OSL_ENSURE( !m_nEndDiff, "History was not deleted after REDO" );
- SwHistoryHint * pHt =
- new SwHistoryChangeFormatColl( pColl, nNodeIdx, nWhichNd );
- m_SwpHstry.push_back( pHt );
+ std::unique_ptr<SwHistoryHint> pHt(
+ new SwHistoryChangeFormatColl( pColl, nNodeIdx, nWhichNd ));
+ m_SwpHstry.push_back( std::move(pHt) );
}
void SwHistory::Add(const ::sw::mark::IMark& rBkmk, bool bSavePos, bool bSaveOtherPos)
{
OSL_ENSURE( !m_nEndDiff, "History was not deleted after REDO" );
- SwHistoryHint * pHt = new SwHistoryBookmark(rBkmk, bSavePos, bSaveOtherPos);
- m_SwpHstry.push_back( pHt );
+ std::unique_ptr<SwHistoryHint> pHt(new SwHistoryBookmark(rBkmk, bSavePos, bSaveOtherPos));
+ m_SwpHstry.push_back( std::move(pHt) );
}
void SwHistory::Add( SwFrameFormat& rFormat )
{
- SwHistoryHint * pHt = new SwHistoryChangeFlyAnchor( rFormat );
- m_SwpHstry.push_back( pHt );
+ std::unique_ptr<SwHistoryHint> pHt(new SwHistoryChangeFlyAnchor( rFormat ));
+ m_SwpHstry.push_back( std::move(pHt) );
}
void SwHistory::Add( SwFlyFrameFormat& rFormat, sal_uInt16& rSetPos )
@@ -994,8 +990,8 @@ void SwHistory::Add( SwFlyFrameFormat& rFormat, sal_uInt16& rSetPos )
const sal_uInt16 nWh = rFormat.Which();
if( RES_FLYFRMFMT == nWh || RES_DRAWFRMFMT == nWh )
{
- SwHistoryHint * pHint = new SwHistoryTextFlyCnt( &rFormat );
- m_SwpHstry.push_back( pHint );
+ std::unique_ptr<SwHistoryHint> pHint(new SwHistoryTextFlyCnt( &rFormat ));
+ m_SwpHstry.push_back( std::move(pHint) );
const SwFormatChain* pChainItem;
if( SfxItemState::SET == rFormat.GetItemState( RES_CHAIN, false,
@@ -1003,9 +999,9 @@ void SwHistory::Add( SwFlyFrameFormat& rFormat, sal_uInt16& rSetPos )
{
if( pChainItem->GetNext() || pChainItem->GetPrev() )
{
- SwHistoryHint * pHt =
- new SwHistoryChangeFlyChain( rFormat, *pChainItem );
- m_SwpHstry.insert( m_SwpHstry.begin() + rSetPos++, pHt );
+ std::unique_ptr<SwHistoryHint> pHt(
+ new SwHistoryChangeFlyChain( rFormat, *pChainItem ));
+ m_SwpHstry.insert( m_SwpHstry.begin() + rSetPos++, std::move(pHt) );
if ( pChainItem->GetNext() )
{
SwFormatChain aTmp( pChainItem->GetNext()->GetChain() );
@@ -1026,15 +1022,15 @@ void SwHistory::Add( SwFlyFrameFormat& rFormat, sal_uInt16& rSetPos )
void SwHistory::Add( const SwTextFootnote& rFootnote )
{
- SwHistoryHint *pHt = new SwHistorySetFootnote( rFootnote );
- m_SwpHstry.push_back( pHt );
+ std::unique_ptr<SwHistoryHint> pHt(new SwHistorySetFootnote( rFootnote ));
+ m_SwpHstry.push_back( std::move(pHt) );
}
// #i27615#
void SwHistory::Add(const SfxItemSet & rSet, const SwCharFormat & rFormat)
{
- SwHistoryHint * pHt = new SwHistoryChangeCharFormat(rSet, rFormat.GetName());
- m_SwpHstry.push_back( pHt );
+ std::unique_ptr<SwHistoryHint> pHt(new SwHistoryChangeCharFormat(rSet, rFormat.GetName()));
+ m_SwpHstry.push_back( std::move(pHt) );
}
bool SwHistory::Rollback( SwDoc* pDoc, sal_uInt16 nStart )
@@ -1044,9 +1040,8 @@ bool SwHistory::Rollback( SwDoc* pDoc, sal_uInt16 nStart )
for ( sal_uInt16 i = Count(); i > nStart ; )
{
- SwHistoryHint * pHHt = m_SwpHstry[ --i ];
+ SwHistoryHint * pHHt = m_SwpHstry[ --i ].get();
pHHt->SetInDoc( pDoc, false );
- delete pHHt;
}
m_SwpHstry.erase( m_SwpHstry.begin() + nStart, m_SwpHstry.end() );
m_nEndDiff = 0;
@@ -1059,12 +1054,11 @@ bool SwHistory::TmpRollback( SwDoc* pDoc, sal_uInt16 nStart, bool bToFirst )
if ( !Count() || !nEnd || nStart >= nEnd )
return false;
- SwHistoryHint * pHHt;
if ( bToFirst )
{
for ( ; nEnd > nStart; ++m_nEndDiff )
{
- pHHt = m_SwpHstry[ --nEnd ];
+ SwHistoryHint* pHHt = m_SwpHstry[ --nEnd ].get();
pHHt->SetInDoc( pDoc, true );
}
}
@@ -1072,7 +1066,7 @@ bool SwHistory::TmpRollback( SwDoc* pDoc, sal_uInt16 nStart, bool bToFirst )
{
for ( ; nStart < nEnd; ++m_nEndDiff, ++nStart )
{
- pHHt = m_SwpHstry[ nStart ];
+ SwHistoryHint* pHHt = m_SwpHstry[ nStart ].get();
pHHt->SetInDoc( pDoc, true );
}
}
@@ -1081,11 +1075,7 @@ bool SwHistory::TmpRollback( SwDoc* pDoc, sal_uInt16 nStart, bool bToFirst )
void SwHistory::Delete()
{
- for ( sal_uInt16 n = Count(); n > 0; )
- {
- delete m_SwpHstry[ --n ];
- m_SwpHstry.erase( m_SwpHstry.begin() + n );
- }
+ m_SwpHstry.clear();
m_nEndDiff = 0;
}
@@ -1245,27 +1235,27 @@ void SwRegHistory::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
}
else if (pOld && RES_ATTRSET_CHG == pNew->Which())
{
- SwHistoryHint* pNewHstr(nullptr);
+ std::unique_ptr<SwHistoryHint> pNewHstr;
const SfxItemSet& rSet = *static_cast< const SwAttrSetChg* >(pOld)->GetChgSet();
if ( 1 < rSet.Count() )
{
- pNewHstr = new SwHistorySetAttrSet( rSet, m_nNodeIndex, m_WhichIdSet );
+ pNewHstr.reset( new SwHistorySetAttrSet( rSet, m_nNodeIndex, m_WhichIdSet ) );
}
else if (const SfxPoolItem* pItem = SfxItemIter( rSet ).FirstItem())
{
if ( m_WhichIdSet.count( pItem->Which() ) )
{
- pNewHstr = new SwHistorySetFormat( pItem, m_nNodeIndex );
+ pNewHstr.reset( new SwHistorySetFormat( pItem, m_nNodeIndex ) );
}
else
{
- pNewHstr = new SwHistoryResetFormat( pItem, m_nNodeIndex );
+ pNewHstr.reset( new SwHistoryResetFormat( pItem, m_nNodeIndex ) );
}
}
if (pNewHstr)
- m_pHistory->m_SwpHstry.push_back( pNewHstr );
+ m_pHistory->m_SwpHstry.push_back( std::move(pNewHstr) );
}
}
}
@@ -1322,9 +1312,9 @@ bool SwRegHistory::InsertItems( const SfxItemSet& rSet,
// nothing at all to be inserted
assert(std::find_if(
m_pHistory->m_SwpHstry.begin(), m_pHistory->m_SwpHstry.end(),
- [nExpected](SwHistoryHint *const pHint) -> bool {
+ [nExpected](std::unique_ptr<SwHistoryHint> const& pHint) -> bool {
SwHistoryResetText const*const pReset(
- dynamic_cast<SwHistoryResetText const*>(pHint));
+ dynamic_cast<SwHistoryResetText const*>(pHint.get()));
return pReset && (pReset->GetWhich() == nExpected);
}) != m_pHistory->m_SwpHstry.end());
}