[PATCH] Replace SvULongs with vector and code clean up

Maciej Rumianowski maciej.rumianowski at gmail.com
Sat Aug 6 06:27:06 PDT 2011


Instead of SvULongs use std::vector<sal_uInt32>
Remove unnecessary german comments
Translate some comments
replace sal_Bool with bool where variable is not interfering with return value
---
 svx/inc/svx/numfmtsh.hxx      |    7 +-
 svx/source/items/numfmtsh.cxx |  222 ++++++++++++-----------------------------
 2 files changed, 66 insertions(+), 163 deletions(-)

diff --git a/svx/inc/svx/numfmtsh.hxx b/svx/inc/svx/numfmtsh.hxx
index a7c6f95..f4e7c06 100644
--- a/svx/inc/svx/numfmtsh.hxx
+++ b/svx/inc/svx/numfmtsh.hxx
@@ -46,6 +46,7 @@
 
 #include <svl/svstdarr.hxx>
 
+#include <vector>
 // forward ---------------------------------------------------------------
 
 class Color;
@@ -228,9 +229,9 @@ private:
     String					aValStr;
     double					nValNum;
     sal_Bool					bUndoAddList;
-    SvULongs				aAddList;
-    SvULongs				aDelList;
-    SvULongs				aCurEntryList;
+    std::vector<sal_uInt32> aAddList;
+    std::vector<sal_uInt32> aDelList;
+    std::vector<sal_uInt32> aCurEntryList;
     sal_uInt32				nInitFormatKey;
     sal_uInt32				nCurFormatKey;
     short					nCurCategory;
diff --git a/svx/source/items/numfmtsh.cxx b/svx/source/items/numfmtsh.cxx
index 837fdea..8ca37fe 100644
--- a/svx/source/items/numfmtsh.cxx
+++ b/svx/source/items/numfmtsh.cxx
@@ -159,16 +159,10 @@ SvxNumberFormatShell::~SvxNumberFormatShell()
         // Hinzugefuegte Formate sind nicht gueltig:
         // => wieder entfernen:
 
-        for ( sal_uInt16 i = 0; i < aAddList.Count(); ++i )
-            pFormatter->DeleteEntry( aAddList[i] );
+        for ( std::vector<sal_uInt32>::const_iterator it = aAddList.begin(); it != aAddList.end(); ++it )
+            pFormatter->DeleteEntry( *it );
     }
 
-    //--------------------------------
-    // Add-/Remove-Listen leerraeumen:
-    //--------------------------------
-    aAddList.Remove( 0, aAddList.Count() );
-    aDelList.Remove( 0, aAddList.Count() );
-
     if(aCurrencyFormatList.Count()>0)
         aCurrencyFormatList.DeleteAndDestroy(0,aCurrencyFormatList.Count());
 }
@@ -177,20 +171,21 @@ SvxNumberFormatShell::~SvxNumberFormatShell()
 
 sal_uInt32 SvxNumberFormatShell::GetUpdateDataCount() const
 {
-    return aDelList.Count();
+    return aDelList.size();
 }
 
 // -----------------------------------------------------------------------
 
 void SvxNumberFormatShell::GetUpdateData( sal_uInt32* pDelArray, const sal_uInt32 nSize )
 {
-    const sal_uInt32 nCount = aDelList.Count();
+    const sal_uInt32 nListSize = aDelList.size();
+    std::vector<sal_uInt32>::const_iterator it;
 
-    DBG_ASSERT( pDelArray && ( nSize == nCount ), "Array nicht initialisiert!" );
+    DBG_ASSERT( pDelArray && ( nSize == nListSize ), "Array is not initialized" );
 
-    if ( pDelArray && ( nSize == nCount ) )
-        for ( sal_uInt16 i = 0; i < aDelList.Count(); ++i )
-            *pDelArray++ = aDelList[i];
+    if ( pDelArray && ( nSize == nListSize ) )
+        for ( it = aDelList.end(); it != aDelList.end(); ++it )
+            *pDelArray++ = *it;
 }
 
 // -----------------------------------------------------------------------
