"Daniel P. Berrange" <berra...@redhat.com> writes:

> There is quite alot of code using an enumeration of possible
> values, which also needs todo conversions to/from a string
> representation of enum values. These string <-> int conversions
> have been repeated in an adhoc manner throughout the code.
>
> This makes it hard to report on the list of valid strings,
> eg in help output, or todo proper validation in the qemu
> config/option parsing routines.

Correct.

> This addresses the first problem by introducing a standard
> set of routines for performing string <-> int conversions
> for enums. There are two restrictions on using these helpers,
> the first enum value must be 0, and there must be a sentinal
> in the enum to provide the max value.
>
> For each enumeration, three functions will be made available
>
>  - string to int convertor:
>
>    int XXXX_from_string(const char *value);
>
>    Returns -1 if the value was not an allowed string for the
>    enumeration. Returns >= 0 for a valid value
>
>  - int to string convertor
>
>    const char * XXXX_to_string(int value);
>
>    Returns NULL if the value was not a member of the
>    enumeration. Returns a non-NULL sstring for valid value
>
>  - string list generator
>
>    char * XXXX_to_string_list(void);
>
>    Returns a malloc'd string containing all valid values,
>    separated by commas. Caller must free the string.

Make the separator an argument?

Return a malloc'ed char **, NULL terminated?

> The general usage pattern is as follows.
[...]

Reply via email to