[PATCH] SvUShorts -> std::vector

Daniel Di Marco d.dimarco at gmx.de
Wed Oct 19 18:06:49 PDT 2011


---
 sw/source/core/bastyp/swcache.cxx |   21 ++++++++--------
 sw/source/core/doc/doctxm.cxx     |   47 +++++++++++++++++++------------------
 sw/source/core/inc/doctxm.hxx     |    5 +--
 sw/source/core/inc/swcache.hxx    |    5 ++-
 4 files changed, 39 insertions(+), 39 deletions(-)

diff --git a/sw/source/core/bastyp/swcache.cxx b/sw/source/core/bastyp/swcache.cxx
index 98bb4bb..88c04f4 100644
--- a/sw/source/core/bastyp/swcache.cxx
+++ b/sw/source/core/bastyp/swcache.cxx
@@ -75,9 +75,9 @@ void SwCache::Check()
         OSL_ENSURE( pObj != pRekursive, "Recursion in SwCache." );
     }
     OSL_ENSURE( bFirstFound, "First not Found." );
-    OSL_ENSURE( (nCnt + aFreePositions.Count()) == Count(), "Lost Chain." );
+    OSL_ENSURE( (nCnt + aFreePositions.size()) == Count(), "Lost Chain." );
     if ( Count() == nCurMax )
-        OSL_ENSURE( (nCurMax - nCnt) == aFreePositions.Count(), "Lost FreePositions." );
+        OSL_ENSURE( (nCurMax - nCnt) == aFreePositions.size(), "Lost FreePositions." );
 }
 #endif
 
@@ -98,7 +98,6 @@ SwCache::SwCache( const sal_uInt16 nInitSize, const sal_uInt16 nGrowSize
 #endif
     ) :
     SwCacheObjArr( (sal_uInt8)nInitSize, (sal_uInt8)nGrowSize ),
-    aFreePositions( 5, 5 ),
     pRealFirst( 0 ),
     pFirst( 0 ),
     pLast( 0 ),
@@ -227,7 +226,7 @@ void SwCache::Flush( const sal_uInt8 )
         {
             pTmp = (SwCacheObj*)pObj;
             pObj = pTmp->GetNext();
-            aFreePositions.Insert( pTmp->GetCachePos(), aFreePositions.Count() );
+            aFreePositions.push_back( pTmp->GetCachePos() );
             *(pData + pTmp->GetCachePos()) = (void*)0;
             delete pTmp;
             INCREMENT( nFlushedObjects );
@@ -379,13 +378,13 @@ void SwCache::DeleteObj( SwCacheObj *pObj )
     if ( pObj->GetNext() )
         pObj->GetNext()->SetPrev( pObj->GetPrev() );
 
-    aFreePositions.Insert( pObj->GetCachePos(), aFreePositions.Count() );
+    aFreePositions.push_back( pObj->GetCachePos() );
     *(pData + pObj->GetCachePos()) = (void*)0;
     delete pObj;
 
     CHECK;
     if ( Count() > nCurMax &&
-         (nCurMax <= (Count() - aFreePositions.Count())) )
+         (nCurMax <= (Count() - aFreePositions.size())) )
     {
         //Falls moeglich wieder verkleinern, dazu muessen allerdings ausreichend
         //Freie Positionen bereitstehen.
@@ -402,7 +401,7 @@ void SwCache::DeleteObj( SwCacheObj *pObj )
             else
                 pTmpObj->SetCachePos( i );
         }
-        aFreePositions.Remove( 0, aFreePositions.Count() );
+        aFreePositions.clear();
     }
     CHECK;
 }
@@ -434,14 +433,14 @@ sal_Bool SwCache::Insert( SwCacheObj *pNew )
         nPos = Count();
         SwCacheObjArr::C40_INSERT( SwCacheObj, pNew, nPos );
     }
