On 02/01/2011 01:57 PM, Jonathan Callen wrote:
> The attached patch replaces usage of LinkList (declared as
> DECLARE_LIST(LinkList, Link*) with std::list<Link>.
> 
> I used list<Link> instead of list<Link*> because 1) the elements of the
> list were only ever used from within the .cxx file declaring the list
> itself and 2) each element was already allocated on addition and
> deallocated on removal, so I just made that more explicit by letting
> std::list handle it.
> 
> As with all my patches, this is LGPLv3+/MPL.
> 

This version of the patch uses BOOST_FOREACH to simplify a few of the loops.

-- 
Jonathan Callen
From 64ddb5ec682dd7bd2adfd8ced73f57c7e4f72f07 Mon Sep 17 00:00:00 2001
From: Jonathan Callen <a...@gentoo.org>
Date: Tue, 1 Feb 2011 01:32:54 -0500
Subject: [PATCH] Convert tools/list.hxx usage to std::list

---
 svtools/prj/build.lst                 |    2 +-
 svtools/source/config/htmlcfg.cxx     |   19 ++++++++---------
 svtools/source/config/menuoptions.cxx |   34 +++++++++++++++-----------------
 svtools/source/config/miscopt.cxx     |   23 +++++++++------------
 4 files changed, 36 insertions(+), 42 deletions(-)

diff --git a/svtools/prj/build.lst b/svtools/prj/build.lst
index a7d8569..e8ac011 100644
--- a/svtools/prj/build.lst
+++ b/svtools/prj/build.lst
@@ -1,4 +1,4 @@
-st     svtools :       l10n svl offuh toolkit ucbhelper unotools JPEG:jpeg 
cppu cppuhelper comphelper sal sot jvmfwk NULL
+st     svtools :       l10n svl offuh toolkit ucbhelper unotools JPEG:jpeg 
cppu cppuhelper comphelper sal sot jvmfwk BOOST:boost NULL
 st     svtools                                                         usr1    
-       all     st_mkout NULL
 st     svtools\inc                                                     nmake   
-       all     st_inc NULL
 st     svtools\bmpmaker                                        nmake   -       
all     st_bmp st_inc NULL
diff --git a/svtools/source/config/htmlcfg.cxx 
b/svtools/source/config/htmlcfg.cxx
index b44dfe2..18a3fdd 100644
--- a/svtools/source/config/htmlcfg.cxx
+++ b/svtools/source/config/htmlcfg.cxx
@@ -33,9 +33,10 @@
 #include <svtools/parhtml.hxx>
 #include <unotools/syslocale.hxx>
 #include <tools/debug.hxx>
-#include <tools/list.hxx>
 #include <tools/link.hxx>
 #include <sal/macros.h>
+#include <list>
+#include <boost/foreach.hpp>
 
 // -----------------------------------------------------------------------
 #define HTMLCFG_UNKNOWN_TAGS                   0x01
@@ -54,13 +55,11 @@ using namespace com::sun::star::uno;
 
 static SvxHtmlOptions* pOptions = 0;
 
