[PATCH] convert detdata.cxx in SC module to std::vector

2012-02-08 Thread Noel Grandin

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::vectorScDetOpData* ScDetOpDataVector;
 
-class ScDetOpList : public ScDetOpArr_Impl
+class ScDetOpList
 {
 sal_BoolbHasAddError;   // updated in append
+   ScDetOpDataVector aDetOpDataVector;
 
 public:
 ScDetOpList() : bHasAddError(false) {}
 ScDetOpList(const ScDetOpList rList);
-~ScDetOpList() {}
+~ScDetOpList();
 
 voidDeleteOnTab( SCTAB nTab );
 voidUpdateReference( ScDocument* pDoc, UpdateRefMode eUpdateRefMode,
@@ -97,9 +92,12 @@ public:
 
 sal_Booloperator==( const ScDetOpList r ) const;   // for ref-undo
 
-voidAppend( ScDetOpData* pData );
+void Append( ScDetOpData* pData );
+   ScDetOpData* GetObject(int i) const;
+   void DeleteAndDestroy(int i);
 
 sal_BoolHasAddError() 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; inCount; 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; inCount; 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; inCount  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 

Re: [PATCH] convert detdata.cxx in SC module to std::vector

2012-02-08 Thread Eike Rathke
Hi Noel,

On Wednesday, 2012-02-08 13:05:42 +0200, Noel Grandin wrote:

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

SV_DECL_PTRARR_DEL is one of those containers that take ownership of the
objects pointed to, as you noticed and introduced deleting elements and
DeleteAndDestroy() method, and as such it is a candidate for
boost::ptr_vector instead of std::vector which makes workarounds like
DeleteAndDestroy() unnecessary, erase()'ing an element will also delete
the object. Care has to be taken when adding elements, ptr_vector if an
element could not be added deletes the object, so a dangling pointer
might be left and could be accessed, and a further delete would be
attempted twice.

I'd appreciate if you could rework the patch to use boost::ptr_vector
instead.

Thanks
  Eike

-- 
LibreOffice Calc developer. Number formatter stricken i18n transpositionizer.
GnuPG key 0x293C05FD : 997A 4C60 CE41 0149 0DB3  9E96 2F1A D073 293C 05FD


pgpdlXurcNafg.pgp
Description: PGP signature
___
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice


Re: [PATCH] convert detdata.cxx in SC module to std::vector

2012-02-08 Thread Noel Grandin

will do.

On 2012-02-08 16:44, Eike Rathke wrote:

Hi Noel,

On Wednesday, 2012-02-08 13:05:42 +0200, Noel Grandin wrote:


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

SV_DECL_PTRARR_DEL is one of those containers that take ownership of the
objects pointed to, as you noticed and introduced deleting elements and
DeleteAndDestroy() method, and as such it is a candidate for
boost::ptr_vector instead of std::vector which makes workarounds like
DeleteAndDestroy() unnecessary, erase()'ing an element will also delete
the object. Care has to be taken when adding elements, ptr_vector if an
element could not be added deletes the object, so a dangling pointer
might be left and could be accessed, and a further delete would be
attempted twice.

I'd appreciate if you could rework the patch to use boost::ptr_vector
instead.

Thanks
   Eike



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


___
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice