diff options
author | Noel Grandin <noel@peralex.com> | 2012-07-13 15:42:51 +0200 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2012-07-17 15:33:40 +0200 |
commit | 66c7b8fe56fd7aa518ba28986a4cfd773bf1319b (patch) | |
tree | 504ccef846e0348ac697c1f5309ce13fdaffe504 /sw | |
parent | 4b41b87e52007897131088e61ffff41d22122acc (diff) |
Convert SV_DECL_PTRARR_SORT_DEL(_SetGetExpFlds) to o3tl::sorted_vector
Change-Id: Ibdb223f0209a999028d5d63536a895a9d1f473f2
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/core/crsr/crstrvl.cxx | 40 | ||||
-rw-r--r-- | sw/source/core/doc/doc.cxx | 4 | ||||
-rw-r--r-- | sw/source/core/doc/docfld.cxx | 92 | ||||
-rw-r--r-- | sw/source/core/fields/docufld.cxx | 26 | ||||
-rw-r--r-- | sw/source/core/fields/fldlst.cxx | 12 | ||||
-rw-r--r-- | sw/source/core/inc/docfld.hxx | 14 |
6 files changed, 101 insertions, 87 deletions
diff --git a/sw/source/core/crsr/crstrvl.cxx b/sw/source/core/crsr/crstrvl.cxx index 8c833899bd60..dbe766bab966 100644 --- a/sw/source/core/crsr/crstrvl.cxx +++ b/sw/source/core/crsr/crstrvl.cxx @@ -623,7 +623,7 @@ void lcl_MakeFldLst( _SetGetExpFlds& rLst, const SwFieldType& rFldType, _SetGetExpFld* pNew = new _SetGetExpFld( SwNodeIndex( rTxtNode ), pTxtFld ); pNew->SetBodyPos( *pCFrm ); - rLst.Insert( pNew ); + rLst.insert( pNew ); } } } @@ -633,7 +633,7 @@ sal_Bool SwCrsrShell::MoveFldType( const SwFieldType* pFldType, sal_Bool bNext, sal_uInt16 nSubType, sal_uInt16 nResType ) { // sorted list of all fields - _SetGetExpFlds aSrtLst( 64 ); + _SetGetExpFlds aSrtLst; if (pFldType) { @@ -669,10 +669,10 @@ sal_Bool SwCrsrShell::MoveFldType( const SwFieldType* pFldType, sal_Bool bNext, } // found no fields? - if( !aSrtLst.Count() ) + if( aSrtLst.empty() ) return sal_False; - sal_uInt16 nPos; + _SetGetExpFlds::const_iterator it; SwCursor* pCrsr = getShellCrsr( true ); { // (1998): Always use field for search so that the right one is found as @@ -705,27 +705,43 @@ sal_Bool SwCrsrShell::MoveFldType( const SwFieldType* pFldType, sal_Bool bNext, aSrch.SetBodyPos( *pTNd->getLayoutFrm( GetLayout(), &aPt, &rPos, sal_False ) ); } - sal_Bool bFound = aSrtLst.Seek_Entry( &aSrch, &nPos ); + it = aSrtLst.lower_bound( &aSrch ); if( bDelFld ) { delete (SwFmtFld*)&pTxtFld->GetAttr(); delete pTxtFld; } - if( bFound ) + if( it != aSrtLst.end() && **it == aSrch ) // found { if( bNext ) { - if( ++nPos >= aSrtLst.Count() ) + if( ++it == aSrtLst.end() ) return sal_False; // already at the end } - else if( !nPos-- ) - return sal_False; // no more steps forward possible + else + { + if( it == aSrtLst.begin() ) + return sal_False; // no more steps backward possible + it--; + } + } + else // not found + { + if( bNext ) + { + if( it == aSrtLst.end() ) + return sal_False; + } + else + { + if( it == aSrtLst.begin() ) + return sal_False; // no more steps backward possible + it--; + } } - else if( bNext ? nPos >= aSrtLst.Count() : !nPos--) - return sal_False; } - const _SetGetExpFld& rFnd = **( aSrtLst.GetData() + nPos ); + const _SetGetExpFld& rFnd = **it; SET_CURR_SHELL( this ); diff --git a/sw/source/core/doc/doc.cxx b/sw/source/core/doc/doc.cxx index 9d6a3363e5ca..33a6af27170b 100644 --- a/sw/source/core/doc/doc.cxx +++ b/sw/source/core/doc/doc.cxx @@ -1221,7 +1221,7 @@ bool lcl_GetPostIts( { SwNodeIndex aIdx( pTxtFld->GetTxtNode() ); _PostItFld* pNew = new _PostItFld( aIdx, pTxtFld ); - pSrtLst->Insert( pNew ); + pSrtLst->insert( pNew ); } else break; // we just wanted to check for the existence of postits ... @@ -1396,7 +1396,7 @@ void SwDoc::UpdatePagesForPrintingWithPostItData( sal_Int16 nPostItMode = (sal_Int16) rOptions.getIntValue( "PrintAnnotationMode", 0 ); OSL_ENSURE(nPostItMode == POSTITS_NONE || rData.HasPostItData(), "print post-its without post-it data?" ); - const sal_uInt16 nPostItCount = rData.HasPostItData() ? rData.m_pPostItFields->Count() : 0; + const sal_uInt16 nPostItCount = rData.HasPostItData() ? rData.m_pPostItFields->size() : 0; if (nPostItMode != POSTITS_NONE && nPostItCount > 0) { SET_CURR_SHELL( rData.m_pPostItShell.get() ); diff --git a/sw/source/core/doc/docfld.cxx b/sw/source/core/doc/docfld.cxx index 559bac2d05d8..435330fe58a6 100644 --- a/sw/source/core/doc/docfld.cxx +++ b/sw/source/core/doc/docfld.cxx @@ -32,7 +32,6 @@ #include <float.h> #include <comphelper/string.hxx> #include <tools/datetime.hxx> -#include <svl/svarray.hxx> #include <vcl/svapp.hxx> #include <unotools/charclass.hxx> #include <unotools/transliterationwrapper.hxx> @@ -74,8 +73,6 @@ using namespace ::com::sun::star::uno; extern sal_Bool IsFrameBehind( const SwTxtNode& rMyNd, sal_uInt16 nMySttPos, const SwTxtNode& rBehindNd, sal_uInt16 nSttPos ); -SV_IMPL_OP_PTRARR_SORT( _SetGetExpFlds, _SetGetExpFldPtr ) - /*-------------------------------------------------------------------- Description: Insert field types --------------------------------------------------------------------*/ @@ -890,19 +887,19 @@ void _SetGetExpFld::SetBodyPos( const SwCntntFrm& rFrm ) } } -sal_Bool _SetGetExpFld::operator<( const _SetGetExpFld& rFld ) const +bool _SetGetExpFld::operator<( const _SetGetExpFld& rFld ) const { if( nNode < rFld.nNode || ( nNode == rFld.nNode && nCntnt < rFld.nCntnt )) - return sal_True; + return true; else if( nNode != rFld.nNode || nCntnt != rFld.nCntnt ) - return sal_False; + return false; const SwNode *pFirst = GetNodeFromCntnt(), *pNext = rFld.GetNodeFromCntnt(); // Position is the same: continue only if both field pointers are set! if( !pFirst || !pNext ) - return sal_False; + return false; // same Section? if( pFirst->StartOfSectionNode() != pNext->StartOfSectionNode() ) @@ -1107,16 +1104,14 @@ void SwDoc::FldsToCalc( SwCalc& rCalc, const _SetGetExpFld& rToThisFld ) SwNewDBMgr* pMgr = GetNewDBMgr(); pMgr->CloseAll(sal_False); - if( pUpdtFlds->GetSortLst()->Count() ) + if( !pUpdtFlds->GetSortLst()->empty() ) { - sal_uInt16 nLast; - _SetGetExpFld* pFld = (_SetGetExpFld*)&rToThisFld; - if( pUpdtFlds->GetSortLst()->Seek_Entry( pFld, &nLast ) ) - ++nLast; + _SetGetExpFlds::const_iterator itLast = pUpdtFlds->GetSortLst()->lower_bound( (_SetGetExpFld*)&rToThisFld ); + if( **itLast == rToThisFld ) + ++itLast; - const _SetGetExpFldPtr* ppSortLst = pUpdtFlds->GetSortLst()->GetData(); - for( sal_uInt16 n = 0; n < nLast; ++n, ++ppSortLst ) - lcl_CalcFld( *this, rCalc, **ppSortLst, pMgr ); + for( _SetGetExpFlds::const_iterator it = pUpdtFlds->GetSortLst()->begin(); it != itLast; ++it ) + lcl_CalcFld( *this, rCalc, **it, pMgr ); } pMgr->CloseAll(sal_False); @@ -1131,15 +1126,13 @@ void SwDoc::FldsToCalc( SwCalc& rCalc, sal_uLong nLastNd, sal_uInt16 nLastCnt ) SwNewDBMgr* pMgr = GetNewDBMgr(); pMgr->CloseAll(sal_False); - const _SetGetExpFldPtr* ppSortLst = pUpdtFlds->GetSortLst()->GetData(); - - for( sal_uInt16 n = pUpdtFlds->GetSortLst()->Count(); - n && - ( (*ppSortLst)->GetNode() < nLastNd || - ( (*ppSortLst)->GetNode() == nLastNd && (*ppSortLst)->GetCntnt() <= nLastCnt ) + for( _SetGetExpFlds::const_iterator it = pUpdtFlds->GetSortLst()->begin(); + it != pUpdtFlds->GetSortLst()->end() && + ( (*it)->GetNode() < nLastNd || + ( (*it)->GetNode() == nLastNd && (*it)->GetCntnt() <= nLastCnt ) ); - --n, ++ppSortLst ) - lcl_CalcFld( *this, rCalc, **ppSortLst, pMgr ); + ++it ) + lcl_CalcFld( *this, rCalc, **it, pMgr ); pMgr->CloseAll(sal_False); } @@ -1153,24 +1146,20 @@ void SwDoc::FldsToExpand( SwHash**& ppHashTbl, sal_uInt16& rTblSize, // Hash table for all string replacements is filled on-the-fly. // Try to fabricate an uneven number. - rTblSize = (( pUpdtFlds->GetSortLst()->Count() / 7 ) + 1 ) * 7; + rTblSize = (( pUpdtFlds->GetSortLst()->size() / 7 ) + 1 ) * 7; ppHashTbl = new SwHash*[ rTblSize ]; memset( ppHashTbl, 0, sizeof( _HashStr* ) * rTblSize ); - sal_uInt16 nLast; + _SetGetExpFlds::const_iterator itLast; { - _SetGetExpFld* pTmp = (_SetGetExpFld*)&rToThisFld; - if( pUpdtFlds->GetSortLst()->Seek_Entry( pTmp, &nLast ) ) - ++nLast; + itLast = pUpdtFlds->GetSortLst()->lower_bound( (_SetGetExpFld*)&rToThisFld ); + if( **itLast == rToThisFld ) + ++itLast; } - sal_uInt16 nPos; - SwHash* pFnd; - String aNew; - const _SetGetExpFldPtr* ppSortLst = pUpdtFlds->GetSortLst()->GetData(); - for( ; nLast; --nLast, ++ppSortLst ) + for( _SetGetExpFlds::const_iterator it = pUpdtFlds->GetSortLst()->begin(); it != itLast; ++it ) { - const SwTxtFld* pTxtFld = (*ppSortLst)->GetFld(); + const SwTxtFld* pTxtFld = (*it)->GetFld(); if( !pTxtFld ) continue; @@ -1183,6 +1172,7 @@ void SwDoc::FldsToExpand( SwHash**& ppHashTbl, sal_uInt16& rTblSize, // set the new value in the hash table // is the formula a field? SwSetExpField* pSFld = (SwSetExpField*)pFld; + String aNew; LookString( ppHashTbl, rTblSize, pSFld->GetFormula(), aNew ); if( !aNew.Len() ) // nothing found, then the formula is @@ -1195,7 +1185,8 @@ void SwDoc::FldsToExpand( SwHash**& ppHashTbl, sal_uInt16& rTblSize, // look up the field's name aNew = ((SwSetExpFieldType*)pSFld->GetTyp())->GetSetRefName(); // Entry present? - pFnd = Find( aNew, ppHashTbl, rTblSize, &nPos ); + sal_uInt16 nPos; + SwHash* pFnd = Find( aNew, ppHashTbl, rTblSize, &nPos ); if( pFnd ) // modify entry in the hash table ((_HashStr*)pFnd)->aSetStr = pSFld->GetExpStr(); @@ -1211,7 +1202,8 @@ void SwDoc::FldsToExpand( SwHash**& ppHashTbl, sal_uInt16& rTblSize, // Insert entry in the hash table // Entry present? - pFnd = Find( rName, ppHashTbl, rTblSize, &nPos ); + sal_uInt16 nPos; + SwHash* pFnd = Find( rName, ppHashTbl, rTblSize, &nPos ); String const value(pFld->ExpandField(IsClipBoard())); if( pFnd ) { @@ -1241,7 +1233,7 @@ void SwDoc::UpdateExpFlds( SwTxtFld* pUpdtFld, bool bUpdRefFlds ) pUpdtFlds->MakeFldList( *this, sal_True, GETFLD_ALL ); mbNewFldLst = sal_False; - if( !pUpdtFlds->GetSortLst()->Count() ) + if( pUpdtFlds->GetSortLst()->empty() ) { if( bUpdRefFlds ) UpdateRefFlds(NULL); @@ -1297,10 +1289,9 @@ void SwDoc::UpdateExpFlds( SwTxtFld* pUpdtFld, bool bUpdRefFlds ) pMgr->CloseAll(sal_False); String aNew; - const _SetGetExpFldPtr* ppSortLst = pUpdtFlds->GetSortLst()->GetData(); - for( n = pUpdtFlds->GetSortLst()->Count(); n; --n, ++ppSortLst ) + for( _SetGetExpFlds::const_iterator it = pUpdtFlds->GetSortLst()->begin(); it != pUpdtFlds->GetSortLst()->end(); ++it ) { - SwSection* pSect = (SwSection*)(*ppSortLst)->GetSection(); + SwSection* pSect = (SwSection*)(*it)->GetSection(); if( pSect ) { @@ -1311,7 +1302,7 @@ void SwDoc::UpdateExpFlds( SwTxtFld* pUpdtFld, bool bUpdRefFlds ) continue; } - SwTxtFld* pTxtFld = (SwTxtFld*)(*ppSortLst)->GetFld(); + SwTxtFld* pTxtFld = (SwTxtFld*)(*it)->GetFld(); if( !pTxtFld ) { OSL_ENSURE( !this, "what's wrong now'" ); @@ -1471,7 +1462,7 @@ void SwDoc::UpdateExpFlds( SwTxtFld* pUpdtFld, bool bUpdRefFlds ) if( MAXLEVEL > nLvl ) { // test if the Number needs to be updated - pSeqNd = GetNodes()[ (*ppSortLst)->GetNode() ]; + pSeqNd = GetNodes()[ (*it)->GetNode() ]; const SwTxtNode* pOutlNd = pSeqNd-> FindOutlineNodeOfLevel( nLvl ); @@ -2181,7 +2172,7 @@ void SwDocUpdtFld::InsDelFldInFldLst( sal_Bool bIns, const SwTxtFld& rFld ) { if( !bIns ) // if list is present and deleted return; // don't do a thing - pFldSortLst = new _SetGetExpFlds( 64 ); + pFldSortLst = new _SetGetExpFlds; } if( bIns ) // insert anew: @@ -2190,10 +2181,13 @@ void SwDocUpdtFld::InsDelFldInFldLst( sal_Bool bIns, const SwTxtFld& rFld ) { // look up via the pTxtFld pointer. It is a sorted list, but it's sorted by node // position. Until this is found, the search for the pointer is already done. - for( sal_uInt16 n = 0; n < pFldSortLst->Count(); ++n ) + for( sal_uInt16 n = 0; n < pFldSortLst->size(); ++n ) if( &rFld == (*pFldSortLst)[ n ]->GetPointer() ) - pFldSortLst->DeleteAndDestroy( n--, 1 ); - // one field can occur multiple times + { + delete (*pFldSortLst)[n]; + pFldSortLst->erase( n ); + n--; // one field can occur multiple times + } } } @@ -2208,7 +2202,7 @@ void SwDocUpdtFld::_MakeFldList( SwDoc& rDoc, int eGetMode ) { // new version: walk all fields of the attribute pool delete pFldSortLst; - pFldSortLst = new _SetGetExpFlds( 64 ); + pFldSortLst = new _SetGetExpFlds; /// consider and unhide sections /// with hide condition, only in mode GETFLD_ALL (<eGetMode == GETFLD_ALL>) @@ -2432,7 +2426,7 @@ void SwDocUpdtFld::GetBodyNode( const SwTxtFld& rTFld, sal_uInt16 nFldWhich ) } if( pNew != NULL ) - if( !pFldSortLst->Insert( pNew )) + if( !pFldSortLst->insert( pNew ).second ) delete pNew; } @@ -2470,7 +2464,7 @@ void SwDocUpdtFld::GetBodyNode( const SwSectionNode& rSectNd ) if( !pNew ) pNew = new _SetGetExpFld( rSectNd ); - if( !pFldSortLst->Insert( pNew )) + if( !pFldSortLst->insert( pNew ).second ) delete pNew; } diff --git a/sw/source/core/fields/docufld.cxx b/sw/source/core/fields/docufld.cxx index b13e3c7e74be..7a2299058857 100644 --- a/sw/source/core/fields/docufld.cxx +++ b/sw/source/core/fields/docufld.cxx @@ -2168,7 +2168,7 @@ void SwRefPageGetFieldType::Modify( const SfxPoolItem* pOld, const SfxPoolItem* if( !pNew && !pOld && GetDepends() ) { // sammel erstmal alle SetPageRefFelder ein. - _SetGetExpFlds aTmpLst( 10 ); + _SetGetExpFlds aTmpLst; if( MakeSetList( aTmpLst ) ) { SwIterator<SwFmtFld,SwFieldType> aIter( *this ); @@ -2221,12 +2221,12 @@ sal_uInt16 SwRefPageGetFieldType::MakeSetList( _SetGetExpFlds& rTmpLst ) &aPos.nContent ); } - if( !rTmpLst.Insert( pNew )) + if( !rTmpLst.insert( pNew ).second) delete pNew; } } - return rTmpLst.Count(); + return rTmpLst.size(); } void SwRefPageGetFieldType::UpdateField( SwTxtFld* pTxtFld, @@ -2243,12 +2243,12 @@ void SwRefPageGetFieldType::UpdateField( SwTxtFld* pTxtFld, SwNodeIndex aIdx( *pTxtNode ); _SetGetExpFld aEndFld( aIdx, pTxtFld ); - sal_uInt16 nLast; - rSetList.Seek_Entry( &aEndFld, &nLast ); + _SetGetExpFlds::const_iterator itLast = rSetList.lower_bound( &aEndFld ); - if( nLast-- ) + if( itLast != rSetList.begin() ) { - const SwTxtFld* pRefTxtFld = rSetList[ nLast ]->GetFld(); + itLast--; + const SwTxtFld* pRefTxtFld = (*itLast)->GetFld(); const SwRefPageSetField* pSetFld = (SwRefPageSetField*)pRefTxtFld->GetFld().GetFld(); if( pSetFld->IsOn() ) @@ -2316,7 +2316,7 @@ void SwRefPageGetField::ChangeExpansion( const SwFrm* pFrm, OSL_ENSURE( !pFrm->IsInDocBody(), "Flag ist nicht richtig, Frame steht im DocBody" ); // sammel erstmal alle SetPageRefFelder ein. - _SetGetExpFlds aTmpLst( 10 ); + _SetGetExpFlds aTmpLst; if( !pGetType->MakeSetList( aTmpLst ) ) return ; @@ -2333,13 +2333,13 @@ void SwRefPageGetField::ChangeExpansion( const SwFrm* pFrm, _SetGetExpFld aEndFld( aPos.nNode, pFld, &aPos.nContent ); - sal_uInt16 nLast; - aTmpLst.Seek_Entry( &aEndFld, &nLast ); + _SetGetExpFlds::const_iterator itLast = aTmpLst.lower_bound( &aEndFld ); - if( !nLast-- ) - return ; // es gibt kein entsprechendes Set - Feld vor mir + if( itLast == aTmpLst.begin() ) + return; // es gibt kein entsprechendes Set - Feld vor mir + itLast--; - const SwTxtFld* pRefTxtFld = aTmpLst[ nLast ]->GetFld(); + const SwTxtFld* pRefTxtFld = (*itLast)->GetFld(); const SwRefPageSetField* pSetFld = (SwRefPageSetField*)pRefTxtFld->GetFld().GetFld(); Point aPt; diff --git a/sw/source/core/fields/fldlst.cxx b/sw/source/core/fields/fldlst.cxx index 8b7aa5c3a6c2..59c70948e912 100644 --- a/sw/source/core/fields/fldlst.cxx +++ b/sw/source/core/fields/fldlst.cxx @@ -84,7 +84,7 @@ SwInputFieldList::SwInputFieldList( SwEditShell* pShell, sal_Bool bBuildTmpLst ) { SwNodeIndex aIdx( rTxtNode ); _SetGetExpFld* pNew = new _SetGetExpFld(aIdx, pTxtFld ); - pSrtLst->Insert( pNew ); + pSrtLst->insert( pNew ); } } } @@ -103,7 +103,7 @@ SwInputFieldList::~SwInputFieldList() sal_uInt16 SwInputFieldList::Count() const { - return pSrtLst->Count(); + return pSrtLst->size(); } @@ -177,7 +177,7 @@ sal_uInt16 SwInputFieldList::BuildSortLst() { SwNodeIndex aIdx( rTxtNode ); _SetGetExpFld* pNew = new _SetGetExpFld(aIdx, pTxtFld ); - pSrtLst->Insert( pNew ); + pSrtLst->insert( pNew ); } else aTmpLst.erase( it ); @@ -188,7 +188,7 @@ sal_uInt16 SwInputFieldList::BuildSortLst() // die Pointer werden nicht mehr gebraucht aTmpLst.clear(); - return pSrtLst->Count(); + return pSrtLst->size(); } /*-------------------------------------------------------------------- @@ -211,8 +211,8 @@ void SwInputFieldList::RemoveUnselectedFlds() if (aPos >= *PCURCRSR->Start() && aPos < *PCURCRSR->End()) { // Feld innerhalb der Selektion - pNewLst->Insert( (*pSrtLst)[i] ); - pSrtLst->Remove(i, 1); + pNewLst->insert( (*pSrtLst)[i] ); + pSrtLst->erase( i ); } else i++; diff --git a/sw/source/core/inc/docfld.hxx b/sw/source/core/inc/docfld.hxx index 850d46124c40..212b64850b34 100644 --- a/sw/source/core/inc/docfld.hxx +++ b/sw/source/core/inc/docfld.hxx @@ -30,6 +30,7 @@ #define _DOCFLD_HXX #include <calc.hxx> +#include <o3tl/sorted_vector.hxx> class SwTxtFld; class SwIndex; @@ -86,11 +87,11 @@ public: _SetGetExpFld( const SwFlyFrmFmt& rFlyFmt, const SwPosition* pPos = 0 ); - sal_Bool operator==( const _SetGetExpFld& rFld ) const - { return nNode == rFld.nNode && nCntnt == rFld.nCntnt && + bool operator==( const _SetGetExpFld& rFld ) const + { return nNode == rFld.nNode && nCntnt == rFld.nCntnt && ( !CNTNT.pTxtFld || !rFld.CNTNT.pTxtFld || CNTNT.pTxtFld == rFld.CNTNT.pTxtFld ); } - sal_Bool operator<( const _SetGetExpFld& rFld ) const; + bool operator<( const _SetGetExpFld& rFld ) const; const SwTxtFld* GetFld() const { return TEXTFIELD == eSetGetExpFldType ? CNTNT.pTxtFld : 0; } @@ -118,8 +119,11 @@ public: void SetBodyPos( const SwCntntFrm& rFrm ); }; -typedef _SetGetExpFld* _SetGetExpFldPtr; -SV_DECL_PTRARR_SORT_DEL( _SetGetExpFlds, _SetGetExpFldPtr, 0 ) +class _SetGetExpFlds : public o3tl::sorted_vector<_SetGetExpFld*, o3tl::less_ptr_to<_SetGetExpFld> > +{ +public: + ~_SetGetExpFlds() { DeleteAndDestroyAll(); } +}; // struct for saving strings from the SetExp's string fields struct _HashStr : public SwHash |