On 03/30/2010 09:55 AM, Daniel P. Berrange wrote:
> + INTMAP_ENTRY(ETHERTYPE_ARP , "arp"),
> + INTMAP_ENTRY(ETHERTYPE_IP , "ipv4"),
> + INTMAP_ENTRY(ETHERTYPE_IPV6, "ipv6"),
> + INTMAP_ENTRY_LAST
> };
This should all really be replaced with a standard call to VIR_ENUM_DECL +
VIR_ENUM_IMPL which do compile time validation that you have the correct
number of strings to match the enum, and allow O(1) int to string conversion,
though string to int is still O(n).
If I understand util.h right, those macros only work for enumerators
that are consecutive and which start at 0. But Stefan is mapping
external constants, with no guarantee that they are consecutive nor that
they start at 0. The only way to use VIR_ENUM_DECL is to write our own
wrapper enums, naming them something like VIR_ETHERTYPE_ARP; but I don't
see what it would buy us, because then we would have to convert from our
wrapper to the known external constants.
--
Eric Blake eblake(a)redhat.com +1-801-349-2682
Libvirt virtualization library
http://libvirt.org