1/* GObject - GLib Type, Object, Parameter and Signal Library
2 * Copyright (C) 2003 Red Hat, Inc.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General
15 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef __TEST_COMMON_H__
19#define __TEST_COMMON_H__
20
21G_BEGIN_DECLS
22
23#define DEFINE_TYPE_FULL(name, prefix, \
24 class_init, base_init, instance_init, \
25 parent_type, interface_decl) \
26GType \
27prefix ## _get_type (void) \
28{ \
29 static GType object_type = 0; \
30 \
31 if (!object_type) \
32 { \
33 static const GTypeInfo object_info = \
34 { \
35 sizeof (name ## Class), \
36 (GBaseInitFunc) base_init, \
37 (GBaseFinalizeFunc) NULL, \
38 (GClassInitFunc) class_init, \
39 (GClassFinalizeFunc) NULL, \
40 NULL, /* class_data */ \
41 sizeof (name), \
42 0, /* n_prelocs */ \
43 (GInstanceInitFunc) instance_init, \
44 (const GTypeValueTable *) NULL, \
45 }; \
46 \
47 object_type = g_type_register_static (parent_type, \
48 # name, \
49 &object_info, 0); \
50 interface_decl \
51 } \
52 \
53 return object_type; \
54}
55
56#define DEFINE_TYPE(name, prefix, \
57 class_init, base_init, instance_init, \
58 parent_type) \
59 DEFINE_TYPE_FULL(name, prefix, class_init, base_init, \
60 instance_init, parent_type, {})
61
62#define DEFINE_IFACE(name, prefix, base_init, dflt_init) \
63GType \
64prefix ## _get_type (void) \
65{ \
66 static GType iface_type = 0; \
67 \
68 if (!iface_type) \
69 { \
70 static const GTypeInfo iface_info = \
71 { \
72 sizeof (name ## Class), \
73 (GBaseInitFunc) base_init, \
74 (GBaseFinalizeFunc) NULL, \
75 (GClassInitFunc) dflt_init, \
76 (GClassFinalizeFunc) NULL, \
77 (gconstpointer) NULL, \
78 (guint16) 0, \
79 (guint16) 0, \
80 (GInstanceInitFunc) NULL, \
81 (const GTypeValueTable*) NULL, \
82 }; \
83 \
84 iface_type = g_type_register_static (G_TYPE_INTERFACE, \
85 # name, \
86 &iface_info, 0); \
87 } \
88 return iface_type; \
89}
90
91#define INTERFACE_FULL(type, init_func, iface_type) \
92{ \
93 static GInterfaceInfo const iface = \
94 { \
95 (GInterfaceInitFunc) init_func, NULL, NULL \
96 }; \
97 \
98 g_type_add_interface_static (type, iface_type, &iface); \
99}
100#define INTERFACE(init_func, iface_type) \
101 INTERFACE_FULL(object_type, init_func, iface_type)
102
103G_END_DECLS
104
105#endif /* __TEST_COMMON_H__ */
106

source code of gtk/subprojects/glib/gobject/tests/testcommon.h