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


Hi

Attached path converts usage of SV_DECL_PTRARR_DEL in sc/inc/detdata.hxx and associated code to std::vector.

Code is contributed under MPL+/LGPL+/GPL+

Regards, Noel Grandin

Disclaimer: http://www.peralex.com/disclaimer.html


diff --git a/sc/inc/detdata.hxx b/sc/inc/detdata.hxx
index 811dde8..9697679 100644
--- a/sc/inc/detdata.hxx
+++ b/sc/inc/detdata.hxx
@@ -35,10 +35,6 @@
 
 
 //------------------------------------------------------------------------
-
-#define SC_DETOP_GROW   4
-
-//------------------------------------------------------------------------
 enum ScDetOpType
 {
     SCDETOP_ADDSUCC,
@@ -78,18 +74,17 @@ public:
 //  list of operators
 //
 
-typedef ScDetOpData* ScDetOpDataPtr;
-
-SV_DECL_PTRARR_DEL(ScDetOpArr_Impl, ScDetOpDataPtr, SC_DETOP_GROW)
+typedef std::vector<ScDetOpData*> ScDetOpDataVector;
 
-class ScDetOpList : public ScDetOpArr_Impl
+class ScDetOpList
 {
     sal_Bool    bHasAddError;       // updated in append
+       ScDetOpDataVector aDetOpDataVector;
 
 public:
         ScDetOpList() : bHasAddError(false) {}
         ScDetOpList(const ScDetOpList& rList);
-        ~ScDetOpList() {}
+        ~ScDetOpList();
 
     void    DeleteOnTab( SCTAB nTab );
     void    UpdateReference( ScDocument* pDoc, UpdateRefMode eUpdateRefMode,
@@ -97,9 +92,12 @@ public:
 
     sal_Bool    operator==( const ScDetOpList& r ) const;       // for ref-undo
 
-    void    Append( ScDetOpData* pData );
+    void         Append( ScDetOpData* pData );
+       ScDetOpData* GetObject(int i) const;
+       void         DeleteAndDestroy(int i);
 
     sal_Bool    HasAddError() const     { return bHasAddError; }
+       int         Count() const { return aDetOpDataVector.size(); }
 };
 
 
diff --git a/sc/source/core/tool/detdata.cxx b/sc/source/core/tool/detdata.cxx
index 17f6e32..28c5236 100644
--- a/sc/source/core/tool/detdata.cxx
+++ b/sc/source/core/tool/detdata.cxx
@@ -37,18 +37,19 @@
 
 //------------------------------------------------------------------------
 
-SV_IMPL_PTRARR( ScDetOpArr_Impl, ScDetOpDataPtr );
-
-//------------------------------------------------------------------------
-
 ScDetOpList::ScDetOpList(const ScDetOpList& rList) :
-    ScDetOpArr_Impl(),
     bHasAddError( false )
 {
     sal_uInt16 nCount = rList.Count();
 
     for (sal_uInt16 i=0; i<nCount; i++)
-        Append( new ScDetOpData(*rList[i]) );
+        Append( new ScDetOpData(*rList.GetObject(i)) );
+}
+
+ScDetOpList::~ScDetOpList()
+{
+    for(ScDetOpDataVector::iterator it = aDetOpDataVector.begin(); it != aDetOpDataVector.end(); 
++it)
+               delete *it;
 }
 
 void ScDetOpList::DeleteOnTab( SCTAB nTab )
@@ -58,8 +59,8 @@ void ScDetOpList::DeleteOnTab( SCTAB nTab )
     {
         // look for operations on the deleted sheet
 
-        if ( (*this)[nPos]->GetPos().Tab() == nTab )
-            Remove(nPos);
+        if ( GetObject(nPos)->GetPos().Tab() == nTab )
+            DeleteAndDestroy(nPos);
         else
             ++nPos;
     }
@@ -71,7 +72,7 @@ void ScDetOpList::UpdateReference( ScDocument* pDoc, UpdateRefMode eUpdateRefMod
     sal_uInt16 nCount = Count();
     for (sal_uInt16 i=0; i<nCount; i++)
     {
-        ScAddress aPos = (*this)[i]->GetPos();
+        ScAddress aPos = GetObject(i)->GetPos();
         SCCOL nCol1 = aPos.Col();
         SCROW nRow1 = aPos.Row();
         SCTAB nTab1 = aPos.Tab();
@@ -85,7 +86,7 @@ void ScDetOpList::UpdateReference( ScDocument* pDoc, UpdateRefMode eUpdateRefMod
                 rRange.aEnd.Col(), rRange.aEnd.Row(), rRange.aEnd.Tab(), nDx, nDy, nDz,
                 nCol1, nRow1, nTab1, nCol2, nRow2, nTab2 );
         if ( eRes != UR_NOTHING )
-            (*this)[i]->SetPos( ScAddress( nCol1, nRow1, nTab1 ) );
+            GetObject(i)->SetPos( ScAddress( nCol1, nRow1, nTab1 ) );
     }
 }
 
@@ -94,7 +95,7 @@ void ScDetOpList::Append( ScDetOpData* pDetOpData )
     if ( pDetOpData->GetOperation() == SCDETOP_ADDERROR )
         bHasAddError = sal_True;
 
-    Insert( pDetOpData, Count() );
+    Append( pDetOpData );
 }
 
 
@@ -105,12 +106,26 @@ sal_Bool ScDetOpList::operator==( const ScDetOpList& r ) const
     sal_uInt16 nCount = Count();
     sal_Bool bEqual = ( nCount == r.Count() );
     for (sal_uInt16 i=0; i<nCount && bEqual; i++)       // Reihenfolge muss auch gleich sein
-        if ( !(*(*this)[i] == *r[i]) )              // Eintraege unterschiedlich ?
+        if ( !(*(GetObject(i)) == *(r.GetObject(i))) )              // Eintraege unterschiedlich ?
             bEqual = false;
 
     return bEqual;
 }
 
