shared: add NMOptionBool as alternative to NMTernary

NMTernary is part of libnm's public API. It thus cannot be used by code
without libnm/libnm-core dependency.

Add another enum with the same purpose.

The name "NMTernary" is already taken, and we should not use some macro
trickery to use (effectively) different types under the same name.
Another possible name would be "NMTern", but for no strong reasons
we choose NMOptionBool. The naming reminds of rust's std::option::Option.
This commit is contained in:
Thomas Haller 2021-01-10 11:44:25 +01:00
parent d2464c260f
commit 0dc5ea2412
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
2 changed files with 30 additions and 0 deletions

View file

@ -230,6 +230,24 @@ _NM_SETTING_WIRED_WAKE_ON_LAN_CAST(NMSettingWiredWakeOnLan v)
/*****************************************************************************/
static inline NMTernary
NM_TERNARY_FROM_OPTION_BOOL(NMOptionBool v)
{
nm_assert(NM_IN_SET(v, NM_OPTION_BOOL_DEFAULT, NM_OPTION_BOOL_TRUE, NM_OPTION_BOOL_FALSE));
return (NMTernary) v;
}
static inline NMOptionBool
NM_TERNARY_TO_OPTION_BOOL(NMTernary v)
{
nm_assert(NM_IN_SET(v, NM_TERNARY_DEFAULT, NM_TERNARY_TRUE, NM_TERNARY_FALSE));
return (NMOptionBool) v;
}
/*****************************************************************************/
typedef enum { /*< skip >*/
NM_SETTING_PARSE_FLAGS_NONE = 0,
NM_SETTING_PARSE_FLAGS_STRICT = 1LL << 0,

View file

@ -8,6 +8,18 @@
#include <netinet/in.h>
/*****************************************************************************/
/* An optional boolean (like NMTernary, with identical numerical
* enum values). Note that this enum type is _nm_packed! */
typedef enum _nm_packed {
NM_OPTION_BOOL_DEFAULT = -1,
NM_OPTION_BOOL_FALSE = 0,
NM_OPTION_BOOL_TRUE = 1,
} NMOptionBool;
/*****************************************************************************/
static inline gboolean
nm_is_ascii(char ch)
{