Sign in to follow this  
jjd

Global lookup

Recommended Posts

I have a property that I expose to the user through an enum (I'm using C++ FYI). Basically, the enum contains a bunch of qualitative options so that the user doesn't have to worry about raw numbers (designers... [rolleyes]). Now, I want to create a lookup table of the values that the various enum terms correspond to and I wanted to know what is a "good" (read: safe, design friendly, not make me look like-the-n00b-I-am) way of doing this?

Share this post


Link to post
Share on other sites
Quote:
Original post by jjd
I have a property that I expose to the user through an enum (I'm using C++ FYI). Basically, the enum contains a bunch of qualitative options so that the user doesn't have to worry about raw numbers (designers... [rolleyes]). Now, I want to create a lookup table of the values that the various enum terms correspond to and I wanted to know what is a "good" (read: safe, design friendly, not make me look like-the-n00b-I-am) way of doing this?
I don't presume to have an answer, but I'm curious as to what exactly you mean by a lookup table in this context. Do you mean mapping the enum values to some other set of values, or perhaps vice versa?

Share this post


Link to post
Share on other sites
Quote:
Original post by jjd
That's right, a one-to-one mapping between the enum values and a bunch of other numbers.
std::map<>?

[Edit: That's assuming the enum-values are non-contiguous and/or don't start at 0. Otherwise a simple array might suffice.]

Share this post


Link to post
Share on other sites
Yeah, that's the obvious first approach but I don't really want to create a global variable that I will have to pass among all the projects in our game. I was hoping there might be some subclassing magic that I could invoke.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this