From 2f286446af5cf80eb5c43083f76fce6468e54d1f Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Fri, 11 Jun 2010 13:44:27 +0100 Subject: [PATCH] Add COGL_{OBJECT,HANDLE}_DEFINE_WITH_CODE This macro is similar to COGL_HANDLE_DEFINE_WITH_CODE except that it allows a snippet of code to be inserted into the _get_type() function. This is similar to how G_DEFINE_TYPE_WITH_CODE works. COGL_HANDLE_DEFINE is now just a wrapper around COGL_HANDLE_DEFINE_WITH_CODE. --- cogl/cogl-object-private.h | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/cogl/cogl-object-private.h b/cogl/cogl-object-private.h index d3254a2bf..691ef3846 100644 --- a/cogl/cogl-object-private.h +++ b/cogl/cogl-object-private.h @@ -106,7 +106,7 @@ struct _CoglObject #define _COGL_HANDLE_DEBUG_UNREF _COGL_OBJECT_DEBUG_UNREF #define COGL_HANDLE_DEBUG_FREE COGL_OBJECT_DEBUG_FREE -#define COGL_OBJECT_DEFINE(TypeName, type_name) \ +#define COGL_OBJECT_DEFINE_WITH_CODE(TypeName, type_name, code) \ \ static CoglObjectClass _cogl_##type_name##_class; \ \ @@ -115,7 +115,10 @@ _cogl_object_##type_name##_get_type (void) \ { \ static GQuark type = 0; \ if (!type) \ - type = g_quark_from_static_string ("Cogl"#TypeName); \ + { \ + type = g_quark_from_static_string ("Cogl"#TypeName); \ + { code; } \ + } \ return type; \ } \ \ @@ -191,10 +194,13 @@ cogl_##type_name##_unref (void *object) \ cogl_handle_unref (object); \ } +#define COGL_OBJECT_DEFINE(TypeName, type_name) \ + COGL_OBJECT_DEFINE_WITH_CODE (TypeName, type_name, (void) 0) + /* For temporary compatability */ -#define COGL_HANDLE_DEFINE(TypeName, type_name) \ +#define COGL_HANDLE_DEFINE_WITH_CODE(TypeName, type_name, code) \ \ -COGL_OBJECT_DEFINE (TypeName, type_name) \ +COGL_OBJECT_DEFINE_WITH_CODE (TypeName, type_name, code) \ \ static Cogl##TypeName * \ _cogl_##type_name##_handle_new (CoglHandle handle) \ @@ -202,5 +208,8 @@ _cogl_##type_name##_handle_new (CoglHandle handle) \ return _cogl_##type_name##_object_new (handle); \ } +#define COGL_HANDLE_DEFINE(TypeName, type_name) \ + COGL_HANDLE_DEFINE_WITH_CODE (TypeName, type_name, (void) 0) + #endif /* __COGL_OBJECT_PRIVATE_H */