[cogl/lionel/introspection-next: 1/42] cogl2: add boilerplate to define fundamental types



commit 050b96d64df74c39be796022b77258a8cdb81953
Author: Lionel Landwerlin <llandwerlin gmail com>
Date:   Mon Sep 2 16:02:42 2013 +0100

    cogl2: add boilerplate to define fundamental types

 cogl/Makefile.am           |   36 +++++++-
 cogl/cogl-gtype-private.h  |  229 +++++++++++++++++++++++++++++++++++++++++++-
 cogl/cogl-gtype.c          |  153 +++++++++++++++++++++++++++++
 cogl/cogl-object-private.h |   77 +++++++++++----
 cogl/cogl-object.c         |    3 +
 cogl/cogl-object.h         |   11 ++
 cogl/cogl-types.h          |    7 ++
 7 files changed, 490 insertions(+), 26 deletions(-)
---
diff --git a/cogl/Makefile.am b/cogl/Makefile.am
index 6ac1284..fdeb0f0 100644
--- a/cogl/Makefile.am
+++ b/cogl/Makefile.am
@@ -140,6 +140,15 @@ cogl_experimental_h = \
        $(srcdir)/cogl-error.h                  \
        $(NULL)
 
+cogl_additional_experimental_h = \
+       $(srcdir)/cogl-bitmap.h                 \
+       $(srcdir)/cogl-color.h                  \
+       $(srcdir)/cogl-matrix.h                 \
+       $(srcdir)/cogl-texture.h                \
+       $(srcdir)/cogl-types.h                  \
+       $(srcdir)/cogl-gtype-private.h          \
+       $(NULL)
+
 cogl_nodist_experimental_h = \
        $(NULL)
 
@@ -354,6 +363,7 @@ cogl_sources_c = \
        $(srcdir)/cogl-flags.h                          \
        $(srcdir)/cogl-bitmask.h                        \
        $(srcdir)/cogl-bitmask.c                        \
+       $(srcdir)/cogl-gtype.c                          \
        $(srcdir)/cogl-gtype-private.h                  \
        $(srcdir)/cogl-point-in-poly-private.h          \
        $(srcdir)/cogl-point-in-poly.c                  \
@@ -670,12 +680,36 @@ Cogl_1_0_gir_FILES += \
        $(top_srcdir)/cogl-path/cogl-path-types.h \
        $(top_srcdir)/cogl-path/cogl1-path-functions.h
 endif
+
+Cogl-2.0.gir: libcogl.la Makefile
+
+Cogl_2_0_gir_NAMESPACE = Cogl
+Cogl_2_0_gir_VERSION = 2.0
+Cogl_2_0_gir_LIBS = libcogl.la
+if UNIT_TESTS
+Cogl_2_0_gir_LIBS += $(top_builddir)/test-fixtures/libtest-fixtures.la
+endif
+Cogl_2_0_gir_FILES = $(cogl_experimental_h) $(cogl_additional_experimental_h) cogl-enum-types.h
+if BUILD_COGL_PATH
+Cogl_2_0_gir_FILES += \
+       $(top_builddir)/cogl-path/cogl-path-enum-types.h \
+       $(top_srcdir)/cogl-path/cogl-path-types.h \
+       $(top_srcdir)/cogl-path/cogl1-path-functions.h
+endif
+
+
 Cogl_1_0_gir_CFLAGS = $(AM_CPPFLAGS) $(COGL_DEP_CFLAGS) -UCOGL_ENABLE_EXPERIMENTAL_API 
-UCOGL_ENABLE_EXPERIMENTAL_2_0_API -UCOGL_COMPILATION -D__COGL_H_INSIDE__ -D__COGL_XLIB_H_INSIDE__
 Cogl_1_0_gir_INCLUDES = GL-1.0 GObject-2.0
 Cogl_1_0_gir_EXPORT_PACKAGES = cogl-1.0
 Cogl_1_0_gir_SCANNERFLAGS = --warn-all --c-include='cogl/cogl.h'
 