@@ -229,21 +224,18 @@ void SvxNumberFormatShell::FormatChanged( sal_uInt16  nFmtLbPos,
                                           String& rPreviewStr,
                                           Color*& rpFontColor )
 {
-    //nCurFormatKey = pCurFmtTable->GetKey( pCurFmtTable->GetObject( nFmtLbPos ) );
-
-    if(nFmtLbPos<aCurEntryList.Count())
+    if( nFmtLbPos < aCurEntryList.size() )
     {
-        nCurFormatKey=aCurEntryList[nFmtLbPos];
+        nCurFormatKey = aCurEntryList[nFmtLbPos];
 
-        if(nCurFormatKey!=NUMBERFORMAT_ENTRY_NOT_FOUND)
+        if( nCurFormatKey != NUMBERFORMAT_ENTRY_NOT_FOUND )
         {
             GetPreviewString_Impl( rPreviewStr, rpFontColor );
         }
-        else if(nCurCategory==NUMBERFORMAT_CURRENCY)
+        else if(nCurCategory == NUMBERFORMAT_CURRENCY)
         {
             if(nFmtLbPos<aCurrencyFormatList.Count())
             {
-                //nCurFormatKey=nFmtLbPos;
                 MakePrevStringFromVal(*aCurrencyFormatList[nFmtLbPos],
                                     rPreviewStr,rpFontColor,nValNum);
             }
@@ -263,20 +255,20 @@ sal_Bool SvxNumberFormatShell::AddFormat( String& rFormat,  xub_StrLen& rErrPos,
     {
         if ( IsRemoved_Impl( nAddKey ) )
         {
-            // Key suchen und loeschen
             sal_Bool	bFound	= sal_False;
-            sal_uInt16	nAt		= 0;
+            std::vector<sal_uInt32>::iterator nAt = aDelList.begin();
+            std::vector<sal_uInt32>::iterator it;
 
-            for ( sal_uInt16 i = 0; !bFound && i < aDelList.Count(); ++i )
+            for ( it = aDelList.begin(); !bFound && it != aDelList.end(); ++it )
             {
-                if ( aDelList[i] == nAddKey )
+                if ( *it == nAddKey )
                 {
                     bFound	= sal_True;
-                    nAt		= i;
+                    nAt		= it;
                 }
             }
             DBG_ASSERT( bFound, "Key not found" );
-            aDelList.Remove( nAt );
+            aDelList.erase( nAt );
             bInserted = sal_True;
         }
         else
@@ -295,7 +287,7 @@ sal_Bool SvxNumberFormatShell::AddFormat( String& rFormat,  xub_StrLen& rErrPos,
     {
         nCurFormatKey = nAddKey;
         DBG_ASSERT( !IsAdded_Impl( nCurFormatKey ), "Doppeltes Format!" );
-        aAddList.Insert( nCurFormatKey, aAddList.Count() );
+        aAddList.push_back( nCurFormatKey );
 
         // aktuelle Tabelle holen
         pCurFmtTable = &(pFormatter->GetEntryTable( nCurCategory,
@@ -326,32 +318,32 @@ sal_Bool SvxNumberFormatShell::RemoveFormat( const String& 	rFormat,
 {
     sal_uInt32 nDelKey = pFormatter->GetEntryKey( rFormat, eCurLanguage );
 
-    DBG_ASSERT( nDelKey != NUMBERFORMAT_ENTRY_NOT_FOUND, "Eintrag nicht gefunden!" );
-    DBG_ASSERT( !IsRemoved_Impl( nDelKey ), "Eintrag bereits geloescht!" );
+    DBG_ASSERT( nDelKey != NUMBERFORMAT_ENTRY_NOT_FOUND, "Entry not found!" );
+    DBG_ASSERT( !IsRemoved_Impl( nDelKey ), "Entry already removed!" );
 
     if ( (nDelKey != NUMBERFORMAT_ENTRY_NOT_FOUND) && !IsRemoved_Impl( nDelKey ) )
     {
-        aDelList.Insert( nDelKey, aDelList.Count() );
+        aDelList.push_back( nDelKey );
 
         if ( IsAdded_Impl( nDelKey ) )
         {
-            // Key suchen und loeschen
-            sal_Bool	bFound	= sal_False;
-            sal_uInt16	nAt		= 0;
+            bool bFound = false;
+            std::vector<sal_uInt32>::iterator nAt	= aAddList.begin();
+            std::vector<sal_uInt32>::iterator it;
 
-            for ( sal_uInt16 i = 0; !bFound && i < aAddList.Count(); ++i )
+            for ( it = aAddList.begin(); !bFound && it != aAddList.end(); ++it )
             {
-                if ( aAddList[i] == nDelKey )
+                if ( *it == nDelKey )
                 {
-                    bFound	= sal_True;
-                    nAt		= i;
+                    bFound = true;
+                    nAt = it;
                 }
             }
             DBG_ASSERT( bFound, "Key not found" );
-            aAddList.Remove( nAt );
+            aAddList.erase( nAt );
         }
 
-        nCurCategory=pFormatter->GetType(nDelKey); //@@ 01.10.97
+        nCurCategory=pFormatter->GetType(nDelKey);
         pCurFmtTable = &(pFormatter->GetEntryTable( nCurCategory,
                                                     nCurFormatKey,
                                                     eCurLanguage ));
@@ -361,7 +353,6 @@ sal_Bool SvxNumberFormatShell::RemoveFormat( const String& 	rFormat,
 
         CategoryToPos_Impl( nCurCategory, rCatLbSelPos );
         rFmtSelPos = FillEntryList_Impl( rFmtEntries );
-        //rFmtSelPos = (short) nCurFormatKey; //@@ 01.10.97
     }
     return sal_True;
 }
@@ -587,7 +578,7 @@ short SvxNumberFormatShell::FillEntryList_Impl( SvStrings& rList )
      * so wird SELPOS_NONE geliefert.
      */
     short nSelPos=0;
-    aCurEntryList.Remove(nSelPos,aCurEntryList.Count());
+    aCurEntryList.clear();
     sal_uInt16			nPrivCat = CAT_CURRENCY;
     nSelPos=SELPOS_NONE;
 
@@ -721,11 +712,11 @@ short SvxNumberFormatShell::FillEListWithFormats_Impl( SvStrings& rList,short nS
 
         if ( nNFEntry == nCurFormatKey )
         {
-            nSelPos = ( !IsRemoved_Impl( nNFEntry ) ) ? aCurEntryList.Count() : SELPOS_NONE;
+            nSelPos = ( !IsRemoved_Impl( nNFEntry ) ) ? aCurEntryList.size() : SELPOS_NONE;
         }
 
         rList.Insert( pStr,rList.Count());
-        aCurEntryList.Insert( nNFEntry, aCurEntryList.Count() );
+        aCurEntryList.erase( aCurEntryList.begin()+nNFEntry, aCurEntryList.end() );
     }
 
     return nSelPos;
@@ -766,11 +757,11 @@ short SvxNumberFormatShell::FillEListWithDateTime_Impl( SvStrings& rList,short n
 
             if ( nNFEntry == nCurFormatKey )
             {
-                nSelPos = ( !IsRemoved_Impl( nNFEntry ) ) ? aCurEntryList.Count() : SELPOS_NONE;
+                nSelPos = ( !IsRemoved_Impl( nNFEntry ) ) ? aCurEntryList.size() : SELPOS_NONE;
             }
 
             rList.Insert( pStr,rList.Count());
-            aCurEntryList.Insert( nNFEntry, aCurEntryList.Count() );
+            aCurEntryList.push_back( nNFEntry );
         }
     }
 
@@ -855,11 +846,11 @@ short SvxNumberFormatShell::FillEListWithSysCurrencys( SvStrings& rList,short nS
 
         if ( nNFEntry == nCurFormatKey )
         {
-            nSelPos = ( !IsRemoved_Impl( nNFEntry ) ) ? aCurEntryList.Count() : SELPOS_NONE;
+            nSelPos = ( !IsRemoved_Impl( nNFEntry ) ) ? aCurEntryList.size() : SELPOS_NONE;
         }
 
         rList.Insert( pStr,rList.Count());
-        aCurEntryList.Insert( nNFEntry, aCurEntryList.Count() );
+        aCurEntryList.push_back( nNFEntry );
     }
 
     if(nCurCategory!=NUMBERFORMAT_ALL)
@@ -896,9 +887,9 @@ short SvxNumberFormatShell::FillEListWithSysCurrencys( SvStrings& rList,short nS
 
                     const StringPtr pStr = new String(aNewFormNInfo);
 
-                    if ( nKey == nCurFormatKey ) nSelPos =aCurEntryList.Count();
+                    if ( nKey == nCurFormatKey ) nSelPos =aCurEntryList.size();
                     rList.Insert( pStr,rList.Count());
-                    aCurEntryList.Insert( nKey, aCurEntryList.Count() );
+                    aCurEntryList.push_back( nKey );
                 }
             }
             pNumEntry = pCurFmtTable->Next();
@@ -932,7 +923,7 @@ short SvxNumberFormatShell::FillEListWithUserCurrencys( SvStrings& rList,short n
     XubString		rBankSymbol;
 
     SvStrings		aList;
-    SvULongs		aKeyList;
+    std::vector<sal_uInt32> aKeyList;
 
     /*sal_Bool bFlag=*/pFormatter->GetNewCurrencySymbolString(nCurFormatKey,rSymbol,
                 &pTmpCurrencyEntry,&bTmpBanking);
@@ -1016,7 +1007,7 @@ short SvxNumberFormatShell::FillEListWithUserCurrencys( SvStrings& rList,short n
                     const StringPtr pStr = new String(aNewFormNInfo);
 
                     aList.Insert( pStr,aList.Count());
-                    aKeyList.Insert( nKey, aKeyList.Count() );
+                    aKeyList.push_back( nKey );
                 }
             }
         }
@@ -1071,23 +1062,23 @@ short SvxNumberFormatShell::FillEListWithUserCurrencys( SvStrings& rList,short n
         if(bFlag)
         {
             rList.Insert(new String(aInsStr),nPos);
-            aCurEntryList.Insert( NUMBERFORMAT_ENTRY_NOT_FOUND, nPos++);
+            aCurEntryList.insert( aCurEntryList.begin()+nPos++, NUMBERFORMAT_ENTRY_NOT_FOUND);
         }
         else
         {
             rList.Insert(aList[j],nPos);
             aList.Remove(j);
-            aCurEntryList.Insert( aKeyList[j],nPos++);
-            aKeyList.Remove(j);
+            aCurEntryList.insert( aCurEntryList.begin()+nPos++, aKeyList[j]);
+            aKeyList.erase( aKeyList.begin()+j );
         }
     }
 
-    for(i=0;i<aKeyList.Count();i++)
+    for( i=0; i < aKeyList.size(); ++i)
     {
-        if(aKeyList[i]!=NUMBERFORMAT_ENTRY_NOT_FOUND)
+        if( aKeyList[i] != NUMBERFORMAT_ENTRY_NOT_FOUND )
         {
             rList.Insert(aList[i],rList.Count());
-            aCurEntryList.Insert( aKeyList[i],aCurEntryList.Count());
+            aCurEntryList.push_back( aKeyList[i] );
         }
     }
 
@@ -1156,9 +1147,9 @@ short SvxNumberFormatShell::FillEListWithUsD_Impl( SvStrings& rList, sal_uInt16
                 {
                     const StringPtr pStr = new String(aNewFormNInfo);
 
-                    if ( nKey == nCurFormatKey ) nSelPos =aCurEntryList.Count();
+                    if ( nKey == nCurFormatKey ) nSelPos = aCurEntryList.size();
                     rList.Insert( pStr,rList.Count());
-                    aCurEntryList.Insert( nKey, aCurEntryList.Count() );
+                    aCurEntryList.push_back( nKey );
                 }
             }
         }
@@ -1189,8 +1180,9 @@ void SvxNumberFormatShell::GetPreviewString_Impl( String& rString, Color*& rpCol
 sal_Bool SvxNumberFormatShell::IsRemoved_Impl( sal_uInt32 nKey )
 {
     sal_Bool bFound = sal_False;
-    for ( sal_uInt16 i = 0; !bFound && i < aDelList.Count(); ++i )
-        if ( aDelList[i] == nKey )
+    std::vector<sal_uInt32>::const_iterator it;
+    for ( it = aDelList.begin(); !bFound && it != aDelList.end(); ++it )
+        if ( *it == nKey )
             bFound = sal_True;
     return bFound;
 }
@@ -1200,8 +1192,9 @@ sal_Bool SvxNumberFormatShell::IsRemoved_Impl( sal_uInt32 nKey )
 sal_Bool SvxNumberFormatShell::IsAdded_Impl( sal_uInt32 nKey )
 {
     sal_Bool bFound = sal_False;
-    for ( sal_uInt16 i = 0; !bFound && i < aAddList.Count(); ++i )
-        if ( aAddList[i] == nKey )
+    std::vector<sal_uInt32>::const_iterator it;
+    for ( it = aAddList.begin(); !bFound && it != aAddList.end(); ++it )
+        if ( *it == nKey )
             bFound = sal_True;
     return bFound;
 }
@@ -1279,21 +1272,6 @@ void SvxNumberFormatShell::MakePrevStringFromVal(
     pFormatter->GetPreviewString( rFormatStr, nValue, rPreviewStr, &rpFontColor, eCurLanguage );
 }
 
-/*************************************************************************
-#*	Member:		GetComment4Entry							Datum:30.10.97
-#*------------------------------------------------------------------------
-#*
-#*  Klasse:		SvxNumberFormatShell
-#*
-#*  Funktion:	Liefert den Kommentar fuer einen gegebenen
-#*				Eintrag zurueck.
-#*
-#*  Input:		Nummer des Eintrags
-#*
-#*	Output:		Kommentar-String
-#*
-#************************************************************************/
-
 void SvxNumberFormatShell::SetComment4Entry(short nEntry,String aEntStr)
 {
     SvNumberformat *pNumEntry;
@@ -1303,21 +1281,6 @@ void SvxNumberFormatShell::SetComment4Entry(short nEntry,String aEntStr)
     if(pNumEntry!=NULL) pNumEntry->SetComment(aEntStr);
 }
 
-/*************************************************************************
-#*	Member:		GetComment4Entry							Datum:30.10.97
-#*------------------------------------------------------------------------
-#*
-#*  Klasse:		SvxNumberFormatShell
-#*
-#*  Funktion:	Liefert den Kommentar fuer einen gegebenen
-#*				Eintrag zurueck.
-#*
-#*  Input:		Nummer des Eintrags
-#*
-#*	Output:		Kommentar-String
-#*
-#************************************************************************/
-
 String SvxNumberFormatShell::GetComment4Entry(short nEntry)
 {
     const SvNumberformat *pNumEntry;
@@ -1325,7 +1288,7 @@ String SvxNumberFormatShell::GetComment4Entry(short nEntry)
     if(nEntry < 0)
         return String();
 
-    if(nEntry<aCurEntryList.Count())
+    if(nEntry < (short)aCurEntryList.size())
     {
         sal_uInt32	nMyNfEntry=aCurEntryList[nEntry];
         pNumEntry = pFormatter->GetEntry(nMyNfEntry);
@@ -1336,27 +1299,12 @@ String SvxNumberFormatShell::GetComment4Entry(short nEntry)
     return String();
 }
 
-/*************************************************************************
-#*	Member:		GetCategory4Entry							Datum:30.10.97
-#*------------------------------------------------------------------------
-#*
-#*  Klasse:		SvxNumberFormatShell
-#*
-#*  Funktion:	Liefert die Kategorie- Nummer fuer einen gegebenen
-#*				Eintrag zurueck.
-#*
-#*  Input:		Nummer des Eintrags
-#*
-#*	Output:		Kategorie- Nummer
-#*
-#************************************************************************/
-
 short SvxNumberFormatShell::GetCategory4Entry(short nEntry)
 {
     const SvNumberformat *pNumEntry;
     if(nEntry<0) return 0;
 
-    if(nEntry<aCurEntryList.Count())
+    if(nEntry < (short)aCurEntryList.size())
     {
         sal_uInt32	nMyNfEntry=aCurEntryList[nEntry];
 
@@ -1382,26 +1330,11 @@ short SvxNumberFormatShell::GetCategory4Entry(short nEntry)
 
 }
 
-/*************************************************************************
-#*	Member:		GetUserDefined4Entry						Datum:31.10.97
-#*------------------------------------------------------------------------
-#*
-#*  Klasse:		SvxNumberFormatShell
-#*
-#*  Funktion:	Liefert die Information, ob ein Eintrag
-#*				benutzerspezifisch ist zurueck.
-#*
-#*  Input:		Nummer des Eintrags
-#*
-#*	Output:		Benutzerspezifisch?
-#*
-#************************************************************************/
-
 sal_Bool SvxNumberFormatShell::GetUserDefined4Entry(short nEntry)
 {
     const SvNumberformat *pNumEntry;
     if(nEntry<0) return 0;
-    if(nEntry<aCurEntryList.Count())
+    if(nEntry < (short)aCurEntryList.size())
     {
         sal_uInt32	nMyNfEntry=aCurEntryList[nEntry];
         pNumEntry = pFormatter->GetEntry(nMyNfEntry);
@@ -1417,22 +1350,6 @@ sal_Bool SvxNumberFormatShell::GetUserDefined4Entry(short nEntry)
     return sal_False;
 }
 
-
-/*************************************************************************
-#*	Member:		GetFormat4Entry								Datum:30.10.97
-#*------------------------------------------------------------------------
-#*
-#*  Klasse:		SvxNumberFormatShell
-#*
-#*  Funktion:	Liefert den Format- String fuer einen gegebenen
-#*				Eintrag zurueck.
-#*
-#*  Input:		Nummer des Eintrags
-#*
-#*	Output:		Format- String
-#*
-#************************************************************************/
-
 String SvxNumberFormatShell::GetFormat4Entry(short nEntry)
 {
     const SvNumberformat *pNumEntry;
@@ -1456,27 +1373,12 @@ String SvxNumberFormatShell::GetFormat4Entry(short nEntry)
     return String();
 }
 
-/*************************************************************************
-#*	Member:		GetListPos4Entry							Datum:31.10.97
-#*------------------------------------------------------------------------
-#*
-#*  Klasse:		SvxNumberFormatShell
-#*
-#*  Funktion:	Liefert die Listen- Nummer fuer einen gegebenen
-#*				Formatindex zurueck.
-#*
-#*  Input:		Nummer des Eintrags
-#*
-#*	Output:		Kategorie- Nummer
-#*
-#************************************************************************/
-
 short SvxNumberFormatShell::GetListPos4Entry(sal_uInt32 nIdx)
 {
     short nSelP=SELPOS_NONE;
-    if( aCurEntryList.Count() <= 0x7fff )
+    if( aCurEntryList.size() <= 0x7fff )
     {
-        for(short i=0;i<aCurEntryList.Count();i++)
+        for(short i = 0; i < (short)aCurEntryList.size(); i++)
         {
             if(aCurEntryList[i]==nIdx)
             {
-- 
1.7.4.1


--=-R8SBPjGPdysnJ+ao4mmO--



More information about the LibreOffice mailing list