-DECLARE_LIST( LinkList, Link * )
-
 #define C2U(cChar) OUString::createFromAscii(cChar)
 
 struct HtmlOptions_Impl
 {
-    LinkList    aList;
+    ::std::list<Link> aList;
     sal_Int32  nFlags;
     sal_Int32  nExportMode;
     sal_Int32  aFontSizeArr[HTML_FONT_COUNT];
@@ -268,16 +267,16 @@ void      SvxHtmlOptions::Commit()
 
 void SvxHtmlOptions::AddListenerLink( const Link& rLink )
 {
-    pImp->aList.Insert( new Link( rLink ) );
+    pImp->aList.push_back( rLink );
 }
 
 void SvxHtmlOptions::RemoveListenerLink( const Link& rLink )
 {
-    for ( USHORT n=0; n<pImp->aList.Count(); n++ )
+    for ( ::std::list<Link>::iterator iter = pImp->aList.begin(); iter != 
pImp->aList.end(); ++iter )
     {
-        if ( (*pImp->aList.GetObject(n) ) == rLink )
+        if ( *iter == rLink )
         {
-            delete pImp->aList.Remove(n);
+            pImp->aList.erase(iter);
             break;
         }
     }
@@ -285,8 +284,8 @@ void SvxHtmlOptions::RemoveListenerLink( const Link& rLink )
 
 void SvxHtmlOptions::CallListeners()
 {
-    for ( USHORT n = 0; n < pImp->aList.Count(); ++n )
-        pImp->aList.GetObject(n)->Call( this );
+    BOOST_FOREACH(const Link& link, pImp->aList)
+        link.Call( this );
 }
 
 
diff --git a/svtools/source/config/menuoptions.cxx 
b/svtools/source/config/menuoptions.cxx
index e0b57c5..48e7678 100644
--- a/svtools/source/config/menuoptions.cxx
+++ b/svtools/source/config/menuoptions.cxx
@@ -40,6 +40,9 @@
 #include <rtl/logfile.hxx>
 #include "itemholder2.hxx"
 
+#include <list>
+#include <boost/foreach.hpp>
+
 
//_________________________________________________________________________________________________________________
 //     namespaces
 
//_________________________________________________________________________________________________________________
@@ -71,8 +74,6 @@ using namespace ::com::sun::star::uno ;
 #define PROPERTYCOUNT                           4
 
 #include <tools/link.hxx>
-#include <tools/list.hxx>
-DECLARE_LIST( LinkList, Link * )
 
 
//_________________________________________________________________________________________________________________
 //     private declarations!
@@ -85,7 +86,7 @@ class SvtMenuOptions_Impl : public ConfigItem
     
//-------------------------------------------------------------------------------------------------------------
 
     private:
-        LinkList    aList;
+        ::std::list<Link> aList;
         sal_Bool       m_bDontHideDisabledEntries                      ;       
/// cache "DontHideDisabledEntries" of Menu section
         sal_Bool       m_bFollowMouse                                          
;       /// cache "FollowMouse" of Menu section
         sal_Int16      m_nMenuIcons                                            
;       /// cache "MenuIcons" of Menu section
@@ -171,8 +172,8 @@ class SvtMenuOptions_Impl : public ConfigItem
                     {
                         m_bDontHideDisabledEntries = bState;
                         SetModified();
-                        for ( USHORT n=0; n<aList.Count(); n++ )
-                            aList.GetObject(n)->Call( this );
+                        BOOST_FOREACH(const Link& link, aList)
+                            link.Call( this );
                         Commit();
                     }
 
@@ -180,8 +181,8 @@ class SvtMenuOptions_Impl : public ConfigItem
                     {
                         m_bFollowMouse = bState;
                         SetModified();
-                        for ( USHORT n=0; n<aList.Count(); n++ )
-                            aList.GetObject(n)->Call( this );
+                        BOOST_FOREACH(const Link& link, aList)
+                            link.Call( this );
                         Commit();
                     }
 
@@ -189,8 +190,8 @@ class SvtMenuOptions_Impl : public ConfigItem
                     {
                         m_nMenuIcons = nState;
                         SetModified();
-                        for ( USHORT n=0; n<aList.Count(); n++ )
-                            aList.GetObject(n)->Call( this );
+                        BOOST_FOREACH(const Link& link, aList)
+                            link.Call( this );
                         Commit();
                     }
 
@@ -300,9 +301,6 @@ SvtMenuOptions_Impl::~SvtMenuOptions_Impl()
     {
         Commit();
     }
-
-    for ( USHORT n=0; n<aList.Count(); )
-        delete aList.Remove(n);
 }
 
 
//*****************************************************************************************************************
@@ -353,8 +351,8 @@ void SvtMenuOptions_Impl::Notify( const Sequence< OUString 
>& seqPropertyNames )
     if ( bMenuSettingsChanged )
         m_nMenuIcons = bSystemMenuIcons ? 2 : bMenuIcons;
 
-    for ( USHORT n=0; n<aList.Count(); n++ )
-        aList.GetObject(n)->Call( this );
+    BOOST_FOREACH(const Link& link, aList)
+        link.Call( this );
 }
 
 
