Just use std::map<unsigned int,std::string> and be done with it. Move onto something that is far more important and hasn't already been done. It would be nice if the language natively supported this behavior but it does not. However it can be mimicked using one or more of the stl containers.
Doesn't really sound like it, to be honest, but you should probably stick to your plan/idea at this point.I think my method is a lot more efficient...
You are already hardcoding in the form of the enum. I know you have another program to auto generate those, but you could just as easily do something similar with strings. Eg, one decent idea would be to load these from a text file* into something like:
So the map would be key/value pairs: the key (string) would be the name of the tag, the value (vector) would be a list of possible attributes (these could be pointers into a similar map of attributes with vectors of possible values). That would eliminate the need for some of these functions, I think.Code:map<string, <vector<string*> > htmltags;
WRT to memory, that is the point of references and pointers (also, html tag names are generally quite short -- a enum int is still 4 bytes).
As it is now, it sounds like you are having to do the enum to string conversion basically everywhere you use the enum anyway.
*also more user friendly, and, in fact, removes the hardcoded aspect completely (which remember, your enum is still hardcoded in -- the fact that you did not type the code out manually has nothing to do with the concept of "hardcoded") since the entire tag list would be loaded at runtime. This would make the functionality "data independent", more extensible, and easier to maintain and adapt.
Last edited by MK27; 06-04-2010 at 04:41 PM.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
Good idea...
No, I only have to use it once for each enum, and I only have a couple of enums.You are already hardcoding in the form of the enum. I know you have another program to auto generate those, but you could just as easily do something similar with strings. Eg, one decent idea would be to load these from a text file* into something like:
So the map would be key/value pairs: the key (string) would be the name of the tag, the value (vector) would be a list of possible attributes (these could be pointers into a similar map of attributes with vectors of possible values). That would eliminate the need for some of these functions, I think.Code:map<string, <vector<string*> > htmltags;
WRT to memory, that is the point of references and pointers (also, html tag names are generally quite short -- a enum int is still 4 bytes).
As it is now, it sounds like you are having to do the enum to string conversion basically everywhere you use the enum anyway.
Maybe so, but I meant "hard-coded" as in having to manually type up every string.*also more user friendly, and, in fact, removes the hardcoded aspect completely (which remember, your enum is still hardcoded in -- the fact that you did not type the code out manually has nothing to do with the concept of "hardcoded") since the entire tag list would be loaded at runtime. This would make the functionality "data independent", more extensible, and easier to maintain and adapt.
I might try your method, once I practice with maps a little first.
That's more than one question...
And if you had not forgotten (and/or neglected to read) "the rest of my detail-happy" post, you would know the answer to those questions.
You keep talking about std::maps with an unsigned int key value, and a std::string mapped value, but I still haven't seen an example of this working to get the string name of an enum value. I looked at the map reference, but its not really clear how to do something like that with a map, though I'm trying to write something like that right now to test it.
Last edited by Programmer_P; 06-05-2010 at 09:28 AM.
I have posted a modified version of C_ntua's example in your other thread.Originally Posted by Programmer_P
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)