gobject: Add private field access macros
authorEmmanuele Bassi <ebassi@gnome.org>
Sun, 23 Jun 2013 13:50:49 +0000 (14:50 +0100)
committerEmmanuele Bassi <ebassi@gnome.org>
Mon, 24 Jun 2013 13:18:01 +0000 (14:18 +0100)
Similar to G_STRUCT_MEMBER and G_STRUCT_MEMBER_P, but automatically using
the G_PRIVATE_OFFSET macro.

https://bugzilla.gnome.org/show_bug.cgi?id=700035

gobject/gtype.h

index c21936d..a3152a8 100644 (file)
@@ -1599,6 +1599,43 @@ guint     g_type_get_type_registration_serial (void);
 #define G_PRIVATE_OFFSET(TypeName, field) \
   (TypeName##_private_offset + (G_STRUCT_OFFSET (TypeName##Private, field)))
 
+/**
+ * G_PRIVATE_FIELD_P:
+ * @TypeName: the name of the type in CamelCase
+ * @inst: the instance of @TypeName you wish to access
+ * @field_name: the name of the field in the private data structure
+ *
+ * Evaluates to a pointer to the @field_name inside the @inst private data
+ * structure for @TypeName.
+ *
+ * Note that this macro can only be used together with the G_DEFINE_TYPE_*
+ * and G_ADD_PRIVATE() macros, since it depends on variable names from
+ * those macros.
+ *
+ * Since: 2.38
+ */
+#define G_PRIVATE_FIELD_P(TypeName, inst, field_name) \
+  G_STRUCT_MEMBER_P (inst, G_PRIVATE_OFFSET (TypeName, field_name))
+
+/**
+ * G_PRIVATE_FIELD:
+ * @TypeName: the name of the type in CamelCase
+ * @inst: the instance of @TypeName you wish to access
+ * @field_type: the type of the field in the private data structure
+ * @field_name: the name of the field in the private data structure
+ *
+ * Evaluates to the @field_name inside the @inst private data
+ * structure for @TypeName.
+ *
+ * Note that this macro can only be used together with the G_DEFINE_TYPE_*
+ * and G_ADD_PRIVATE() macros, since it depends on variable names from
+ * those macros.
+ *
+ * Since: 2.38
+ */
+#define G_PRIVATE_FIELD(TypeName, inst, field_type, field_name) \
+  G_STRUCT_MEMBER (field_type, inst, G_PRIVATE_OFFSET (TypeName, field_name))
+
 #define _G_DEFINE_TYPE_EXTENDED_BEGIN(TypeName, type_name, TYPE_PARENT, flags) \
 \
 static void     type_name##_init              (TypeName        *self); \