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


Made a new patch, with the fixes now im using size_t to handle size, also
ensuring we dont add a null object.
From 5150ccd35013ab47f6a01cc58d9eb802b5d22ae0 Mon Sep 17 00:00:00 2001
From: Rafael Dominguez <venccsralph@gmail.com>
Date: Tue, 7 Jun 2011 19:00:29 -0430
Subject: [PATCH] Replace List with std::vector<XclObj*>.

---
 sc/source/filter/excel/xeescher.cxx |    6 +-
 sc/source/filter/inc/xcl97rec.hxx   |   28 +++++++++++--
 sc/source/filter/xcl97/xcl97rec.cxx |   75 ++++++++++++++++++++++-------------
 3 files changed, 74 insertions(+), 35 deletions(-)

diff --git a/sc/source/filter/excel/xeescher.cxx b/sc/source/filter/excel/xeescher.cxx
index c8b6cfc..e466614 100644
--- a/sc/source/filter/excel/xeescher.cxx
+++ b/sc/source/filter/excel/xeescher.cxx
@@ -1605,7 +1605,7 @@ XclExpMsoDrawing* XclExpObjectManager::GetMsodrawingPerSheet()
 
 bool XclExpObjectManager::HasObj() const
 {
-    return mxObjList->Count() > 0;
+    return !mxObjList->empty();
 }
 
 sal_uInt16 XclExpObjectManager::AddObj( XclObj* pObjRec )
@@ -1615,8 +1615,8 @@ sal_uInt16 XclExpObjectManager::AddObj( XclObj* pObjRec )
 
 XclObj* XclExpObjectManager::RemoveLastObj()
 {
-    XclObj* pLastObj = static_cast< XclObj* >( mxObjList->Last() );
-    mxObjList->Remove();    // remove current, which is the Last()
+    XclObj* pLastObj = mxObjList->back();
+    mxObjList->pop_back();
     return pLastObj;
 }
 
diff --git a/sc/source/filter/inc/xcl97rec.hxx b/sc/source/filter/inc/xcl97rec.hxx
index 7248bd9..aa8ce0b 100644
--- a/sc/source/filter/inc/xcl97rec.hxx
+++ b/sc/source/filter/inc/xcl97rec.hxx
@@ -39,19 +39,37 @@ class XclObj;
 class XclExpMsoDrawing;
 class SdrCaptionObj;
 
-class XclExpObjList : public List, public ExcEmptyRec, protected XclExpRoot
+class XclExpObjList : public ExcEmptyRec, protected XclExpRoot
 {
 public:
+
+    typedef std::vector<XclObj*>::iterator iterator;
+
     explicit            XclExpObjList( const XclExpRoot& rRoot, XclEscherEx& rEscherEx );
     virtual             ~XclExpObjList();
 
-    XclObj*             First() { return (XclObj*) List::First(); }
-    XclObj*             Next() { return (XclObj*) List::Next(); }
-
     /// return: 1-based ObjId
     ///! count>=0xFFFF: Obj will be deleted, return 0
     sal_uInt16              Add( XclObj* );
 
+    XclObj* back () { return maObjs.empty() ? NULL : maObjs.back(); }
+
+    /**
+     *
+     * @brief Remove last element in the list.
+     *
+     */
+
+    void pop_back ();
+
+    inline bool empty () const { return maObjs.empty(); }
+
+    inline size_t size () const { return maObjs.size(); }
+
+    inline iterator begin () { return maObjs.begin(); }
+
+    inline iterator end () { return maObjs.end(); }
+
     inline XclExpMsoDrawing* GetMsodrawingPerSheet() { return pMsodrawingPerSheet; }
 
                                 /// close groups and DgContainer opened in ctor
@@ -69,6 +87,8 @@ private:
     XclEscherEx&        mrEscherEx;
     XclExpMsoDrawing*   pMsodrawingPerSheet;
     XclExpMsoDrawing*   pSolverContainer;
+
+    std::vector<XclObj*> maObjs;
 };
 
 
