mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-07-23 10:27:51 +02:00
Add G_DEFINE_INTERFACE
This is a macro similar to G_DEFINE_TYPE but it lets you define interfaces rather than classes. For discussion, see bug #320482
This commit is contained in:
committed by
Alexander Larsson
parent
74a970f754
commit
91d96350a7
@@ -22,36 +22,6 @@
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
|
||||
#define G_DEFINE_INTERFACE(TN, t_n, T_P) G_DEFINE_INTERFACE_WITH_CODE(TN, t_n, T_P, ;)
|
||||
#define G_DEFINE_INTERFACE_WITH_CODE(TN, t_n, T_P, _C_) _G_DEFINE_INTERFACE_EXTENDED_BEGIN(TN, t_n, T_P) {_C_;} _G_DEFINE_INTERFACE_EXTENDED_END()
|
||||
/* _default_init, ##Interface, if(TYPE_PREREQ); */
|
||||
#define _G_DEFINE_INTERFACE_EXTENDED_BEGIN(TypeName, type_name, TYPE_PREREQ) \
|
||||
static void type_name##_default_init (TypeName##Interface *klass); \
|
||||
GType \
|
||||
type_name##_get_type (void) \
|
||||
{ \
|
||||
static volatile gsize g_define_type_id__volatile = 0; \
|
||||
if (g_once_init_enter (&g_define_type_id__volatile)) \
|
||||
{ \
|
||||
GType g_define_type_id = \
|
||||
g_type_register_static_simple (G_TYPE_INTERFACE, \
|
||||
g_intern_static_string (#TypeName), \
|
||||
sizeof (TypeName##Interface), \
|
||||
(GClassInitFunc) type_name##_default_init, \
|
||||
0, \
|
||||
(GInstanceInitFunc) NULL, \
|
||||
(GTypeFlags) 0); \
|
||||
if (TYPE_PREREQ) \
|
||||
g_type_interface_add_prerequisite (g_define_type_id, TYPE_PREREQ); \
|
||||
{ /* custom code follows */
|
||||
#define _G_DEFINE_INTERFACE_EXTENDED_END() \
|
||||
/* following custom code */ \
|
||||
} \
|
||||
g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \
|
||||
} \
|
||||
return g_define_type_id__volatile; \
|
||||
} /* closes type_name##_get_type() */
|
||||
|
||||
static volatile int mtsafe_call_counter = 0; /* multi thread safe call counter */
|
||||
static int unsafe_call_counter = 0; /* single-threaded call counter */
|
||||
|
||||
|
Reference in New Issue
Block a user