//*****************************************************************************************************************
@@ -417,16 +415,16 @@ Sequence< OUString > 
SvtMenuOptions_Impl::impl_GetPropertyNames()
 
 void SvtMenuOptions_Impl::AddListenerLink( const Link& rLink )
 {
-    aList.Insert( new Link( rLink ) );
+    aList.push_back( rLink );
 }
 
 void SvtMenuOptions_Impl::RemoveListenerLink( const Link& rLink )
 {
-    for ( USHORT n=0; n<aList.Count(); n++ )
+    for ( ::std::list<Link>::iterator iter = aList.begin(); iter != 
aList.end(); ++iter )
     {
-        if ( (*aList.GetObject(n) ) == rLink )
+        if ( *iter == rLink )
         {
-            delete aList.Remove(n);
+            aList.erase(iter);
             break;
         }
     }
diff --git a/svtools/source/config/miscopt.cxx 
b/svtools/source/config/miscopt.cxx
index f5aa5db..14c302c 100644
--- a/svtools/source/config/miscopt.cxx
+++ b/svtools/source/config/miscopt.cxx
@@ -39,7 +39,6 @@
 #include <com/sun/star/uno/Any.hxx>
 #include <com/sun/star/uno/Sequence.hxx>
 #include <tools/link.hxx>
-#include <tools/list.hxx>
 #include <tools/wldcrd.hxx>
 #include <tools/urlobj.hxx>
 
@@ -49,6 +48,9 @@
 #include <imgdef.hxx>
 #include <vcl/svapp.hxx>
 
+#include <list>
+#include <boost/foreach.hpp>
+
 
//_________________________________________________________________________________________________________________
 //     namespaces
 
//_________________________________________________________________________________________________________________
@@ -94,8 +96,6 @@ using namespace ::com::sun::star;
 
 #define VCL_TOOLBOX_STYLE_FLAT                         ((USHORT)0x0004) // 
from <vcl/toolbox.hxx>
 
-DECLARE_LIST( LinkList, Link * )
-
 
//_________________________________________________________________________________________________________________
 //     private declarations!
 
//_________________________________________________________________________________________________________________
@@ -107,7 +107,7 @@ class SvtMiscOptions_Impl : public ConfigItem
     
//-------------------------------------------------------------------------------------------------------------
 
     private:
-    LinkList    aList;
+    ::std::list<Link> aList;
     sal_Bool    m_bUseSystemFileDialog;
     sal_Bool    m_bIsUseSystemFileDialogRO;
     sal_Bool    m_bTryODMADialog;
@@ -469,9 +469,6 @@ SvtMiscOptions_Impl::~SvtMiscOptions_Impl()
     {
         Commit();
     }
-
-    for ( USHORT n=0; n<aList.Count(); )
-        delete aList.Remove(n);
 }
 
 static int lcl_MapPropertyName( const ::rtl::OUString rCompare,
@@ -580,16 +577,16 @@ void SvtMiscOptions_Impl::Load( const Sequence< OUString 
>& rPropertyNames )
 
 void SvtMiscOptions_Impl::AddListenerLink( const Link& rLink )
 {
-    aList.Insert( new Link( rLink ) );
+    aList.push_back( rLink );
 }
 
 void SvtMiscOptions_Impl::RemoveListenerLink( const Link& rLink )
 {
-    for ( USHORT n=0; n<aList.Count(); n++ )
+    for ( ::std::list<Link>::iterator iter = aList.begin(); iter != 
aList.end(); ++iter )
     {
-        if ( (*aList.GetObject(n) ) == rLink )
+        if ( *iter == rLink )
         {
-            delete aList.Remove(n);
+            aList.erase(iter);
             break;
         }
     }
@@ -597,8 +594,8 @@ void SvtMiscOptions_Impl::RemoveListenerLink( const Link& 
rLink )
 
 void SvtMiscOptions_Impl::CallListeners()
 {
-    for ( USHORT n = 0; n < aList.Count(); ++n )
-        aList.GetObject(n)->Call( this );
+    BOOST_FOREACH(const Link& link, aList)
+        link.Call( this );
 }
 
 void SvtMiscOptions_Impl::SetToolboxStyle( sal_Int16 nStyle, bool 
_bSetModified )
-- 
1.7.4.rc3

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice

Reply via email to