-INTROSPECTION_GIRS += Cogl-1.0.gir
+
+Cogl_2_0_gir_CFLAGS = $(AM_CPPFLAGS) $(COGL_DEP_CFLAGS) -DCOGL_ENABLE_EXPERIMENTAL_API=1 -UCOGL_COMPILATION 
-D__COGL_H_INSIDE__ -D__COGL_XLIB_H_INSIDE__
+Cogl_2_0_gir_INCLUDES = GL-1.0 GObject-2.0
+Cogl_2_0_gir_EXPORT_PACKAGES = cogl-2.0-experimental
+Cogl_2_0_gir_SCANNERFLAGS = --warn-all --c-include='cogl/cogl.h'
+
+INTROSPECTION_GIRS += Cogl-1.0.gir Cogl-2.0.gir
 
 girdir = $(datadir)/gir-1.0
 gir_DATA = $(INTROSPECTION_GIRS)
diff --git a/cogl/cogl-gtype-private.h b/cogl/cogl-gtype-private.h
index 5715d01..12281f3 100644
--- a/cogl/cogl-gtype-private.h
+++ b/cogl/cogl-gtype-private.h
@@ -22,15 +22,41 @@
  *
  */
 
+#ifndef __COGL_GTYPE_PRIVATE_H__
+#define __COGL_GTYPE_PRIVATE_H__
+
+#include "config.h"
+
 #include <glib.h>
 #include <glib-object.h>
 
-#ifndef __COGL_GTYPE_PRIVATE_H__
-#define __COGL_GTYPE_PRIVATE_H__
+#include "cogl-object-private.h"
+
+/* Move this to public headers? */
+typedef struct _CoglGtypeObject CoglGtypeObject;
+typedef struct _CoglGtypeClass  CoglGtypeClass;
+
+struct _CoglGtypeObject
+{
+  GTypeInstance parent_instance;
 
-#define COGL_GTYPE_DEFINE_BOXED(Name, underscore_name, copy_func, free_func) \
+  guint dummy;
+};
+
+struct _CoglGtypeClass
+{
+  GTypeClass base_class;
+
+  guint dummy;
+};
+
+#define I_(str)  (g_intern_static_string ((str)))
+
+/**/
+
+#define COGL_GTYPE_DEFINE_BOXED(Name,underscore_name,copy_func,free_func) \
 GType \
-cogl_gtype_ ## underscore_name ## _get_type (void) \
+cogl_##underscore_name##_get_gtype (void) \
 { \
    static volatile size_t type_volatile = 0; \
    if (g_once_init_enter (&type_volatile)) \
@@ -44,5 +70,198 @@ cogl_gtype_ ## underscore_name ## _get_type (void) \
    return type_volatile; \
 }
 
