[Qt-interest] "Double Sided Map"?

Jefferson Bandeira jbsilva at ufrj.br
Wed Feb 10 00:37:13 CET 2010


Hello guys, i hope you can answer my question.
Actually in my application I need to map some values to Strings, however, I
also need to make a "reverse mapping", i mean, i want to be able to see
which QString is mapped to the number 3, but i also need to know which
Number the QString "three" is mapped to.
At the moment i'm doing something like this :
----------------------------------------------
QMap<int, QString> i2string;
QMap<QString, int> string2i;
i2string[3] = QString("three");
string2i["three"] = 3;
----------------------------------------------
This indeed works for what i need, however, that's a bit messy, since any
changes i make to one of the maps i must do to the other and this is kinda
dangerous, since someone can easily forget about this, or the maps can be
Desynched.
So, My question is :
Is there any Structure i can use in which i can insert the pair of things
once, and i can query the structure to give me what i want, both ways?
Something like :
MagicStructure<int, QString> struct;
struct.insert(3, QString("three"));
struct.get(3); // Returns "three"
struct.get("three"); // Returns 3
PS : I can ensure that both values are unique through all structure, so that
won't be a problem.
Regards,
Jefferson Bandeira
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100209/b8cb3483/attachment.html 


More information about the Qt-interest-old mailing list