diff options
author | Kohei Yoshida <kohei.yoshida@suse.com> | 2011-11-16 17:06:35 -0500 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@suse.com> | 2011-11-18 14:13:20 -0500 |
commit | 5ca8b63c0377889a1cc8c9d4a378d673fe54e69a (patch) | |
tree | 993c5cbdc099a68d0e3246a293a89acdae4928fe | |
parent | 965d933ed94371b3c96695a58ecc9b69742c660b (diff) |
A little cleanup.
-rw-r--r-- | sc/source/core/tool/queryparam.cxx | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/sc/source/core/tool/queryparam.cxx b/sc/source/core/tool/queryparam.cxx index 3b5a958fc84b..b551ddc22b59 100644 --- a/sc/source/core/tool/queryparam.cxx +++ b/sc/source/core/tool/queryparam.cxx @@ -45,7 +45,15 @@ public: FindByField(SCCOLROW nField) : mnField(nField) {} bool operator() (const ScQueryEntry& rEntry) const { - return rEntry.nField == mnField; + return rEntry.bDoQuery && rEntry.nField == mnField; + } +}; + +struct FindUnused : public std::unary_function<ScQueryEntry, bool> +{ + bool operator() (const ScQueryEntry& rEntry) const + { + return !rEntry.bDoQuery; } }; @@ -90,16 +98,13 @@ ScQueryEntry& ScQueryParamBase::GetEntry(SCSIZE n) ScQueryEntry* ScQueryParamBase::FindEntryByField(SCCOLROW nField, bool bNew) { - size_t n = maEntries.size(); - for (SCSIZE i = 0; i < n; ++i) - { - ScQueryEntry& rEntry = GetEntry(i); - if (!rEntry.bDoQuery) - break; + EntriesType::iterator itr = std::find_if( + maEntries.begin(), maEntries.end(), FindByField(nField)); - if (rEntry.nField == nField) - // existing entry found! - return &rEntry; + if (itr != maEntries.end()) + { + // existing entry found! + return &(*itr); } if (!bNew) @@ -107,12 +112,9 @@ ScQueryEntry* ScQueryParamBase::FindEntryByField(SCCOLROW nField, bool bNew) return NULL; // Find the first unused entry. - for (SCSIZE i = 0; i < n; ++i) - { - ScQueryEntry& rEntry = GetEntry(i); - if (!rEntry.bDoQuery) - return &rEntry; - } + itr = std::find_if(maEntries.begin(), maEntries.end(), FindUnused()); + if (itr != maEntries.end()) + return &(*itr); // Add a new entry to the end. maEntries.push_back(new ScQueryEntry); @@ -121,7 +123,9 @@ ScQueryEntry* ScQueryParamBase::FindEntryByField(SCCOLROW nField, bool bNew) void ScQueryParamBase::RemoveEntryByField(SCCOLROW nField) { - EntriesType::iterator itr = std::find_if(maEntries.begin(), maEntries.end(), FindByField(nField)); + EntriesType::iterator itr = std::find_if( + maEntries.begin(), maEntries.end(), FindByField(nField)); + if (itr != maEntries.end()) { maEntries.erase(itr); |