incubator-ooo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r1355342 - in /incubator/ooo/trunk/main/sw: inc/doc.hxx inc/flypos.hxx source/core/doc/doclay.cxx source/core/layout/flypos.cxx source/core/unocore/unoobj2.cxx source/filter/html/htmlfly.cxx source/filter/ww8/writerhelper.cxx
Date Fri, 29 Jun 2012 12:40:02 GMT
Author: alg
Date: Fri Jun 29 12:39:59 2012
New Revision: 1355342

URL: http://svn.apache.org/viewvc?rev=1355342&view=rev
Log:
#120106# Use boost::shared_ptr and stl tools to implement a SwPosFlyFrms which can be used
and handed over by value and cleans up it's content to avoid memory leaks.
Found by: Chao Huang
Patch by: Chao Huang, alg
Review by: Chao Huang, alg

Modified:
    incubator/ooo/trunk/main/sw/inc/doc.hxx
    incubator/ooo/trunk/main/sw/inc/flypos.hxx
    incubator/ooo/trunk/main/sw/source/core/doc/doclay.cxx
    incubator/ooo/trunk/main/sw/source/core/layout/flypos.cxx
    incubator/ooo/trunk/main/sw/source/core/unocore/unoobj2.cxx
    incubator/ooo/trunk/main/sw/source/filter/html/htmlfly.cxx
    incubator/ooo/trunk/main/sw/source/filter/ww8/writerhelper.cxx

Modified: incubator/ooo/trunk/main/sw/inc/doc.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sw/inc/doc.hxx?rev=1355342&r1=1355341&r2=1355342&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sw/inc/doc.hxx (original)
+++ incubator/ooo/trunk/main/sw/inc/doc.hxx Fri Jun 29 12:39:59 2012
@@ -89,6 +89,7 @@ class SwList;
 
 #include <boost/scoped_ptr.hpp>
 #include <boost/shared_ptr.hpp>
+#include <flypos.hxx>
 
 class SvxForbiddenCharactersTable;
 class SwExtTextInput;
@@ -153,7 +154,6 @@ class SwNodes;
 class SwNumRule;
 class SwNumRuleTbl;
 class SwPageDesc;
-class SwPosFlyFrms;
 class SwPagePreViewPrtData;
 class SwRedline;
 class SwRedlineTbl;
@@ -1056,8 +1056,7 @@ public:
 	// FlyFrames von der ::com::sun::star::awt::Selection vollstaendig umschlossen sein
 	// ( Start < Pos < End ) !!!
 	// (wird fuer die Writer benoetigt)
-	void GetAllFlyFmts( SwPosFlyFrms& rPosFlyFmts, const SwPaM* = 0,
-						sal_Bool bDrawAlso = sal_False ) const;
+	SwPosFlyFrms GetAllFlyFmts( const SwPaM* = 0, sal_Bool bDrawAlso = sal_False ) const;
 
     // wegen swrtf.cxx und define private public, jetzt hier
 	SwFlyFrmFmt  *MakeFlyFrmFmt (const String &rFmtName, SwFrmFmt *pDerivedFrom);

Modified: incubator/ooo/trunk/main/sw/inc/flypos.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sw/inc/flypos.hxx?rev=1355342&r1=1355341&r2=1355342&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sw/inc/flypos.hxx (original)
+++ incubator/ooo/trunk/main/sw/inc/flypos.hxx Fri Jun 29 12:39:59 2012
@@ -23,9 +23,9 @@
 #ifndef _FLYPOS_HXX
 #define _FLYPOS_HXX
 
-
-#include <svl/svarray.hxx>
 #include <swdllapi.h>
+#include <boost/shared_ptr.hpp>
+#include <set>
 
 class SwFrmFmt;
 class SwNodeIndex;
@@ -34,23 +34,24 @@ class SwNodeIndex;
 class SW_DLLPUBLIC SwPosFlyFrm
 {
 	const SwFrmFmt* pFrmFmt;	// das FlyFrmFmt
-//	SwPosition* pPos;			// Position in den ContentNode
 	SwNodeIndex* pNdIdx;		// es reicht ein Index auf den Node
 	sal_uInt32 nOrdNum;
 public:
 	SwPosFlyFrm( const SwNodeIndex& , const SwFrmFmt*, sal_uInt16 nArrPos );
 	virtual ~SwPosFlyFrm(); // virtual fuer die Writer (DLL !!)
 
-	// operatoren fuer das Sort-Array
-	sal_Bool operator==( const SwPosFlyFrm& );
-	sal_Bool operator<( const SwPosFlyFrm& );
-
 	const SwFrmFmt& GetFmt() const { return *pFrmFmt; }
 	const SwNodeIndex& GetNdIndex() const { return *pNdIdx; }
 	sal_uInt32 GetOrdNum() const { return nOrdNum; }
 };
 
