glib-aux: add NM_VALUE_TYPE_NONE

We have NM_VALUE_TYPE_UNSPEC (with numeric value 1).
NM_VALUE_TYPE_UNSPEC means that there is some undefined opaque
type, that cannot be handled generically.

But what we also need is NM_VALUE_TYPE_NONE (with numeric value 0) to
express that no type was set.
This commit is contained in:
Thomas Haller 2021-06-28 17:02:52 +02:00
parent c2e46b7786
commit 0a2711eaad
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
2 changed files with 8 additions and 0 deletions

View file

@ -339,6 +339,7 @@ nm_value_type_to_json(NMValueType value_type, GString *gstr, gconstpointer p_fie
case NM_VALUE_TYPE_STRING: case NM_VALUE_TYPE_STRING:
nm_json_gstr_append_string(gstr, *((const char *const *) p_field)); nm_json_gstr_append_string(gstr, *((const char *const *) p_field));
return; return;
case NM_VALUE_TYPE_NONE:
case NM_VALUE_TYPE_UNSPEC: case NM_VALUE_TYPE_UNSPEC:
break; break;
} }
@ -368,6 +369,7 @@ nm_value_type_from_json(const NMJsonVt * vt,
case NM_VALUE_TYPE_STRING: case NM_VALUE_TYPE_STRING:
return (nm_jansson_json_as_string(vt, elem, out_val) > 0); return (nm_jansson_json_as_string(vt, elem, out_val) > 0);
case NM_VALUE_TYPE_NONE:
case NM_VALUE_TYPE_UNSPEC: case NM_VALUE_TYPE_UNSPEC:
break; break;
} }

View file

@ -7,6 +7,7 @@
#define __NM_VALUE_TYPE_H__ #define __NM_VALUE_TYPE_H__
typedef enum _nm_packed { typedef enum _nm_packed {
NM_VALUE_TYPE_NONE = 0,
NM_VALUE_TYPE_UNSPEC = 1, NM_VALUE_TYPE_UNSPEC = 1,
NM_VALUE_TYPE_BOOL = 2, NM_VALUE_TYPE_BOOL = 2,
NM_VALUE_TYPE_INT32 = 3, NM_VALUE_TYPE_INT32 = 3,
@ -90,6 +91,7 @@ nm_value_type_cmp(NMValueType value_type, gconstpointer p_a, gconstpointer p_b)
return 0; return 0;
case NM_VALUE_TYPE_STRING: case NM_VALUE_TYPE_STRING:
return nm_strcmp0(*((const char *const *) p_a), *((const char *const *) p_b)); return nm_strcmp0(*((const char *const *) p_a), *((const char *const *) p_b));
case NM_VALUE_TYPE_NONE:
case NM_VALUE_TYPE_UNSPEC: case NM_VALUE_TYPE_UNSPEC:
break; break;
} }
@ -129,6 +131,7 @@ nm_value_type_copy(NMValueType value_type, gpointer dst, gconstpointer src)
*((char **) dst) = g_strdup(*((const char *const *) src)); *((char **) dst) = g_strdup(*((const char *const *) src));
} }
return; return;
case NM_VALUE_TYPE_NONE:
case NM_VALUE_TYPE_UNSPEC: case NM_VALUE_TYPE_UNSPEC:
break; break;
} }
@ -169,6 +172,7 @@ nm_value_type_get_from_variant(NMValueType value_type,
* clear how many bits we would need. */ * clear how many bits we would need. */
/* fall-through */ /* fall-through */
case NM_VALUE_TYPE_NONE:
case NM_VALUE_TYPE_UNSPEC: case NM_VALUE_TYPE_UNSPEC:
break; break;
} }
@ -198,6 +202,7 @@ nm_value_type_to_variant(NMValueType value_type, gconstpointer src)
* clear how many bits we would need. */ * clear how many bits we would need. */
/* fall-through */ /* fall-through */
case NM_VALUE_TYPE_NONE:
case NM_VALUE_TYPE_UNSPEC: case NM_VALUE_TYPE_UNSPEC:
break; break;
} }
@ -225,6 +230,7 @@ nm_value_type_get_variant_type(NMValueType value_type)
* clear how many bits we would need. */ * clear how many bits we would need. */
/* fall-through */ /* fall-through */
case NM_VALUE_TYPE_NONE:
case NM_VALUE_TYPE_UNSPEC: case NM_VALUE_TYPE_UNSPEC:
break; break;
} }