[Libreoffice-commits] .: sc/inc sc/source
Kohei Yoshida
kohei at kemper.freedesktop.org
Thu Dec 9 17:08:02 PST 2010
sc/inc/rangelst.hxx | 24 ++++++-
sc/source/core/data/clipparam.cxx | 2
sc/source/core/data/table2.cxx | 2
sc/source/core/tool/rangelst.cxx | 112 +++++++++++++++++++++++++++++----
sc/source/core/tool/rangeutl.cxx | 2
sc/source/core/tool/reftokenhelper.cxx | 2
sc/source/filter/excel/xehelper.cxx | 2
sc/source/filter/html/htmlpars.cxx | 5 +
sc/source/ui/miscdlgs/acredlin.cxx | 2
sc/source/ui/miscdlgs/highred.cxx | 2
sc/source/ui/unoobj/cellsuno.cxx | 10 +-
sc/source/ui/unoobj/chart2uno.cxx | 2
12 files changed, 137 insertions(+), 30 deletions(-)
New commits:
commit 9a6e58b21588070743d251e04cfc01450f58aec5
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Thu Dec 9 20:07:11 2010 -0500
First cut on making ScRangeList not a child class of std::vector.
Also fixed some memory leaks along the way.
diff --git a/sc/inc/rangelst.hxx b/sc/inc/rangelst.hxx
index 6f71f1b..cb42c6c 100644
--- a/sc/inc/rangelst.hxx
+++ b/sc/inc/rangelst.hxx
@@ -37,8 +37,7 @@
class ScDocument;
typedef ScRange* ScRangePtr;
-typedef ::std::vector< ScRangePtr > ScRangeListBase;
-class SC_DLLPUBLIC ScRangeList : public ScRangeListBase, public SvRefBase
+class SC_DLLPUBLIC ScRangeList : public SvRefBase
{
public:
ScRangeList() {}
@@ -69,12 +68,31 @@ public:
SCsTAB nDz
);
- ScRange* Find( const ScAddress& ) const;
+ const ScRange* Find( const ScAddress& ) const;
+ ScRange* Find( const ScAddress& );
bool operator==( const ScRangeList& ) const;
bool operator!=( const ScRangeList& r ) const;
bool Intersects( const ScRange& ) const;
bool In( const ScRange& ) const;
size_t GetCellCount() const;
+
+ ScRange* Remove(size_t nPos);
+
+ bool empty() const;
+ size_t size() const;
+ ScRange* at(size_t idx);
+ const ScRange* at(size_t idx) const;
+ ScRange* operator[](size_t idx);
+ const ScRange* operator[](size_t idx) const;
+ ScRange* front();
+ const ScRange* front() const;
+ ScRange* back();
+ const ScRange* back() const;
+ void push_back(ScRange* p);
+ void clear();
+
+private:
+ ::std::vector<ScRange*> maRanges;
};
SV_DECL_IMPL_REF( ScRangeList );
diff --git a/sc/source/core/data/clipparam.cxx b/sc/source/core/data/clipparam.cxx
index 967c10a..b4edeea 100644
--- a/sc/source/core/data/clipparam.cxx
+++ b/sc/source/core/data/clipparam.cxx
@@ -126,7 +126,7 @@ ScRange ScClipParam::getWholeRange() const
bool bFirst = true;
for ( size_t i = 0, n = maRanges.size(); i < n; ++i )
{
- ScRange* p = maRanges[ i ];
+ const ScRange* p = maRanges[i];
if (bFirst)
{
aWhole = *p;
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index 4061354..3a7752a 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -926,7 +926,7 @@ BOOL ScTable::HasScenarioRange( const ScRange& rRange ) const
{
for ( size_t j = 0, n = pList->size(); j < n; j++ )
{
- ScRange* pR = pList->at( j );
+ const ScRange* pR = pList->at( j );
if ( pR->Intersects( aTabRange ) )
return TRUE;
}
diff --git a/sc/source/core/tool/rangelst.cxx b/sc/source/core/tool/rangelst.cxx
index 19b3639..e404e76 100644
--- a/sc/source/core/tool/rangelst.cxx
+++ b/sc/source/core/tool/rangelst.cxx
@@ -44,11 +44,14 @@
#include "rechead.hxx"
#include "compiler.hxx"
+using ::std::vector;
+using ::std::advance;
+
// === ScRangeList ====================================================
ScRangeList::~ScRangeList()
{
- std::vector<ScRangePtr>::iterator itr = begin(), itrEnd = end();
+ std::vector<ScRangePtr>::iterator itr = maRanges.begin(), itrEnd = maRanges.end();
for (; itr != itrEnd; ++itr)
delete *itr;
clear();
@@ -124,7 +127,7 @@ void ScRangeList::Format( String& rStr, USHORT nFlags, ScDocument* pDoc,
void ScRangeList::Join( const ScRange& r, bool bIsInList )
{
- if ( empty() )
+ if ( maRanges.empty() )
{
Append( r );
return ;
@@ -136,13 +139,14 @@ void ScRangeList::Join( const ScRange& r, bool bIsInList )
SCROW nRow2 = r.aEnd.Row();
SCTAB nTab2 = r.aEnd.Tab();
- ScRangePtr pOver = (ScRangePtr) &r; // fies aber wahr wenn bInList
+ ScRange* pOver = (ScRange*) &r; // fies aber wahr wenn bInList
size_t nOldPos = 0;
if ( bIsInList )
- { // merken um ggbf. zu loeschen bzw. wiederherzustellen
- for ( size_t i = 0, nRanges = size(); i < nRanges; ++i )
+ {
+ // Find the current position of this range.
+ for ( size_t i = 0, nRanges = maRanges.size(); i < nRanges; ++i )
{
- if ( at( i ) == pOver )
+ if ( maRanges[i] == pOver )
{
nOldPos = i;
break;
@@ -151,9 +155,9 @@ void ScRangeList::Join( const ScRange& r, bool bIsInList )
}
bool bJoinedInput = false;
- for ( size_t i = 0, nRanges = size(); i < nRanges && pOver; ++i )
+ for ( size_t i = 0, nRanges = maRanges.size(); i < nRanges && pOver; ++i )
{
- ScRangePtr p = at( i );
+ ScRange* p = maRanges[i];
if ( p == pOver )
continue; // derselbe, weiter mit dem naechsten
bool bJoined = false;
@@ -205,7 +209,7 @@ void ScRangeList::Join( const ScRange& r, bool bIsInList )
{
if ( bIsInList )
{ // innerhalb der Liste Range loeschen
- erase( begin() + nOldPos );
+ Remove(nOldPos);
delete pOver;
pOver = NULL;
if ( nOldPos )
@@ -284,11 +288,22 @@ bool ScRangeList::UpdateReference(
return bChanged;
}
-ScRange* ScRangeList::Find( const ScAddress& rAdr ) const
+const ScRange* ScRangeList::Find( const ScAddress& rAdr ) const
+{
+ for ( size_t j = 0, nListCount = size(); j < nListCount; j++ )
+ {
+ const ScRange* pR = maRanges[j];
+ if ( pR->In( rAdr ) )
+ return pR;
+ }
+ return NULL;
+}
+
+ScRange* ScRangeList::Find( const ScAddress& rAdr )
{
for ( size_t j = 0, nListCount = size(); j < nListCount; j++ )
{
- ScRangePtr pR = at( j );
+ ScRange* pR = maRanges[j];
if ( pR->In( rAdr ) )
return pR;
}
@@ -297,7 +312,6 @@ ScRange* ScRangeList::Find( const ScAddress& rAdr ) const
ScRangeList::ScRangeList( const ScRangeList& rList ) :
- ScRangeListBase(),
SvRefBase()
{
for ( size_t j = 0, nListCount = rList.size(); j < nListCount; j++ )
@@ -339,7 +353,7 @@ size_t ScRangeList::GetCellCount() const
size_t nCellCount = 0;
for ( size_t j = 0, nListCount = size(); j < nListCount; j++ )
{
- ScRangePtr pR = at( j );
+ const ScRange* pR = maRanges[j];
nCellCount += size_t(pR->aEnd.Col() - pR->aStart.Col() + 1)
* size_t(pR->aEnd.Row() - pR->aStart.Row() + 1)
* size_t(pR->aEnd.Tab() - pR->aStart.Tab() + 1);
@@ -347,6 +361,78 @@ size_t ScRangeList::GetCellCount() const
return nCellCount;
}
+ScRange* ScRangeList::Remove(size_t nPos)
+{
+ if (maRanges.size() <= nPos)
+ // Out-of-bound condition. Bail out.
+ return NULL;
+
+ vector<ScRange*>::iterator itr = maRanges.begin();
+ advance(itr, nPos);
+ ScRange* p = *itr;
+ maRanges.erase(itr);
+ return p;
+}
+
+bool ScRangeList::empty() const
+{
+ return maRanges.empty();
+}
+
+size_t ScRangeList::size() const
+{
+ return maRanges.size();
+}
+
+ScRange* ScRangeList::at(size_t idx)
+{
+ return maRanges.at(idx);
+}
+
+const ScRange* ScRangeList::at(size_t idx) const
+{
+ return maRanges.at(idx);
+}
+
+ScRange* ScRangeList::operator [](size_t idx)
+{
+ return maRanges[idx];
+}
+
+const ScRange* ScRangeList::operator [](size_t idx) const
+{
+ return maRanges[idx];
+}
+
+ScRange* ScRangeList::front()
+{
+ return maRanges.front();
+}
+
+const ScRange* ScRangeList::front() const
+{
+ return maRanges.front();
+}
+
+ScRange* ScRangeList::back()
+{
+ return maRanges.back();
+}
+
+const ScRange* ScRangeList::back() const
+{
+ return maRanges.back();
+}
+
+void ScRangeList::push_back(ScRange* p)
+{
+ maRanges.push_back(p);
+}
+
+void ScRangeList::clear()
+{
+ maRanges.clear();
+}
// === ScRangePairList ====================================================
diff --git a/sc/source/core/tool/rangeutl.cxx b/sc/source/core/tool/rangeutl.cxx
index f5b172d..7c32e67 100644
--- a/sc/source/core/tool/rangeutl.cxx
+++ b/sc/source/core/tool/rangeutl.cxx
@@ -725,7 +725,7 @@ void ScRangeStringConverter::GetStringFromRangeList(
{
for( size_t nIndex = 0, nCount = pRangeList->size(); nIndex < nCount; nIndex++ )
{
- const ScRangePtr pRange = pRangeList->at( nIndex );
+ const ScRange* pRange = pRangeList->at( nIndex );
if( pRange )
GetStringFromRange( sRangeListStr, *pRange, pDocument, eConv, cSeperator, sal_True, nFormatFlags );
}
diff --git a/sc/source/core/tool/reftokenhelper.cxx b/sc/source/core/tool/reftokenhelper.cxx
index 8c3f3a2..013c4fc 100644
--- a/sc/source/core/tool/reftokenhelper.cxx
+++ b/sc/source/core/tool/reftokenhelper.cxx
@@ -202,7 +202,7 @@ void ScRefTokenHelper::getTokensFromRangeList(vector<ScSharedTokenRef>& pTokens,
aTokens.reserve(nCount);
for (size_t i = 0; i < nCount; ++i)
{
- ScRange* pRange = rRanges[ i ];
+ const ScRange* pRange = rRanges[i];
if (!pRange)
// failed.
return;
diff --git a/sc/source/filter/excel/xehelper.cxx b/sc/source/filter/excel/xehelper.cxx
index 47fa4b4..b5da0c6 100644
--- a/sc/source/filter/excel/xehelper.cxx
+++ b/sc/source/filter/excel/xehelper.cxx
@@ -264,7 +264,7 @@ void XclExpAddressConverter::ValidateRangeList( ScRangeList& rScRanges, bool bWa
{
ScRangePtr pScRange = rScRanges[ --nRange ];
if( !CheckRange( *pScRange, bWarn ) )
- rScRanges.erase( rScRanges.begin() + nRange );
+ delete rScRanges.Remove(nRange);
}
}
diff --git a/sc/source/filter/html/htmlpars.cxx b/sc/source/filter/html/htmlpars.cxx
index 83fa26b..7b4cc2b 100644
--- a/sc/source/filter/html/htmlpars.cxx
+++ b/sc/source/filter/html/htmlpars.cxx
@@ -397,7 +397,10 @@ void ScHTMLLayoutParser::SkipLocked( ScEEParseEntry* pE, BOOL bJoin )
void ScHTMLLayoutParser::Adjust()
{
+ for (size_t i = 0, n = xLockedList->size(); i < n; ++i)
+ delete xLockedList->at(i);
xLockedList->clear();
+
ScHTMLAdjustStack aStack;
ScHTMLAdjustStackEntry* pS;
USHORT nTab = 0;
@@ -2037,7 +2040,7 @@ const SfxItemSet& ScHTMLTable::GetCurrItemSet() const
ScHTMLSize ScHTMLTable::GetSpan( const ScHTMLPos& rCellPos ) const
{
ScHTMLSize aSpan( 1, 1 );
- ScRange* pRange = 0;
+ const ScRange* pRange = NULL;
if( ( (pRange = maVMergedCells.Find( rCellPos.MakeAddr() ) ) != 0)
|| ( (pRange = maHMergedCells.Find( rCellPos.MakeAddr() ) ) != 0)
)
diff --git a/sc/source/ui/miscdlgs/acredlin.cxx b/sc/source/ui/miscdlgs/acredlin.cxx
index f74d8e7..ceb3a80 100644
--- a/sc/source/ui/miscdlgs/acredlin.cxx
+++ b/sc/source/ui/miscdlgs/acredlin.cxx
@@ -300,7 +300,7 @@ void __EXPORT ScAcceptChgDlg::Init()
if( !aChangeViewSet.GetTheRangeList().empty() )
{
- ScRangePtr pRangeEntry = aChangeViewSet.GetTheRangeList().front();
+ const ScRange* pRangeEntry = aChangeViewSet.GetTheRangeList().front();
String aRefStr;
pRangeEntry->Format( aRefStr, ABS_DREF3D, pDoc );
pTPFilter->SetRange(aRefStr);
diff --git a/sc/source/ui/miscdlgs/highred.cxx b/sc/source/ui/miscdlgs/highred.cxx
index 1b5f211..7f0ac1e 100644
--- a/sc/source/ui/miscdlgs/highred.cxx
+++ b/sc/source/ui/miscdlgs/highred.cxx
@@ -166,7 +166,7 @@ void __EXPORT ScHighlightChgDlg::Init()
if ( !aChangeViewSet.GetTheRangeList().empty() )
{
String aRefStr;
- ScRangePtr pRangeEntry = aChangeViewSet.GetTheRangeList().front();
+ const ScRange* pRangeEntry = aChangeViewSet.GetTheRangeList().front();
pRangeEntry->Format( aRefStr, ABS_DREF3D, pDoc );
aFilterCtr.SetRange(aRefStr);
}
diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx
index 774377b..34fa7ac 100644
--- a/sc/source/ui/unoobj/cellsuno.cxx
+++ b/sc/source/ui/unoobj/cellsuno.cxx
@@ -890,7 +890,7 @@ BOOL lcl_WholeSheet( const ScRangeList& rRanges )
{
if ( rRanges.size() == 1 )
{
- ScRange* pRange = rRanges[ 0 ];
+ const ScRange* pRange = rRanges[0];
if ( pRange && pRange->aStart.Col() == 0 && pRange->aEnd.Col() == MAXCOL &&
pRange->aStart.Row() == 0 && pRange->aEnd.Row() == MAXROW )
return TRUE;
@@ -2968,7 +2968,7 @@ ScMemChart* ScCellRangesBase::CreateMemChart_Impl() const
// (nur hier, Listener werden auf den ganzen Bereich angemeldet)
//! direkt testen, ob es ein ScTableSheetObj ist?
- ScRange* pRange = aRanges[ 0 ];
+ const ScRange* pRange = aRanges[0];
if ( pRange->aStart.Col() == 0 && pRange->aEnd.Col() == MAXCOL &&
pRange->aStart.Row() == 0 && pRange->aEnd.Row() == MAXROW )
{
@@ -3039,7 +3039,7 @@ ScRangeListRef ScCellRangesBase::GetLimitedChartRanges_Impl( long nDataColumns,
{
if ( aRanges.size() == 1 )
{
- ScRange* pRange = aRanges[ 0 ];
+ const ScRange* pRange = aRanges[0];
if ( pRange->aStart.Col() == 0 && pRange->aEnd.Col() == MAXCOL &&
pRange->aStart.Row() == 0 && pRange->aEnd.Row() == MAXROW )
{
@@ -4791,8 +4791,8 @@ void ScCellRangeObj::RefChanged()
DBG_ASSERT(rRanges.size() == 1, "was fuer Ranges ?!?!");
if ( !rRanges.empty() )
{
- const ScRangePtr pFirst = rRanges[ 0 ];
- aRange = *pFirst;
+ const ScRange* pFirst = rRanges[0];
+ aRange = ScRange(*pFirst);
aRange.Justify();
}
}
diff --git a/sc/source/ui/unoobj/chart2uno.cxx b/sc/source/ui/unoobj/chart2uno.cxx
index 6de0d00..8e9ebee 100644
--- a/sc/source/ui/unoobj/chart2uno.cxx
+++ b/sc/source/ui/unoobj/chart2uno.cxx
@@ -2638,7 +2638,7 @@ void ScChart2DataSequence::UpdateTokensFromRanges(const ScRangeList& rRanges)
for ( size_t i = 0, nCount = rRanges.size(); i < nCount; ++i )
{
ScSharedTokenRef pToken;
- ScRangePtr pRange = rRanges[ i ];
+ const ScRange* pRange = rRanges[i];
DBG_ASSERT(pRange, "range object is NULL.");
ScRefTokenHelper::getTokenFromRange(pToken, *pRange);
More information about the Libreoffice-commits
mailing list