[Libreoffice-commits] .: 2 commits - sc/inc sc/source

Eike Rathke erack at kemper.freedesktop.org
Fri Feb 10 08:27:36 PST 2012


 sc/inc/detdata.hxx                |   18 +++++++---------
 sc/source/core/tool/detdata.cxx   |   41 ++++++++++++++++----------------------
 sc/source/filter/xml/xmlexprt.cxx |    8 +++----
 sc/source/ui/docshell/docfunc.cxx |    6 ++---
 sc/source/ui/undo/undocell.cxx    |    8 +++----
 5 files changed, 37 insertions(+), 44 deletions(-)

New commits:
commit 43aa1115c88f1300c73337a3622c2c03faa699f7
Author: Eike Rathke <erack at redhat.com>
Date:   Fri Feb 10 17:26:44 2012 +0100

    changes to "convert detdata.cxx in SC module to boost:ptr_vector"
    
    * for includes from other modules use <> instead of "", i.e.
      <boost/ptr_container/ptr_vector.hpp>
    * use size_t instead of int for container positions and count
    * no need for DeleteAndDestroy(), in fact delete p followed by
      ptr_vector::erase() attempted to delete the instance twice and would crash
    * adapted places that accessed DeleteAndDestroy() to operate on the vector
      instead
      * introduced GetDataVector() for that
    * changed the DeleteOnTab() loop that used DeleteAndDestroy() to properly
      iterate over the container instead
    * changed UpdateReference() to a loop using iterator
    * changed operator==() to use size_t instead of sal_uInt16
      * note aside: mixing sal_uInt16 with a container's size isn't a good idea
    * adapted places that access Count() and GetObject() to use size_t instead of
      sal_uInt16
    * made GetObject() const and return const ScDetOpData*
    * changed indentation to 4 spaces per level

diff --git a/sc/inc/detdata.hxx b/sc/inc/detdata.hxx
index 891c803..6ba78c7 100644
--- a/sc/inc/detdata.hxx
+++ b/sc/inc/detdata.hxx
@@ -30,8 +30,8 @@
 #define SC_DETDATA_HXX
 
 #include <svl/svarray.hxx>
+#include <boost/ptr_container/ptr_vector.hpp>
 #include "global.hxx"
-#include "boost/ptr_container/ptr_vector.hpp"
 
 
 //------------------------------------------------------------------------
@@ -79,7 +79,7 @@ typedef boost::ptr_vector<ScDetOpData> ScDetOpDataVector;
 class ScDetOpList
 {
     sal_Bool    bHasAddError;       // updated in append
-	 ScDetOpDataVector aDetOpDataVector;
+    ScDetOpDataVector aDetOpDataVector;
 
 public:
         ScDetOpList() : bHasAddError(false) {}
@@ -93,11 +93,11 @@ public:
     sal_Bool    operator==( const ScDetOpList& r ) const;       // for ref-undo
 
     void         Append( ScDetOpData* pData );
-	 ScDetOpData* GetObject(int i);
-	 void         DeleteAndDestroy(int i);
+    ScDetOpDataVector&  GetDataVector() { return aDetOpDataVector; }
+    const ScDetOpData* GetObject( size_t nPos ) const;
 
     sal_Bool    HasAddError() const     { return bHasAddError; }
-	 int         Count() const { return aDetOpDataVector.size(); }
+    size_t      Count() const { return aDetOpDataVector.size(); }
 };
 
 
diff --git a/sc/source/core/tool/detdata.cxx b/sc/source/core/tool/detdata.cxx
index d23208c..5a0ed3a 100644
--- a/sc/source/core/tool/detdata.cxx
+++ b/sc/source/core/tool/detdata.cxx
@@ -40,33 +40,30 @@
 ScDetOpList::ScDetOpList(const ScDetOpList& rList) :
     bHasAddError( false )
 {
-    sal_uInt16 nCount = rList.Count();
+    size_t nCount = rList.Count();
 
-    for (sal_uInt16 i=0; i<nCount; i++)
+    for (size_t i=0; i<nCount; i++)
         Append( new ScDetOpData(rList.aDetOpDataVector[i]) );
 }
 
 void ScDetOpList::DeleteOnTab( SCTAB nTab )
 {
-    sal_uInt16 nPos = 0;
-    while ( nPos < Count() )
+    for (ScDetOpDataVector::iterator it = aDetOpDataVector.begin(); it != aDetOpDataVector.end(); /*noop*/ )
     {
         // look for operations on the deleted sheet
-
-        if ( GetObject(nPos)->GetPos().Tab() == nTab )
-            DeleteAndDestroy(nPos);
+        if (it->GetPos().Tab() == nTab)
+            it = aDetOpDataVector.erase( it);
         else
-            ++nPos;
+            ++it;
     }
 }
 
 void ScDetOpList::UpdateReference( ScDocument* pDoc, UpdateRefMode eUpdateRefMode,
                                 const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz )
 {
-    sal_uInt16 nCount = Count();
-    for (sal_uInt16 i=0; i<nCount; i++)
+    for (ScDetOpDataVector::iterator it = aDetOpDataVector.begin(); it != aDetOpDataVector.end(); ++it )
     {
-        ScAddress aPos = GetObject(i)->GetPos();
+        ScAddress aPos = it->GetPos();
         SCCOL nCol1 = aPos.Col();
         SCROW nRow1 = aPos.Row();
         SCTAB nTab1 = aPos.Tab();
@@ -80,7 +77,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 )
-            GetObject(i)->SetPos( ScAddress( nCol1, nRow1, nTab1 ) );
+            it->SetPos( ScAddress( nCol1, nRow1, nTab1 ) );
     }
 }
 