-typedef SwPosFlyFrm* SwPosFlyFrmPtr;
-SV_DECL_PTRARR_SORT_VISIBILITY( SwPosFlyFrms, SwPosFlyFrmPtr, 0, 40, SW_DLLPUBLIC )
+// define needed classes to safely handle an array of allocated SwPosFlyFrm(s).
+// SwPosFlyFrms can be handled by value (as return value), only refcounts to
+// contained SwPosFlyFrm* will be copied. When releasing the last SwPosFlyFrmPtr
+// instance the allocated instance will be freed. The array is sorted by
+// GetNdIndex by using a ::std::set container.
+typedef ::boost::shared_ptr< SwPosFlyFrm > SwPosFlyFrmPtr;
+struct SwPosFlyFrmCmp { bool operator()(const SwPosFlyFrmPtr& rA, const SwPosFlyFrmPtr&
rB) const; };
+typedef ::std::set< SwPosFlyFrmPtr, SwPosFlyFrmCmp > SwPosFlyFrms;
 
 #endif // _FLYPOS_HXX

Modified: incubator/ooo/trunk/main/sw/source/core/doc/doclay.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sw/source/core/doc/doclay.cxx?rev=1355342&r1=1355341&r2=1355342&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sw/source/core/doc/doclay.cxx (original)
+++ incubator/ooo/trunk/main/sw/source/core/doc/doclay.cxx Fri Jun 29 12:39:59 2012
@@ -1084,10 +1084,9 @@ sal_Bool TstFlyRange( const SwPaM* pPam,
 }
 
 
-void SwDoc::GetAllFlyFmts( SwPosFlyFrms& rPosFlyFmts,
-						   const SwPaM* pCmpRange, sal_Bool bDrawAlso ) const
+SwPosFlyFrms SwDoc::GetAllFlyFmts( const SwPaM* pCmpRange, sal_Bool bDrawAlso ) const
 {
-	SwPosFlyFrm *pFPos = 0;
+    SwPosFlyFrms aRetval;
 	SwFrmFmt *pFly;
 
 	// erstmal alle Absatzgebundenen einsammeln
@@ -1108,8 +1107,7 @@ void SwDoc::GetAllFlyFmts( SwPosFlyFrms&
 				if( pCmpRange &&
 					!TstFlyRange( pCmpRange, pAPos, rAnchor.GetAnchorId() ))
 						continue;		// kein gueltiger FlyFrame
-				pFPos = new SwPosFlyFrm( pAPos->nNode, pFly, rPosFlyFmts.Count() );
-				rPosFlyFmts.Insert( pFPos );
+                aRetval.insert(SwPosFlyFrmPtr(new SwPosFlyFrm(pAPos->nNode, pFly, aRetval.size())));
 			}
 		}
 	}
@@ -1117,9 +1115,10 @@ void SwDoc::GetAllFlyFmts( SwPosFlyFrms&
 	// kein Layout oder nur ein Teil, dann wars das
 	// Seitenbezogen Flys nur, wenn vollstaendig "gewuenscht" wird !
 	if( !GetCurrentViewShell() || pCmpRange )	//swmod 071108//swmod 071225
-		return;
+    {
+		return aRetval;
+    }
 
-	pFPos = 0;
 	SwPageFrm *pPage = (SwPageFrm*)GetCurrentLayout()->GetLower();	//swmod 080218
 	while( pPage )
 	{
@@ -1157,18 +1156,15 @@ void SwDoc::GetAllFlyFmts( SwPosFlyFrms&
 					if ( pCntntFrm )
 					{
 						SwNodeIndex aIdx( *pCntntFrm->GetNode() );
-						pFPos = new SwPosFlyFrm( aIdx, pFly, rPosFlyFmts.Count() );
+                        aRetval.insert(SwPosFlyFrmPtr(new SwPosFlyFrm(aIdx, pFly, aRetval.size())));
 					}
 				}
-				if ( pFPos )
-				{
-					rPosFlyFmts.Insert( pFPos );
-					pFPos = 0;
-				}
 			}
 		}
 		pPage = (SwPageFrm*)pPage->GetNext();
 	}
+
+    return aRetval;
 }
 
 /*************************************************************************

Modified: incubator/ooo/trunk/main/sw/source/core/layout/flypos.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sw/source/core/layout/flypos.cxx?rev=1355342&r1=1355341&r2=1355342&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sw/source/core/layout/flypos.cxx (original)
+++ incubator/ooo/trunk/main/sw/source/core/layout/flypos.cxx Fri Jun 29 12:39:59 2012
@@ -37,7 +37,15 @@
 #include "ndindex.hxx"
 #include "switerator.hxx"
 
-SV_IMPL_OP_PTRARR_SORT( SwPosFlyFrms, SwPosFlyFrmPtr )
+bool SwPosFlyFrmCmp::operator()(const SwPosFlyFrmPtr& rA, const SwPosFlyFrmPtr& rB)
const 
+{ 
+    if(rA->GetNdIndex() == rB->GetNdIndex())
+    {
+        return rA->GetOrdNum() < rB->GetOrdNum();
+    }
+
+    return rA->GetNdIndex() < rB->GetNdIndex(); 
+}
 
 SwPosFlyFrm::SwPosFlyFrm( const SwNodeIndex& rIdx, const SwFrmFmt* pFmt,
 							sal_uInt16 nArrPos )
@@ -89,20 +97,4 @@ SwPosFlyFrm::~SwPosFlyFrm()
     }
 }
 
-sal_Bool SwPosFlyFrm::operator==( const SwPosFlyFrm& )
-{
-	return sal_False;	// FlyFrames koennen auf der gleichen Position stehen
-}
-
-sal_Bool SwPosFlyFrm::operator<( const SwPosFlyFrm& rPosFly )
-{
-	if( pNdIdx->GetIndex() == rPosFly.pNdIdx->GetIndex() )
-	{
-		// dann entscheidet die Ordnungsnummer!
-		return nOrdNum < rPosFly.nOrdNum;
-	}
-	return pNdIdx->GetIndex() < rPosFly.pNdIdx->GetIndex();
-}
-
-
-
+// eof

Modified: incubator/ooo/trunk/main/sw/source/core/unocore/unoobj2.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sw/source/core/unocore/unoobj2.cxx?rev=1355342&r1=1355341&r2=1355342&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sw/source/core/unocore/unoobj2.cxx (original)
+++ incubator/ooo/trunk/main/sw/source/core/unocore/unoobj2.cxx Fri Jun 29 12:39:59 2012
@@ -1885,20 +1885,18 @@ SwXParaFrameEnumeration::SwXParaFrameEnu
     {
         if (PARAFRAME_PORTION_TEXTRANGE == eParaFrameMode)
         {
-            SwPosFlyFrms aFlyFrms;
             //get all frames that are bound at paragraph or at character
-            rPaM.GetDoc()->GetAllFlyFmts(aFlyFrms, m_pImpl->GetCursor());
-            for(sal_uInt16 i = 0; i < aFlyFrms.Count(); i++)
+            SwPosFlyFrms aFlyFrms(rPaM.GetDoc()->GetAllFlyFmts(m_pImpl->GetCursor()));
+
+            for(SwPosFlyFrms::const_iterator aIter(aFlyFrms.begin()); aIter != aFlyFrms.end();
aIter++)
             {
-                SwPosFlyFrm* pPosFly = aFlyFrms[i];
-                SwFrmFmt *const pFrmFmt =
-                    const_cast<SwFrmFmt*>(&pPosFly->GetFmt());
+                SwFrmFmt *const pFrmFmt = const_cast<SwFrmFmt*>(&((*aIter)->GetFmt()));
+
                 // create SwDepend for frame and insert into array
-                SwDepend *const pNewDepend =
-                    new SwDepend(m_pImpl.get(), pFrmFmt);
-                m_pImpl->m_Frames.push_back(
-                        ::boost::shared_ptr<SwDepend>(pNewDepend) );
+                SwDepend *const pNewDepend = new SwDepend(m_pImpl.get(), pFrmFmt);
+                m_pImpl->m_Frames.push_back(::boost::shared_ptr<SwDepend>(pNewDepend));
             }
+            
             //created from any text range
             if (m_pImpl->GetCursor()->HasMark())
             {
@@ -1914,6 +1912,7 @@ SwXParaFrameEnumeration::SwXParaFrameEnu
                         *m_pImpl->GetCursor()->GetMark());
             }
         }
+
         lcl_FillFrame(*m_pImpl.get(), *m_pImpl->GetCursor(), m_pImpl->m_Frames);
     }
 }

Modified: incubator/ooo/trunk/main/sw/source/filter/html/htmlfly.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sw/source/filter/html/htmlfly.cxx?rev=1355342&r1=1355341&r2=1355342&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sw/source/filter/html/htmlfly.cxx (original)
+++ incubator/ooo/trunk/main/sw/source/filter/html/htmlfly.cxx Fri Jun 29 12:39:59 2012
@@ -310,12 +310,11 @@ void SwHTMLWriter::CollectFlyFrms()
 			"number of browser configurations has changed" );
 
 	sal_uInt8 nSz = (sal_uInt8)Min( pDoc->GetSpzFrmFmts()->Count(), sal_uInt16(255) );
-	SwPosFlyFrms aFlyPos( nSz, nSz );
-	pDoc->GetAllFlyFmts( aFlyPos, bWriteAll ? 0 : pCurPam, sal_True );
+	SwPosFlyFrms aFlyPos(pDoc->GetAllFlyFmts(bWriteAll ? 0 : pCurPam, sal_True));
 
-	for( sal_uInt16 i=0; i< aFlyPos.Count(); i++ )
+    for(SwPosFlyFrms::const_iterator aIter(aFlyPos.begin()); aIter != aFlyPos.end(); aIter++)
 	{
-		const SwFrmFmt& rFrmFmt = aFlyPos[i]->GetFmt();
+		const SwFrmFmt& rFrmFmt = (*aIter)->GetFmt();
 		const SdrObject *pSdrObj = 0;
 		const SwPosition *pAPos;
 		const SwCntntNode *pACNd;
@@ -365,8 +364,7 @@ void SwHTMLWriter::CollectFlyFrms()
 		if( !pHTMLPosFlyFrms )
 			pHTMLPosFlyFrms = new SwHTMLPosFlyFrms;
 
-		SwHTMLPosFlyFrm *pNew =
-			new SwHTMLPosFlyFrm( *aFlyPos[i], pSdrObj, nMode );
+		SwHTMLPosFlyFrm *pNew = new SwHTMLPosFlyFrm(**aIter, pSdrObj, nMode);
 		pHTMLPosFlyFrms->Insert( pNew );
 	}
 }

Modified: incubator/ooo/trunk/main/sw/source/filter/ww8/writerhelper.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sw/source/filter/ww8/writerhelper.cxx?rev=1355342&r1=1355341&r2=1355342&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sw/source/filter/ww8/writerhelper.cxx (original)
+++ incubator/ooo/trunk/main/sw/source/filter/ww8/writerhelper.cxx Fri Jun 29 12:39:59 2012
@@ -140,17 +140,24 @@ namespace
     sw::Frames SwPosFlyFrmsToFrames(const SwPosFlyFrms &rFlys)
     {
         sw::Frames aRet;
-        sal_uInt16 nEnd = rFlys.Count();
-        for (sal_uInt16 nI = 0; nI < nEnd; ++nI)
+
+        for(SwPosFlyFrms::const_iterator aPos(rFlys.begin()); aPos != rFlys.end(); aPos++)
         {
-            const SwFrmFmt &rEntry = rFlys[nI]->GetFmt();
+            const SwFrmFmt &rEntry = (*aPos)->GetFmt();
+
             if (const SwPosition* pAnchor = rEntry.GetAnchor().GetCntntAnchor())
+            {
                 aRet.push_back(sw::Frame(rEntry, *pAnchor));
+            }
             else
             {
-                SwPosition aPos(rFlys[nI]->GetNdIndex());
+                SwPosition aPos((*aPos)->GetNdIndex());
+                
                 if (SwTxtNode* pTxtNd = aPos.nNode.GetNode().GetTxtNode())
+                {
                     aPos.nContent.Assign(pTxtNd, 0);
+                }
+                
                 aRet.push_back(sw::Frame(rEntry, aPos));
             }
         }
@@ -567,11 +574,8 @@ namespace sw
            */
         Frames GetFrames(const SwDoc &rDoc, SwPaM *pPaM /*, bool bAll*/)
         {
-            SwPosFlyFrms aFlys;
-            rDoc.GetAllFlyFmts(aFlys, pPaM, true);
+            SwPosFlyFrms aFlys(rDoc.GetAllFlyFmts(pPaM, true));
             sw::Frames aRet(SwPosFlyFrmsToFrames(aFlys));
-            for (sal_uInt16 i = aFlys.Count(); i > 0;)
-                delete aFlys[--i];
             return aRet;
         }
 



Mime
View raw message