If your enumerated values are dense enough, you can define an array to hold the strings and just look them up (use NULL for any skipped value and add a special case handler on your lookup routine).
char *DogList[] = {
"vizsla", /* element 0 */
NULL,
NULL,
NULL,
"terrier", /* element 3 */
...
};
This is inefficient for sparse enumerations.
Even if the enumeration is not dense, you can use an array of structs to hold the mapping.
typedef struct DogMaps {
DogType index;
char * name;
} DogMapt;
DogMapt DogMap[] = {
{kVizsla, "vizsla"},
{kTerrier, "terrier"},
{kYellowLab, "yellow lab"},
NULL
};
The second approach is very flexible, but it does mean a search through the mapping every time you need to use the data. For large data sets consider a b-tree or hash instead of an array.
Either method can be generalized to connect more data. In the first use an array of structs, in the second just add more members to the struct.
You will, of course, want to write various handlers to simplify your interaction with these data structures.
@Hershi By all means, separate code and data. The above examples are meant to be clear rather than functional.
I blush to admit that I still use whitespace separated flat files for that purpose, rather than the kind of structured input you exhibit, but my production code would read as much of the data from external sources as possible.
Wait, I see that you mean code generation.
Sure. Nothing wrong with that.
I suspect, though that the OP was interested in what the generated code should look like...