[Qt-interest] "Double Sided Map"?

Benjamin Lau blwy10v at gmail.com
Wed Feb 10 01:42:08 CET 2010


Try Boost.Bimap?

http://www.boost.org/doc/libs/1_42_0/libs/bimap/doc/html/index.html

Hope this helps!
Ben

On Wed, Feb 10, 2010 at 7:37 AM, Jefferson Bandeira <jbsilva at ufrj.br> wrote:
> 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
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>



More information about the Qt-interest-old mailing list