diff --git a/sc/source/filter/xcl97/xcl97rec.cxx b/sc/source/filter/xcl97/xcl97rec.cxx
index 7c8c921..4e24160 100644
--- a/sc/source/filter/xcl97/xcl97rec.cxx
+++ b/sc/source/filter/xcl97/xcl97rec.cxx
@@ -118,28 +118,43 @@ XclExpObjList::XclExpObjList( const XclExpRoot& rRoot, XclEscherEx& rEscherEx 
)
 
 XclExpObjList::~XclExpObjList()
 {
-    for ( XclObj* p = First(); p; p = Next() )
-        delete p;
+    std::vector<XclObj*>::iterator pIter;
+    for ( pIter = maObjs.begin(); pIter != maObjs.end(); ++pIter )
+        delete *pIter;
     delete pMsodrawingPerSheet;
     delete pSolverContainer;
 }
 
 sal_uInt16 XclExpObjList::Add( XclObj* pObj )
 {
-    OSL_ENSURE( Count() < 0xFFFF, "XclExpObjList::Add: too much for Xcl" );
-    if ( Count() < 0xFFFF )
-    {
-        Insert( pObj, LIST_APPEND );
-        sal_uInt16 nCnt = (sal_uInt16) Count();
-        pObj->SetId( nCnt );
-        pObj->SetTab( mnScTab );
-        return nCnt;
-    }
-    else
+    size_t nSize = 0;
+
+    if (pObj)
     {
-        delete pObj;
-        return 0;
+        nSize = maObjs.size();
+
+        OSL_ENSURE( nSize < 0xFFFF, "XclExpObjList::Add: too much for Xcl" );
+
+        if ( nSize < 0xFFFF )
+        {
+            maObjs.push_back(pObj);
+            ++nSize;
+            pObj->SetId( nSize );
+            pObj->SetTab( mnScTab );
+        }
+        else
+        {
+            delete pObj;
+            nSize = 0;
+        }
     }
+
+    return nSize;
+}
+
+void XclExpObjList::pop_back ()
+{
+    maObjs.pop_back();
 }
 
 void XclExpObjList::EndSheet()
@@ -157,16 +172,17 @@ void XclExpObjList::Save( XclExpStream& rStrm )
     //! Escher must be written, even if there are no objects
     pMsodrawingPerSheet->Save( rStrm );
 
-    for ( XclObj* p = First(); p; p = Next() )
-        p->Save( rStrm );
+    std::vector<XclObj*>::iterator pIter;
+    for ( pIter = maObjs.begin(); pIter != maObjs.end(); ++pIter )
+        (*pIter)->Save( rStrm );
 
     if( pSolverContainer )
         pSolverContainer->Save( rStrm );
 }
 
-static bool IsVmlObject( const XclObj& rObj )
+static bool IsVmlObject( const XclObj *rObj )
 {
-    switch( rObj.GetObjType() )
+    switch( rObj->GetObjType() )
     {
         case EXC_OBJTYPE_NOTE:
             return true;
@@ -180,8 +196,9 @@ static sal_Int32 GetVmlObjectCount( XclExpObjList& rList )
 {
     sal_Int32 nNumVml = 0;
 
-    for ( XclObj* p = rList.First(); p; p = rList.Next() )
-        if( IsVmlObject( *p ) )
+    std::vector<XclObj*>::iterator pIter;
+    for ( pIter = rList.begin(); pIter != rList.end(); ++pIter )
+        if( IsVmlObject( *pIter ) )
             ++nNumVml;
 
     return nNumVml;
@@ -191,7 +208,7 @@ static sal_Int32 GetVmlObjectCount( XclExpObjList& rList )
 static void SaveDrawingMLObjects( XclExpObjList& rList, XclExpXmlStream& rStrm, sal_Int32& 
nDrawingMLCount )
 {
     sal_Int32 nVmlObjects = GetVmlObjectCount( rList );
-    if( (rList.Count() - nVmlObjects) == 0 )
+    if( (rList.size() - nVmlObjects) == 0 )
         return;
 
     sal_Int32 nDrawing = ++nDrawingMLCount;
@@ -215,11 +232,12 @@ static void SaveDrawingMLObjects( XclExpObjList& rList, XclExpXmlStream& 
rStrm,
             FSNS( XML_xmlns, XML_r ),   
"http://schemas.openxmlformats.org/officeDocument/2006/relationships";,
             FSEND );
 
-    for ( XclObj* p = rList.First(); p; p = rList.Next() )
+    std::vector<XclObj*>::iterator pIter;
+    for ( pIter = rList.begin(); pIter != rList.end(); ++pIter )
     {
-        if( IsVmlObject( *p ) )
+        if( IsVmlObject( *pIter ) )
             continue;
-        p->SaveXml( rStrm );
+        (*pIter)->SaveXml( rStrm );
     }
 
     pDrawing->endElement( FSNS( XML_xdr, XML_wsDr ) );
@@ -254,11 +272,12 @@ static void SaveVmlObjects( XclExpObjList& rList, XclExpXmlStream& rStrm, 
sal_In
             FSNS( XML_xmlns, XML_x ),   "urn:schemas-microsoft-com:office:excel",
             FSEND );
 
-    for ( XclObj* p = rList.First(); p; p = rList.Next() )
+    std::vector<XclObj*>::iterator pIter;
+    for ( pIter = rList.begin(); pIter != rList.end(); ++pIter )
     {
-        if( !IsVmlObject( *p ) )
+        if( !IsVmlObject( *pIter ) )
             continue;
-        p->SaveXml( rStrm );
+        (*pIter)->SaveXml( rStrm );
     }
 
     pVmlDrawing->endElement( XML_xml );
@@ -272,7 +291,7 @@ void XclExpObjList::SaveXml( XclExpXmlStream& rStrm )
     if( pSolverContainer )
         pSolverContainer->SaveXml( rStrm );
 
-    if( Count() == 0 )
+    if( maObjs.empty())
         return;
 
     SaveDrawingMLObjects( *this, rStrm, mnDrawingMLCount );
-- 
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.