1
0
Fork 0

Extender iterative search APIs with a 'has-next' return arg, to enable better iteration UI.

This commit is contained in:
jmt 2009-10-04 22:14:14 +00:00 committed by Tim Moore
parent c08cc9693e
commit 5c2dbb4239
2 changed files with 20 additions and 8 deletions

View file

@ -646,7 +646,7 @@ FGPositioned::findNextWithPartialId(FGPositionedRef aCur, const std::string& aId
} }
FGPositionedRef FGPositionedRef
FGPositioned::findWithPartialId(const std::string& aId, Filter* aFilter, int aOffset) FGPositioned::findWithPartialId(const std::string& aId, Filter* aFilter, int aOffset, bool& aNext)
{ {
// see comment in findNextWithPartialId concerning upperBoundId // see comment in findNextWithPartialId concerning upperBoundId
std::string upperBoundId = aId; std::string upperBoundId = aId;
@ -654,6 +654,7 @@ FGPositioned::findWithPartialId(const std::string& aId, Filter* aFilter, int aOf
NamedPositionedIndex::const_iterator upperBound = global_namedIndex.lower_bound(upperBoundId); NamedPositionedIndex::const_iterator upperBound = global_namedIndex.lower_bound(upperBoundId);
NamedIndexRange range = global_namedIndex.equal_range(aId); NamedIndexRange range = global_namedIndex.equal_range(aId);
FGPositionedRef result;
while (range.first != upperBound) { while (range.first != upperBound) {
for (; range.first != range.second; ++range.first) { for (; range.first != range.second; ++range.first) {
@ -668,8 +669,12 @@ FGPositioned::findWithPartialId(const std::string& aId, Filter* aFilter, int aOf
} }
} }
if (aOffset == 0) { if (result) {
return candidate; aNext = true;
return result;
} else if (aOffset == 0) {
// okay, found our result. we need to go around once more to set aNext
result = candidate;
} else { } else {
--aOffset; // seen one more valid result, decrement the count --aOffset; // seen one more valid result, decrement the count
} }
@ -679,7 +684,10 @@ FGPositioned::findWithPartialId(const std::string& aId, Filter* aFilter, int aOf
range = global_namedIndex.equal_range(range.second->first); range = global_namedIndex.equal_range(range.second->first);
} }
return NULL; // Reached the end of the valid sequence with no match. // if we fell out, we reached the end of the valid range. We might have a
// valid result, but we definitiely don't have a next result.
aNext = false;
return result;
} }
/** /**
@ -715,16 +723,20 @@ private:
}; };
FGPositionedRef FGPositionedRef
FGPositioned::findClosestWithPartialId(const SGGeod& aPos, const std::string& aId, Filter* aFilter, int aOffset) FGPositioned::findClosestWithPartialId(const SGGeod& aPos, const std::string& aId, Filter* aFilter, int aOffset, bool& aNext)
{ {
PartialIdentFilter pf(aId, aFilter); PartialIdentFilter pf(aId, aFilter);
List matches = spatialGetClosest(aPos, aOffset + 1, 1000.0, &pf); // why aOffset +2 ? at offset=3, we want the fourth search result, but also
// to know if the fifth result exists (to set aNext flag for iterative APIs)
List matches = spatialGetClosest(aPos, aOffset + 2, 1000.0, &pf);
if ((int) matches.size() <= aOffset) { if ((int) matches.size() <= aOffset) {
SG_LOG(SG_GENERAL, SG_INFO, "FGPositioned::findClosestWithPartialId, couldn't match enough with prefix:" << aId); SG_LOG(SG_GENERAL, SG_INFO, "FGPositioned::findClosestWithPartialId, couldn't match enough with prefix:" << aId);
aNext = false;
return NULL; // couldn't find a match within the cutoff distance return NULL; // couldn't find a match within the cutoff distance
} }
aNext = ((int) matches.size() >= (aOffset + 2));
return matches[aOffset]; return matches[aOffset];
} }

View file

@ -161,7 +161,7 @@ public:
/** /**
* As above, but searches using an offset index * As above, but searches using an offset index
*/ */
static FGPositionedRef findWithPartialId(const std::string& aId, Filter* aFilter, int aOffset); static FGPositionedRef findWithPartialId(const std::string& aId, Filter* aFilter, int aOffset, bool& aNext);
/** /**
* Find all items with the specified ident, and return then sorted by * Find all items with the specified ident, and return then sorted by
@ -197,7 +197,7 @@ public:
* Find the closest match based on partial id (with an offset to allow selecting the n-th closest). * Find the closest match based on partial id (with an offset to allow selecting the n-th closest).
* Cutoff distance is limited internally, to avoid making this very slow. * Cutoff distance is limited internally, to avoid making this very slow.
*/ */
static FGPositionedRef findClosestWithPartialId(const SGGeod& aPos, const std::string& aId, Filter* aFilter, int aOffset); static FGPositionedRef findClosestWithPartialId(const SGGeod& aPos, const std::string& aId, Filter* aFilter, int aOffset, bool& aNext);
/** /**
* Map a candidate type string to a real type. Returns INVALID if the string * Map a candidate type string to a real type. Returns INVALID if the string