Skip to content

Instantly share code, notes, and snippets.

@flatcap
Last active July 10, 2021 13:13
Show Gist options
  • Save flatcap/8a83308c0ae3ecf9478a9b1bf26d6668 to your computer and use it in GitHub Desktop.
Save flatcap/8a83308c0ae3ecf9478a9b1bf26d6668 to your computer and use it in GitHub Desktop.
sort, use_threads, enum
//-------------------------------------------------------------------
// SORT CODE
enum UseThreads
{
UT_FLAT,
UT_THREADS,
UT_REVERSE,
UT_UNSET = ENUM_UNSET,
};
//-------------------------------------------------------------------
// CONFIG CODE
static const struct Mapping UseThreadsTypeMap[] = {
{ "flat", UT_FLAT, },
{ "threads", UT_THREADS, },
{ "reverse", UT_REVERSE, },
//------------------------
{ "no", UT_FLAT, },
{ "yes", UT_THREADS, },
{ NULL, 0, },
};
struct EnumDef UseThreadsTypeDef = {
"use_threads",
3,
(struct Mapping *) &UseThreadsTypeMap,
};
static struct ConfigDef MainVars[] = {
{ "use_threads", DT_ENUM|DT_ENUM_ALLOW_UNSET, UT_UNSET, IP &UseThreadsTypeDef, NULL, "" },
{ NULL },
};
//-------------------------------------------------------------------
// ENUM CODE
#define DT_ENUM_ALLOW_UNSET (1 << 15)
#define ENUM_UNSET 255
enum_string_set()
// looks up string in UseThreadsTypeMap
// validator called
enum_string_get()
// looks up value in UseThreadsTypeMap
// special case for ENUM_UNSET (if DT_ENUM_ALLOW_UNSET is set)
enum_native_set()
// looks up value in UseThreadsTypeMap
// cannot set to ENUM_UNSET
// validator called
enum_native_get()
// gets value, no validation
enum_reset()
// reset to initial value
// validator called
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment