[Libreoffice-commits] core.git: sw/inc sw/source
Armin Le Grand
alg at apache.org
Mon May 13 12:38:40 PDT 2013
sw/inc/doc.hxx | 4 ++--
sw/inc/flypos.hxx | 15 +++++++++------
sw/source/core/doc/doclay.cxx | 22 +++++++++-------------
sw/source/core/layout/flypos.cxx | 28 +++++++++++-----------------
sw/source/core/unocore/unoobj2.cxx | 18 ++++++++----------
sw/source/filter/html/htmlfly.cxx | 10 ++++------
sw/source/filter/ww8/writerhelper.cxx | 19 ++++++++++++-------
7 files changed, 55 insertions(+), 61 deletions(-)
New commits:
commit 72e54b69601dc44932d4a3c9882d24d2380ae3b7
Author: Armin Le Grand <alg at apache.org>
Date: Fri Jun 29 11:39:59 2012 +0000
Resolves: #i120106# implement a SwPosFlyFrms which avoids memory leaks
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
(cherry picked from commit c26f80aa1ba65b63e313dce9c6d7e40ab8efede6)
Conflicts:
sw/inc/doc.hxx
sw/inc/flypos.hxx
sw/source/core/doc/doclay.cxx
sw/source/core/layout/flypos.cxx
sw/source/core/unocore/unoobj2.cxx
sw/source/filter/html/htmlfly.cxx
sw/source/filter/ww8/writerhelper.cxx
Change-Id: If610457654b1056d799d4336cd249815f7878a96
Fix build breaker from i120106
Patch by: Chao Huang
Suggested by: alg
(cherry picked from commit 880aadbeba4e31049d5b7f0a34323553fb6249fb)
Conflicts:
sw/source/filter/ww8/writerhelper.cxx
Change-Id: I516fcb6ee69944c54cc9eb76c069eb8b28749050
diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index d1956b8..f0b97f0 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -53,6 +53,7 @@ class SwList;
#include <swatrset.hxx>
#include <toxe.hxx> // enums
#include <flyenum.hxx>
+#include <flypos.hxx>
#include <itabenum.hxx>
#include <swdbdata.hxx>
#include <chcmprse.hxx>
@@ -143,7 +144,6 @@ class SwNodes;
class SwNumRule;
class SwNumRuleTbl;
class SwPageDesc;
-class SwPosFlyFrms;
class SwPagePreViewPrtData;
class SwRedline;
class SwRedlineTbl;
@@ -1048,7 +1048,7 @@ public:
have to be surrounded completely by ::com::sun::star::awt::Selection.
( Start < Pos < End ) !!!
(Required for Writers.) */
- void GetAllFlyFmts( SwPosFlyFrms& rPosFlyFmts, const SwPaM* = 0,
+ SwPosFlyFrms GetAllFlyFmts( const SwPaM* = 0,
bool bDrawAlso = false,
bool bAsCharAlso = false ) const;
diff --git a/sw/inc/flypos.hxx b/sw/inc/flypos.hxx
index fadc98c..e7b9fa0 100644
--- a/sw/inc/flypos.hxx
+++ b/sw/inc/flypos.hxx
@@ -19,8 +19,8 @@
#ifndef _FLYPOS_HXX
#define _FLYPOS_HXX
-
#include <swdllapi.h>
+#include <boost/shared_ptr.hpp>
#include <set>
class SwFrmFmt;
@@ -37,16 +37,19 @@ public:
SwPosFlyFrm( const SwNodeIndex& , const SwFrmFmt*, sal_uInt16 nArrPos );
virtual ~SwPosFlyFrm(); ///< Virtual for Writer (DLL !!)
- /// Operators for 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; }
};
-class SwPosFlyFrms : public std::multiset<SwPosFlyFrm*> {};
+// 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
diff --git a/sw/source/core/doc/doclay.cxx b/sw/source/core/doc/doclay.cxx
index b3920de..b320e79 100644
--- a/sw/source/core/doc/doclay.cxx
+++ b/sw/source/core/doc/doclay.cxx
@@ -1002,11 +1002,10 @@ static bool lcl_TstFlyRange( const SwPaM* pPam, const SwPosition* pFlyPos,
return bOk;
}
-void SwDoc::GetAllFlyFmts( SwPosFlyFrms& rPosFlyFmts,
- const SwPaM* pCmpRange, bool bDrawAlso,
+SwPosFlyFrms SwDoc::GetAllFlyFmts( const SwPaM* pCmpRange, bool bDrawAlso,
bool bAsCharAlso ) const
{
- SwPosFlyFrm *pFPos = 0;
+ SwPosFlyFrms aRetval;
SwFrmFmt *pFly;
// collect all anchored somehow to paragraphs
@@ -1028,8 +1027,7 @@ void SwDoc::GetAllFlyFmts( SwPosFlyFrms& rPosFlyFmts,
if( pCmpRange &&
!lcl_TstFlyRange( pCmpRange, pAPos, rAnchor.GetAnchorId() ))
continue; // not a valid FlyFrame
- pFPos = new SwPosFlyFrm( pAPos->nNode, pFly, rPosFlyFmts.size() );
- rPosFlyFmts.insert( pFPos );
+ aRetval.insert(SwPosFlyFrmPtr(new SwPosFlyFrm(pAPos->nNode, pFly, aRetval.size())));
}
}
}
@@ -1037,9 +1035,10 @@ void SwDoc::GetAllFlyFmts( SwPosFlyFrms& rPosFlyFmts,
// If we don't have a layout we can't get page anchored FlyFrames.
// Also, page anchored FlyFrames are only returned if no range is specified.
if( !GetCurrentViewShell() || pCmpRange ) //swmod 071108//swmod 071225
- return;
+ {
+ return aRetval;
+ }
- pFPos = 0;
SwPageFrm *pPage = (SwPageFrm*)GetCurrentLayout()->GetLower(); //swmod 080218
while( pPage )
{
@@ -1077,18 +1076,15 @@ void SwDoc::GetAllFlyFmts( SwPosFlyFrms& rPosFlyFmts,
if ( pCntntFrm )
{
SwNodeIndex aIdx( *pCntntFrm->GetNode() );
- pFPos = new SwPosFlyFrm( aIdx, pFly, rPosFlyFmts.size() );
+ aRetval.insert(SwPosFlyFrmPtr(new SwPosFlyFrm(aIdx, pFly, aRetval.size())));
}
}
- if ( pFPos )
- {
- rPosFlyFmts.insert( pFPos );
- pFPos = 0;
- }
}
}
pPage = (SwPageFrm*)pPage->GetNext();
}
+
+ return aRetval;
}
/* #i6447# changed behaviour if lcl_CpyAttr:
diff --git a/sw/source/core/layout/flypos.cxx b/sw/source/core/layout/flypos.cxx
index 44e2aa8..7a5f807 100644
--- a/sw/source/core/layout/flypos.cxx
+++ b/sw/source/core/layout/flypos.cxx
@@ -31,6 +31,17 @@
#include "ndindex.hxx"
#include "switerator.hxx"
+bool SwPosFlyFrmCmp::operator()(const SwPosFlyFrmPtr& rA, const SwPosFlyFrmPtr& rB) const
+{
+ if(rA->GetNdIndex() == rB->GetNdIndex())
+ {
+ // In this case, the order number decides!
+ return rA->GetOrdNum() < rB->GetOrdNum();
+ }
+
+ return rA->GetNdIndex() < rB->GetNdIndex();
+}
+
SwPosFlyFrm::SwPosFlyFrm( const SwNodeIndex& rIdx, const SwFrmFmt* pFmt,
sal_uInt16 nArrPos )
: pFrmFmt( pFmt ), pNdIdx( (SwNodeIndex*) &rIdx )
@@ -81,21 +92,4 @@ SwPosFlyFrm::~SwPosFlyFrm()
}
}
-sal_Bool SwPosFlyFrm::operator==( const SwPosFlyFrm& )
-{
- return sal_False; // FlyFrames can sit at the same position
-}
-
-sal_Bool SwPosFlyFrm::operator<( const SwPosFlyFrm& rPosFly )
-{
- if( pNdIdx->GetIndex() == rPosFly.pNdIdx->GetIndex() )
- {
- // In this case, the order number decides!
- return nOrdNum < rPosFly.nOrdNum;
- }
- return pNdIdx->GetIndex() < rPosFly.pNdIdx->GetIndex();
-}
-
-
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/unocore/unoobj2.cxx b/sw/source/core/unocore/unoobj2.cxx
index aa71134..7b46c17 100644
--- a/sw/source/core/unocore/unoobj2.cxx
+++ b/sw/source/core/unocore/unoobj2.cxx
@@ -1874,21 +1874,19 @@ SwXParaFrameEnumeration::SwXParaFrameEnumeration(
{
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(), false, true);
- for(SwPosFlyFrms::iterator it = aFlyFrms.begin(); it != aFlyFrms.end(); ++it)
+ SwPosFlyFrms aFlyFrms(rPaM.GetDoc()->GetAllFlyFmts(m_pImpl->GetCursor(), false, true));
+
+ for(SwPosFlyFrms::const_iterator aIter(aFlyFrms.begin()); aIter != aFlyFrms.end(); aIter++)
{
- SwPosFlyFrm* pPosFly = *it;
- 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));
}
}
+
lcl_FillFrame(*m_pImpl.get(), *m_pImpl->GetCursor(), m_pImpl->m_Frames);
}
}
diff --git a/sw/source/filter/html/htmlfly.cxx b/sw/source/filter/html/htmlfly.cxx
index a5ae153..47426ef 100644
--- a/sw/source/filter/html/htmlfly.cxx
+++ b/sw/source/filter/html/htmlfly.cxx
@@ -301,12 +301,11 @@ void SwHTMLWriter::CollectFlyFrms()
OSL_ENSURE( HTML_CFG_MAX+1 == MAX_BROWSERS,
"number of browser configurations has changed" );
- SwPosFlyFrms aFlyPos;
- pDoc->GetAllFlyFmts( aFlyPos, bWriteAll ? 0 : pCurPam, true );
+ SwPosFlyFrms aFlyPos(pDoc->GetAllFlyFmts(bWriteAll ? 0 : pCurPam, true));
- for(SwPosFlyFrms::iterator it = aFlyPos.begin(); it != aFlyPos.end(); ++it)
+ for(SwPosFlyFrms::const_iterator aIter(aFlyPos.begin()); aIter != aFlyPos.end(); ++aIter)
{
- const SwFrmFmt& rFrmFmt = (*it)->GetFmt();
+ const SwFrmFmt& rFrmFmt = (*aIter)->GetFmt();
const SdrObject *pSdrObj = 0;
const SwPosition *pAPos;
const SwCntntNode *pACNd;
@@ -356,8 +355,7 @@ void SwHTMLWriter::CollectFlyFrms()
if( !pHTMLPosFlyFrms )
pHTMLPosFlyFrms = new SwHTMLPosFlyFrms;
- SwHTMLPosFlyFrm *pNew =
- new SwHTMLPosFlyFrm( **it, pSdrObj, nMode );
+ SwHTMLPosFlyFrm *pNew = new SwHTMLPosFlyFrm(**aIter, pSdrObj, nMode);
pHTMLPosFlyFrms->insert( pNew );
}
}
diff --git a/sw/source/filter/ww8/writerhelper.cxx b/sw/source/filter/ww8/writerhelper.cxx
index d903255..228bc59 100644
--- a/sw/source/filter/ww8/writerhelper.cxx
+++ b/sw/source/filter/ww8/writerhelper.cxx
@@ -118,16 +118,24 @@ namespace
sw::Frames SwPosFlyFrmsToFrames(const SwPosFlyFrms &rFlys)
{
sw::Frames aRet;
- for(SwPosFlyFrms::const_reverse_iterator it = rFlys.rbegin(); it != rFlys.rend(); ++it)
+
+ for(SwPosFlyFrms::const_iterator aIter(rFlys.begin()); aIter != rFlys.end(); ++aIter)
{
- const SwFrmFmt &rEntry = (*it)->GetFmt();
+ const SwFrmFmt &rEntry = (*aIter)->GetFmt();
+
if (const SwPosition* pAnchor = rEntry.GetAnchor().GetCntntAnchor())
+ {
aRet.push_back(sw::Frame(rEntry, *pAnchor));
+ }
else
{
- SwPosition aPos((*it)->GetNdIndex());
+ SwPosition aPos((*aIter)->GetNdIndex());
+
if (SwTxtNode* pTxtNd = aPos.nNode.GetNode().GetTxtNode())
+ {
aPos.nContent.Assign(pTxtNd, 0);
+ }
+
aRet.push_back(sw::Frame(rEntry, aPos));
}
}
@@ -514,11 +522,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(SwPosFlyFrms::const_reverse_iterator it = aFlys.rbegin(); it != aFlys.rend(); ++it)
- delete *it;
return aRet;
}
More information about the Libreoffice-commits
mailing list