S
Steve555
Hi
I have a class which makes much use of a Map:
typedef map<char, string, less<char> > LSysRule;
As you can see, text strings are stored with characters as the key.
I'm trying to re-use the class in another app that uses a GUI table,
the data for the table being provided by my Map type.
I'm stuck with the design of the table and the problem is that it uses
row indexing.
If for instance I have 3 Map elements, with keys C, A, B, these are
obviosly stored in the Map in alphabetical order, and then displayed
in my table as rows: 0:A, 1:B, 2C.
But when the user clicks on the table, the only info I recieve is the
row number. I now need to access my Map by index, rather than key.
After fiddling for a while, I've got this to work but it seems very
long winded:
LSysRule::iterator iter;
long i=0;
for(iter = rulesMap->begin(); iter != rulesMap->end(); iter++)
{
i++;
if(i == rowNumber)
FoundIt = *iter:
}
Is there a neater/faster way to do this?
Thanks
Steve
I have a class which makes much use of a Map:
typedef map<char, string, less<char> > LSysRule;
As you can see, text strings are stored with characters as the key.
I'm trying to re-use the class in another app that uses a GUI table,
the data for the table being provided by my Map type.
I'm stuck with the design of the table and the problem is that it uses
row indexing.
If for instance I have 3 Map elements, with keys C, A, B, these are
obviosly stored in the Map in alphabetical order, and then displayed
in my table as rows: 0:A, 1:B, 2C.
But when the user clicks on the table, the only info I recieve is the
row number. I now need to access my Map by index, rather than key.
After fiddling for a while, I've got this to work but it seems very
long winded:
LSysRule::iterator iter;
long i=0;
for(iter = rulesMap->begin(); iter != rulesMap->end(); iter++)
{
i++;
if(i == rowNumber)
FoundIt = *iter:
}
Is there a neater/faster way to do this?
Thanks
Steve