+ScDetOpData* ScDetOpList::GetObject(int i) const
+{
+       return aDetOpDataVector[i];
+}
+
+void ScDetOpList::DeleteAndDestroy(int i)
+{
+       ScDetOpData* p = aDetOpDataVector[i];
+       if (p != NULL)
+       {
+               delete p;
+               aDetOpDataVector.erase(aDetOpDataVector.begin() + i);
+       }
+}
 
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx
index a211534..ffc4730 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -493,7 +493,7 @@ sal_Bool ScDocFunc::DetectiveRefresh( sal_Bool bAutomatic )
         sal_uInt16 nCount = pList->Count();
         for (sal_uInt16 i=0; i<nCount; i++)
         {
-            ScDetOpData* pData = (*pList)[i];
+            ScDetOpData* pData = pList->GetObject(i);
             if (pData)
             {
                 ScAddress aPos = pData->GetPos();
diff --git a/sc/source/ui/undo/undocell.cxx b/sc/source/ui/undo/undocell.cxx
index d0d85ca..321cf78 100644
--- a/sc/source/ui/undo/undocell.cxx
+++ b/sc/source/ui/undo/undocell.cxx
@@ -1029,9 +1029,9 @@ void ScUndoDetective::Undo()
         if (pList && pList->Count())
         {
             sal_uInt16 nPos = pList->Count() - 1;
-            ScDetOpData* pData = (*pList)[nPos];
+            ScDetOpData* pData = pList->GetObject(nPos);
             if ( pData->GetOperation() == (ScDetOpType) nAction && pData->GetPos() == aPos )
-                pList->DeleteAndDestroy( nPos, 1 );
+                pList->DeleteAndDestroy( nPos );
             else
             {
                 OSL_FAIL("Detektiv-Eintrag in der Liste nicht gefunden");

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.