-    else if ( aFreePositions.Count() )
+    else if ( !aFreePositions.empty() )
     {
         //Es exitieren Platzhalter, also den letzten benutzen.
         INCREMENT( nInsertFree );
-        const sal_uInt16 nFreePos = aFreePositions.Count() - 1;
+        const sal_uInt16 nFreePos = aFreePositions.size() - 1;
         nPos = aFreePositions[ nFreePos ];
         *(pData + nPos) = pNew;
-        aFreePositions.Remove( nFreePos );
+        aFreePositions.erase( aFreePositions.begin() + nFreePos );
     }
     else
     {
@@ -505,7 +504,7 @@ sal_Bool SwCache::Insert( SwCacheObj *pNew )
 
 void SwCache::SetLRUOfst( const sal_uInt16 nOfst )
 {
-    if ( !pRealFirst || ((Count() - aFreePositions.Count()) < nOfst) )
+    if ( !pRealFirst || ((Count() - aFreePositions.size()) < nOfst) )
         return;
 
     CHECK;
diff --git a/sw/source/core/doc/doctxm.cxx b/sw/source/core/doc/doctxm.cxx
index 1ffb259..e8818e9 100644
--- a/sw/source/core/doc/doctxm.cxx
+++ b/sw/source/core/doc/doctxm.cxx
@@ -1905,9 +1905,9 @@ void SwTOXBaseSection::UpdatePageNum()
     for( sal_uInt16 nCnt = 0; nCnt < aSortArr.Count(); ++nCnt )
     {
         // Schleife ueber alle SourceNodes
-        SvUShorts aNums;        //Die Seitennummern
+        std::vector<sal_uInt16> aNums; //Die Seitennummern
         SvPtrarr  aDescs;       //Die PageDescriptoren passend zu den Seitennummern.
-        SvUShorts* pMainNums = 0; // contains page numbers of main entries
+        std::vector<sal_uInt16> *pMainNums = 0; // contains page numbers of main entries
 
         // process run in lines
         sal_uInt16 nRange = 0;
@@ -1961,12 +1961,12 @@ void SwTOXBaseSection::UpdatePageNum()
                     }
 
                     // sortiert einfuegen
-                    for( i = 0; i < aNums.Count() && aNums[i] < nPage; ++i )
+                    for( i = 0; i < aNums.size() && aNums[i] < nPage; ++i )
                         ;
 
-                    if( i >= aNums.Count() || aNums[ i ] != nPage )
+                    if( i >= aNums.size() || aNums[ i ] != nPage )
                     {
-                        aNums.Insert( nPage, i );
+                        aNums.insert(aNums.begin() + i, nPage);
                         aDescs.Insert( (void*)pAktPage->GetPageDesc(), i );
                     }
                     // is it a main entry?
@@ -1974,8 +1974,8 @@ void SwTOXBaseSection::UpdatePageNum()
                         rTOXSource.bMainEntry)
                     {
                         if(!pMainNums)
-                            pMainNums = new SvUShorts;
-                        pMainNums->Insert(nPage, pMainNums->Count());
+                            pMainNums = new std::vector<sal_uInt16>;
+                        pMainNums->push_back(nPage);
                     }
                 }
             }
@@ -1990,7 +1990,7 @@ void SwTOXBaseSection::UpdatePageNum()
                                 aIntl );
             }
             DELETEZ(pMainNums);
-            aNums.Remove(0, aNums.Count());
+            aNums.clear();
         }
     }
     // nach dem Setzen der richtigen Seitennummer, das Mapping-Array
@@ -2002,22 +2002,22 @@ void SwTOXBaseSection::UpdatePageNum()
      Beschreibung: Austausch der Seitennummer-Platzhalter
  --------------------------------------------------------------------*/
 // search for the page no in the array of main entry page numbers