@@ -97,29 +94,18 @@ sal_Bool ScDetOpList::operator==( const ScDetOpList& r ) const
 {
     // fuer Ref-Undo
 
-    sal_uInt16 nCount = Count();
+    size_t nCount = Count();
     sal_Bool bEqual = ( nCount == r.Count() );
-    for (sal_uInt16 i=0; i<nCount && bEqual; i++)       // Reihenfolge muss auch gleich sein
+    for (size_t i=0; i<nCount && bEqual; i++)       // Reihenfolge muss auch gleich sein
         if ( !(aDetOpDataVector[i] == r.aDetOpDataVector[i]) )    // Eintraege unterschiedlich ?
             bEqual = false;
 
     return bEqual;
 }
 
-ScDetOpData* ScDetOpList::GetObject(int i)
+const ScDetOpData* ScDetOpList::GetObject( size_t nPos ) const
 {
-	return &aDetOpDataVector[i];
+    return &aDetOpDataVector[nPos];
 }
 
-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/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx
index 8a8dde7..01689d2 100644
--- a/sc/source/filter/xml/xmlexprt.cxx
+++ b/sc/source/filter/xml/xmlexprt.cxx
@@ -910,17 +910,17 @@ void ScXMLExport::GetDetectiveOpList( ScMyDetectiveOpContainer& rDetOp )
         ScDetOpList* pOpList(pDoc->GetDetOpList());
         if( pOpList )
         {
-            sal_uInt32 nCount(pOpList->Count());
-            for( sal_uInt32 nIndex = 0; nIndex < nCount; ++nIndex )
+            size_t nCount = pOpList->Count();
+            for (size_t nIndex = 0; nIndex < nCount; ++nIndex )
             {
-                ScDetOpData* pDetData(pOpList->GetObject( static_cast<sal_uInt16>(nIndex) ));
+                const ScDetOpData* pDetData = pOpList->GetObject( nIndex);
                 if( pDetData )
                 {
                     const ScAddress& rDetPos = pDetData->GetPos();
                     SCTAB nTab = rDetPos.Tab();
                     if ( nTab < pDoc->GetTableCount() )
                     {
-                        rDetOp.AddOperation( pDetData->GetOperation(), rDetPos, nIndex );
+                        rDetOp.AddOperation( pDetData->GetOperation(), rDetPos, static_cast<sal_uInt32>( nIndex) );
 
                         // cells with detective operations are written even if empty
                         pSharedData->SetLastColumn( nTab, rDetPos.Col() );
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx
index ffc4730..8b9d068 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -490,10 +490,10 @@ sal_Bool ScDocFunc::DetectiveRefresh( sal_Bool bAutomatic )
 
         //  Wiederholen
 
-        sal_uInt16 nCount = pList->Count();
-        for (sal_uInt16 i=0; i<nCount; i++)
+        size_t nCount = pList->Count();
+        for (size_t i=0; i < nCount; ++i)
         {
-            ScDetOpData* pData = pList->GetObject(i);
+            const 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 321cf78..1149642 100644
--- a/sc/source/ui/undo/undocell.cxx
+++ b/sc/source/ui/undo/undocell.cxx
@@ -1028,10 +1028,10 @@ void ScUndoDetective::Undo()
         ScDetOpList* pList = pDoc->GetDetOpList();
         if (pList && pList->Count())
         {
-            sal_uInt16 nPos = pList->Count() - 1;
-            ScDetOpData* pData = pList->GetObject(nPos);
-            if ( pData->GetOperation() == (ScDetOpType) nAction && pData->GetPos() == aPos )
-                pList->DeleteAndDestroy( nPos );
+            ScDetOpDataVector& rVec = pList->GetDataVector();
+            ScDetOpDataVector::iterator it = rVec.begin() + rVec.size() - 1;
+            if ( it->GetOperation() == (ScDetOpType) nAction && it->GetPos() == aPos )
+                rVec.erase( it);
             else
             {
                 OSL_FAIL("Detektiv-Eintrag in der Liste nicht gefunden");
commit d4a31e6ae28825a42cb8b1935fdfd777cda41e8f
Author: Noel Grandin <noel at peralex.com>
Date:   Fri Feb 10 13:47:22 2012 +0100

    convert detdata.cxx in SC module to boost:ptr_vector
    
    converts usage of SV_DECL_PTRARR_DEL in sc/inc/detdata.hxx and associated code
    to boost::ptr_vector

diff --git a/sc/inc/detdata.hxx b/sc/inc/detdata.hxx
index 811dde8..891c803 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");


More information about the Libreoffice-commits mailing list