qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 03/19] Add enum handlers for easy & efficient st


From: Markus Armbruster
Subject: Re: [Qemu-devel] [PATCH 03/19] Add enum handlers for easy & efficient string <-> int conversion
Date: Sat, 26 Jun 2010 08:52:28 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

"Daniel P. Berrange" <address@hidden> 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

[Prev in Thread] Current Thread [Next in Thread]