ETable.xcc
Benoit Dupont de Dinechin (Benoit.Dupont-de-Dinechin@st.com)
Copyright 2007 STMicroelectronics. Copyright 1995 - 1998 Commissariat a l'Energie Atomique.
This program is free software; you can redistribute it and/or modify it under the terms of either (at your option): the GNU General Public License (GPL) version 2; the GNU Lesser General Public License (LGPL) version 2.1; any later version of these licences as published by the Free Software Foundation.
ETableEntry— ETable entry defined as { NAME, VALUE }.
struct ETableEntry_ { const char *NAME; // Name as string. int32_t VALUE; // Integer value. uint32_t HASH; // Hash value for NAME. struct ETableEntry_ *LINK; // Link to entry of same HASH. };
ETableEntry_COUNT— Count the number of ETableEntry_ in an array.
#define ETableEntry_COUNT(array) (sizeof(array)/sizeof(ETableEntry_))
ETableENTRY— Static initializer for a ETableEntry_.
#define ETableENTRY(Enum, name) { #name, Enum##_##name, 0, NULL } #define ETableENTRY_NULL { NULL }
ETable— Table to map enum value to name and name to value.
The mapping from VALUE to NAME is obtained by sorting the ENTRIES during initialization, then using dichotomy search. The mapping from NAME to VALUE is obtained by hashing.
struct ETable_ { //@args Memory memory, ETableEntry_ *entries Memory MEMORY; ETableEntry_ *ENTRIES; // This ETable ETableEntry(s). int32_t COUNT; // Count this ETable ENTRIES. uint32_t MASK; // Count this ETable BUCKETS. ETableEntry *BUCKETS; // This ETable buckets for hashing. };
ETable_entries— For use by ETable_FOREACH_ETableEntry.
static inline ETableEntry_ * ETable_entries(const_ETable this) { return ETable_ENTRIES(this); }
ETable_count— For use by ETable_FOREACH_ETableEntry.
static inline int32_t ETable_count(const_ETable this) { return ETable_COUNT(this); }
ETable_FOREACH_ETableEntry— Iterate over this ETable entries.
#define ETable_FOREACH_ETableEntry(this, entry) { \ ETableEntry_ *ETable_ENTRIES = ETable_entries(this); \ int32_t ETable_COUNT = ETable_count(this), ETable_I = 0; \ for (; ETable_I < ETable_COUNT; ETable_I++) { \ ETableEntry entry = ETable_ENTRIES + ETable_I; #define ETable_ENDEACH_ETableEntry \ } \ }
ETable_FORBACK_ETableEntry— Iterate over this ETable entries.
#define ETable_FORBACK_ETableEntry(this, entry) { \ ETableEntry_ *ETable_ENTRIES = ETable_entries(this); \ int32_t ETable_COUNT = ETable_count(this), ETable_I = ETable_COUNT - 1; \ for (; ETable_I >= 0; ETable_I--) { \ ETableEntry entry = ETable_ENTRIES + ETable_I; #define ETable_ENDBACK_ETableEntry \ } \ }
ETable_name— Get a name from a value.
const char * ETable_name(const_ETable this, int32_t value);
ETable_value— Get a value from a name.
int32_t ETable_value(const_ETable this, const char *name);
ETable_pretty— Pretty print the full ETable
bool ETable_pretty(ETable this, const char *prefix, FILE *file);
ETable_prettyFlags— Extract and pretty values out of flags.
bool ETable_prettyFlags(ETable this, uint32_t flags, const char *sep, FILE *file);
ETable_parseFlags— Parse a set of flags separated by sep
from a string
.
Returns false if the string contains an undetermined flag.
bool ETable_parseFlags(ETable this, const char *string, char sep, uint32_t *flags);