[Libreoffice-commits] .: sc/source
Kohei Yoshida
kohei at kemper.freedesktop.org
Fri Dec 10 09:21:29 PST 2010
sc/source/core/tool/rangelst.cxx | 53 ++++++++++++++++++++++-----------------
1 file changed, 30 insertions(+), 23 deletions(-)
New commits:
commit d33c4f78830ad1997659877980d1ca231fe9771b
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Fri Dec 10 12:21:14 2010 -0500
More on using iterators over manual loops.
diff --git a/sc/source/core/tool/rangelst.cxx b/sc/source/core/tool/rangelst.cxx
index d7c152e..bc6b9c2 100644
--- a/sc/source/core/tool/rangelst.cxx
+++ b/sc/source/core/tool/rangelst.cxx
@@ -51,17 +51,32 @@ using ::std::for_each;
namespace {
-class FindRangeByAddress : public ::std::unary_function<bool, ScRange*>
+template<typename T>
+class FindEnclosingRange : public ::std::unary_function<bool, ScRange*>
+{
+public:
+ FindEnclosingRange(const T& rTest) : mrTest(rTest) {}
+ FindEnclosingRange(const FindEnclosingRange& r) : mrTest(r.mrTest) {}
+ bool operator() (const ScRange* pRange) const
+ {
+ return pRange->In(mrTest);
+ }
+private:
+ const T& mrTest;
+};
+
+template<typename T>
+class FindIntersectingRange : public ::std::unary_function<bool, ScRange*>
{
public:
- FindRangeByAddress(const ScAddress& rAddr) : mrAddr(rAddr) {}
- FindRangeByAddress(const FindRangeByAddress& r) : mrAddr(r.mrAddr) {}
+ FindIntersectingRange(const T& rTest) : mrTest(rTest) {}
+ FindIntersectingRange(const FindIntersectingRange& r) : mrTest(r.mrTest) {}
bool operator() (const ScRange* pRange) const
{
- return pRange->In(mrAddr);
+ return pRange->Intersects(mrTest);
}
private:
- const ScAddress& mrAddr;
+ const T& mrTest;
};
class AppendToList : public ::std::unary_function<void, const ScRange*>
@@ -333,14 +348,14 @@ bool ScRangeList::UpdateReference(
const ScRange* ScRangeList::Find( const ScAddress& rAdr ) const
{
vector<ScRange*>::const_iterator itr = find_if(
- maRanges.begin(), maRanges.end(), FindRangeByAddress(rAdr));
+ maRanges.begin(), maRanges.end(), FindEnclosingRange<ScAddress>(rAdr));
return itr == maRanges.end() ? NULL : *itr;
}
ScRange* ScRangeList::Find( const ScAddress& rAdr )
{
vector<ScRange*>::iterator itr = find_if(
- maRanges.begin(), maRanges.end(), FindRangeByAddress(rAdr));
+ maRanges.begin(), maRanges.end(), FindEnclosingRange<ScAddress>(rAdr));
return itr == maRanges.end() ? NULL : *itr;
}
@@ -361,26 +376,18 @@ ScRangeList& ScRangeList::operator=(const ScRangeList& rList)
bool ScRangeList::Intersects( const ScRange& rRange ) const
{
- 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;
+ vector<ScRange*>::const_iterator itrEnd = maRanges.end();
+ vector<ScRange*>::const_iterator itr =
+ find_if(maRanges.begin(), itrEnd, FindIntersectingRange<ScRange>(rRange));
+ return itr != itrEnd;
}
bool ScRangeList::In( const ScRange& rRange ) const
{
- 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;
+ vector<ScRange*>::const_iterator itrEnd = maRanges.end();
+ vector<ScRange*>::const_iterator itr =
+ find_if(maRanges.begin(), itrEnd, FindEnclosingRange<ScRange>(rRange));
+ return itr != itrEnd;
}
More information about the Libreoffice-commits
mailing list