-#endif /* __COGL_GTYPE_PRIVATE_H__ */
+#define COGL_GTYPE_IMPLEMENT_INTERFACE(name) {                          \
+    const GInterfaceInfo g_implement_interface_info = {                 \
+      (GInterfaceInitFunc) _cogl_gtype_dummy_iface_init, NULL, NULL     \
+    };                                                                  \
+    g_type_add_interface_static (fundamental_type_id,                   \
+                                 cogl_##name##_get_gtype(),         \
+                                 &g_implement_interface_info);          \
+  }
+
+#define _COGL_GTYPE_DEFINE_BASE_CLASS_BEGIN(Name,name)                  \
+GType                                                                   \
+cogl_##name##_get_gtype (void)                                      \
+{                                                                       \
+  static volatile gsize type_id__volatile = 0;                          \
+  if (g_once_init_enter (&type_id__volatile))                           \
+    {                                                                   \
+      static const GTypeFundamentalInfo finfo = {                       \
+        (G_TYPE_FLAG_CLASSED |                                          \
+         G_TYPE_FLAG_INSTANTIATABLE |                                   \
+         G_TYPE_FLAG_DERIVABLE |                                        \
+         G_TYPE_FLAG_DEEP_DERIVABLE),                                   \
+      };                                                                \
+      static const GTypeValueTable value_table = {                      \
+        _cogl_gtype_object_init_value,                                  \
+        _cogl_gtype_object_free_value,                                  \
+        _cogl_gtype_object_copy_value,                                  \
+        _cogl_gtype_object_peek_pointer,                                \
+        "p",                                                            \
+        _cogl_gtype_object_collect_value,                               \
+        "p",                                                            \
+        _cogl_gtype_object_lcopy_value,                                 \
+      };                                                                \
+      const GTypeInfo node_info = {                                     \
+        sizeof (CoglObjectClass),                                       \
+        (GBaseInitFunc) _cogl_gtype_object_class_base_init,             \
+        (GBaseFinalizeFunc) _cogl_gtype_object_class_base_finalize,     \
+        (GClassInitFunc) _cogl_gtype_object_class_init,                 \
+        (GClassFinalizeFunc) NULL,                                      \
+        NULL,                                                           \
+        sizeof (CoglObject),                                            \
+        0,                                                              \
+        (GInstanceInitFunc) _cogl_gtype_object_init,                    \
+        &value_table,                                                   \
+      };                                                                \
+      GType fundamental_type_id =                                       \
+        g_type_register_fundamental (g_type_fundamental_next (),        \
+                                     I_("Cogl" # Name),                 \
+                                     &node_info, &finfo,                \
+                                     G_TYPE_FLAG_ABSTRACT);             \
+      g_once_init_leave (&type_id__volatile,                            \
+                         fundamental_type_id);
 
+#define _COGL_GTYPE_DEFINE_BASE_CLASS_END()                             \
+    }                                                                   \
+    return type_id__volatile;                                           \
+  }
+
+#define COGL_GTYPE_DEFINE_BASE_CLASS(Name,name,interfaces...)      \
+  _COGL_GTYPE_DEFINE_BASE_CLASS_BEGIN(Name,name)                   \
+  {interfaces;}                                                    \
+  _COGL_GTYPE_DEFINE_BASE_CLASS_END()
+
+#define _COGL_GTYPE_DEFINE_INTERFACE_EXTENDED_BEGIN(Name,name)          \
+                                                                        \
+  static void name##_default_init (Name##Interface *klass);             \
+  GType                                                                 \
+  name##_get_gtype (void)                                               \
+  {                                                                     \
+    static volatile gsize type_id__volatile = 0;                        \
+    if (g_once_init_enter (&type_id__volatile))                         \
+      {                                                                 \
+        GType fundamental_type_id =                                     \
+          g_type_register_static_simple (G_TYPE_INTERFACE,              \
+                                         g_intern_static_string (#Name), \
+                                         sizeof (Name##Interface),    \
+                                         (GClassInitFunc)name##_default_init, \
+                                         0,                             \
+                                         (GInstanceInitFunc)NULL,       \
+                                         (GTypeFlags) 0);               \
+        g_type_interface_add_prerequisite (fundamental_type_id,         \
+                                           cogl_object_get_gtype());    \
+        { /* custom code follows */
+
+#define _COGL_GTYPE_DEFINE_INTERFACE_EXTENDED_END()                     \
+  /* following custom code */                                           \
+  }                                                                     \
+    g_once_init_leave (&type_id__volatile,                              \
+                       fundamental_type_id);                            \
+    }                                                                   \
+    return type_id__volatile;                                           \
+    } /* closes name##_get_type() */
+
+
+#define COGL_GTYPE_DEFINE_INTERFACE(Name,name)                          \
+  typedef struct _Cogl##Name##Iface Cogl##Name##Iface;                  \
+  typedef Cogl##Name##Iface  Cogl##Name##Interface;                     \
+  struct _Cogl##Name##Iface                                             \
+  {                                                                     \
+    /*< private >*/                                                     \
+    GTypeInterface g_iface;                                             \
+  };                                                                    \
+  _COGL_GTYPE_DEFINE_INTERFACE_EXTENDED_BEGIN (Cogl##Name, cogl_##name) \
+  _COGL_GTYPE_DEFINE_INTERFACE_EXTENDED_END ()                          \
+  static void                                                           \
+  cogl_##name##_default_init (Cogl##Name##Interface *iface)             \
+  {                                                                     \
+  }
+
+#define _COGL_GTYPE_DEFINE_TYPE_EXTENDED_BEGIN(Name,name,parent,flags)  \
+                                                                        \
+  static void     name##_init              (Name        *self);         \
+  static void     name##_class_init        (Name##Class *klass);        \
+  static gpointer name##_parent_class = NULL;                           \
+  static gint     Name##_private_offset;                                \
+                                                                        \
+  _G_DEFINE_TYPE_EXTENDED_CLASS_INIT(Name, name)                        \
+                                                                        \
+  static inline gpointer                                                \
+  name##_get_instance_private (Name *self)                              \
+    {                                                                   \
+      return (G_STRUCT_MEMBER_P (self, Name ##_private_offset));        \
+    }                                                                   \
+                                                                        \
+  GType                                                                 \
+  name##_get_gtype (void)                                               \
+  {                                                                     \
+    static volatile gsize type_id__volatile = 0;                        \
+    if (g_once_init_enter (&type_id__volatile))                         \
+      {                                                                 \
+        GType fundamental_type_id =                                     \
+          g_type_register_static_simple (parent,                        \
+                                         g_intern_static_string (#Name), \
+                                         sizeof (Name##Class),          \
+                                         (GClassInitFunc) name##_class_intern_init, \
+                                         sizeof (Name),                 \
+                                         (GInstanceInitFunc) name##_init, \
+                                         (GTypeFlags) flags);           \
+        { /* custom code follows */
+
+#define _COGL_GTYPE_DEFINE_TYPE_EXTENDED_END()                          \
+  /* following custom code */                                           \
+  }                                                                     \
+    g_once_init_leave (&type_id__volatile,                              \
+                       fundamental_type_id);                            \
+    }                                                                   \
+    return type_id__volatile;                                           \
+    } /* closes name##_get_type() */
+
+
+#define COGL_GTYPE_DEFINE_CLASS(Name,name,interfaces...)                \
+  typedef struct _Cogl##Name##Class Cogl##Name##Class;                  \
+  struct _Cogl##Name##Class {                                           \
+    CoglObjectClass parent_class;                                       \
+  };                                                                    \
+  _COGL_GTYPE_DEFINE_TYPE_EXTENDED_BEGIN(Cogl##Name,                    \
+                                         cogl_##name,                   \
+                                         cogl_object_get_gtype(),       \
+                                         0)                             \
+  {interfaces;}                                                         \
+  _COGL_GTYPE_DEFINE_TYPE_EXTENDED_END()                                \
+  static void                                                           \
+  cogl_##name##_init (Cogl##Name *instance)                             \
+  {                                                                     \
+  }                                                                     \
+  static void                                                           \
+  cogl_##name##_class_init (Cogl##Name##Class *klass)                   \
+  {                                                                     \
+  }
+
+void _cogl_gtype_object_init_value (GValue *value);
+void _cogl_gtype_object_free_value (GValue *value);
+void _cogl_gtype_object_copy_value (const GValue *src,
+                                    GValue       *dst);
+gpointer _cogl_gtype_object_peek_pointer (const GValue *value);
+gchar *_cogl_gtype_object_collect_value (GValue      *value,
+                                         guint        n_collect_values,
+                                         GTypeCValue *collect_values,
+                                         guint        collect_flags);
+gchar *_cogl_gtype_object_lcopy_value (const GValue *value,
+                                       guint         n_collect_values,
+                                       GTypeCValue  *collect_values,
+                                       guint         collect_flags);
+
+void _cogl_gtype_object_class_base_init (CoglObjectClass *klass);
+void _cogl_gtype_object_class_base_finalize (CoglObjectClass *klass);
+void _cogl_gtype_object_class_init (CoglObjectClass *klass);
+void _cogl_gtype_object_init (CoglObject *object);
+
+void cogl_object_value_set_object (GValue   *value,
+                                   gpointer  object);
+gpointer cogl_object_value_get_object (const GValue *value);
+
+void _cogl_gtype_dummy_iface_init (gpointer iface);
+
+#endif /* __COGL_GTYPE_PRIVATE_H__ */
diff --git a/cogl/cogl-gtype.c b/cogl/cogl-gtype.c
new file mode 100644
index 0000000..314d8e4
--- /dev/null
+++ b/cogl/cogl-gtype.c
@@ -0,0 +1,153 @@
+#include "cogl-gtype-private.h"
+
+#include <gobject/gvaluecollector.h>
+
+void
+_cogl_gtype_object_init_value (GValue *value)
+{
+  value->data[0].v_pointer = NULL;
+}
+
+void
+_cogl_gtype_object_free_value (GValue *value)
+{
+  if (value->data[0].v_pointer != NULL)
+    cogl_object_unref (value->data[0].v_pointer);
+}
+
+void
+_cogl_gtype_object_copy_value (const GValue *src,
+                               GValue       *dst)
+{
+  if (src->data[0].v_pointer != NULL)
+    dst->data[0].v_pointer = cogl_object_ref (src->data[0].v_pointer);
+  else
+    dst->data[0].v_pointer = NULL;
+}
+
+gpointer
+_cogl_gtype_object_peek_pointer (const GValue *value)
+{
+  return value->data[0].v_pointer;
+}
+
+gchar *
+_cogl_gtype_object_collect_value (GValue      *value,
+                                  guint        n_collect_values,
+                                  GTypeCValue *collect_values,
+                                  guint        collect_flags)
+{
+  CoglObject *object;
+
+  object = collect_values[0].v_pointer;
+
+  if (object == NULL)
+    {
+      value->data[0].v_pointer = NULL;
+      return NULL;
+    }
+
+  if (object->klass == NULL)
+    return g_strconcat ("invalid unclassed CoglObject pointer for "
+                        "value type '",
+                        G_VALUE_TYPE_NAME (value),
+                        "'",
+                        NULL);
+
+  value->data[0].v_pointer = cogl_object_ref (object);
+
+  return NULL;
+}
+
+gchar *
+_cogl_gtype_object_lcopy_value (const GValue *value,
+                                guint         n_collect_values,
+                                GTypeCValue  *collect_values,
+                                guint         collect_flags)
+{
+  CoglObject **object_p = collect_values[0].v_pointer;
+
+  if (object_p == NULL)
+    return g_strconcat ("value location for '",
+                        G_VALUE_TYPE_NAME (value),
+                        "' passed as NULL",
+                        NULL);
+
+  if (value->data[0].v_pointer == NULL)
+    *object_p = NULL;
+  else if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
+    *object_p = value->data[0].v_pointer;
+  else
+    *object_p = cogl_object_ref (value->data[0].v_pointer);
+
+  return NULL;
+}
+
+void
+_cogl_gtype_object_class_base_init (CoglObjectClass *klass)
+{
+}
+
+void
+_cogl_gtype_object_class_base_finalize (CoglObjectClass *klass)
+{
+}
+
+void
+_cogl_gtype_object_class_init (CoglObjectClass *klass)
+{
+}
+
+void
+_cogl_gtype_object_init (CoglObject *object)
+{
+}
+
+void
+_cogl_gtype_dummy_iface_init (gpointer iface)
+{
+}
+
+/**
+ * cogl_object_value_set_object:
+ * @value: a #GValue initialized with %COGL_GTYPE_TYPE_OBJECT
+ * @object: (type Cogl.GtypeObject) (allow-none): a #CoglGtypeObject, or %NULL
+ *
+ * Sets the contents of a #GValue initialized with %COGL_GTYPE_TYPE_OBJECT.
+ *
+ */
+void
+cogl_object_value_set_object (GValue   *value,
+                              gpointer  object)
+{
+  CoglObject *old_object;
+
+  old_object = value->data[0].v_pointer;
+
+  if (object != NULL)
+    {
+      /* take over ownership */
+      value->data[0].v_pointer = object;
+    }
+  else
+    value->data[0].v_pointer = NULL;
+
+  if (old_object != NULL)
+    cogl_object_unref (old_object);
+}
+
+/**
+ * cogl_object_value_get_object:
+ * @value: a #GValue initialized with %COGL_GTYPE_TYPE_OBJECT
+ *
+ * Retrieves a pointer to the #CoglGtypeObject contained inside
+ * the passed #GValue.
+ *
+ * Return value: (transfer none) (type Cogl.GtypeObject): a pointer to
+ *   a #CoglGtypeObject, or %NULL
+ */
+gpointer
+cogl_object_value_get_object (const GValue *value)
+{
+  return value->data[0].v_pointer;
+}
diff --git a/cogl/cogl-object-private.h b/cogl/cogl-object-private.h
index 82fc06c..6019595 100644
--- a/cogl/cogl-object-private.h
+++ b/cogl/cogl-object-private.h
@@ -51,6 +51,9 @@ typedef void (*CoglUserDataDestroyInternalCallback) (void *user_data,
 
 typedef struct _CoglObjectClass
 {
+#ifdef COGL_HAS_GTYPE_SUPPORT
+  GTypeClass base_class;
+#endif
   const char *name;
   void *virt_free;
   void *virt_unref;
@@ -74,7 +77,7 @@ typedef struct
  */
 struct _CoglObject
 {
-  CoglObjectClass  *klass;
+  CoglObjectClass  *klass; /* equivalent to GTypeInstance */
 
   CoglUserDataEntry user_data_entry[
     COGL_OBJECT_N_PRE_ALLOCATED_USER_DATA_ENTRIES];
@@ -118,6 +121,14 @@ struct _CoglObject
 
 #endif /* COGL_OBJECT_DEBUG */
 
+#ifdef COGL_HAS_GTYPE_SUPPORT
+#define _COGL_GTYPE_INIT_CLASS(type_name) do {                                   \
+  _cogl_##type_name##_class.base_class.g_type = cogl_##type_name##_get_gtype (); \
+} while (0)
+#else
+#define _COGL_GTYPE_INIT_CLASS(type_name)
+#endif
+
 #define COGL_OBJECT_COMMON_DEFINE_WITH_CODE(TypeName, type_name, code)  \
                                                                         \
 CoglObjectClass _cogl_##type_name##_class;                              \
@@ -142,6 +153,28 @@ _cogl_object_##type_name##_indirect_free (CoglObject *obj)              \
   _cogl_object_##type_name##_dec ();                                    \
 }                                                                       \
                                                                         \
+static void                                                             \
+_cogl_object_##type_name##_class_init (void)                            \
+{                                                                       \
+  _cogl_object_##type_name##_count = 0;                                 \
+                                                                        \
+    if (_cogl_debug_instances == NULL)                                  \
+      _cogl_debug_instances =                                           \
+        g_hash_table_new (g_str_hash, g_str_equal);                     \
+                                                                        \
+    _cogl_##type_name##_class.virt_free =                               \
+      _cogl_object_##type_name##_indirect_free;                         \
+    _cogl_##type_name##_class.virt_unref =                              \
+      _cogl_object_default_unref;                                       \
+    _cogl_##type_name##_class.name = "Cogl"#TypeName;                   \
+                                                                        \
+    g_hash_table_insert (_cogl_debug_instances,                         \
+                         (void *) _cogl_##type_name##_class.name,       \
+                         &_cogl_object_##type_name##_count);            \
+                                                                        \
+    { code; }                                                           \
+}                                                                       \
+                                                                        \
 static Cogl##TypeName *                                                 \
 _cogl_##type_name##_object_new (Cogl##TypeName *new_obj)                \
 {                                                                       \
@@ -154,23 +187,7 @@ _cogl_##type_name##_object_new (Cogl##TypeName *new_obj)                \
   obj->klass = &_cogl_##type_name##_class;                              \
   if (!obj->klass->virt_free)                                           \
     {                                                                   \
-      _cogl_object_##type_name##_count = 0;                             \
-                                                                        \
-      if (_cogl_debug_instances == NULL)                                \
-        _cogl_debug_instances =                                         \
-          g_hash_table_new (g_str_hash, g_str_equal);                   \
-                                                                        \
-      obj->klass->virt_free =                                           \
-        _cogl_object_##type_name##_indirect_free;                       \
-      obj->klass->virt_unref =                                          \
-        _cogl_object_default_unref;                                     \
-      obj->klass->name = "Cogl"#TypeName,                               \
-                                                                        \
-      g_hash_table_insert (_cogl_debug_instances,                       \
-                           (void *) obj->klass->name,                   \
-                           &_cogl_object_##type_name##_count);          \
-                                                                        \
-      { code; }                                                         \
+      _cogl_object_##type_name##_class_init ();                         \
     }                                                                   \
                                                                         \
   _cogl_object_##type_name##_inc ();                                    \
@@ -178,9 +195,29 @@ _cogl_##type_name##_object_new (Cogl##TypeName *new_obj)                \
   return new_obj;                                                       \
 }
 
+#define COGL_OBJECT_DEFINE_WITH_CODE_GTYPE(TypeName, type_name, code)   \
+                                                                        \
+COGL_OBJECT_COMMON_DEFINE_WITH_CODE(TypeName,                           \
+                                    type_name,                          \
+                                    do { code; } while (0);             \
+                                    _COGL_GTYPE_INIT_CLASS (type_name)) \
+                                                                        \
+CoglBool                                                                \
+cogl_is_##type_name (void *object)                                      \
+{                                                                       \
+  CoglObject *obj = object;                                             \
+                                                                        \
+  if (object == NULL)                                                   \
+    return FALSE;                                                       \
+                                                                        \
+  return obj->klass == &_cogl_##type_name##_class;                      \
+}
+
 #define COGL_OBJECT_DEFINE_WITH_CODE(TypeName, type_name, code)         \
                                                                         \
-COGL_OBJECT_COMMON_DEFINE_WITH_CODE(TypeName, type_name, code)          \
+COGL_OBJECT_COMMON_DEFINE_WITH_CODE(TypeName,                           \
+                                    type_name,                          \
+                                    do { code; } while (0);)            \
                                                                         \
 CoglBool                                                                \
 cogl_is_##type_name (void *object)                                      \
@@ -240,7 +277,7 @@ cogl_##type_name##_unref (void *object)                         \
 }
 
 #define COGL_OBJECT_DEFINE(TypeName, type_name)                 \
-  COGL_OBJECT_DEFINE_WITH_CODE (TypeName, type_name, (void) 0)
+  COGL_OBJECT_DEFINE_WITH_CODE_GTYPE (TypeName, type_name, (void) 0)
 
 #define COGL_OBJECT_INTERNAL_DEFINE(TypeName, type_name)         \
   COGL_OBJECT_INTERNAL_DEFINE_WITH_CODE (TypeName, type_name, (void) 0)
diff --git a/cogl/cogl-object.c b/cogl/cogl-object.c
index 9ae29f7..152f88a 100644
--- a/cogl/cogl-object.c
+++ b/cogl/cogl-object.c
@@ -33,6 +33,9 @@
 #include "cogl-util.h"
 #include "cogl-types.h"
 #include "cogl-object-private.h"
+#include "cogl-gtype-private.h"
+
+COGL_GTYPE_DEFINE_BASE_CLASS (Object, object);
 
 void *
 cogl_object_ref (void *object)
diff --git a/cogl/cogl-object.h b/cogl/cogl-object.h
index a557f80..975e789 100644
--- a/cogl/cogl-object.h
+++ b/cogl/cogl-object.h
@@ -34,6 +34,17 @@ typedef struct _CoglObject      CoglObject;
 #define COGL_OBJECT(X)          ((CoglObject *)X)
 
 /**
+ * CoglObject:
+ *
+ * Ref Func: cogl_object_ref
+ * Unref Func: cogl_object_unref
+ * Set Value Func: cogl_object_value_set_object
+ * Get Value Func: cogl_object_value_get_object
+ */
+
+COGL_GTYPE_DECLARE_TYPE (object);
+
+/**
  * cogl_object_ref: (skip)
  * @object: a #CoglObject
  *
diff --git a/cogl/cogl-types.h b/cogl/cogl-types.h
index 57e0e29..012fb38 100644
--- a/cogl/cogl-types.h
+++ b/cogl/cogl-types.h
@@ -149,6 +149,13 @@ typedef void * CoglHandle;
 GType
 cogl_handle_get_type (void) G_GNUC_CONST;
 
+#define COGL_GTYPE_DECLARE_TYPE(name)       \
+  GType cogl_ ## name ## _get_gtype (void)
+
+#else
+
+#define COGL_GTYPE_DECLARE_TYPE(name)
+
 #endif /* COGL_HAS_GTYPE_SUPPORT */
 
 /**


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]