diff options
-rw-r--r-- | shared/nm-glib-aux/nm-shared-utils.h | 59 |
1 files changed, 41 insertions, 18 deletions
diff --git a/shared/nm-glib-aux/nm-shared-utils.h b/shared/nm-glib-aux/nm-shared-utils.h index 34c7db45d7..a58be69608 100644 --- a/shared/nm-glib-aux/nm-shared-utils.h +++ b/shared/nm-glib-aux/nm-shared-utils.h @@ -1536,35 +1536,32 @@ guint8 *nm_utils_hexstr2bin_alloc (const char *hexstr, /*****************************************************************************/ -#define NM_UTILS_STRING_TABLE_LOOKUP_DEFINE(fcn_name, \ - result_type, \ - entry_cmd, \ - unknown_val_cmd, \ - ...) \ -result_type \ +#define _NM_UTILS_STRING_TABLE_LOOKUP_DEFINE(fcn_name, \ + value_type, \ + value_type_result, \ + entry_cmd, \ + unknown_val_cmd, \ + get_operator, \ + ...) \ +value_type_result \ fcn_name (const char *name) \ { \ static const struct { \ const char *name; \ - result_type value; \ + value_type value; \ } LIST[] = { \ __VA_ARGS__ \ }; \ \ { entry_cmd; } \ \ - if (NM_MORE_ASSERTS > 5) { \ - static gboolean checked = FALSE; \ + if (NM_MORE_ASSERT_ONCE (5)) { \ int i; \ \ - if (!checked) { \ - checked = TRUE; \ - \ - for (i = 0; i < G_N_ELEMENTS (LIST); i++) { \ - nm_assert (LIST[i].name); \ - if (i > 0) \ - nm_assert (strcmp (LIST[i - 1].name, LIST[i].name) < 0); \ - } \ + for (i = 0; i < G_N_ELEMENTS (LIST); i++) { \ + nm_assert (LIST[i].name); \ + if (i > 0) \ + nm_assert (strcmp (LIST[i - 1].name, LIST[i].name) < 0); \ } \ } \ \ @@ -1579,7 +1576,7 @@ fcn_name (const char *name) \ const int cmp = strcmp (LIST[imid].name, name); \ \ if (G_UNLIKELY (cmp == 0)) \ - return LIST[imid].value; \ + return get_operator (LIST[imid].value); \ \ if (cmp < 0) \ imin = imid + 1u; \ @@ -1597,6 +1594,32 @@ fcn_name (const char *name) \ { unknown_val_cmd; } \ } +#define NM_UTILS_STRING_TABLE_LOOKUP_STRUCT_DEFINE(fcn_name, \ + result_type, \ + entry_cmd, \ + unknown_val_cmd, \ + ...) \ + _NM_UTILS_STRING_TABLE_LOOKUP_DEFINE (fcn_name, \ + result_type, \ + const result_type *, \ + entry_cmd, \ + unknown_val_cmd, \ + &, \ + __VA_ARGS__) + +#define NM_UTILS_STRING_TABLE_LOOKUP_DEFINE(fcn_name, \ + result_type, \ + entry_cmd, \ + unknown_val_cmd, \ + ...) \ + _NM_UTILS_STRING_TABLE_LOOKUP_DEFINE (fcn_name, \ + result_type, \ + result_type, \ + entry_cmd, \ + unknown_val_cmd, \ + , \ + __VA_ARGS__) + /*****************************************************************************/ static inline GTask * |