-sal_Bool lcl_HasMainEntry( const SvUShorts* pMainEntryNums, sal_uInt16 nToFind )
+sal_Bool lcl_HasMainEntry( const std::vector<sal_uInt16>* pMainEntryNums, sal_uInt16 nToFind )
 {
-    for(sal_uInt16 i = 0; pMainEntryNums && i < pMainEntryNums->Count(); ++i)
+    for(sal_uInt16 i = 0; pMainEntryNums && i < pMainEntryNums->size(); ++i)
         if(nToFind == (*pMainEntryNums)[i])
             return sal_True;
     return sal_False;
 }
 
 void SwTOXBaseSection::_UpdatePageNum( SwTxtNode* pNd,
-                                    const SvUShorts& rNums,
+                                    const std::vector<sal_uInt16>& rNums,
                                     const SvPtrarr & rDescs,
-                                    const SvUShorts* pMainEntryNums,
+                                    const std::vector<sal_uInt16>* pMainEntryNums,
                                     const SwTOXInternational& rIntl )
 {
     //collect starts end ends of main entry character style
-    SvUShorts* pCharStyleIdx = pMainEntryNums ? new SvUShorts : 0;
+    std::vector<sal_uInt16>* pCharStyleIdx = pMainEntryNums ? new std::vector<sal_uInt16> : 0;
 
     String sSrchStr( cNumRepl );
     sSrchStr.AppendAscii( sPageDeli ) += cNumRepl;
@@ -2026,7 +2026,7 @@ void SwTOXBaseSection::_UpdatePageNum( SwTxtNode* pNd,
     xub_StrLen nEndPos = pNd->GetTxt().Search( sSrchStr );
     sal_uInt16 i;
 
-    if( STRING_NOTFOUND == nEndPos || !rNums.Count() )
+    if( STRING_NOTFOUND == nEndPos || rNums.empty() )
         return;
 
     if( STRING_NOTFOUND == nStartPos || nStartPos > nEndPos)
@@ -2040,7 +2040,7 @@ void SwTOXBaseSection::_UpdatePageNum( SwTxtNode* pNd,
     if( pCharStyleIdx && lcl_HasMainEntry( pMainEntryNums, nBeg ))
     {
         sal_uInt16 nTemp = 0;
-        pCharStyleIdx->Insert( nTemp, pCharStyleIdx->Count());
+        pCharStyleIdx->push_back( nTemp );
     }
 
     // Platzhalter loeschen
@@ -2062,7 +2062,7 @@ void SwTOXBaseSection::_UpdatePageNum( SwTxtNode* pNd,
         }
     pNd->EraseText(aPos, nEndPos - nStartPos + 2);
 
-    for( i = 1; i < rNums.Count(); ++i)
+    for( i = 1; i < rNums.size(); ++i)
     {
         SvxNumberType aType( ((SwPageDesc*)rDescs[i])->GetNumType() );
         if( TOX_INDEX == SwTOXBase::GetType() )
@@ -2100,8 +2100,9 @@ void SwTOXBaseSection::_UpdatePageNum( SwTxtNode* pNd,
                 aNumStr.AppendAscii( sPageDeli );
                 //the change of the character style must apply after sPageDeli is appended
                 if(pCharStyleIdx && bMainEntryChanges)
-                    pCharStyleIdx->Insert(aNumStr.Len(),
-                                                    pCharStyleIdx->Count());
+                {
+                    pCharStyleIdx->push_back(aNumStr.Len());
+                }
                 aNumStr += aType.GetNumStr( nBeg );
                 nCount   = 0;
             }
@@ -2110,7 +2111,7 @@ void SwTOXBaseSection::_UpdatePageNum( SwTxtNode* pNd,
         else
         {   // Alle Nummern eintragen
             aNumStr += aType.GetNumStr( sal_uInt16(rNums[i]) );
-            if(i != (rNums.Count()-1))
+            if(i != (rNums.size()-1))
                 aNumStr.AppendAscii( sPageDeli );
         }
     }
@@ -2145,11 +2146,11 @@ void SwTOXBaseSection::_UpdatePageNum( SwTxtNode* pNd,
     }
 
     //now the main entries should get there character style
-    if(pCharStyleIdx && pCharStyleIdx->Count() && GetMainEntryCharStyle().Len())
+    if(pCharStyleIdx && !pCharStyleIdx->empty() && GetMainEntryCharStyle().Len())
     {
         // eventually the last index must me appended
-        if(pCharStyleIdx->Count()&0x01)
-            pCharStyleIdx->Insert(aNumStr.Len(), pCharStyleIdx->Count());
+        if(pCharStyleIdx->size()&0x01)
+            pCharStyleIdx->push_back(aNumStr.Len());
 
         //search by name
         SwDoc* pDoc = pNd->GetDoc();
@@ -2165,7 +2166,7 @@ void SwTOXBaseSection::_UpdatePageNum( SwTxtNode* pNd,
         //find the page numbers in aNumStr and set the character style
         xub_StrLen nOffset = pNd->GetTxt().Len() - aNumStr.Len();
         SwFmtCharFmt aCharFmt(pCharFmt);
-        for(sal_uInt16 j = 0; j < pCharStyleIdx->Count(); j += 2)
+        for(sal_uInt16 j = 0; j < pCharStyleIdx->size(); j += 2)
         {
             xub_StrLen nStartIdx = (*pCharStyleIdx)[j] + nOffset;
             xub_StrLen nEndIdx = (*pCharStyleIdx)[j + 1]  + nOffset;
diff --git a/sw/source/core/inc/doctxm.hxx b/sw/source/core/inc/doctxm.hxx
index 97ca675..fe0daa1 100644
--- a/sw/source/core/inc/doctxm.hxx
+++ b/sw/source/core/inc/doctxm.hxx
@@ -35,7 +35,6 @@
 #include <section.hxx>
 
 class  SwTOXInternational;
-class  SvUShorts;
 class  SvStringsDtor;
 class  SvPtrarr;
 class  SwPageDesc;
@@ -83,9 +82,9 @@ class SwTOXBaseSection : public SwTOXBase, public SwSection
 
     // Seitennummerplatzhalter gegen aktuelle Nummern austauschen
     void    _UpdatePageNum( SwTxtNode* pNd,
-                            const SvUShorts& rNums,
+                            const std::vector<sal_uInt16>& rNums,
                             const SvPtrarr &rDescs,
-                            const SvUShorts* pMainEntryNums,
+                            const std::vector<sal_uInt16>* pMainEntryNums,
                             const SwTOXInternational& rIntl );
 
     // Bereich fuer Stichwort einfuegen suchen
diff --git a/sw/source/core/inc/swcache.hxx b/sw/source/core/inc/swcache.hxx
index cfb5853..d609ad8 100644
--- a/sw/source/core/inc/swcache.hxx
+++ b/sw/source/core/inc/swcache.hxx
@@ -58,12 +58,13 @@
  *
  */
 
+#include <vector>
+
 #if OSL_DEBUG_LEVEL > 1
 #include <tools/string.hxx>
 #endif
 
 #ifndef _SVSTDARR_HXX
-#define _SVSTDARR_USHORTS
 #include <svl/svstdarr.hxx>
 #endif
 
@@ -73,7 +74,7 @@ SV_DECL_PTRARR_DEL(SwCacheObjArr,SwCacheObj*,1,1)
 
 class SwCache : public SwCacheObjArr
 {
-    SvUShorts aFreePositions;       //Freie Positionen fuer das Insert wenn
+    std::vector<sal_uInt16> aFreePositions; //Freie Positionen fuer das Insert wenn
                                     //die Maximalgrenze nicht erreicht ist.
                                     //Immer wenn ein Objekt ausgetragen wird,
                                     //so wird seine Position hier eingetragen.
-- 
1.7.7


--------------060003030907060907050400--


More information about the LibreOffice mailing list