mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-06 09:40:17 +01:00
shared: add NMUtilsNamedEntry
It is common to have some data indexed by a name.
If you want to sort a list of such data, you would
have to re-implement your own compare function each time.
Instead, add NMUtilsNamedEntry which as first field has
the name. So, you can create your own struct:
struct my_data {
const char *name;
... other fields
}
and compare them with with nm_utils_named_entry_cmp().
For convenience, add another struct NMUtilsNamedValue, which
has only one data field, a pointer.
(cherry picked from commit 3adce12898)
This commit is contained in:
parent
fae12cf956
commit
7e1e1c1f7f
1 changed files with 20 additions and 0 deletions
|
|
@ -407,6 +407,26 @@ char *nm_utils_str_utf8safe_escape_take (char *str, NMUtilsStrUtf8SafeFlags flag
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
} NMUtilsNamedEntry;
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
NMUtilsNamedEntry named_entry;
|
||||
const char *name;
|
||||
};
|
||||
union {
|
||||
const char *value_str;
|
||||
gconstpointer value_ptr;
|
||||
};
|
||||
} NMUtilsNamedValue;
|
||||
|
||||
#define nm_utils_named_entry_cmp nm_strcmp_p
|
||||
#define nm_utils_named_entry_cmp_with_data nm_strcmp_p_with_data
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#define NM_UTILS_NS_PER_SECOND ((gint64) 1000000000)
|
||||
#define NM_UTILS_NS_PER_MSEC ((gint64) 1000000)
|
||||
#define NM_UTILS_NS_TO_MSEC_CEIL(nsec) (((nsec) + (NM_UTILS_NS_PER_MSEC - 1)) / NM_UTILS_NS_PER_MSEC)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue