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 boost::ptr_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..e3880d2 100644
--- a/sc/inc/detdata.hxx
+++ b/sc/inc/detdata.hxx
@@ -31,14 +31,10 @@
 
 #include <svl/svarray.hxx>
 #include "global.hxx"
-#include "address.hxx"
+#include "boost/ptr_container/ptr_vector.hpp"
 
 
 //------------------------------------------------------------------------
-
-#define SC_DETOP_GROW   4
-
-//------------------------------------------------------------------------
 enum ScDetOpType
 {
     SCDETOP_ADDSUCC,
@@ -78,13 +74,12 @@ public:
 //  list of operators
 //
 
-typedef ScDetOpData* ScDetOpDataPtr;
-
-SV_DECL_PTRARR_DEL(ScDetOpArr_Impl, ScDetOpDataPtr, SC_DETOP_GROW)
+typedef boost::ptr_vector<ScDetOpData> ScDetOpDataVector;
 
-class ScDetOpList : public ScDetOpArr_Impl
+class ScDetOpList
 {
     sal_Bool    bHasAddError;       // updated in append
+        ScDetOpDataVector aDetOpDataVector;
 
 public:
         ScDetOpList() : bHasAddError(false) {}
@@ -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);
+        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..d23208c 100644
--- a/sc/source/core/tool/detdata.cxx
+++ b/sc/source/core/tool/detdata.cxx
@@ -37,18 +37,13 @@
 
 //------------------------------------------------------------------------
 
-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.aDetOpDataVector[i]) );
 }
 
 void ScDetOpList::DeleteOnTab( SCTAB nTab )
@@ -58,8 +53,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 +66,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 +80,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 +89,7 @@ void ScDetOpList::Append( ScDetOpData* pDetOpData )
     if ( pDetOpData->GetOperation() == SCDETOP_ADDERROR )
         bHasAddError = sal_True;
 
-    Insert( pDetOpData, Count() );
+    aDetOpDataVector.push_back( pDetOpData );
 }
 
 
@@ -105,12 +100,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 ( !(aDetOpDataVector[i] == r.aDetOpDataVector[i]) )    // Eintraege unterschiedlich ?
             bEqual = false;
 
     return bEqual;
 }
 
+ScDetOpData* ScDetOpList::GetObject(int i)
+{
+       return &aDetOpDataVector[i];
+}
+
+void ScDetOpList::DeleteAndDestroy(int i)
+{
+       const 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.