diff options
author | Philip Chimento <philip.chimento@gmail.com> | 2022-01-28 13:19:59 -0800 |
---|---|---|
committer | Emmanuele Bassi <ebassi@gmail.com> | 2022-02-13 12:25:18 +0000 |
commit | d553ef85919732f8f79401f77ac5bd7a00ae3fb9 (patch) | |
tree | dc1351b9fb83bf874d6ab0af54b3f2cb5060cb41 /girepository | |
parent | 63c1cb8982b78cf329311cec3702e4cbd1f2b2b2 (diff) | |
download | gobject-introspection-d553ef85919732f8f79401f77ac5bd7a00ae3fb9.tar.gz |
gitypeinfo: Add GI_TYPE_TAG_IS_NUMERIC macro
This is a convenience for bindings that want to perform a similar action
for all numeric types. It allows more expressive code in some cases:
if (GI_TYPE_TAG_IS_NUMERIC(tag)) {
do_one_thing();
return;
}
switch (tag) {
case GI_TYPE_TAG_ARRAY:
do_other_thing();
return;
/* ... */
default:
g_assert_not_reached();
}
instead of listing out all of the numeric types in the switch statement.
Diffstat (limited to 'girepository')
-rw-r--r-- | girepository/gitypeinfo.h | 10 | ||||
-rw-r--r-- | girepository/gitypes.h | 4 |
2 files changed, 12 insertions, 2 deletions
diff --git a/girepository/gitypeinfo.h b/girepository/gitypeinfo.h index fd7d5be6..69d0dad6 100644 --- a/girepository/gitypeinfo.h +++ b/girepository/gitypeinfo.h @@ -48,6 +48,16 @@ G_BEGIN_DECLS */ #define G_TYPE_TAG_IS_BASIC(tag) (tag < GI_TYPE_TAG_ARRAY || tag == GI_TYPE_TAG_UNICHAR) +/** + * GI_TYPE_TAG_IS_NUMERIC: + * @tag: a type tag + * + * Checks if @tag is a numeric type. That is, integer or floating point. + * + * Since: 1.72 + */ +#define GI_TYPE_TAG_IS_NUMERIC(tag) ((tag) >= GI_TYPE_TAG_INT8 && (tag) <= GI_TYPE_TAG_DOUBLE) + GI_AVAILABLE_IN_ALL const gchar* g_type_tag_to_string (GITypeTag type); diff --git a/girepository/gitypes.h b/girepository/gitypes.h index 83268e89..47df7903 100644 --- a/girepository/gitypes.h +++ b/girepository/gitypes.h @@ -411,7 +411,7 @@ typedef enum { /* Basic types */ GI_TYPE_TAG_VOID = 0, GI_TYPE_TAG_BOOLEAN = 1, - GI_TYPE_TAG_INT8 = 2, + GI_TYPE_TAG_INT8 = 2, /* Start of GI_TYPE_TAG_IS_NUMERIC types */ GI_TYPE_TAG_UINT8 = 3, GI_TYPE_TAG_INT16 = 4, GI_TYPE_TAG_UINT16 = 5, @@ -420,7 +420,7 @@ typedef enum { GI_TYPE_TAG_INT64 = 8, GI_TYPE_TAG_UINT64 = 9, GI_TYPE_TAG_FLOAT = 10, - GI_TYPE_TAG_DOUBLE = 11, + GI_TYPE_TAG_DOUBLE = 11, /* End of numeric types */ GI_TYPE_TAG_GTYPE = 12, GI_TYPE_TAG_UTF8 = 13, GI_TYPE_TAG_FILENAME = 14, |