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



Also haven't pushed
0002-Replace-List-with-std-vector-XclExpUserBView.calc.patch because I
am not sure about

--- cut ---
 XclExpUserBViewList::XclExpUserBViewList( const ScChangeTrack&
rChangeTrack )
+    : aViews(rChangeTrack.GetUserCollection().GetCount())
[...]
-            List::Insert( new XclExpUserBView( pStrData->GetString(),
aGUID ), LIST_APPEND );
+            aViews.push_back( new XclExpUserBView( pStrData->GetString(),
aGUID ) );
--- cut ---

Why do you initialize the vector with NULL pointers?

IMHO, all the pointers will stay NULL because you later use .push_back().

For example, rChangeTrack has the collection: A B C D and GetCount()
returns 4.
If you initialize the vector, you will end with the vector: 0 0 0 0 A B C D

Or did I miss something?


Nope, heres a patch fixing those issues
From 317ae353106a4c71905fe168c3f4e2a0ab179c9e Mon Sep 17 00:00:00 2001
From: Rafael Dominguez <venccsralph@gmail.com>
Date: Tue, 7 Jun 2011 19:22:40 -0430
Subject: [PATCH] Replace List with std::vector<XclExpUserBView*>.

---
 sc/source/filter/excel/excdoc.cxx            |   10 ++++++----
 sc/source/filter/inc/XclExpChangeTrack.hxx   |   18 +++++++++++++-----
 sc/source/filter/xcl97/XclExpChangeTrack.cxx |   17 ++++++++++++-----
 3 files changed, 31 insertions(+), 14 deletions(-)

diff --git a/sc/source/filter/excel/excdoc.cxx b/sc/source/filter/excel/excdoc.cxx
index 180d57d..8dbc680 100644
--- a/sc/source/filter/excel/excdoc.cxx
+++ b/sc/source/filter/excel/excdoc.cxx
@@ -530,9 +530,10 @@ void ExcTable::FillAsTable( SCTAB nCodeNameIdx )
     // change tracking
     if( rR.pUserBViewList )
     {
-        for( const XclExpUserBView* pBView = rR.pUserBViewList->First(); pBView; pBView = 
rR.pUserBViewList->Next() )
+        XclExpUserBViewList::const_iterator iter;
+        for ( iter = rR.pUserBViewList->begin(); iter != rR.pUserBViewList->end(); ++iter)
         {
-            Add( new XclExpUsersViewBegin( pBView->GetGUID(), nExcTab ) );
+            Add( new XclExpUsersViewBegin( (*iter)->GetGUID(), nExcTab ) );
             Add( new XclExpUsersViewEnd );
         }
     }
@@ -619,9 +620,10 @@ void ExcTable::FillAsXmlTable( SCTAB nCodeNameIdx )
     // change tracking
     if( rR.pUserBViewList )
     {
-        for( const XclExpUserBView* pBView = rR.pUserBViewList->First(); pBView; pBView = 
rR.pUserBViewList->Next() )
+        XclExpUserBViewList::const_iterator iter;
+        for ( iter = rR.pUserBViewList->begin(); iter != rR.pUserBViewList->end(); ++iter )
         {
-            Add( new XclExpUsersViewBegin( pBView->GetGUID(), nExcTab ) );
+            Add( new XclExpUsersViewBegin( (*iter)->GetGUID(), nExcTab ) );
             Add( new XclExpUsersViewEnd );
         }
     }
diff --git a/sc/source/filter/inc/XclExpChangeTrack.hxx b/sc/source/filter/inc/XclExpChangeTrack.hxx
index ef98f77..2c71432 100644
--- a/sc/source/filter/inc/XclExpChangeTrack.hxx
+++ b/sc/source/filter/inc/XclExpChangeTrack.hxx
@@ -64,18 +64,26 @@ public:
 //___________________________________________________________________
 // XclExpUserBViewList - list of UserBView records
 
-class XclExpUserBViewList : public ExcEmptyRec, private List
+class XclExpUserBViewList : public ExcEmptyRec
 {
 private:
-    inline XclExpUserBView*            _First()        { return (XclExpUserBView*) List::First(); }
-    inline XclExpUserBView*            _Next()         { return (XclExpUserBView*) List::Next(); }
+    std::vector<XclExpUserBView*> aViews;
 
 public:
+
+    typedef std::vector<XclExpUserBView*>::iterator iterator;
+    typedef std::vector<XclExpUserBView*>::const_iterator const_iterator;
+
                                 XclExpUserBViewList( const ScChangeTrack& rChangeTrack );
     virtual                                            ~XclExpUserBViewList();
 
-    inline const XclExpUserBView* First()      { return (const XclExpUserBView*) List::First(); }
-    inline const XclExpUserBView* Next()       { return (const XclExpUserBView*) List::Next(); }
+    inline iterator begin () { return aViews.begin(); }
+
+    inline iterator end () { return aViews.end(); }
+
+    inline const_iterator begin () const { return aViews.begin(); }
+
+    inline const_iterator end () const { return aViews.end(); }
 
     virtual void                               Save( XclExpStream& rStrm );
 };
diff --git a/sc/source/filter/xcl97/XclExpChangeTrack.cxx 
b/sc/source/filter/xcl97/XclExpChangeTrack.cxx
index cd78aba..aa9d886 100644
--- a/sc/source/filter/xcl97/XclExpChangeTrack.cxx
+++ b/sc/source/filter/xcl97/XclExpChangeTrack.cxx
@@ -147,29 +147,36 @@ sal_Size XclExpUserBView::GetLen() const
 //___________________________________________________________________
 
 XclExpUserBViewList::XclExpUserBViewList( const ScChangeTrack& rChangeTrack )
+    : aViews(rChangeTrack.GetUserCollection().GetCount())
 {
     sal_uInt8 aGUID[ 16 ];
     sal_Bool bValidGUID = false;
+    XclExpUserBView *pView = NULL;
     const ScStrCollection& rStrColl = rChangeTrack.GetUserCollection();
     for( sal_uInt16 nIndex = 0; nIndex < rStrColl.GetCount(); nIndex++ )
     {
         const StrData* pStrData = (const StrData*) rStrColl.At( nIndex );
         lcl_GenerateGUID( aGUID, bValidGUID );
         if( pStrData )
-            List::Insert( new XclExpUserBView( pStrData->GetString(), aGUID ), LIST_APPEND );
+        {
+            pView = new XclExpUserBView( pStrData->GetString(), aGUID );
+
+            if (pView)
+                aViews.push_back( pView );
+        }
     }
 }
 
 XclExpUserBViewList::~XclExpUserBViewList()
 {
-    for( XclExpUserBView* pRec = _First(); pRec; pRec = _Next() )
-        delete pRec;
+    for( iterator iter = aViews.begin(); iter != aViews.end(); ++iter )
+        delete *iter;
 }
 
 void XclExpUserBViewList::Save( XclExpStream& rStrm )
 {
-    for( XclExpUserBView* pRec = _First(); pRec; pRec = _Next() )
-        pRec->Save( rStrm );
+   for( iterator iter = aViews.begin(); iter != aViews.end(); ++iter )
+        (*iter)->Save( rStrm );
 }
 
 //___________________________________________________________________
-- 
1.7.3.4


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.