[Libreoffice-commits] .: 2 commits - sc/inc sc/source
Kohei Yoshida
kohei at kemper.freedesktop.org
Fri Dec 10 09:07:41 PST 2010
sc/inc/rangelst.hxx | 2
sc/source/core/tool/rangelst.cxx | 142 ++++++++++++++++++++-------------------
2 files changed, 75 insertions(+), 69 deletions(-)
New commits:
commit b6b5b30e92681672d8dc8a3e40da2c0990129296
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Fri Dec 10 12:06:57 2010 -0500
Prefer to use iterators to for loop & element access via [].
diff --git a/sc/source/core/tool/rangelst.cxx b/sc/source/core/tool/rangelst.cxx
index 93e0c11..d7c152e 100644
--- a/sc/source/core/tool/rangelst.cxx
+++ b/sc/source/core/tool/rangelst.cxx
@@ -55,7 +55,7 @@ class FindRangeByAddress : public ::std::unary_function<bool, ScRange*>
{
public:
FindRangeByAddress(const ScAddress& rAddr) : mrAddr(rAddr) {}
-
+ FindRangeByAddress(const FindRangeByAddress& r) : mrAddr(r.mrAddr) {}
bool operator() (const ScRange* pRange) const
{
return pRange->In(mrAddr);
@@ -64,6 +64,19 @@ private:
const ScAddress& mrAddr;
};
+class AppendToList : public ::std::unary_function<void, const ScRange*>
+{
+public:
+ AppendToList(vector<ScRange*>& rRanges) : mrRanges(rRanges) {}
+ AppendToList(const AppendToList& r) : mrRanges(r.mrRanges) {}
+ void operator() (const ScRange* p)
+ {
+ mrRanges.push_back(new ScRange(*p));
+ }
+private:
+ vector<ScRange*>& mrRanges;
+};
+
template<typename T>
struct DeleteObject : public ::std::unary_function<void, T*>
{
@@ -331,40 +344,42 @@ ScRange* ScRangeList::Find( const ScAddress& rAdr )
return itr == maRanges.end() ? NULL : *itr;
}
-
ScRangeList::ScRangeList( const ScRangeList& rList ) :
SvRefBase()
{
- for ( size_t j = 0, nListCount = rList.maRanges.size(); j < nListCount; j++ )
- Append( *rList[ j ] );
+ maRanges.reserve(rList.maRanges.size());
+ for_each(rList.maRanges.begin(), rList.maRanges.end(), AppendToList(maRanges));
}
-
ScRangeList& ScRangeList::operator=(const ScRangeList& rList)
{
RemoveAll();
- for ( size_t j = 0, nListCount = rList.maRanges.size(); j < nListCount; j++ )
- Append( *rList[ j ] );
+ maRanges.reserve(rList.maRanges.size());
+ for_each(rList.maRanges.begin(), rList.maRanges.end(), AppendToList(maRanges));
return *this;
}
-
bool ScRangeList::Intersects( const ScRange& rRange ) const
{
- for ( size_t j = 0, nListCount = maRanges.size(); j < nListCount; j++ )
- if ( at( j )->Intersects( rRange ) )
+ vector<ScRange*>::const_iterator itr = maRanges.begin(), itrEnd = maRanges.end();
+ for (; itr != itrEnd; ++itr)
+ {
+ const ScRange* p = *itr;
+ if (p->Intersects(rRange))
return true;
-
+ }
return false;
}
-
bool ScRangeList::In( const ScRange& rRange ) const
{
- for ( size_t j = 0, nListCount = maRanges.size(); j < nListCount; j++ )
- if ( at( j )->In( rRange ) )
+ vector<ScRange*>::const_iterator itr = maRanges.begin(), itrEnd = maRanges.end();
+ for (; itr != itrEnd; ++itr)
+ {
+ const ScRange* p = *itr;
+ if (p->In(rRange))
return true;
-
+ }
return false;
}
@@ -372,13 +387,16 @@ bool ScRangeList::In( const ScRange& rRange ) const
size_t ScRangeList::GetCellCount() const
{
size_t nCellCount = 0;
- for ( size_t j = 0, nListCount = maRanges.size(); j < nListCount; j++ )
+
+ vector<ScRange*>::const_iterator itr = maRanges.begin(), itrEnd = maRanges.end();
+ for (; itr != itrEnd; ++itr)
{
- const ScRange* pR = maRanges[j];
+ const ScRange* pR = *itr;
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);
}
+
return nCellCount;
}
commit 7e324d5bea53573347ca52fcfa1610a3be925c6e
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Fri Dec 10 11:50:53 2010 -0500
Some cleanup & build fix.
I need to export symbols of ScRangePairList as it is called from
the excel export filter.
diff --git a/sc/inc/rangelst.hxx b/sc/inc/rangelst.hxx
index 620921b..04b6b61 100644
--- a/sc/inc/rangelst.hxx
+++ b/sc/inc/rangelst.hxx
@@ -99,7 +99,7 @@ SV_DECL_IMPL_REF( ScRangeList );
// RangePairList: erster Range (aRange[0]) eigentlicher Range, zweiter
// Range (aRange[1]) Daten zu diesem Range, z.B. Rows eines ColName
-class ScRangePairList : public SvRefBase
+class SC_DLLPUBLIC ScRangePairList : public SvRefBase
{
public:
virtual ~ScRangePairList();
diff --git a/sc/source/core/tool/rangelst.cxx b/sc/source/core/tool/rangelst.cxx
index c11595f..93e0c11 100644
--- a/sc/source/core/tool/rangelst.cxx
+++ b/sc/source/core/tool/rangelst.cxx
@@ -49,6 +49,32 @@ using ::std::advance;
using ::std::find_if;
using ::std::for_each;
+namespace {
+
+class FindRangeByAddress : public ::std::unary_function<bool, ScRange*>
+{
+public:
+ FindRangeByAddress(const ScAddress& rAddr) : mrAddr(rAddr) {}
+
+ bool operator() (const ScRange* pRange) const
+ {
+ return pRange->In(mrAddr);
+ }
+private:
+ const ScAddress& mrAddr;
+};
+
+template<typename T>
+struct DeleteObject : public ::std::unary_function<void, T*>
+{
+ void operator() (T* p)
+ {
+ delete p;
+ }
+};
+
+}
+
// === ScRangeList ====================================================
ScRangeList::~ScRangeList()
@@ -83,8 +109,7 @@ USHORT ScRangeList::Parse( const String& rStr, ScDocument* pDoc, USHORT nMask,
aOne = rStr.GetToken( i, cDelimiter );
aRange.aStart.SetTab( nTab ); // Default Tab wenn nicht angegeben
USHORT nRes = aRange.ParseAny( aOne, pDoc, eConv );
- USHORT nEndRangeBits = SCA_VALID_COL2 | SCA_VALID_ROW2 |
-SCA_VALID_TAB2;
+ USHORT nEndRangeBits = SCA_VALID_COL2 | SCA_VALID_ROW2 | SCA_VALID_TAB2;
USHORT nTmp1 = ( nRes & SCA_BITS );
USHORT nTmp2 = ( nRes & nEndRangeBits );
// If we have a valid single range with
@@ -226,14 +251,19 @@ void ScRangeList::Join( const ScRange& r, bool bIsInList )
bool ScRangeList::operator==( const ScRangeList& r ) const
{
if ( this == &r )
- return true; // identische Referenz
- size_t nCnt = maRanges.size();
- if ( nCnt != r.maRanges.size() )
+ return true;
+
+ if (maRanges.size() != r.maRanges.size())
return false;
- for ( size_t nIdx = 0; nIdx < nCnt; nIdx++ )
+
+ vector<ScRange*>::const_iterator itr1 = maRanges.begin(), itrEnd = maRanges.end();
+ vector<ScRange*>::const_iterator itr2 = r.maRanges.begin();
+ for (; itr1 != itrEnd; ++itr1, ++itr2)
{
- if ( *maRanges.at( nIdx ) != *r.maRanges.at( nIdx ) )
- return false; // auch andere Reihenfolge ist ungleich
+ const ScRange* p1 = *itr1;
+ const ScRange* p2 = *itr2;
+ if (*p1 != *p2)
+ return false;
}
return true;
}
@@ -287,23 +317,6 @@ bool ScRangeList::UpdateReference(
return bChanged;
}
-namespace {
-
-class FindRangeByAddress : public ::std::unary_function<bool, ScRange*>
-{
-public:
- FindRangeByAddress(const ScAddress& rAddr) : mrAddr(rAddr) {}
-
- bool operator() (const ScRange* pRange) const
- {
- return pRange->In(mrAddr);
- }
-private:
- const ScAddress& mrAddr;
-};
-
-}
-
const ScRange* ScRangeList::Find( const ScAddress& rAdr ) const
{
vector<ScRange*>::const_iterator itr = find_if(
@@ -382,21 +395,9 @@ ScRange* ScRangeList::Remove(size_t nPos)
return p;
}
-namespace {
-
-struct DeleteObject : public ::std::unary_function<void, ScRange*>
-{
- void operator() (ScRange* p)
- {
- delete p;
- }
-};
-
-}
-
void ScRangeList::RemoveAll()
{
- for_each(maRanges.begin(), maRanges.end(), DeleteObject());
+ for_each(maRanges.begin(), maRanges.end(), DeleteObject<ScRange>());
maRanges.clear();
}
@@ -457,22 +458,9 @@ void ScRangeList::push_back(ScRange* p)
// === ScRangePairList ========================================================
-namespace {
-
-struct DeletePair : public ::std::unary_function<void, ScRangePair*>
-{
- void operator() (ScRangePair* p)
- {
- delete p;
- }
-};
-
-}
-
-//-----------------------------------------------------------------------------
ScRangePairList::~ScRangePairList()
{
- for_each( maPairs.begin(), maPairs.end(), DeletePair() );
+ for_each( maPairs.begin(), maPairs.end(), DeleteObject<ScRangePair>() );
maPairs.clear();
}
More information about the Libreoffice-commits
mailing list