2006-12-31 04:53:45 -06:00
|
|
|
/*
|
|
|
|
* mootype-macros.h
|
|
|
|
*
|
2008-01-07 03:34:52 -06:00
|
|
|
* Copyright (C) 2004-2008 by Yevgen Muntyan <muntyan@tamu.edu>
|
2006-12-31 04:53:45 -06:00
|
|
|
*
|
2008-09-05 17:20:50 -05:00
|
|
|
* This file is part of medit. medit is free software; you can
|
|
|
|
* redistribute it and/or modify it under the terms of the
|
|
|
|
* GNU Lesser General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2.1 of the License,
|
|
|
|
* or (at your option) any later version.
|
2006-12-31 04:53:45 -06:00
|
|
|
*
|
2008-09-05 17:20:50 -05:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
2006-12-31 04:53:45 -06:00
|
|
|
*/
|
|
|
|
|
2007-04-12 10:31:28 -05:00
|
|
|
#ifndef MOO_TYPE_MACROS_H
|
|
|
|
#define MOO_TYPE_MACROS_H
|
2006-12-31 04:53:45 -06:00
|
|
|
|
|
|
|
#include <glib-object.h>
|
|
|
|
|
|
|
|
|
2006-12-31 05:35:50 -06:00
|
|
|
#if !GLIB_CHECK_VERSION(2,12,0)
|
2006-12-31 04:53:45 -06:00
|
|
|
#define _MOO_REGISTER_TYPE(TypeName,type_name,TYPE_PARENT,flags) \
|
|
|
|
static const GTypeInfo type_info = { \
|
|
|
|
sizeof (TypeName##Class), \
|
|
|
|
(GBaseInitFunc) NULL, \
|
|
|
|
(GBaseFinalizeFunc) NULL, \
|
|
|
|
(GClassInitFunc) type_name##_class_intern_init, \
|
|
|
|
(GClassFinalizeFunc) NULL, \
|
|
|
|
NULL, /* class_data */ \
|
|
|
|
sizeof (TypeName), \
|
|
|
|
0, /* n_preallocs */ \
|
|
|
|
(GInstanceInitFunc) type_name##_init, \
|
|
|
|
NULL /* value_table */ \
|
|
|
|
}; \
|
|
|
|
\
|
2008-01-01 17:53:12 -06:00
|
|
|
g_define_type_id = \
|
2008-08-23 06:32:37 -05:00
|
|
|
g_type_register_static (TYPE_PARENT, #TypeName, &type_info, (GTypeFlags) flags);
|
2006-12-31 04:53:45 -06:00
|
|
|
#else
|
|
|
|
#define _MOO_REGISTER_TYPE(TypeName,type_name,TYPE_PARENT,flags) \
|
2008-01-01 17:53:12 -06:00
|
|
|
g_define_type_id = \
|
2006-12-31 04:53:45 -06:00
|
|
|
g_type_register_static_simple (TYPE_PARENT, \
|
|
|
|
g_intern_static_string (#TypeName), \
|
|
|
|
sizeof (TypeName##Class), \
|
|
|
|
(GClassInitFunc) type_name##_class_intern_init, \
|
|
|
|
sizeof (TypeName), \
|
|
|
|
(GInstanceInitFunc) type_name##_init, \
|
2008-08-23 06:32:37 -05:00
|
|
|
(GTypeFlags) flags);
|
2006-12-31 04:53:45 -06:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2008-01-01 17:53:12 -06:00
|
|
|
#define MOO_DEFINE_TYPE_STATIC_WITH_CODE(TypeName,type_name,TYPE_PARENT,code) \
|
2006-12-31 04:53:45 -06:00
|
|
|
\
|
|
|
|
static GType type_name##_get_type (void) G_GNUC_CONST; \
|
|
|
|
static void type_name##_init (TypeName *self); \
|
|
|
|
static void type_name##_class_init (TypeName##Class *klass); \
|
|
|
|
static gpointer type_name##_parent_class = NULL; \
|
|
|
|
\
|
|
|
|
static void type_name##_class_intern_init (gpointer klass) \
|
|
|
|
{ \
|
2006-12-31 05:35:50 -06:00
|
|
|
type_name##_parent_class = g_type_class_peek_parent (klass); \
|
|
|
|
type_name##_class_init ((TypeName##Class*) klass); \
|
2006-12-31 04:53:45 -06:00
|
|
|
} \
|
|
|
|
\
|
|
|
|
static GType \
|
|
|
|
type_name##_get_type (void) \
|
|
|
|
{ \
|
2008-01-01 17:53:12 -06:00
|
|
|
static GType g_define_type_id; \
|
2006-12-31 04:53:45 -06:00
|
|
|
\
|
2008-01-01 17:53:12 -06:00
|
|
|
if (G_UNLIKELY (!g_define_type_id)) \
|
2006-12-31 04:53:45 -06:00
|
|
|
{ \
|
|
|
|
_MOO_REGISTER_TYPE(TypeName,type_name,TYPE_PARENT,0) \
|
2008-01-01 17:53:12 -06:00
|
|
|
code \
|
2006-12-31 04:53:45 -06:00
|
|
|
} \
|
|
|
|
\
|
2008-01-01 17:53:12 -06:00
|
|
|
return g_define_type_id; \
|
2006-12-31 04:53:45 -06:00
|
|
|
} /* closes type_name##_get_type() */
|
|
|
|
|
2008-01-01 17:53:12 -06:00
|
|
|
#define MOO_DEFINE_TYPE_STATIC(TypeName,type_name,TYPE_PARENT) \
|
|
|
|
MOO_DEFINE_TYPE_STATIC_WITH_CODE (TypeName, type_name, TYPE_PARENT, {})
|
|
|
|
|
2006-12-31 04:53:45 -06:00
|
|
|
|
2007-04-12 10:31:28 -05:00
|
|
|
#endif /* MOO_TYPE_MACROS_H */
|