I’m wanting to create a lookup container for enums which has three fields for each entry, those being: 1) The enum value 2) a human readable string 3) a database string
Here is what I envision the declaration to look like for each enum:
namespace MyNameSpace
{
enum Enum
{
One,
Two,
Three
};
LOOKUP_MAP_BEGIN
(One, "One", "1")
(Two, "Two", "2")
(Three, "Three", "3")
LOOKUP_MAP_END
}
I’m admittedly not a big fan of macros, but in this case it cleans things up nicely and helps keep the map entries in close proximity to the enum to help assure changes to the enum are carried over.
It is assumed that all entries will be unique. I would like to be able to do lookups using any of the three fields as the key and retrieve either of the other two fields. If it would make things significantly simpler, I could make it work by restricting lookups using the string fields as key to only return the corresponding enum value and not the other string.
Is there an existing container that could accomplish something like this, or am I looking at managing several individual (somehow) linked maps/vectors/lists? I do have access to the Boost library.
boost multi_index is probably what you’re looking for.
If you want to do it yourself, you would probably use three maps,
1
map<Enum, TUPLE_TYPE*>, and 2map<String, TUPLE_TYPE*>, encapsulated into it’s own class so that you could implement sane destruction.