diff options
author | Noel Grandin <noel@peralex.com> | 2012-05-24 09:51:14 +0200 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2012-05-25 00:17:08 +0200 |
commit | 9c0ca924446933431d736ee0dd37e6852b4947dc (patch) | |
tree | 97ae6260011cb6eafcc286f1e9f5da508d43215f /sw/source | |
parent | c271eb95a8519c88af809ee7a0e1c750e08beb27 (diff) |
Convert SV_DECL_PTRARR_DEL(SwpHstry) to std::vector
Could not use boost::ptr_vector here because the code moves
pointers around by hand.
Change-Id: I60d19741ad08add18d99ee3b75e9dc3810d2c675
Diffstat (limited to 'sw/source')
-rw-r--r-- | sw/source/core/inc/rolbck.hxx | 19 | ||||
-rw-r--r-- | sw/source/core/undo/rolbck.cxx | 41 |
2 files changed, 35 insertions, 25 deletions
diff --git a/sw/source/core/inc/rolbck.hxx b/sw/source/core/inc/rolbck.hxx index f030c236f422..0eb6efa66cf7 100644 --- a/sw/source/core/inc/rolbck.hxx +++ b/sw/source/core/inc/rolbck.hxx @@ -353,8 +353,11 @@ public: #endif -typedef SwHistoryHint* SwHistoryHintPtr; -SV_DECL_PTRARR_DEL( SwpHstry, SwHistoryHintPtr, 0 ) +class SwpHstry : public std::vector<SwHistoryHint*> { +public: + // the destructor will free all objects still in the vector + ~SwpHstry(); +}; class SwHistory { @@ -386,8 +389,8 @@ public: void Add( const SwTxtFtn& ); void Add( const SfxItemSet & rSet, const SwCharFmt & rCharFmt); - sal_uInt16 Count() const { return m_SwpHstry.Count(); } - sal_uInt16 GetTmpEnd() const { return m_SwpHstry.Count() - m_nEndDiff; } + 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 const* operator[]( sal_uInt16 nPos ) const @@ -397,10 +400,10 @@ public: void Move( sal_uInt16 nPos, SwHistory *pIns, sal_uInt16 nStart = 0, sal_uInt16 nEnd = USHRT_MAX ) { - m_SwpHstry.Insert( &pIns->m_SwpHstry, nPos, nStart, nEnd ); - pIns->m_SwpHstry.Remove( nStart, (nEnd == USHRT_MAX) - ? pIns->Count() - nStart - : nEnd ); + SwpHstry::iterator itSourceBegin = pIns->m_SwpHstry.begin() + nStart; + SwpHstry::iterator itSourceEnd = nEnd == USHRT_MAX ? pIns->m_SwpHstry.end() : pIns->m_SwpHstry.begin() + nEnd; + std::copy( itSourceBegin, itSourceEnd, m_SwpHstry.begin() + nPos ); + pIns->m_SwpHstry.erase( itSourceBegin, itSourceEnd ); } // helper methods for recording attribute in History diff --git a/sw/source/core/undo/rolbck.cxx b/sw/source/core/undo/rolbck.cxx index 38e02bb99a6c..b0ca37d56436 100644 --- a/sw/source/core/undo/rolbck.cxx +++ b/sw/source/core/undo/rolbck.cxx @@ -69,8 +69,6 @@ #include <undo.hrc> #include <bookmrk.hxx> -SV_IMPL_PTRARR( SwpHstry, SwHistoryHintPtr) - String SwHistoryHint::GetDescription() const { return String(); @@ -1015,9 +1013,11 @@ void SwHistoryChangeCharFmt::SetInDoc(SwDoc * pDoc, bool ) SwHistory::SwHistory( sal_uInt16 nInitSz ) - : m_SwpHstry( (sal_uInt8)nInitSz ) + : m_SwpHstry() , m_nEndDiff( 0 ) -{} +{ + m_SwpHstry.reserve( (sal_uInt8)nInitSz ); +} SwHistory::~SwHistory() @@ -1053,7 +1053,7 @@ void SwHistory::Add( const SfxPoolItem* pOldValue, const SfxPoolItem* pNewValue, { pHt = new SwHistoryResetFmt( pNewValue, nNodeIdx ); } - m_SwpHstry.Insert( pHt, Count() ); + m_SwpHstry.push_back( pHt ); } @@ -1098,7 +1098,7 @@ void SwHistory::Add( SwTxtAttr* pHint, sal_uLong nNodeIdx, bool bNewAttr ) pHt = new SwHistoryResetTxt( pHint->Which(), *pHint->GetStart(), *pHint->GetAnyEnd(), nNodeIdx ); } - m_SwpHstry.Insert( pHt, Count() ); + m_SwpHstry.push_back( pHt ); } @@ -1108,7 +1108,7 @@ void SwHistory::Add( SwFmtColl* pColl, sal_uLong nNodeIdx, sal_uInt8 nWhichNd ) SwHistoryHint * pHt = new SwHistoryChangeFmtColl( pColl, nNodeIdx, nWhichNd ); - m_SwpHstry.Insert( pHt, Count() ); + m_SwpHstry.push_back( pHt ); } @@ -1117,14 +1117,14 @@ void SwHistory::Add(const ::sw::mark::IMark& rBkmk, bool bSavePos, bool bSaveOth OSL_ENSURE( !m_nEndDiff, "History was not deleted after REDO" ); SwHistoryHint * pHt = new SwHistoryBookmark(rBkmk, bSavePos, bSaveOtherPos); - m_SwpHstry.Insert( pHt, Count() ); + m_SwpHstry.push_back( pHt ); } void SwHistory::Add( SwFrmFmt& rFmt ) { SwHistoryHint * pHt = new SwHistoryChangeFlyAnchor( rFmt ); - m_SwpHstry.Insert( pHt, Count() ); + m_SwpHstry.push_back( pHt ); } void SwHistory::Add( SwFlyFrmFmt& rFmt, sal_uInt16& rSetPos ) @@ -1136,7 +1136,7 @@ void SwHistory::Add( SwFlyFrmFmt& rFmt, sal_uInt16& rSetPos ) if( RES_FLYFRMFMT == nWh || RES_DRAWFRMFMT == nWh ) { pHint = new SwHistoryTxtFlyCnt( &rFmt ); - m_SwpHstry.Insert( pHint, Count() ); + m_SwpHstry.push_back( pHint ); const SwFmtChain* pChainItem; if( SFX_ITEM_SET == rFmt.GetItemState( RES_CHAIN, sal_False, @@ -1146,7 +1146,7 @@ void SwHistory::Add( SwFlyFrmFmt& rFmt, sal_uInt16& rSetPos ) { SwHistoryHint * pHt = new SwHistoryChangeFlyChain( rFmt, *pChainItem ); - m_SwpHstry.Insert( pHt, rSetPos++ ); + m_SwpHstry.insert( m_SwpHstry.begin() + rSetPos++, pHt ); if ( pChainItem->GetNext() ) { SwFmtChain aTmp( pChainItem->GetNext()->GetChain() ); @@ -1168,14 +1168,14 @@ void SwHistory::Add( SwFlyFrmFmt& rFmt, sal_uInt16& rSetPos ) void SwHistory::Add( const SwTxtFtn& rFtn ) { SwHistoryHint *pHt = new SwHistorySetFootnote( rFtn ); - m_SwpHstry.Insert( pHt, Count() ); + m_SwpHstry.push_back( pHt ); } // #i27615# void SwHistory::Add(const SfxItemSet & rSet, const SwCharFmt & rFmt) { SwHistoryHint * pHt = new SwHistoryChangeCharFmt(rSet, rFmt.GetName()); - m_SwpHstry.Insert(pHt, Count()); + m_SwpHstry.push_back( pHt ); } /************************************************************************* @@ -1200,7 +1200,7 @@ bool SwHistory::Rollback( SwDoc* pDoc, sal_uInt16 nStart ) pHHt->SetInDoc( pDoc, false ); delete pHHt; } - m_SwpHstry.Remove( nStart, Count() - nStart ); + m_SwpHstry.erase( m_SwpHstry.begin() + nStart, m_SwpHstry.end() ); m_nEndDiff = 0; return true; } @@ -1238,7 +1238,8 @@ void SwHistory::Delete( sal_uInt16 nStart ) { for ( sal_uInt16 n = Count(); n > nStart; ) { - m_SwpHstry.DeleteAndDestroy( --n, 1 ); + delete m_SwpHstry[ --n ]; + m_SwpHstry.erase( m_SwpHstry.begin() + n ); } m_nEndDiff = 0; } @@ -1404,7 +1405,7 @@ void SwRegHistory::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew ) pNewHstr = new SwHistoryResetFmt( pItem, m_nNodeIndex ); } } - m_pHistory->m_SwpHstry.Insert( pNewHstr, m_pHistory->Count() ); + m_pHistory->m_SwpHstry.push_back( pNewHstr ); } } } @@ -1452,7 +1453,7 @@ bool SwRegHistory::InsertItems( const SfxItemSet& rSet, pTxtNode->GetIndex(), nStart, nEnd ); // der NodeIndex kann verschoben sein !! - m_pHistory->m_SwpHstry.Insert( pNewHstr, m_pHistory->Count() ); + m_pHistory->m_SwpHstry.push_back( pNewHstr ); } return bInserted; @@ -1506,4 +1507,10 @@ void SwRegHistory::_MakeSetWhichIds() } } +SwpHstry::~SwpHstry() +{ + for(const_iterator it = begin(); it != end(); ++it) + delete *it; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |