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 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, write to the 16 * Free Software Foundation, Inc., 59 Temple Place, Suite 330, 17 * Boston, MA 02111-1307, USA. 18 */ 19 20 #ifndef __TEST_COMMON_H__ 21 #define __TEST_COMMON_H__ 22 23 G_BEGIN_DECLS 24 25 #define DEFINE_TYPE_FULL(name, prefix, \ 26 class_init, base_init, instance_init, \ 27 parent_type, interface_decl) \ 28 GType \ 29 prefix ## _get_type (void) \ 30 { \ 31 static GType object_type = 0; \ 32 \ 33 if (!object_type) \ 34 { \ 35 static const GTypeInfo object_info = \ 36 { \ 37 sizeof (name ## Class), \ 38 (GBaseInitFunc) base_init, \ 39 (GBaseFinalizeFunc) NULL, \ 40 (GClassInitFunc) class_init, \ 41 (GClassFinalizeFunc) NULL, \ 42 NULL, /* class_data */ \ 43 sizeof (name), \ 44 0, /* n_prelocs */ \ 45 (GInstanceInitFunc) instance_init \ 46 }; \ 47 \ 48 object_type = g_type_register_static (parent_type, \ 49 # name, \ 50 &object_info, 0); \ 51 interface_decl \ 52 } \ 53 \ 54 return object_type; \ 55 } 56 57 #define DEFINE_TYPE(name, prefix, \ 58 class_init, base_init, instance_init, \ 59 parent_type) \ 60 DEFINE_TYPE_FULL(name, prefix, class_init, base_init, \ 61 instance_init, parent_type, {}) 62 63 #define DEFINE_IFACE(name, prefix, base_init, dflt_init) \ 64 GType \ 65 prefix ## _get_type (void) \ 66 { \ 67 static GType iface_type = 0; \ 68 \ 69 if (!iface_type) \ 70 { \ 71 static const GTypeInfo iface_info = \ 72 { \ 73 sizeof (name ## Class), \ 74 (GBaseInitFunc) base_init, \ 75 (GBaseFinalizeFunc) NULL, \ 76 (GClassInitFunc) dflt_init, \ 77 }; \ 78 \ 79 iface_type = g_type_register_static (G_TYPE_INTERFACE, \ 80 # name, \ 81 &iface_info, 0); \ 82 } \ 83 return iface_type; \ 84 } 85 86 #define INTERFACE_FULL(type, init_func, iface_type) \ 87 { \ 88 static GInterfaceInfo const iface = \ 89 { \ 90 (GInterfaceInitFunc) init_func, NULL, NULL \ 91 }; \ 92 \ 93 g_type_add_interface_static (type, iface_type, &iface); \ 94 } 95 #define INTERFACE(init_func, iface_type) \ 96 INTERFACE_FULL(object_type, init_func, iface_type) 97 98 G_END_DECLS 99 100 #endif /* __TEST_COMMON_H__ */ 101