On 02/21/2012 09:31 PM, Andreas Färber wrote: >> > +void output_type_enum(Visitor *v, int *obj, const char *strings[], >> > + const char *kind, const char *name, >> > + Error **errp) >> > +{ >> > + int i = 0; >> > + int value = *obj; >> > + char *enum_str; >> > + >> > + assert(strings); >> > + while (strings[i++] != NULL); >> > + if (value < 0 || value >= i - 1) { >> > + error_set(errp, QERR_INVALID_PARAMETER, name ? name : "null"); >> > + return; >> > + } >> > + >> > + enum_str = (char *)strings[value]; > This does not take into account non-linear enum values. > > Maybe name it output_type_linear_enum to allow for alternative enum > lookup implementations? (e.g., hashtable or list of name,value tuples)
I would say that this is the common case and the other one should be named output_type_sparse_enum or something like that, if the need arises... Paolo