David Luff wrote:
Hi folks,

I've run into a tricky problem when using stl map, and am hoping someone might 
be able to point me on the right direction.

I have a map of airports, indexed by string, which is the ICAO code:

map<string, ARP*> apt_map;

Now, I want to emulate the 'search ahead' function of GPS code entry, so that, for instance, entering "KC" will cause 
"KCAD" to be displayed - the first airport in the database starting with "KC".  To do this I use the lower_bound 
function, for both "KC" and "KD".  If the returned iterators don't match, then there is a valid match for 
"KC".

map<string, ARP*>::iterator it1, it2;
it1 = apt_map.lower_bound("KC");
it2 = apt_map.lower_bound("KD");

return(it1 == it2 ? NULL : it1->second);

So far, so good. Now, the problem is that the KLN89 (and probably most/all GPS units) regards A->Z as coming before 0->9, whereas the standard string compare function regards 0->9 as coming before A->Z. So in this instance I might get "KC52" displayed instead of "KCAD" (there isn't really a KC52, but there are many examples outside the US where this bites).

You could use qsort to sort the map just prior to using it: http://www.cplusplus.com/ref/cstdlib/qsort.html

It requires a function that returns <0, 0 or >0 for every sort operation, so you can define the sorting algorithm yourself.

Erik


_______________________________________________ Flightgear-devel mailing list Flightgear-devel@flightgear.org http://mail.flightgear.org/mailman/listinfo/flightgear-devel 2f585eeea02e2c79d7b1d8c4963bae2d

Reply via email to