Date: prev next · Thread: first prev next last
2011 Archives by date, by thread · List index


Hi Eike,
Dnia 2011-08-07, nie o godzinie 21:31 +0200, Eike Rathke pisze:

I suggest

::std::vector<sal_uInt32>::iterator GetAdded_Impl( size_t nKey );

with logically the content of IsAdded_Impl() but using ::std::find()
instead of the awkward loop and returning the position's iterator that
can be used in RemoveFormat(), plus

bool IsAdded_Impl( size_t nKey )
{
    return GetAdded_Impl( nKey) != aAddList.end();
}

for all other places that need only a bool to remain the same. 

As promised I have done this :)

Best,
    Maciej
From 3e1925dec379e88832594b3f6032df1ca6569026 Mon Sep 17 00:00:00 2001
From: Maciej Rumianowski <maciej.rumianowski@gmail.com>
Date: Tue, 9 Aug 2011 01:15:16 +0200
Subject: [PATCH] Use STL find() in SvxNumberFormatShell

With SvULongs replaced by std::vector std::find can be used in IsRemoved_Impl IsAdded_Impl
---
 svx/inc/svx/numfmtsh.hxx      |    8 +++--
 svx/source/items/numfmtsh.cxx |   63 +++++++++++++++--------------------------
 2 files changed, 28 insertions(+), 43 deletions(-)

diff --git a/svx/inc/svx/numfmtsh.hxx b/svx/inc/svx/numfmtsh.hxx
index 4366e93..20970f3 100644
--- a/svx/inc/svx/numfmtsh.hxx
+++ b/svx/inc/svx/numfmtsh.hxx
@@ -256,9 +256,11 @@ private:
     SVX_DLLPRIVATE short                    FillEListWithSysCurrencys( SvStrings& rList,short 
nSelPos);
     SVX_DLLPRIVATE short                    FillEListWithUserCurrencys( SvStrings& rList,short 
nSelPos);
 
-    SVX_DLLPRIVATE short                    FillEListWithUsD_Impl( SvStrings& rList, sal_uInt16 
nPrivCat, short Pos );
-    SVX_DLLPRIVATE sal_Bool                 IsRemoved_Impl( sal_uInt32 nKey );
-    SVX_DLLPRIVATE sal_Bool                 IsAdded_Impl( sal_uInt32 nKey );
+    SVX_DLLPRIVATE short                               FillEListWithUsD_Impl( SvStrings& rList, 
sal_uInt16 nPrivCat, short Pos );
+    SVX_DLLPRIVATE ::std::vector<sal_uInt32>::iterator GetRemoved_Impl( size_t nKey );
+    SVX_DLLPRIVATE bool                                IsRemoved_Impl( size_t nKey );
+    SVX_DLLPRIVATE ::std::vector<sal_uInt32>::iterator GetAdded_Impl( size_t nKey );
+    SVX_DLLPRIVATE bool                                IsAdded_Impl( size_t nKey );
     SVX_DLLPRIVATE void                 GetPreviewString_Impl( String& rString,
                                                    Color*& rpColor );
     SVX_DLLPRIVATE void                 PosToCategory_Impl( sal_uInt16 nPos, short& rCategory );
diff --git a/svx/source/items/numfmtsh.cxx b/svx/source/items/numfmtsh.cxx
index bcbf8c7..e6fb543 100644
--- a/svx/source/items/numfmtsh.cxx
+++ b/svx/source/items/numfmtsh.cxx
@@ -255,20 +255,9 @@ sal_Bool SvxNumberFormatShell::AddFormat( String& rFormat,  xub_StrLen& 
rErrPos,
 
     if ( nAddKey != NUMBERFORMAT_ENTRY_NOT_FOUND ) // bereits vorhanden?
     {
-        if ( IsRemoved_Impl( nAddKey ) )
+        ::std::vector<sal_uInt32>::iterator nAt = GetRemoved_Impl( nAddKey );
+        if ( nAt != aDelList.end() )
         {
-            sal_Bool    bFound  = sal_False;
-            std::vector<sal_uInt32>::iterator nAt = aDelList.begin();
-
-            for (std::vector<sal_uInt32>::iterator it(aDelList.begin()); !bFound && it != 
aDelList.end(); ++it )
-            {
-                if ( *it == nAddKey )
-                {
-                    bFound  = sal_True;
-                    nAt = it;
-                }
-            }
-            DBG_ASSERT( bFound, "Key not found" );
             aDelList.erase( nAt );
             bInserted = sal_True;
         }
@@ -340,22 +329,10 @@ sal_Bool SvxNumberFormatShell::RemoveFormat( const String&  rFormat,
     {
         aDelList.push_back( nDelKey );
 
-        if ( IsAdded_Impl( nDelKey ) )
+        ::std::vector<sal_uInt32>::iterator nAt = GetAdded_Impl( nDelKey );
+        if( nAt != aAddList.end() )
         {
-            bool bFound = false;
-            std::vector<sal_uInt32>::iterator nAt = aAddList.begin();
-
-            for ( std::vector<sal_uInt32>::iterator it(aAddList.begin()); !bFound && it != 
aAddList.end(); ++it )
-            {
-                if ( *it == nDelKey )
-                {
-                    bFound = true;
-                    nAt = it;
-                }
-            }
-            DBG_ASSERT( bFound, "Key not found" );
-            if( bFound )
-                aAddList.erase( nAt );
+            aAddList.erase( nAt );
         }
 
         nCurCategory=pFormatter->GetType(nDelKey);
@@ -1178,24 +1155,30 @@ void SvxNumberFormatShell::GetPreviewString_Impl( String& rString, Color*& 
rpCol
 
 // -----------------------------------------------------------------------
 
-sal_Bool SvxNumberFormatShell::IsRemoved_Impl( sal_uInt32 nKey )
+::std::vector<sal_uInt32>::iterator SvxNumberFormatShell::GetRemoved_Impl( size_t nKey )
 {
-    sal_Bool bFound = sal_False;
-    for (std::vector<sal_uInt32>::const_iterator it(aDelList.begin()); !bFound && it != 
aDelList.end(); ++it )
-        if ( *it == nKey )
-            bFound = sal_True;
-    return bFound;
+    return ::std::find(aDelList.begin(), aDelList.end(), nKey);
 }
 
 // -----------------------------------------------------------------------
 
-sal_Bool SvxNumberFormatShell::IsAdded_Impl( sal_uInt32 nKey )
+bool SvxNumberFormatShell::IsRemoved_Impl( size_t nKey )
+{
+    return GetRemoved_Impl( nKey ) != aDelList.end();
+}
+
+// -----------------------------------------------------------------------
+
+::std::vector<sal_uInt32>::iterator SvxNumberFormatShell::GetAdded_Impl( size_t nKey )
+{
+    return ::std::find(aAddList.begin(), aAddList.end(), nKey);
+}
+
+//------------------------------------------------------------------------
+
+bool SvxNumberFormatShell::IsAdded_Impl( size_t nKey )
 {
-    sal_Bool bFound = sal_False;
-    for ( std::vector<sal_uInt32>::const_iterator it(aAddList.begin()); !bFound && it != 
aAddList.end(); ++it )
-        if ( *it == nKey )
-            bFound = sal_True;
-    return bFound;
+    return GetAdded_Impl( nKey ) != aAddList.end();
 }
 
 // -----------------------------------------------------------------------
-- 
1.7.4.1


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.