[gnome-builder] libide/core: add property macros
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] libide/core: add property macros
- Date: Tue, 23 Aug 2022 01:06:02 +0000 (UTC)
commit 48007a8c8542e41800ec6d88774bd2474a9c30ae
Author: Christian Hergert <chergert redhat com>
Date: Mon Aug 22 14:20:54 2022 -0700
libide/core: add property macros
This adds various macros we can use for string/boolean properties which
are really common and annoying to type every time, let alone maintain.
There will surely be a better way to do this in the future, but this at
least cuts down the boilerplate a bit.
If you want a project for GNOME 44, come modernize the libide/plugin code
to use these instead.
src/libide/core/ide-macros.h | 90 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 90 insertions(+)
---
diff --git a/src/libide/core/ide-macros.h b/src/libide/core/ide-macros.h
index cbbf621bb..e51be8824 100644
--- a/src/libide/core/ide-macros.h
+++ b/src/libide/core/ide-macros.h
@@ -309,6 +309,96 @@ ide_steal_fd (int *fd)
return ret;
}
+#define IDE_DEFINE_BOOLEAN_PROPERTY(name, value, flags, PROP) \
+ properties[PROP_##PROP] = \
+ g_param_spec_boolean(name, NULL, NULL, value, \
+ (flags|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_STATIC_STRINGS));
+#define IDE_DEFINE_BOOLEAN_GETTER(symbol, Symbol, TYPE, name) \
+gboolean symbol##_get_##name (Symbol *self) \
+{ \
+ g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (self, TYPE), FALSE); \
+ return self->name; \
+}
+#define IDE_DEFINE_BOOLEAN_SETTER(symbol, Symbol, TYPE, name, PROP) \
+void symbol##_set_##name (Symbol *self, gboolean name) \
+{ \
+ g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (self, TYPE)); \
+ name = !!name; \
+ if (name != self->name) \
+ { \
+ self->name = name; \
+ g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_##PROP]); \
+ } \
+}
+#define IDE_DEFINE_BOOLEAN_GETTER_PRIVATE(symbol, Symbol, TYPE, name) \
+gboolean symbol##_get_##name (Symbol *self) \
+{ \
+ Symbol##Private *priv = symbol##_get_instance_private(self); \
+ g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (self, TYPE), FALSE); \
+ return priv->name; \
+}
+#define IDE_DEFINE_BOOLEAN_SETTER_PRIVATE(symbol, Symbol, TYPE, name, PROP) \
+void symbol##_set_##name (Symbol *self, gboolean name) \
+{ \
+ Symbol##Private *priv = symbol##_get_instance_private(self); \
+ g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (self, TYPE)); \
+ name = !!name; \
+ if (name != priv->name) \
+ { \
+ priv->name = name; \
+ g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_##PROP]); \
+ } \
+}
+#define IDE_GET_PROPERTY_BOOLEAN(symbol, name, PROP) \
+ case PROP_##PROP: \
+ g_value_set_boolean (value, symbol##_get_##name (self)); \
+ break
+#define IDE_SET_PROPERTY_BOOLEAN(symbol, name, PROP) \
+ case PROP_##PROP: \
+ symbol##_set_##name (self, g_value_get_boolean (value)); \
+ break
+
+#define IDE_DEFINE_STRING_PROPERTY(name, value, flags, PROP) \
+ properties[PROP_##PROP] = \
+ g_param_spec_string(name, NULL, NULL, value, \
+ (flags|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_STATIC_STRINGS));
+#define IDE_DEFINE_STRING_GETTER(symbol, Symbol, TYPE, name) \
+const char *symbol##_get_##name (Symbol *self) \
+{ \
+ g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (self, TYPE), NULL); \
+ return self->name; \
+}
+#define IDE_DEFINE_STRING_SETTER(symbol, Symbol, TYPE, name, PROP) \
+void symbol##_set_##name (Symbol *self, const char *name) \
+{ \
+ g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (self, TYPE)); \
+ if (ide_set_string (&self->name, name)) \
+ g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_##PROP]); \
+}
+#define IDE_DEFINE_STRING_GETTER_PRIVATE(symbol, Symbol, TYPE, name) \
+const char *symbol##_get_##name (Symbol *self) \
+{ \
+ Symbol##Private *priv = symbol##_get_instance_private(self); \
+ g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (self, TYPE), NULL); \
+ return priv->name; \
+}
+#define IDE_DEFINE_STRING_SETTER_PRIVATE(symbol, Symbol, TYPE, name, PROP) \
+void symbol##_set_##name (Symbol *self, const char *name) \
+{ \
+ Symbol##Private *priv = symbol##_get_instance_private(self); \
+ g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (self, TYPE)); \
+ if (ide_set_string (&priv->name, name)) \
+ g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_##PROP]); \
+}
+#define IDE_GET_PROPERTY_STRING(symbol, name, PROP) \
+ case PROP_##PROP: \
+ g_value_set_string (value, symbol##_get_##name (self)); \
+ break
+#define IDE_SET_PROPERTY_STRING(symbol, name, PROP) \
+ case PROP_##PROP: \
+ symbol##_set_##name (self, g_value_get_string (value)); \
+ break
+
G_END_DECLS
#endif /* __GI_SCANNER__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]