[Top][All Lists]
[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.
[...]
- [Qemu-devel] [PATCH 00/19] RFC: Reporting QEMU binary capabilities, Daniel P. Berrange, 2010/06/07
- [Qemu-devel] [PATCH 01/19] Add support for JSON pretty printing, Daniel P. Berrange, 2010/06/07
- [Qemu-devel] [PATCH 02/19] Add support for compile time assertions, Daniel P. Berrange, 2010/06/07
- [Qemu-devel] [PATCH 03/19] Add enum handlers for easy & efficient string <-> int conversion, Daniel P. Berrange, 2010/06/07
- [Qemu-devel] [PATCH 04/19] Add support for a option parameter as an enum, Daniel P. Berrange, 2010/06/07
- [Qemu-devel] [PATCH 05/19] Ensure that QEMU exits if drive_add parsing fails, Daniel P. Berrange, 2010/06/07
- [Qemu-devel] [PATCH 08/19] Convert RTC to use enumerations for configuration parameters, Daniel P. Berrange, 2010/06/07
- [Qemu-devel] [PATCH 07/19] Convert netdev client types to use an enumeration, Daniel P. Berrange, 2010/06/07
- [Qemu-devel] [PATCH 09/19] Change 'query-version' to output broken down version string, Daniel P. Berrange, 2010/06/07