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


Hi

I converted the SV to std::set/vector/deque in sw component.

Could you please push this path?

This and later contributions is licensed under MPL 1.1 / GPL v3+ / LGPL v3+.

Best Regards
Bartosz
From 661b72c0cf13abd9276866766715bd6c22d5706b Mon Sep 17 00:00:00 2001
From: Bartosz Kosiorek <gang65@poczta.onet.pl>
Date: Thu, 15 Mar 2012 07:26:54 +0100
Subject: [PATCH 3/3] Convert SVARRAY SORT into STL set

---
 sw/source/core/doc/docdraw.cxx    |    3 --
 sw/source/core/doc/docedt.cxx     |    9 ++---
 sw/source/core/docnode/ndcopy.cxx |   56 ++++++++++++++++++------------------
 sw/source/core/inc/mvsave.hxx     |    5 +--
 4 files changed, 34 insertions(+), 39 deletions(-)

diff --git a/sw/source/core/doc/docdraw.cxx b/sw/source/core/doc/docdraw.cxx
index 2d5671c..cbff064 100644
--- a/sw/source/core/doc/docdraw.cxx
+++ b/sw/source/core/doc/docdraw.cxx
@@ -76,9 +76,6 @@
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::linguistic2;
 
-
-SV_IMPL_VARARR_SORT( _ZSortFlys, _ZSortFly )
-
 /*************************************************************************
 |*
 |*  SwDoc::GroupSelection / SwDoc::UnGroupSelection
diff --git a/sw/source/core/doc/docedt.cxx b/sw/source/core/doc/docedt.cxx
index 26a2ad8..6c73ba1 100644
--- a/sw/source/core/doc/docedt.cxx
+++ b/sw/source/core/doc/docedt.cxx
@@ -163,7 +163,6 @@ struct _SaveRedline
 
 SV_DECL_PTRARR_DEL( _SaveRedlines, _SaveRedline*, 0 )
 
-SV_IMPL_VARARR( _SaveFlyArr, _SaveFly )
 SV_IMPL_PTRARR( _SaveRedlines, _SaveRedline* )
 
 bool lcl_MayOverwrite( const SwTxtNode *pNode, const xub_StrLen nPos )
@@ -191,7 +190,7 @@ void _RestFlyInRange( _SaveFlyArr & rArr, const SwNodeIndex& rSttIdx,
                       const SwNodeIndex* pInsertPos )
 {
     SwPosition aPos( rSttIdx );
-    for( sal_uInt16 n = 0; n < rArr.Count(); ++n )
+    for( size_t n = 0; n < rArr.size(); ++n )
     {
         // create new anchor
         _SaveFly& rSave = rArr[n];
@@ -234,7 +233,7 @@ void _SaveFlyInRange( const SwNodeRange& rRg, _SaveFlyArr& rArr )
         {
             _SaveFly aSave( pAPos->nNode.GetIndex() - rRg.aStart.GetIndex(),
                             pFmt, sal_False );
-            rArr.Insert( aSave, rArr.Count());
+            rArr.push_back( aSave );
             pFmt->DelFrms();
             rFmts.Remove( n--, 1 );
         }
@@ -295,7 +294,7 @@ void _SaveFlyInRange( const SwPaM& rPam, const SwNodeIndex& rInsPos,
             {
                 _SaveFly aSave( pAPos->nNode.GetIndex() - rSttNdIdx.GetIndex(),
                                 pFmt, bInsPos );
-                rArr.Insert( aSave, rArr.Count());
+                rArr.push_back( aSave );
                 pFmt->DelFrms();
                 rFmts.Remove( n--, 1 );
             }
@@ -1188,7 +1187,7 @@ bool SwDoc::MoveNodeRange( SwNodeRange& rRange, SwNodeIndex& rPos,
     }
 
     // move the Flys to the new position
-    if( aSaveFlyArr.Count() )
+    if( !aSaveFlyArr.empty() )
         _RestFlyInRange( aSaveFlyArr, aIdx, NULL );
 
     // Add the Bookmarks back to the Document
diff --git a/sw/source/core/docnode/ndcopy.cxx b/sw/source/core/docnode/ndcopy.cxx
index 2461505..978bfee 100644
--- a/sw/source/core/docnode/ndcopy.cxx
+++ b/sw/source/core/docnode/ndcopy.cxx
@@ -53,6 +53,8 @@
 #include <pagedesc.hxx>
 #include <poolfmt.hxx>
 #include <SwNodeNum.hxx>
+#include <set>
+#include <vector>
 
 #ifdef DBG_UTIL
 #define CHECK_TABLE(t) (t).CheckConsistency();
@@ -328,7 +330,7 @@ sal_Bool lcl_CopyTblLine( const SwTableLine*& rpLine, void* pPara );
 
 sal_Bool lcl_CopyTblBox( const SwTableBox*& rpBox, void* pPara )
 {
-    _CopyTable* pCT = (_CopyTable*)pPara;
+    _CopyTable* pCT = reinterpret_cast< _CopyTable* >(pPara);
 
     SwTableBoxFmt* pBoxFmt = (SwTableBoxFmt*)rpBox->GetFrmFmt();
     pCT->rMapArr.ForEach( lcl_SrchNew, &pBoxFmt );
@@ -392,7 +394,7 @@ sal_Bool lcl_CopyTblBox( const SwTableBox*& rpBox, void* pPara )
 
 sal_Bool lcl_CopyTblLine( const SwTableLine*& rpLine, void* pPara )
 {
-    _CopyTable* pCT = (_CopyTable*)pPara;
+    _CopyTable* pCT = reinterpret_cast< _CopyTable* >(pPara);
     SwTableLineFmt* pLineFmt = (SwTableLineFmt*)rpLine->GetFrmFmt();
     pCT->rMapArr.ForEach( lcl_SrchNew, &pLineFmt );
     if( pLineFmt == rpLine->GetFrmFmt() )   // ein neues anlegen ??
@@ -1403,7 +1405,7 @@ void SwDoc::CopyFlyInFlyImpl( const SwNodeRange& rRg,
     //            die Ordnungsnummer (wird nur im DrawModel verwaltet)
     //            beibehalten.
     SwDoc *const pDest = rStartIdx.GetNode().GetDoc();
-    _ZSortFlys aArr;
+    ::std::set< _ZSortFly > aSet;
     sal_uInt16 nArrLen = GetSpzFrmFmts()->Count();
 
     for ( sal_uInt16 n = 0; n < nArrLen; ++n )
@@ -1467,22 +1469,20 @@ void SwDoc::CopyFlyInFlyImpl( const SwNodeRange& rRg,
                 }
             }
             if( bAdd )
-                aArr.Insert( _ZSortFly( pFmt, pAnchor, nArrLen + aArr.Count() ));
+                aSet.insert( _ZSortFly( pFmt, pAnchor, nArrLen + aSet.size() ));
         }
     }
 
     //Alle kopierten (also die neu erzeugten) Rahmen in ein weiteres Array
     //stopfen. Dort sizten sie passend zu den Originalen, damit hinterher
     //die Chains entsprechend aufgebaut werden koennen.
-    SvPtrarr aNewArr( 10 );
+    ::std::vector< SwFrmFmt* > aVecSwFrmFmt;
 
-    for ( sal_uInt16 n = 0; n < aArr.Count(); ++n )
+    for (::std::set< _ZSortFly >::const_iterator it=aSet.begin() ; it != aSet.end(); it++ )
     {
-        const _ZSortFly& rZSortFly = aArr[ n ];
-
         // #i59964#
         // correct determination of new anchor position
-        SwFmtAnchor aAnchor( *rZSortFly.GetAnchor() );
+        SwFmtAnchor aAnchor( *(*it).GetAnchor() );
         SwPosition* pNewPos = (SwPosition*)aAnchor.GetCntntAnchor();
         // for at-paragraph and at-character anchored objects the new anchor
         // position can *not* be determined by the difference of the current
@@ -1571,7 +1571,7 @@ void SwDoc::CopyFlyInFlyImpl( const SwNodeRange& rRg,
         sal_Bool bMakeCpy = sal_True;
         if( pDest == this )
         {
-            const SwFmtCntnt& rCntnt = rZSortFly.GetFmt()->GetCntnt();
+            const SwFmtCntnt& rCntnt = (*it).GetFmt()->GetCntnt();
             const SwStartNode* pSNd;
             if( rCntnt.GetCntntIdx() &&
                 0 != ( pSNd = rCntnt.GetCntntIdx()->GetNode().GetStartNode() ) &&
@@ -1579,42 +1579,42 @@ void SwDoc::CopyFlyInFlyImpl( const SwNodeRange& rRg,
                 rStartIdx.GetIndex() < pSNd->EndOfSectionIndex() )
             {
                 bMakeCpy = sal_False;
-                aArr.Remove( n, 1 );
-                --n;
+                aSet.erase ( it );
             }
         }
 
         // Format kopieren und den neuen Anker setzen
         if( bMakeCpy )
-            aNewArr.Insert( pDest->CopyLayoutFmt( *rZSortFly.GetFmt(),
-                        aAnchor, false, true ), aNewArr.Count() );
+            aVecSwFrmFmt.push_back( pDest->CopyLayoutFmt( *(*it).GetFmt(),
+                        aAnchor, false, true ) );
     }
 
     //Alle chains, die im Original vorhanden sind, soweit wie moeglich wieder
     //aufbauen.
-    OSL_ENSURE( aArr.Count() == aNewArr.Count(), "Missing new Flys" );
-    if ( aArr.Count() == aNewArr.Count() )
+    OSL_ENSURE( aSet.size() == aVecSwFrmFmt.size(), "Missing new Flys" );
+    if ( aSet.size() == aVecSwFrmFmt.size() )
     {
-        for ( sal_uInt16 n = 0; n < aArr.Count(); ++n )
+        size_t n = 0;
+        for (::std::set< _ZSortFly >::const_iterator nIt=aSet.begin() ; nIt != aSet.end(); ++nIt, 
++n )
         {
-            const SwFrmFmt *pFmt = aArr[n].GetFmt();
-            const SwFmtChain &rChain = pFmt->GetChain();
+            const SwFrmFmt *pFmtN = (*nIt).GetFmt();
+            const SwFmtChain &rChain = pFmtN->GetChain();
             int nCnt = 0 != rChain.GetPrev();
             nCnt += rChain.GetNext() ? 1: 0;
-            for ( sal_uInt16 k = 0; nCnt && k < aArr.Count(); ++k )
+            size_t k = 0;
+            for (::std::set< _ZSortFly >::const_iterator kIt=aSet.begin() ; kIt != aSet.end(); 
++kIt, ++k )
             {
-                const _ZSortFly &rTmp = aArr[k];
-                const SwFrmFmt *pTmp = rTmp.GetFmt();
-                if ( rChain.GetPrev() == pTmp )
+                const SwFrmFmt *pFmtK = (*kIt).GetFmt();
+                if ( rChain.GetPrev() == pFmtK )
                 {
-                    ::lcl_ChainFmts( (SwFlyFrmFmt*)aNewArr[k],
-                                     (SwFlyFrmFmt*)aNewArr[n] );
+                    ::lcl_ChainFmts( dynamic_cast< SwFlyFrmFmt* >(aVecSwFrmFmt[k]),
+                                     dynamic_cast< SwFlyFrmFmt* >(aVecSwFrmFmt[n]) );
                     --nCnt;
                 }
-                else if ( rChain.GetNext() == pTmp )
+                else if ( rChain.GetNext() == pFmtK )
                 {
-                    ::lcl_ChainFmts( (SwFlyFrmFmt*)aNewArr[n],
-                                     (SwFlyFrmFmt*)aNewArr[k] );
+                    ::lcl_ChainFmts( dynamic_cast< SwFlyFrmFmt* >(aVecSwFrmFmt[n]),
+                                     dynamic_cast< SwFlyFrmFmt* >(aVecSwFrmFmt[k]) );
                     --nCnt;
                 }
             }
diff --git a/sw/source/core/inc/mvsave.hxx b/sw/source/core/inc/mvsave.hxx
index 6e99ade..1e68cae 100644
--- a/sw/source/core/inc/mvsave.hxx
+++ b/sw/source/core/inc/mvsave.hxx
@@ -32,6 +32,7 @@
 #include <svl/svarray.hxx>
 #include <IDocumentMarkAccess.hxx>
 #include <vector>
+#include <deque>
 
 namespace sfx2 {
     class MetadatableUndo;
@@ -111,7 +112,7 @@ struct _SaveFly
     { }
 };
 
-SV_DECL_VARARR( _SaveFlyArr, _SaveFly, 0 )
+typedef ::std::deque< _SaveFly > _SaveFlyArr;
 
 void _RestFlyInRange( _SaveFlyArr& rArr, const SwNodeIndex& rSttIdx,
                       const SwNodeIndex* pInsPos );
@@ -182,8 +183,6 @@ public:
     const SwFmtAnchor* GetAnchor() const        { return pAnchor; }
 };
 
-SV_DECL_VARARR_SORT( _ZSortFlys, _ZSortFly, 0 )
-
 
 class SwTblNumFmtMerge
 {
-- 
1.7.5.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.